Example usage for org.springframework.util ClassUtils hasMethod

List of usage examples for org.springframework.util ClassUtils hasMethod

Introduction

In this page you can find the example usage for org.springframework.util ClassUtils hasMethod.

Prototype

public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) 

Source Link

Document

Determine whether the given class has a public method with the given signature.

Usage

From source file:org.jdal.dao.hibernate.HibernateDao.java

/**
 * Create a Criteria from filter. If filter is a entity class instance, 
 * return a Criteria with a Example Criterion applied.
 * If not try four options in order:/*from w  w w .ja  va2s.  c  om*/
 * 
 *    1. if there are a filter with name filter.getName() enable it and return criteria
 *  2. if there are a criteria builder with name filter.getName() use it to create Critera.
 *  4. if there are a method named createCritera + filter.getName() invoke it to create Criteria
 *  5. Return a Criteria for this entity class without Criterion applied.
 * 
 * @param filter the filter
 * @return a new Criteria 
 */
protected Criteria getCriteria(Page<?> page) {
    Criteria executableCriteria = getSession().createCriteria(getEntityClass());
    Object filter = page.getFilter();
    // apply filter, if any
    if (filter != null) {
        if (ClassUtils.isAssignable(getEntityClass(), filter.getClass())) {
            // try a findByExample...
            executableCriteria.add(Example.create(getEntityClass()));
        } else if (filter instanceof Filter) {
            Filter f = (Filter) filter;

            if (!enableFilter(f)) {
                if (log.isDebugEnabled())
                    log.debug("No hibernate filter found with name: " + f.getFilterName()
                            + ", try criteria builder.");
                // if no filter, try criteria builder
                if (criteriaBuilderMap.containsKey(f.getFilterName())) {
                    CriteriaBuilder cb = criteriaBuilderMap.get(f.getFilterName());
                    if (log.isDebugEnabled())
                        log.debug("Found criteria builder with name: " + f.getFilterName()
                                + " - criteria builder class: " + cb.getClass().getSimpleName());
                    executableCriteria = cb.build(executableCriteria, f);
                }
                // if no criteria builder try subclass method
                else if (ClassUtils.hasMethod(getClass(), "createCriteria" + f.getFilterName(),
                        new Class[] { Criteria.class })) {
                    Method method = ClassUtils.getMethodIfAvailable(getClass(),
                            "createCriteria" + f.getFilterName(), new Class[] { Criteria.class });
                    if (method != null) {
                        try {
                            executableCriteria = (Criteria) method.invoke(this, executableCriteria);
                        } catch (Exception e) {
                            log.error(e);
                        }
                    }
                }
            }
        } else {
            log.warn("Cannot manage filter of type: " + filter.getClass());
        }
    }

    return executableCriteria;
}

From source file:com.laxser.blitz.web.impl.module.ControllerRef.java

private boolean ignoresCommonMethod(Method method) {
    // ? Object /*  w  w w.  ja v  a  2s  . c o m*/
    if (ClassUtils.hasMethod(Object.class, method.getName(), method.getParameterTypes())) {
        return true;
    }

    // ?java bean??
    String name = method.getName();
    if (name.startsWith("get") && name.length() > 3 && Character.isUpperCase(name.charAt("get".length()))
            && method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
        if (null == method.getAnnotation(Get.class)) {
            return true;
        }
    }
    if (name.startsWith("is") && name.length() > 3 && Character.isUpperCase(name.charAt("is".length()))
            && method.getParameterTypes().length == 0
            && (method.getReturnType() == boolean.class || method.getReturnType() == Boolean.class)) {
        if (null == method.getAnnotation(Get.class)) {
            return true;
        }
    }
    if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt("set".length()))
            && method.getParameterTypes().length == 1 && method.getReturnType() == void.class) {
        if (null == method.getAnnotation(Post.class)) {
            return true;
        }
    }
    return false;
}

From source file:org.beangle.spring.bind.AutoConfigProcessor.java

public static boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) {
    Method wm = pd.getWriteMethod();
    if (wm == null) {
        return false;
    }//www .j  a  v a2s.  c om
    if (!wm.getDeclaringClass().getName().contains("$$")) {
        // Not a CGLIB method so it's OK.
        return false;
    }
    // It was declared by CGLIB, but we might still want to autowire it
    // if it was actually declared by the superclass.
    Class<?> superclass = wm.getDeclaringClass().getSuperclass();
    return !ClassUtils.hasMethod(superclass, wm.getName(), wm.getParameterTypes());
}

From source file:org.springframework.aop.framework.CglibAopProxy.java

/**
 * Check whether the given method is declared on any of the given interfaces.
 *//* w  ww . j a v  a  2s .  c o m*/
private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) {
    for (Class<?> ifc : ifcs) {
        if (ClassUtils.hasMethod(ifc, method.getName(), method.getParameterTypes())) {
            return true;
        }
    }
    return false;
}