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.healthcit.cacure.test.DataSetTestExecutionListener.java

Annotation findAnnotation(Method method, Class<? extends Annotation> annotationType) {
    Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
    return annotation == null ? AnnotationUtils.findAnnotation(method.getDeclaringClass(), annotationType)
            : annotation;//from   w w w  . j  av a2 s.  c o m
}

From source file:com.mastfrog.acteur.ClasspathResourcePage.java

protected boolean isDynamicContent() {
    Boolean dynContent = overridesProcessContent.get(getClass());
    if (dynContent == null) {
        try {/*from  w  w w . j  av a 2  s .c  om*/
            Method m = findMethod(getClass(), "processContent", String.class);
            dynContent = m == null ? false : m.getDeclaringClass() == ClasspathResourcePage.class;
            overridesProcessContent.put(getClass(), dynContent);
        } catch (SecurityException ex) {
            Logger.getLogger(ClasspathResourcePage.class.getName()).log(Level.SEVERE, null, ex);
            dynContent = true;
        }
    }
    return dynContent;
}

From source file:com.dianping.resource.io.util.ClassUtils.java

/**
 * Determine whether the given method is overridable in the given target class.
 * @param method the method to check//www . j  a v  a2 s. c  o  m
 * @param targetClass the target class to check against
 */
private static boolean isOverridable(Method method, Class<?> targetClass) {
    if (Modifier.isPrivate(method.getModifiers())) {
        return false;
    }
    if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
        return true;
    }
    return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
}

From source file:org.apache.beehive.controls.system.ejb.EJBControlImpl.java

protected boolean isHomeMethod(Method m) {
    return m.getDeclaringClass().isAssignableFrom(_homeInterface);
}

From source file:com.ixxus.IxxusAbstractTest.java

@BeforeMethod(alwaysRun = true)
protected void startSession(Method method) throws Exception {
    String testName = method.getName();
    if (logger.isTraceEnabled()) {
        logger.trace(String.format("Test run:%s.%s", method.getDeclaringClass().getCanonicalName(), testName));
    }//  w  ww .j a v  a 2 s  .com
}

From source file:org.apache.beehive.controls.system.ejb.EJBControlImpl.java

/**
 * Return true if the method is from the ControlBean.
 * @param m Method to check./* w ww . jav  a 2s . c  om*/
 */
protected boolean isControlBeanMethod(Method m) {
    return (m.getDeclaringClass().getAnnotation(ControlExtension.class) != null);
}

From source file:org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.java

private boolean isMethodAllowed(Method method) {
    Class<?> declaringClass = method.getDeclaringClass();
    //methods of the Object.class are forbidden (except toString, which is allowed)
    return declaringClass != Object.class || TO_STRING_METHOD.equals(method.getName());
}

From source file:com.freetmp.common.util.ClassUtils.java

private static boolean isOverridable(Method method, Class<?> targetClass) {
    if (Modifier.isPrivate(method.getModifiers())) {
        return false;
    }//from  w  w  w  .j  a  v a 2  s  . c  o  m
    if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
        return true;
    }
    return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
}

From source file:com.lakeside.data.sqldb.BaseDao.java

/**
 * ?/*from  w  w  w .  j  a v a 2  s . com*/
 * @param entity
 * @return
 */
public T merge(final T entity) {
    Assert.notNull(entity, "entity?");
    Session session = getSession();
    String idName = getIdName();
    PropertyDescriptor idp = BeanUtils.getPropertyDescriptor(entityClass, idName);
    PK idvalue = null;
    try {
        idvalue = (PK) idp.getReadMethod().invoke(entity);
    } catch (Exception e) {
        throw new FatalBeanException("Could not copy properties from source to target", e);
    }
    T dest = null;
    if (idvalue != null) {
        dest = (T) session.get(entityClass, idvalue);
    }
    if (dest != null) {
        // merge the properties
        PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(entityClass);
        for (PropertyDescriptor p : descriptors) {
            if (p.getWriteMethod() != null) {
                try {
                    Method readMethod = p.getReadMethod();
                    if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
                        readMethod.setAccessible(true);
                    }
                    Object value = readMethod.invoke(entity);
                    if (value == null) {
                        continue;
                    }
                    Method writeMethod = p.getWriteMethod();
                    if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
                        writeMethod.setAccessible(true);
                    }
                    writeMethod.invoke(dest, value);
                } catch (Throwable ex) {
                    throw new FatalBeanException("Could not copy properties from source to target", ex);
                }
            }
        }
    } else {
        // destination object is empty, save the entity object parameted
        dest = entity;
    }
    session.saveOrUpdate(dest);
    logger.debug("merge entity: {}", entity);
    return dest;
}

From source file:org.bytesoft.bytetcc.supports.spring.CompensableAnnotationValidator.java

private void validateTransactionalRollbackFor(Method method, Class<?> clazz, String beanName)
        throws IllegalStateException {
    Transactional transactional = method.getAnnotation(Transactional.class);
    if (transactional == null) {
        Class<?> declaringClass = method.getDeclaringClass();
        transactional = declaringClass.getAnnotation(Transactional.class);
    }//  w w w .j  a  v a2s  .  co  m

    if (transactional == null) {
        throw new IllegalStateException(
                String.format("Method(%s) must be specificed a Transactional annotation!", method));
    }

    String[] rollbackForClassNameArray = transactional.rollbackForClassName();
    if (rollbackForClassNameArray != null && rollbackForClassNameArray.length > 0) {
        throw new IllegalStateException(String.format(
                "The transactional annotation on the confirm/cancel class does not support the property rollbackForClassName yet(beanId= %s)!",
                beanName));
    }

    Class<?>[] rollErrorArray = transactional.rollbackFor();

    Class<?>[] errorTypeArray = method.getExceptionTypes();
    for (int j = 0; errorTypeArray != null && j < errorTypeArray.length; j++) {
        Class<?> errorType = errorTypeArray[j];
        if (RuntimeException.class.isAssignableFrom(errorType)) {
            continue;
        }

        boolean matched = false;
        for (int k = 0; rollErrorArray != null && k < rollErrorArray.length; k++) {
            Class<?> rollbackError = rollErrorArray[k];
            if (rollbackError.isAssignableFrom(errorType)) {
                matched = true;
                break;
            }
        }

        if (matched == false) {
            throw new IllegalStateException(String.format(
                    "The value of Transactional.rollbackFor annotated on method(%s) must includes %s!", method,
                    errorType.getName()));
        }
    }
}