Example usage for org.springframework.util ReflectionUtils findMethod

List of usage examples for org.springframework.util ReflectionUtils findMethod

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils findMethod.

Prototype

@Nullable
public static Method findMethod(Class<?> clazz, String name) 

Source Link

Document

Attempt to find a Method on the supplied class with the supplied name and no parameters.

Usage

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

private String getValue(Annotation[] annotations, Class<? extends Annotation> annotationClass) {
    for (Annotation annotation : annotations) {
        if (annotationClass.isInstance(annotation)) {
            Method valueMethod = ReflectionUtils.findMethod(annotationClass, "value");
            if (valueMethod != null) {
                return (String) ReflectionUtils.invokeMethod(valueMethod, annotation);
            } else {
                return null;
            }//from w  w w.j  a v  a2 s .co m
        }
    }

    return null;
}

From source file:com.taobao.itest.spring.aop.LogInterceptor.java

private String stringBuilder(Object obj) {
    if (null == obj) {
        return null;
    }/*from  w w  w .  j a v  a  2s. c  o  m*/
    if (ReflectionUtils.findMethod(obj.getClass(), "toString") != null) {
        return obj.toString();
    } else {
        return ToStringBuilder.reflectionToString(obj, ToStringStyle.MULTI_LINE_STYLE);
    }
}

From source file:org.shept.persistence.provider.DaoUtils.java

private static Serializable getIdValue_old(DaoSupport dao, Object model) {
    checkProvider(dao);//from   w w w  . j av  a  2s.c  o  m
    String idStr = getIdentifierPropertyName_old(dao, model);
    if (!(StringUtils.hasText(idStr))) {
        return null;
    }
    Method idMth = ReflectionUtils.findMethod(model.getClass(), "get" + StringUtils.capitalize(idStr));
    Serializable idxObj = (Serializable) ReflectionUtils.invokeMethod(idMth, model);
    return idxObj;
}

From source file:org.grails.plugin.platform.events.registry.SpringIntegrationEventsRegistry.java

public String addListener(String scope, String topic, Object bean, String callbackName) {
    return registerHandler(bean, ReflectionUtils.findMethod(bean.getClass(), callbackName), scope, topic, null);
}

From source file:org.jboss.spring.vfs.VFSUtil.java

public static File getPhysicalFile(Object virtualFile) throws IOException {
    if (VFS2_PACKAGE_NAME.equals(vfsPackageName)) {
        if ((Boolean) invokeVfsMethod(VFS_UTILS_METHOD_IS_NESTED_FILE, null, virtualFile)) {
            throw new IOException("File resolution not supported for nested resource: " + virtualFile);
        }/*from ww w.j  av  a  2s  .com*/
        try {
            return new File((URI) invokeVfsMethod(VFS_UTILS_METHOD_GET_COMPATIBLE_URI, null, virtualFile));
        } catch (Exception ex) {
            throw new NestedIOException("Failed to obtain File reference for " + virtualFile, ex);
        }
    } else {
        return (File) invokeVfsMethod(ReflectionUtils.findMethod(VIRTUAL_FILE_CLASS, "getPhysicalFile"),
                virtualFile);
    }
}

From source file:ch.qos.logback.ext.spring.web.WebLogbackConfigurer.java

/**
 * Shut down Logback, properly releasing all file locks
 * and resetting the web app root system property.
 *
 * @param servletContext the current ServletContext
 * @see WebUtils#removeWebAppRootSystemProperty
 *//*from  w w w. ja v a  2 s  .c  o m*/
public static void shutdownLogging(ServletContext servletContext) {
    //Uninstall the SLF4J java.util.logging bridge *before* shutting down the Logback framework.
    try {
        Class<?> julBridge = ClassUtils.forName("org.slf4j.bridge.SLF4JBridgeHandler",
                ClassUtils.getDefaultClassLoader());
        Method uninstall = ReflectionUtils.findMethod(julBridge, "uninstall");
        if (uninstall != null) {
            servletContext.log("Uninstalling JUL to SLF4J bridge");
            ReflectionUtils.invokeMethod(uninstall, null);
        }
    } catch (ClassNotFoundException ignored) {
        //No need to shutdown the java.util.logging bridge. If it's not on the classpath, it wasn't started either.
    }

    try {
        servletContext.log("Shutting down Logback");
        LogbackConfigurer.shutdownLogging();
    } finally {
        // Remove the web app root system property.
        if (exposeWebAppRoot(servletContext)) {
            WebUtils.removeWebAppRootSystemProperty(servletContext);
        }
    }
}

From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityMetadataSupport.java

private Method findMethod(String propertyName) {
    Method method = ReflectionUtils.findMethod(domainType, toGetMethodName(propertyName));
    if (method == null) {
        method = ReflectionUtils.findMethod(domainType, toIsMethodName(propertyName));
    }//from  www.  jav  a 2  s. c o  m
    return method;

}

From source file:org.grails.datastore.gorm.events.DomainEventListener.java

private void findAndCacheEvent(String event, Class<?> javaClass, Map<String, Method> events) {
    final Method method = ReflectionUtils.findMethod(javaClass, event);
    if (method != null) {
        events.put(event, method);//from  w  ww .  j  av  a  2 s . c  o  m
    }
}

From source file:org.grails.plugin.platform.events.registry.SpringIntegrationEventsRegistry.java

public String addListener(String scope, String topic, Object bean, String callbackName, Object filter) {
    return registerHandler(bean, ReflectionUtils.findMethod(bean.getClass(), callbackName), scope, topic,
            filter);/*from  www .  j a v a2  s.co m*/
}

From source file:ch.digitalfondue.npjt.QueryType.java

protected Object buildOptional(List<Object> res) {
    if (res.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, res.size());
    }/*from   w w  w  . java  2 s.co m*/

    try {
        Class<?> clazz = Class.forName("java.util.Optional");
        if (res.isEmpty()) {
            return ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(clazz, "empty"), null);
        } else {
            return ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(clazz, "ofNullable", Object.class),
                    null, res.iterator().next());
        }
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    }
}