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.googlecode.ehcache.annotations.key.SimpleReflectionHelper.java

public boolean implementsEquals(Object element) {
    final MutableBoolean found = new MutableBoolean();

    ReflectionUtils.doWithMethods(element.getClass(), new MethodCallback() {
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            if (found.value || method.getDeclaringClass() == Object.class) {
                return;
            }//from  w ww  .  j a  va  2s .com

            if (ReflectionUtils.isEqualsMethod(method)) {
                found.value = true;
            }
        }
    });

    return found.value;
}

From source file:com.googlecode.ehcache.annotations.key.SimpleReflectionHelper.java

public boolean implementsHashCode(Object element) {
    final MutableBoolean found = new MutableBoolean();

    ReflectionUtils.doWithMethods(element.getClass(), new MethodCallback() {
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            if (found.value || method.getDeclaringClass() == Object.class) {
                return;
            }// w ww . ja  v  a2s  . com

            if (ReflectionUtils.isHashCodeMethod(method)) {
                found.value = true;
            }
        }
    });

    return found.value;
}

From source file:com.googlecode.ehcache.annotations.key.SimpleReflectionHelper.java

public boolean implementsToString(Object element) {
    final MutableBoolean found = new MutableBoolean();

    ReflectionUtils.doWithMethods(element.getClass(), new MethodCallback() {
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            if (found.value || method.getDeclaringClass() == Object.class) {
                return;
            }//  ww w. j av a  2  s  .  com

            if (ReflectionUtils.isToStringMethod(method)) {
                found.value = true;
            }
        }
    });

    return found.value;
}

From source file:org.jboss.seam.spring.utils.AnnotationInvocationHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    // delegate methods to
    if (method.getDeclaringClass().equals(AnnotationInvocationHandler.class)
            || method.getDeclaringClass().equals(Object.class)
            || method.getDeclaringClass().equals(Annotation.class)) {
        return method.invoke(this, args);
    }//from   w  w  w  . j a va  2s.co  m
    if (registeredValues != null && registeredValues.containsKey(method.getName())) {
        if (conversionService != null) {
            return conversionService.convert(registeredValues.get(method.getName()), method.getReturnType());
        } else {
            return registeredValues.get(method.getName());
        }
    } else {
        return method.getDefaultValue();
    }
}

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

/**
 * {@inheritDoc}/*from   w w  w  .j ava  2 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();

    final Object[] arguments = invocation.getArguments();
    if (Map.class.isAssignableFrom(declaringClass) && invocation instanceof ReflectiveMethodInvocation
            && arguments.length == 1) {
        // TODO Check if we should hide all potential methods of Map-instances by claiming the map contains the name as key and
        // returning defaultNoSuchPropertyValue as the value
        switch (MapMethodName.methodLiteralOf(method.getName())) {
        case GET: {
            // handling get("size") / get("length") if backing map does not contain explicit value
            if (this.claimSizeProperty && "size".equals(arguments[0])
                    && (!(invocation.getThis() instanceof Map<?, ?>)
                            || !((Map<?, ?>) invocation.getThis()).containsKey("size"))) {
                result = this.defaultNoSuchPropertyValue;
            } else if ("length".equals(arguments[0]) && (!(invocation.getThis() instanceof Map<?, ?>)
                    || !((Map<?, ?>) invocation.getThis()).containsKey("length"))) {
                result = Integer
                        .valueOf(((Map<?, ?>) ((ReflectiveMethodInvocation) invocation).getProxy()).size());
            } else {
                result = invocation.proceed();
            }
        }
            break;
        case CONTAINSKEY: {
            // need to explicitly state that we contain both "size" and "length", otherwise script engine may not retrieve value
            // in case of "size", script engine may fall back on method handle to Map.size
            if ((this.claimSizeProperty && "size".equals(arguments[0])) || "length".equals(arguments[0])) {
                result = Boolean.TRUE;
            } else {
                result = invocation.proceed();
            }
        }
            break;
        default:
            result = invocation.proceed();
        }
    } else {
        result = invocation.proceed();
    }

    return result;
}

From source file:org.bytesoft.openjtcc.supports.spring.NativeCompensableProxy.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (Object.class.equals(method.getDeclaringClass())) {
        return method.invoke(this.target, args);
    }/* w w  w .ja  v a2 s.  c o m*/

    try {
        if (Compensable.class.equals(method.getDeclaringClass())) {
            return method.invoke(this.target, args);
        } else if (BeanNameAware.class.equals(method.getDeclaringClass())) {
            return method.invoke(this, args);
        }
    } catch (IllegalAccessException ex) {
        RuntimeException rex = new RuntimeException();
        rex.initCause(ex);
        throw rex;
    } catch (InvocationTargetException ex) {
        throw ex.getTargetException();
    }

    return this.invokeBizMethod(method, args);
}

From source file:com.mtgi.analytics.aop.BehaviorTrackingAdvice.java

public Object invoke(MethodInvocation invocation) throws Throwable {

    Method m = invocation.getMethod();
    String eventName = m.getDeclaringClass().getName() + "." + m.getName();

    BehaviorEvent event = trackingManager.createEvent(eventType, eventName);

    //log method parameters.  would be nice if we could figure
    //out parameter names here.
    EventDataElement data = event.addData();
    EventDataElement parameters = data.addElement("parameters");
    Class<?>[] sig = m.getParameterTypes();
    Object[] args = invocation.getArguments();

    for (int i = 0; i < sig.length; ++i) {
        Object val = args[i];
        logValue(parameters, "param", sig[i], val);
    }/*www.ja v a 2s  .co m*/

    trackingManager.start(event);
    try {
        Object ret = invocation.proceed();
        logValue(data, "result", m.getReturnType(), ret);
        return ret;
    } catch (Throwable error) {
        event.setError(error);
        throw error;
    } finally {
        trackingManager.stop(event);
    }
}

From source file:org.ext4spring.parameter.DefaultParameterResolver.java

private String resolveDomain(Method method) {
    String domain;//from w  w  w  .  ja  v  a  2s. co  m
    if (method.getDeclaringClass().isAnnotationPresent(ParameterBean.class) && !ParameterBean.UNDEFINED
            .equals(method.getDeclaringClass().getAnnotation(ParameterBean.class).domain())) {
        domain = method.getDeclaringClass().getAnnotation(ParameterBean.class).domain();
    } else {
        domain = method.getDeclaringClass().getCanonicalName();
    }
    return domain;
}

From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiAnnotationMappingDiscoverer.java

public String getMapping(Method method) {

    Assert.notNull(method, "Method must not be null!");
    return getMapping(method.getDeclaringClass(), method);
}

From source file:com.nineteendrops.tracdrops.api.ticket.ticket.TicketTestBase.java

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

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