io.dyn.core.handler.HandlerMethod.java Source code

Java tutorial

Introduction

Here is the source code for io.dyn.core.handler.HandlerMethod.java

Source

/*
 * Copyright (c) 2011-2012 by the original author or authors.
 *
 * 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 io.dyn.core.handler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.springframework.core.BridgeMethodResolver;
import org.springframework.util.ReflectionUtils;

/**
 * @author Jon Brisbin <jon@jbrisbin.com>
 */
public class HandlerMethod {

    private Method method;
    private Method bridgedMethod;
    private HandlerMethodArgument[] arguments;
    private Guard guard;
    private InvocationHandler invocationHandler;

    public HandlerMethod(Method method, HandlerMethodArgument[] arguments, Guard guard) {
        this.method = method;
        ReflectionUtils.makeAccessible(method);
        this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
        ReflectionUtils.makeAccessible(bridgedMethod);
        this.arguments = arguments;
        this.guard = guard;
        this.invocationHandler = (Proxy.isProxyClass(method.getDeclaringClass())
                ? Proxy.getInvocationHandler(method.getDeclaringClass())
                : null);
    }

    public Method method() {
        return method;
    }

    public Method bridgedMethod() {
        return (bridgedMethod == method ? method : bridgedMethod);
    }

    public Method methodToInvoke() {
        return (bridgedMethod == method ? method : bridgedMethod);
    }

    public InvocationHandler invocationHandler() {
        return invocationHandler;
    }

    public Guard guard() {
        return guard;
    }

    public HandlerMethodArgument[] arguments() {
        return arguments;
    }

}