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:org.docksidestage.dbflute.svflute.GodHandableControllerInterceptor.java

protected String buildActionName(HandlerMethod handlerMethod) {
    final Method method = handlerMethod.getMethod();
    final Class<?> declaringClass = method.getDeclaringClass();
    return declaringClass.getSimpleName();
}

From source file:com.interface21.aop.framework.RegexpMethodPointcut.java

/**
 * Try to match the regular expression against
 * the fully qualified name of the method's declaring class, plus the
 * name of the method. Note that the declaring class is that class
 * that originally declared the method, not necessarily the class
 * that's currently exposing it./* w  w  w  .  j  av a2  s  .c o  m*/
 * For example, <code>java.lang.Object.hashCode</code> matches
 * any subclass of object's hashCode() method.
 * @see com.interface21.aop.framework.StaticMethodPointcut#applies(java.lang.reflect.Method, org.aopalliance.intercept.AttributeRegistry)
 */
public boolean applies(Method m, AttributeRegistry attributeRegistry) {
    String patt = m.getDeclaringClass().getName() + "." + m.getName();
    boolean matched = this.matcher.matches(patt, this.compiledPattern);
    if (logger.isDebugEnabled())
        logger.debug("Candidate is: '" + patt + "'; pattern is " + this.compiledPattern.getPattern()
                + "; matched=" + matched);
    return matched;
}

From source file:org.acoveo.tools.Reflection.java

static Method mostDerived(Method meth1, Method meth2) {
    if (meth1 == null)
        return meth2;
    if (meth2 == null)
        return meth1;

    Class cls2 = meth2.getDeclaringClass();
    Class cls1 = meth1.getDeclaringClass();

    if (cls1.equals(cls2)) {
        Class ret1 = meth1.getReturnType();
        Class ret2 = meth2.getReturnType();
        if (ret1.isAssignableFrom(ret2))
            return meth2;
        else if (ret2.isAssignableFrom(ret1))
            return meth1;
        else/*  w ww  .  ja  v  a 2 s.com*/
            throw new IllegalArgumentException("most-derived-unrelated-same-type" + meth1 + meth2);
    } else {
        if (cls1.isAssignableFrom(cls2))
            return meth2;
        else if (cls2.isAssignableFrom(cls1))
            return meth1;
        else
            throw new IllegalArgumentException("most-derived-unrelated" + meth1 + meth2);
    }
}

From source file:org.springmodules.cache.interceptor.caching.CachingModelSourceAdvisorTests.java

public void testMatchesWithModelSourceReturningModel() throws Exception {
    advisor = new CachingModelSourceAdvisor(interceptor);

    Method method = defaultMethod();
    Class targetClass = method.getDeclaringClass();
    modelSourceControl.expectAndReturn(modelSource.model(method, targetClass), new MockCachingModel());

    modelSourceControl.replay();//from w  w  w  .j a v  a 2s.co m

    assertTrue(advisor.matches(method, targetClass));

    modelSourceControl.verify();
}

From source file:org.springmodules.cache.interceptor.caching.CachingModelSourceAdvisorTests.java

public void testMatchesWithModelSourceReturningNull() throws Exception {
    advisor = new CachingModelSourceAdvisor(interceptor);

    Method method = defaultMethod();
    Class targetClass = method.getDeclaringClass();
    modelSourceControl.expectAndReturn(modelSource.model(method, targetClass), null);

    modelSourceControl.replay();/* w w  w .  jav a2  s .c  o m*/

    assertFalse(advisor.matches(method, targetClass));

    modelSourceControl.verify();
}

From source file:org.springmodules.cache.interceptor.flush.FlushingModelSourceAdvisorTests.java

public void testMatchesWithModelSourceReturningNull() throws Exception {
    advisor = new FlushingModelSourceAdvisor(interceptor);

    Method method = defaultMethod();
    Class targetClass = method.getDeclaringClass();
    modelSourceControl.expectAndReturn(modelSource.getFlushingModel(method, targetClass), null);

    modelSourceControl.replay();/*from w  w  w. ja va  2  s .  co m*/

    assertFalse(advisor.matches(method, targetClass));

    modelSourceControl.verify();
}

From source file:org.springmodules.cache.interceptor.flush.FlushingModelSourceAdvisorTests.java

public void testMatchesWithModelSourceReturningModel() throws Exception {
    advisor = new FlushingModelSourceAdvisor(interceptor);

    Method method = defaultMethod();
    Class targetClass = method.getDeclaringClass();
    modelSourceControl.expectAndReturn(modelSource.getFlushingModel(method, targetClass),
            new MockFlushingModel());

    modelSourceControl.replay();//from   w  w  w.j a  v a  2 s.c  om

    assertTrue(advisor.matches(method, targetClass));

    modelSourceControl.verify();
}

From source file:com.github.parisoft.resty.response.ResponseInvocationHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    final Class<?> declaringClass = method.getDeclaringClass();

    try {//from   ww  w.j a v a  2 s.co  m
        if (declaringClass.isAssignableFrom(HttpResponse.class)) {
            return method.invoke(httpResponse, args);
        }

        if (declaringClass.isAssignableFrom(EntityReader.class)) {
            return method.invoke(entityReader, args);
        }

        if (declaringClass.isAssignableFrom(HttpResponseExtension.class)) {
            responseExtension.setResponse((Response) proxy);
            return method.invoke(responseExtension, args);
        }
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }

    return null;
}

From source file:info.rmapproject.webapp.auth.AuthenticationInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    HandlerMethod hm = (HandlerMethod) handler;
    Method method = hm.getMethod();

    if (method.getDeclaringClass().isAnnotationPresent(Controller.class)) {
        if (method.isAnnotationPresent(LoginRequired.class)) {
            OAuthProviderAccount account = (OAuthProviderAccount) request.getSession()
                    .getAttribute(ACCOUNT_SESSION_ATTRIBUTE);
            if (account == null) {
                response.sendRedirect(request.getContextPath() + USER_LOGIN_PATH);
                return false;
            }// w ww .ja  v  a  2  s . co  m

            User user = (User) request.getSession().getAttribute(USER_SESSION_ATTRIBUTE);
            if ((!method.getName().equals(SIGNUPFORM_METHOD) && !method.getName().equals(ADDUSER_METHOD))
                    && (user == null || user.getUserId() == 0)) {
                //new user, get them signed up!
                response.sendRedirect(request.getContextPath() + USER_SIGNUP_PATH);
                return false;
            }
        }
    }
    return true;

}

From source file:com.nineteendrops.tracdrops.api.search.populator.SearchTestInitializator.java

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

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