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.nineteendrops.tracdrops.api.ticket.ticket.TicketTestBase.java

@DataProvider(name = "updateTicketProvider")
public Iterator<Object[]> updateTicketProvider(Method method) {

    return new LinesIterator(method.getDeclaringClass(), method, "ticketUpdate.txt", new SimpleLineConverter());
}

From source file:org.apache.hama.ipc.AsyncRPC.java

/**
 * Expert: Make multiple, parallel calls to a set of servers.
 * /*ww  w  .  j  a v  a  2  s .  c  o m*/
 * @param method
 * @param params
 * @param addrs
 * @param ticket
 * @param conf
 * @return response object array
 * @throws IOException
 * @throws InterruptedException
 */
public static Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs,
        UserGroupInformation ticket, 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]);
    AsyncClient client = CLIENTS.getClient(conf);
    try {
        Writable[] wrappedValues = client.call(invocations, addrs, method.getDeclaringClass(), ticket, conf);

        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:io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterAspect.java

@Around(value = "matchAnnotatedClassOrMethod(limitedService)", argNames = "proceedingJoinPoint, limitedService")
public Object rateLimiterAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, RateLimiter limitedService)
        throws Throwable {
    RateLimiter targetService = limitedService;
    Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
    String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
    if (targetService == null) {
        targetService = getRateLimiterAnnotation(proceedingJoinPoint);
    }/* w  w  w.j av  a  2 s  .c o  m*/
    String name = targetService.name();
    io.github.resilience4j.ratelimiter.RateLimiter rateLimiter = getOrCreateRateLimiter(methodName, name);
    return handleJoinPoint(proceedingJoinPoint, rateLimiter, methodName);
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.aop.ScriptableBaseAdapterInterceptor.java

/**
 * {@inheritDoc}//from w w  w .  ja  va2 s. c  o  m
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
    final Object result;
    final Method method = invocation.getMethod();
    final Class<?> declaringClass = method.getDeclaringClass();
    if (Scriptable.class.equals(declaringClass) && invocation instanceof ProxyMethodInvocation) {
        final ProxyMethodInvocation pInvocation = (ProxyMethodInvocation) invocation;
        final Object proxy = pInvocation.getProxy();

        final String methodName = method.getName();
        final Object[] arguments = invocation.getArguments();

        // String-switch not supported in Java < 8
        switch (ScriptableMethodName.methodLiteralOf(methodName)) {
        case GETPARENTSCOPE:
            result = this.parentScope.get(proxy);
            break;
        case SETPARENTSCOPE:
            if (arguments.length > 0 && arguments[0] instanceof Scriptable) {
                this.parentScope.put(proxy, (Scriptable) arguments[0]);
            }
            // void return type
            result = null;
            break;
        case GETPROTOTYPE:
            result = this.prototype.get(proxy);
            break;
        case SETPROTOTYPE:
            if (arguments.length > 0 && arguments[0] instanceof Scriptable) {
                this.prototype.put(proxy, (Scriptable) arguments[0]);
            }
            // void return type
            result = null;
            break;
        case HASINSTANCE:
            // proxies can never be used for hasInstance checks
            result = Boolean.FALSE;
            break;
        case GETDEFAULVALUE:
            if (arguments.length > 0) {
                if (arguments[0] == null || ScriptRuntime.StringClass == arguments[0]) {
                    result = proxy.toString();
                } else {
                    result = null;
                }
            } else {
                result = null;
            }
            break;
        default:
            // simply delegate further
            result = invocation.proceed();
            break;
        }
    } else {
        result = invocation.proceed();
    }

    return result;
}

From source file:net.paslavsky.springrest.SpringRestClientMethodInterceptor.java

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Method method = invocation.getMethod();
    RestMethodMetadata metadata = annotationPreprocessor.parse(method.getDeclaringClass(), method);

    Object[] arguments = invocation.getArguments();
    URI uri = new UriBuilder(baseUrl, arguments).build(metadata);

    Object body = getRequestBody(metadata, arguments);
    HttpHeaders headers = helper.getHttpHeaders(metadata.getRequestHeaderParameters(), arguments);

    if (authenticationManager != null) {
        headers.putAll(authenticationManager.getAuthenticationHeaders());
    }//from  w  w  w  . j  a v  a 2 s.c o  m

    HttpEntity<?> httpEntity = new HttpEntity<Object>(body, headers);

    ResponseEntity<?> responseEntity = restTemplate.exchange(uri, metadata.getHttpMethod(), httpEntity,
            metadata.getResponseClass());

    if (metadata.getMethodReturnType() == ResponseEntity.class) {
        return responseEntity;
    } else {
        return responseEntity.getBody();
    }
}

From source file:org.apache.hadoop.hive.ql.exec.MapredContext.java

private boolean needClose(Closeable func) {
    try {/*from   ww  w .j  a v  a  2 s .c om*/
        Method closeMethod = func.getClass().getMethod("close");
        return closeMethod.getDeclaringClass() != GenericUDF.class
                && closeMethod.getDeclaringClass() != GenericUDAFEvaluator.class;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.apache.pig.JVMReuseImpl.java

private String getMethodNames(List<Method> staticCleanupMethods) {
    StringBuilder sb = new StringBuilder();
    for (Method m : staticCleanupMethods) {
        if (m == null) {
            sb.append("null,");
        } else {//from w w w .  ja  v  a 2 s.c o m
            sb.append(m.getDeclaringClass() == null ? "anonymous" : m.getDeclaringClass().getName());
            sb.append(".").append(m.getName()).append(",");
        }
    }
    if (sb.length() > 1) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean.java

/**
 * {@inheritDoc}//  w  ww.  ja v a 2 s . c  o  m
 */
public Object invoke(MethodInvocation invocation) throws Throwable {

    // handle toString()
    Method method = invocation.getMethod();
    if (method.getDeclaringClass() == Object.class && method.getName().equals("toString")) {
        return proxyObject.getClass().getName() + "@" + System.identityHashCode(proxyObject);
    }

    // get return type
    Type retType = (invocation.getMethod().getGenericReturnType() != null)
            ? invocation.getMethod().getGenericReturnType()
            : invocation.getMethod().getReturnType();

    // get arguments
    Object arguments = ReflectionUtil.parseArguments(invocation.getMethod(), invocation.getArguments(),
            useNamedParams);

    // invoke it
    return jsonRpcHttpClient.invoke(invocation.getMethod().getName(), arguments, retType, extraHttpHeaders);
}

From source file:de.contentreich.instrumentation.SpringBeansHelper.java

public List<String[]> getPublicMethodSignatures(String className) {
    logger.debug("Get public method signatures for class " + className);
    ArrayList<String[]> methodSignatures = new ArrayList<String[]>();
    try {//from   w  w  w .  j a v a  2  s.  com
        Class clazz = Class.forName(className);
        List<Method> methods = (List<Method>) Arrays.asList(clazz.getMethods());
        // Filtering - a pita in java
        for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) {
            Method method = iterator.next();
            if (!method.getDeclaringClass().getName().startsWith("java")
                    && Modifier.isPublic(method.getModifiers())) {
                methodSignatures.add(new String[] { method.toString(), method.getDeclaringClass().getName() });
            }
        }
        Collections.sort(methodSignatures, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                String s1 = ((String[]) o1)[0];
                String s2 = ((String[]) o2)[0];
                return s1.compareTo(s2);
            }

        });
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }
    return methodSignatures;
}

From source file:io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerAspect.java

@Around(value = "matchAnnotatedClassOrMethod(backendMonitored)", argNames = "proceedingJoinPoint, backendMonitored")
public Object circuitBreakerAroundAdvice(ProceedingJoinPoint proceedingJoinPoint,
        CircuitBreaker backendMonitored) throws Throwable {
    Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
    String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
    if (backendMonitored == null) {
        backendMonitored = getBackendMonitoredAnnotation(proceedingJoinPoint);
    }/* ww  w . j a v a2 s.c o  m*/
    String backend = backendMonitored.backend();
    io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = getOrCreateCircuitBreaker(methodName,
            backend);
    return handleJoinPoint(proceedingJoinPoint, circuitBreaker, methodName);
}