Example usage for java.lang.reflect Method getDeclaringClass

List of usage examples for java.lang.reflect Method getDeclaringClass

Introduction

In this page you can find the example usage for java.lang.reflect Method getDeclaringClass.

Prototype

@Override
public Class<?> getDeclaringClass() 

Source Link

Document

Returns the Class object representing the class or interface that declares the method represented by this object.

Usage

From source file:com.icfcc.cache.interceptor.AbstractFallbackCacheOperationSource.java

private Collection<CacheOperation> computeCacheOperations(Method method, Class<?> targetClass) {
    // Don't allow no-public methods as required.
    if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
        return null;
    }/*from  www .j a v  a 2 s.c om*/

    // The method may be on an interface, but we need attributes from the target class.
    // If the target class is null, the method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
    // If we are dealing with method with generic parameters, find the original method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    // First try is the method in the target class.
    Collection<CacheOperation> opDef = findCacheOperations(specificMethod);
    if (opDef != null) {
        return opDef;
    }

    // Second try is the caching operation on the target class.
    opDef = findCacheOperations(specificMethod.getDeclaringClass());
    if (opDef != null) {
        return opDef;
    }

    if (specificMethod != method) {
        // Fall back is to look at the original method.
        opDef = findCacheOperations(method);
        if (opDef != null) {
            return opDef;
        }
        // Last fall back is the class of the original method.
        return findCacheOperations(method.getDeclaringClass());
    }
    return null;
}

From source file:org.ff4j.aop.FeatureAdvisor.java

private boolean shouldCallAlterClazzMethod(final MethodInvocation pMInvoc, Class<?> alterClass, Logger logger) {
    boolean callAlterBeanMethod = false;
    Method method = pMInvoc.getMethod();
    Class<?> currentClass = pMInvoc.getThis().getClass();
    if (alterClass != null && (alterClass != NullType.class)) {
        callAlterBeanMethod = !currentClass.equals(alterClass);
        if (!callAlterBeanMethod) {
            logger.debug("FeatureFlipping on method:{} class:{} already on the alterClazz {}", method.getName(),
                    method.getDeclaringClass().getName(), alterClass);
        }/* ww  w  . java  2  s  .  c om*/
    }
    return callAlterBeanMethod;
}

From source file:com.sinosoft.one.data.jade.statement.JdbcStatement.java

public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters,
        Querier querier) {//ww  w . j ava 2  s .  c o m
    this.metaData = statementMetaData;
    this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters;
    this.querier = querier;
    this.sqlType = sqlType;
    if (sqlType == SQLType.WRITE) {
        Method method = statementMetaData.getMethod();
        Class<?>[] types = method.getParameterTypes();
        Class<?> returnType = method.getReturnType();
        if (returnType.isPrimitive()) {
            returnType = ClassUtils.primitiveToWrapper(returnType);
        }
        if (types.length > 0 && List.class.isAssignableFrom(types[0])) {
            this.batchUpdate = true;
            if (returnType != void.class && returnType != int[].class && returnType != Integer[].class
                    && returnType != Integer.class) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        } else {
            this.batchUpdate = false;
            if (returnType != void.class && returnType != Boolean.class
                    && !Number.class.isAssignableFrom(returnType)) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        }
    } else {
        this.batchUpdate = false;
    }
}

From source file:net.paoding.rose.jade.statement.JdbcStatement.java

public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters,
        Querier querier) {//from  www.  ja v a 2 s  . c  o  m
    this.metaData = statementMetaData;
    this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters;
    this.querier = querier;
    this.sqlType = sqlType;
    if (sqlType == SQLType.WRITE) {
        Method method = statementMetaData.getMethod();
        Class<?>[] types = method.getParameterTypes();
        Class<?> returnType = method.getReturnType();
        if (returnType.isPrimitive()) {
            returnType = ClassUtils.primitiveToWrapper(returnType);
        }
        if (types.length > 0 && List.class.isAssignableFrom(types[0])) {
            this.batchUpdate = true;
            if (returnType != void.class && returnType != int[].class && returnType != Integer[].class
                    && returnType != Integer.class) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        } else {
            this.batchUpdate = false;
            if (Number.class.isAssignableFrom(returnType)) {
                throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName()
                        + "#" + method.getName() + "-->" + returnType);
            }
        }
    } else {
        this.batchUpdate = false;
    }
}

From source file:hudson.model.Descriptor.java

/**
 * Creates a configured instance from the submitted form.
 *
 * <p>//from   ww  w. j  a va 2 s.c o  m
 * Hudson only invokes this method when the user wants an instance of <tt>T</tt>.
 * So there's no need to check that in the implementation.
 *
 * <p>
 * Starting 1.206, the default implementation of this method does the following:
 * <pre>
 * req.bindJSON(clazz,formData);
 * </pre>
 * <p>
 * ... which performs the databinding on the constructor of {@link #clazz}.
 *
 * @param req
 *      Always non-null. This object includes represents the entire submisison.
 * @param formData
 *      The JSON object that captures the configuration data for this {@link Descriptor}.
 *      See http://hudson.gotdns.com/wiki/display/HUDSON/Structured+Form+Submission
 *
 * @throws FormException
 *      Signals a problem in the submitted form.
 * @since 1.145
 */
public T newInstance(StaplerRequest req, JSONObject formData) throws FormException {
    try {
        Method m = getClass().getMethod("newInstance", StaplerRequest.class);

        if (!Modifier.isAbstract(m.getDeclaringClass().getModifiers())) {
            // this class overrides newInstance(StaplerRequest).
            // maintain the backward compatible behavior
            return newInstance(req);
        } else {
            // new behavior as of 1.206
            return req.bindJSON(clazz, formData);
        }
    } catch (NoSuchMethodException e) {
        throw new AssertionError(e); // impossible
    }
}

From source file:org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.java

private boolean isValidMethodCall(Method method) {
    Class clazz = method.getDeclaringClass();
    if (clazz.isAssignableFrom(seiClazz)
            || clazz.isAssignableFrom(org.apache.axis2.jaxws.spi.BindingProvider.class)
            || clazz.isAssignableFrom(javax.xml.ws.BindingProvider.class)) {
        return true;
    }/*  ww  w  .j  a  v  a 2  s .c  om*/
    return false;
}

From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java

@Test
public void testProcessAnnotations_Fallback() throws Exception {
    Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTestFallback", String.class, String.class,
            Integer.class);

    assumeTrue("does not have java 8 parameter names", hasJava8ParameterNames(method));

    MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method);

    assertEquals("/advanced/testfallback/{id}", data.template().url());
    assertEquals("PUT", data.template().method());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, data.template().headers().get("Accept").iterator().next());

    assertEquals("Authorization", data.indexToName().get(0).iterator().next());
    assertEquals("id", data.indexToName().get(1).iterator().next());
    assertEquals("amount", data.indexToName().get(2).iterator().next());

    assertEquals("{Authorization}", data.template().headers().get("Authorization").iterator().next());
    assertEquals("{amount}", data.template().queries().get("amount").iterator().next());
}

From source file:org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.java

private boolean isBindingProviderInvoked(Method method) {
    Class methodsClass = method.getDeclaringClass();
    return (seiClazz == methodsClass) ? false : true;
}

From source file:ipc.WritableRpcEngine.java

/** Expert: Make multiple, parallel calls to a set of servers. */
public Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Configuration conf)
        throws IOException, InterruptedException {

    Invocation[] invocations = new Invocation[params.length];
    for (int i = 0; i < params.length; i++)
        invocations[i] = new Invocation(method, params[i]);
    Client client = CLIENTS.getClient(conf);
    try {//from  w w  w.ja va  2 s.c  om
        Writable[] wrappedValues = client.call(invocations, addrs, method.getDeclaringClass());

        if (method.getReturnType() == Void.TYPE) {
            return null;
        }

        Object[] values = (Object[]) Array.newInstance(method.getReturnType(), wrappedValues.length);
        for (int i = 0; i < values.length; i++)
            if (wrappedValues[i] != null)
                values[i] = ((ObjectWritable) wrappedValues[i]).get();

        return values;
    } finally {
        CLIENTS.stopClient(client);
    }
}

From source file:com.espertech.esper.epl.expression.ExprNodeUtility.java

public static ExprNodeUtilMethodDesc resolveMethodAllowWildcardAndStream(String className, Class optionalClass,
        String methodName, List<ExprNode> parameters, MethodResolutionService methodResolutionService,
        EventAdapterService eventAdapterService, String statementId, boolean allowWildcard,
        final EventType wildcardType, ExprNodeUtilResolveExceptionHandler exceptionHandler, String functionName)
        throws ExprValidationException {
    Class[] paramTypes = new Class[parameters.size()];
    ExprEvaluator[] childEvals = new ExprEvaluator[parameters.size()];
    int count = 0;
    boolean[] allowEventBeanType = new boolean[parameters.size()];
    boolean[] allowEventBeanCollType = new boolean[parameters.size()];
    ExprEvaluator[] childEvalsEventBeanReturnTypes = new ExprEvaluator[parameters.size()];
    boolean allConstants = true;
    for (ExprNode childNode : parameters) {
        if (childNode instanceof ExprLambdaGoesNode) {
            throw new ExprValidationException(
                    "Unexpected lambda-expression encountered as parameter to UDF or static method '"
                            + methodName + "'");
        }// ww  w. j av a  2 s .c o  m
        if (childNode instanceof ExprNumberSetWildcardMarker) {
            if (wildcardType == null || !allowWildcard) {
                throw new ExprValidationException("Failed to resolve wildcard parameter to a given event type");
            }
            childEvals[count] = new ExprNodeUtilExprEvalStreamNumUnd(0, wildcardType.getUnderlyingType());
            childEvalsEventBeanReturnTypes[count] = new ExprNodeUtilExprEvalStreamNumEvent(0);
            paramTypes[count] = wildcardType.getUnderlyingType();
            allowEventBeanType[count] = true;
            allConstants = false;
            count++;
            continue;
        }
        if (childNode instanceof ExprStreamUnderlyingNode) {
            ExprStreamUnderlyingNode und = (ExprStreamUnderlyingNode) childNode;
            childEvals[count] = childNode.getExprEvaluator();
            childEvalsEventBeanReturnTypes[count] = new ExprNodeUtilExprEvalStreamNumEvent(und.getStreamId());
            paramTypes[count] = childEvals[count].getType();
            allowEventBeanType[count] = true;
            allConstants = false;
            count++;
            continue;
        }
        if (childNode instanceof ExprEvaluatorEnumeration) {
            ExprEvaluatorEnumeration enumeration = (ExprEvaluatorEnumeration) childNode;
            EventType eventType = enumeration.getEventTypeSingle(eventAdapterService, statementId);
            childEvals[count] = childNode.getExprEvaluator();
            paramTypes[count] = childEvals[count].getType();
            allConstants = false;
            if (eventType != null) {
                childEvalsEventBeanReturnTypes[count] = new ExprNodeUtilExprEvalStreamNumEnumSingle(
                        enumeration);
                allowEventBeanType[count] = true;
                count++;
                continue;
            }
            EventType eventTypeColl = enumeration.getEventTypeCollection(eventAdapterService);
            if (eventTypeColl != null) {
                childEvalsEventBeanReturnTypes[count] = new ExprNodeUtilExprEvalStreamNumEnumColl(enumeration);
                allowEventBeanCollType[count] = true;
                count++;
                continue;
            }
        }
        ExprEvaluator eval = childNode.getExprEvaluator();
        childEvals[count] = eval;
        paramTypes[count] = eval.getType();
        count++;
        if (!(childNode.isConstantResult())) {
            allConstants = false;
        }
    }

    // Try to resolve the method
    final FastMethod staticMethod;
    Method method;
    try {
        if (optionalClass != null) {
            method = methodResolutionService.resolveMethod(optionalClass, methodName, paramTypes,
                    allowEventBeanType, allowEventBeanCollType);
        } else {
            method = methodResolutionService.resolveMethod(className, methodName, paramTypes,
                    allowEventBeanType, allowEventBeanCollType);
        }
        FastClass declaringClass = FastClass.create(Thread.currentThread().getContextClassLoader(),
                method.getDeclaringClass());
        staticMethod = declaringClass.getMethod(method);
    } catch (Exception e) {
        throw exceptionHandler.handle(e);
    }

    // rewrite those evaluator that should return the event itself
    if (CollectionUtil.isAnySet(allowEventBeanType)) {
        for (int i = 0; i < parameters.size(); i++) {
            if (allowEventBeanType[i] && method.getParameterTypes()[i] == EventBean.class) {
                childEvals[i] = childEvalsEventBeanReturnTypes[i];
            }
        }
    }

    // rewrite those evaluators that should return the event collection
    if (CollectionUtil.isAnySet(allowEventBeanCollType)) {
        for (int i = 0; i < parameters.size(); i++) {
            if (allowEventBeanCollType[i] && method.getParameterTypes()[i] == Collection.class) {
                childEvals[i] = childEvalsEventBeanReturnTypes[i];
            }
        }
    }

    // add an evaluator if the method expects a context object
    if (method.getParameterTypes().length > 0 && method.getParameterTypes()[method.getParameterTypes().length
            - 1] == EPLMethodInvocationContext.class) {
        childEvals = (ExprEvaluator[]) CollectionUtil.arrayExpandAddSingle(childEvals,
                new ExprNodeUtilExprEvalMethodContext(functionName));
    }

    return new ExprNodeUtilMethodDesc(allConstants, paramTypes, childEvals, method, staticMethod);
}