Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.remoting.transporter;
 
 
Simple handler that uses reflection to make calls on target POJO (as supplied in the constructor) when receive invocation requests.

Author(s):
Tom Elrod
 
 public class TransporterHandler implements ServerInvocationHandler
 {
    private Object targetPOJO = null;
 
    public TransporterHandler(Object target)
    {
       this. = target;
    }

   
Takes the invocation request, which should have a internal parameter of NameBasedInvocation, and convert that to a method call on the target POJO (using reflection). Then return the Object returned from the method call on the target POJO.

Parameters:
invocation
Returns:
Throws:
java.lang.Throwable
 
    public Object invoke(InvocationRequest invocationthrows Throwable
    {
       Object request = invocation.getParameter();
 
       // Am expecting a NameBasedInvocation as the parameter
       NameBasedInvocation nbInvocation = (NameBasedInvocationrequest;
 
       final String methodName = nbInvocation.getMethodName();
       Object[] params = nbInvocation.getParameters();
       String[] sig = nbInvocation.getSignature();
       final Class[] classSig = new Class[sig.length];
       for(int x = 0; x < sig.lengthx++)
       {
          Class signature = getPrimitiveType(sig[x]);
          if(signature != null)
          {
             classSig[x] = signature;
          }
          else
          {
             classSig[x] = Class.forName(sig[x]);
          }
       }
 
       // use reflection to make the call
       Method method = getMethod(.getClass(), methodNameclassSig);      
       Object responseObject = method.invoke(params);
 
       return responseObject;
    }
 
    private Class getPrimitiveType(String name)
    {
       if (name.equals("byte")) return .;
       if (name.equals("short")) return .;
       if (name.equals("int")) return .;
       if (name.equals("long")) return .;
       if (name.equals("char")) return .;
       if (name.equals("float")) return .;
      if (name.equals("double")) return .;
      if (name.equals("boolean")) return .;
      if (name.equals("void")) return .;
      return null;
   }


   
set the mbean server that the handler can reference

Parameters:
server
   public void setMBeanServer(MBeanServer server)
   {
      //NOOP
   }

   
set the invoker that owns this handler

Parameters:
invoker
   public void setInvoker(ServerInvoker invoker)
   {
      //NOOP
   }

   
Adds a callback handler that will listen for callbacks from the server invoker handler.

Parameters:
callbackHandler
   public void addListener(InvokerCallbackHandler callbackHandler)
   {
      //NOOP
   }

   
Removes the callback handler that was listening for callbacks from the server invoker handler.

Parameters:
callbackHandler
   public void removeListener(InvokerCallbackHandler callbackHandler)
   {
      //NOOP
   }
   static private Method getMethod(final Class cfinal String namefinal Class[] parameterTypes)
   {
      if (SecurityUtility.skipAccessControl())
      {
         return c.getMethod(nameparameterTypes);
      }
      try
      {
         return (Method) AccessController.doPrivilegednew PrivilegedExceptionAction()
         {
            public Object run() throws NoSuchMethodException
            {
               return c.getMethod(nameparameterTypes);
            }
         });
      }
      catch (PrivilegedActionException e)
      {
         throw (NoSuchMethodExceptione.getCause();
      }
   }
New to GrepCode? Check out our FAQ X