List of usage examples for org.apache.commons.beanutils MethodUtils getAccessibleMethod
public static Method getAccessibleMethod(Class clazz, String methodName, Class[] parameterTypes)
Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters.
From source file:com.googlecode.psiprobe.tools.logging.log4j.Log4JManagerAccessor.java
public Log4JManagerAccessor(ClassLoader cl) throws ClassNotFoundException { Class clazz = cl.loadClass("org.apache.log4j.LogManager"); Method m = MethodUtils.getAccessibleMethod(clazz, "exists", new Class[] { String.class }); if (m == null) { throw new RuntimeException("The LogManager is part of the slf4j bridge."); }// w w w.jav a 2 s . c o m setTarget(clazz); }
From source file:com.googlecode.psiprobe.tools.logging.jdk.Jdk14ManagerAccessor.java
public Jdk14ManagerAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class clazz = cl.loadClass("java.util.logging.LogManager"); Method getManager = MethodUtils.getAccessibleMethod(clazz, "getLogManager", new Class[] {}); Object manager = getManager.invoke(null, null); if (manager == null) { throw new NullPointerException(clazz.getName() + ".getLogManager() returned null"); }/*ww w .jav a2 s . c om*/ setTarget(manager); }
From source file:com.googlecode.psiprobe.tools.logging.log4j.Log4JManagerAccessor.java
public Log4JLoggerAccessor getRootLogger() { try {//from w w w . j av a2s. c om Class clazz = (Class) getTarget(); Method m = MethodUtils.getAccessibleMethod(clazz, "getRootLogger", new Class[] {}); Object logger = m.invoke(null, null); if (logger == null) { throw new NullPointerException(getTarget().getClass().getName() + "#getRootLogger() returned null"); } Log4JLoggerAccessor accessor = new Log4JLoggerAccessor(); accessor.setTarget(logger); accessor.setApplication(getApplication()); return accessor; } catch (Exception e) { log.error(getTarget().getClass().getName() + "#getRootLogger() failed", e); } return null; }
From source file:com.dianping.squirrel.client.spring.StoreInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); Store store = AnnotationUtils.findAnnotation(method, Store.class); if (store == null) { Class<? extends Object> targetClazz = invocation.getThis().getClass(); method = MethodUtils.getAccessibleMethod(targetClazz, method.getName(), method.getParameterTypes()); store = AnnotationUtils.findAnnotation(method, Store.class); }/*w w w. jav a 2 s . c o m*/ if (store != null) { StoreOperation operation = store.operation(); StoreKey storeKey = StoreAnnotationUtils.getStoreKey(method, invocation.getArguments()); if (operation == StoreOperation.SetAndGet) { Object storedItem = storeClient.get(storeKey); if (storedItem != null) { return storedItem; } Object item = invocation.proceed(); // TODO: consider create an null object instead of null if (item != null) { storeClient.add(storeKey, item); } return item; } else if (operation == StoreOperation.Update || operation == StoreOperation.Remove) { storeClient.delete(storeKey); return invocation.proceed(); } } return invocation.proceed(); }
From source file:com.dianping.avatar.cache.interceptor.CacheInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); Cache cache = AnnotationUtils.findAnnotation(method, Cache.class); if (cache == null) { Class<? extends Object> targetClazz = invocation.getThis().getClass(); method = MethodUtils.getAccessibleMethod(targetClazz, method.getName(), method.getParameterTypes()); cache = AnnotationUtils.findAnnotation(method, Cache.class); }/*from w ww . ja va2s .c o m*/ if (cache != null) { CacheOperation operation = cache.operation(); CacheKey cacheKey = CacheAnnotationUtils.getCacheKey(method, invocation.getArguments()); if (operation == CacheOperation.SetAndGet) { Object cachedItem = cacheService.get(cacheKey); if (cachedItem != null) { return cachedItem; } Object item = invocation.proceed(); // consider create an null object instead of null cacheService.add(cacheKey, item); return item; } else if (operation == CacheOperation.Update || operation == CacheOperation.Remove) { cacheService.remove(cacheKey); return invocation.proceed(); } } return invocation.proceed(); }
From source file:fr.isima.reflexbench.architecture.ApacheReflect.java
@Override public void searchForMethods(Object obj) { String methodToSearch = ((SampleSourceCode) obj).getSearchingMethod(); Class<?> param = null;// w ww.j a v a 2 s. c o m MethodUtils.getAccessibleMethod(obj.getClass(), methodToSearch, param); }
From source file:com.googlecode.psiprobe.tools.logging.logback.LogbackFactoryAccessor.java
/** * Attempts to initialize a Logback logger factory via the given class loader. * /*w w w . j ava 2 s. c o m*/ * @param cl the ClassLoader to use when fetching the factory */ public LogbackFactoryAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Get the singleton SLF4J binding, which may or may not be Logback, depending on the // binding. Class clazz = cl.loadClass("org.slf4j.impl.StaticLoggerBinder"); Method m1 = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[] {}); Object singleton = m1.invoke(null, null); Method m = MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[] {}); Object loggerFactory = m.invoke(singleton, null); // Check if the binding is indeed Logback Class loggerFactoryClass = cl.loadClass("ch.qos.logback.classic.LoggerContext"); if (!loggerFactoryClass.isInstance(loggerFactory)) { throw new RuntimeException("The singleton SLF4J binding was not Logback"); } setTarget(loggerFactory); }
From source file:com.googlecode.psiprobe.tools.logging.tomcatSlf4jLogback.TomcatSlf4jLogbackFactoryAccessor.java
/** * Attempts to initialize a TomcatSlf4jLogback logger factory via the given class loader. * /*from w ww . j av a 2 s . co m*/ * @param cl the ClassLoader to use when fetching the factory */ public TomcatSlf4jLogbackFactoryAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Get the singleton SLF4J binding, which may or may not be Logback, depending on the binding. Class clazz = cl.loadClass("org.apache.juli.logging.org.slf4j.impl.StaticLoggerBinder"); Method m1 = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[] {}); Object singleton = m1.invoke(null, null); Method m = MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[] {}); Object loggerFactory = m.invoke(singleton, null); // Check if the binding is indeed Logback Class loggerFactoryClass = cl.loadClass("org.apache.juli.logging.ch.qos.logback.classic.LoggerContext"); if (!loggerFactoryClass.isInstance(loggerFactory)) { throw new RuntimeException("The singleton SLF4J binding was not Logback"); } setTarget(loggerFactory); }
From source file:com.googlecode.psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackFactoryAccessor.java
/** * Attempts to initialize a TomcatSlf4jLogback logger factory via the given class loader. * /*from w w w . j a v a 2s.c om*/ * @param cl the ClassLoader to use when fetching the factory */ public TomcatSlf4jLogbackFactoryAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Get the singleton SLF4J binding, which may or may not be Logback, depending on the binding. Class clazz = cl.loadClass("org.apache.juli.logging.org.slf4j.impl.StaticLoggerBinder"); Method getSingleton = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[] {}); Object singleton = getSingleton.invoke(null, null); Method getLoggerFactory = MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[] {}); Object loggerFactory = getLoggerFactory.invoke(singleton, null); // Check if the binding is indeed Logback Class loggerFactoryClass = cl.loadClass("org.apache.juli.logging.ch.qos.logback.classic.LoggerContext"); if (!loggerFactoryClass.isInstance(loggerFactory)) { throw new RuntimeException("The singleton SLF4J binding was not Logback"); } setTarget(loggerFactory); }
From source file:com.cyclopsgroup.levistone.torque.TorquePeerAdapter.java
/** * Constructor for class TorquePeerAdapter * * @param entityType/*from w w w . ja va2s . c om*/ * @param peerType Entity type * @throws Exception */ public TorquePeerAdapter(Class entityType, Class peerType) throws Exception { this.entityType = entityType; this.peerType = peerType; Class[] entityConnectionTypes = new Class[] { entityType, Connection.class }; doInsert = MethodUtils.getAccessibleMethod(peerType, "doInsert", entityConnectionTypes); doUpdate = MethodUtils.getAccessibleMethod(peerType, "doUpdate", entityConnectionTypes); doDelete = MethodUtils.getAccessibleMethod(peerType, "doDelete", entityConnectionTypes); retrieveByPK = MethodUtils.getAccessibleMethod(peerType, "retrieveByPK", KEY_CONNECTION_TYPES); doSelect = MethodUtils.getAccessibleMethod(peerType, "doSelect", CRITERIA_CONNECTION_TYPES); }