Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2010-2011. Axon Framework
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.axonframework.util;
 
 
 import static java.security.AccessController.doPrivileged;

Represents a method recognized as a handler by the handler inspector (see AbstractHandlerInspector).

Author(s):
Allard Buijze
Since:
1.0
 
 public class Handler {
 
     private final Method method;
     private final Class<?> parameterType;
     private final boolean optionalParameter;
     private final Class<?> declaringClass;

    
Create a handler instance for the given method. A method is regarded a handler method if it has either 1 or 2 parameters, of which the first parameter is primary parameter.

Parameters:
method the method found to be a handler
 
     public Handler(Method method) {
         this. = method;
         Class<?>[] parameterTypes = method.getParameterTypes();
         this. = parameterTypes[0];
         this. = parameterTypes.length > 1;
         this. = method.getDeclaringClass();
         if (!method.isAccessible()) {
             doPrivileged(new MemberAccessibilityCallback(method));
         }
     }

    
Returns the method found to be a handler.

Returns:
the method instance
 
     public Method getMethod() {
         return ;
     }

    
Returns the main parameter of the handler.

Returns:
the main parameter of the handler
 
     public Class<?> getParameterType() {
         return ;
     }

    
Returns the class on which the handler method is declared.

Returns:
the class on which the handler method is declared
 
     public Class<?> getDeclaringClass() {
         return ;
     }

    
Indicates whether or not this handler has an optional second parameter.

Returns:
true if the handler has a second parameter, false otherwise.
 
     public boolean hasOptionalParameter() {
         return ;
     }

    
Invokes the handler method on given target using given parameter and -when available on the handler- the given secondHandlerParameter. If the handler only specifies a single parameter, the secondHandlerParameter is ignored.

Parameters:
target The instance to invoke the handler on
parameter The first parameter of the handler method
secondHandlerParameter The (optional) second parameter of the handler method
Returns:
The return value of the handler invocation
Throws:
java.lang.IllegalAccessException If the handler method could not be accessed
java.lang.reflect.InvocationTargetException If the target handler threw an exception
    public Object invoke(Object targetObject parameterObject secondHandlerParameter)
            throws IllegalAccessExceptionInvocationTargetException {
        Object retVal;
        if (hasOptionalParameter()) {
            retVal = getMethod().invoke(targetparametersecondHandlerParameter);
        } else {
            retVal = getMethod().invoke(targetparameter);
        }
        return retVal;
    }
New to GrepCode? Check out our FAQ X