List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Return the number of methods with a given name (with any argument types), * for the given class and/or its superclasses. Includes non-public methods. * @param clazz the clazz to check/*from w ww .j a v a 2 s .c om*/ * @param methodName the name of the method * @return the number of methods with the given name */ public static int getMethodCountForName(Class clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); int count = 0; Method[] declaredMethods = clazz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { Method method = declaredMethods[i]; if (methodName.equals(method.getName())) { count++; } } Class[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { count += getMethodCountForName(ifcs[i], methodName); } if (clazz.getSuperclass() != null) { count += getMethodCountForName(clazz.getSuperclass(), methodName); } return count; }
From source file:com.ivanzhangwb.interpose.core.InterposeBootStrap.java
@Override public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException { if (interposeClassPathApplicationContext == null) { interposeClassPathApplicationContext = new InterposeClassPathApplicationContext( this.applicationContext); }//from w w w.ja va 2 s . c om boolean needInterpose = false; Class beanClass = bean.getClass(); do { Method[] methods = beanClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (Interpose.class != null && methods[i].isAnnotationPresent(Interpose.class) && methods[i].equals(ClassUtils.getMostSpecificMethod(methods[i], bean.getClass()))) { needInterpose = true; handleMethodAnnotation(methods[i]); } } beanClass = beanClass.getSuperclass(); } while (beanClass != null); if (needInterpose) { ConfigurableApplicationContext atx = (ConfigurableApplicationContext) interposeClassPathApplicationContext; DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) atx.getBeanFactory(); ProxyFactoryBean factoryBean = new ProxyFactoryBean(); factoryBean.setTarget(bean); factoryBean.setInterceptorNames(new String[] { InterposeConstants.INTERPOSE_CORE_INTERCEPTOR }); factoryBean.setBeanFactory(beanFactory); return factoryBean.getObject(); } else { return bean; } }
From source file:org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver.java
public void invokeService(JsonReader jsonReader, Object serviceObj, String operation_name, MessageContext outMes) throws AxisFault { String msg;/*www . j av a 2 s . c o m*/ Class implClass = serviceObj.getClass(); Method[] allMethods = implClass.getDeclaredMethods(); Method method = JsonUtils.getOpMethod(operation_name, allMethods); Class[] paramClasses = method.getParameterTypes(); try { int paramCount = paramClasses.length; Object retObj = JsonUtils.invokeServiceClass(jsonReader, serviceObj, method, paramClasses, paramCount); // handle response outMes.setProperty(JsonConstant.RETURN_OBJECT, retObj); outMes.setProperty(JsonConstant.RETURN_TYPE, method.getReturnType()); } catch (IllegalAccessException e) { msg = "Does not have access to " + "the definition of the specified class, field, method or constructor"; log.error(msg, e); throw AxisFault.makeFault(e); } catch (InvocationTargetException e) { msg = "Exception occurred while trying to invoke service method " + (method != null ? method.getName() : "null"); log.error(msg, e); throw AxisFault.makeFault(e); } catch (IOException e) { msg = "Exception occur while encording or " + "access to the input string at the JsonRpcMessageReceiver"; log.error(msg, e); throw AxisFault.makeFault(e); } }
From source file:com.github.tddts.jet.config.spring.postprocessor.EventBusBeanPostProcessor.java
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Pair<Class<?>, Object> typeObjectPair = SpringUtil.checkForDinamicProxy(bean); Class<?> type = typeObjectPair.getLeft(); Object target = typeObjectPair.getRight(); for (Method method : type.getDeclaredMethods()) { if (method.isAnnotationPresent(Subscribe.class)) { eventBus.register(target);//from www . ja v a2 s. c o m logger.debug("Bean registered to EventBus: [" + beanName + "]"); return bean; } } return bean; }
From source file:io.cloudslang.runtime.impl.java.JavaExecutor.java
private Method getMethodByName(Class actionClass, String methodName) { Method[] methods = actionClass.getDeclaredMethods(); Method actionMethod = null;// w ww . ja v a2 s .co m for (Method m : methods) { if (m.getName().equals(methodName)) { actionMethod = m; } } return actionMethod; }
From source file:com.hc.wx.server.common.bytecode.ReflectUtils.java
public static Map<String, Method> getBeanPropertyReadMethods(Class cl) { Map<String, Method> properties = new HashMap<String, Method>(); for (; cl != null; cl = cl.getSuperclass()) { Method[] methods = cl.getDeclaredMethods(); for (Method method : methods) { if (isBeanPropertyReadMethod(method)) { method.setAccessible(true); String property = getPropertyNameFromBeanReadMethod(method); properties.put(property, method); }//from w w w .j a v a 2 s .com } } return properties; }
From source file:org.appcelerator.locator.AnnotationBasedLocator.java
/** * find the first method annotation so we can inspect the instance * @param <T> some type of annotation * @param service to check for methods//from w w w. j av a2s .c om * @param annotationClass representing the annotation we're looking for * @return instance of the provided annotationClass annotating one of the methods in the passed in service */ @SuppressWarnings("unchecked") private <T extends Annotation> T findFirstMethodAnnotation(Class<?> service, Class<T> annotationClass) { Method[] ms = service.getDeclaredMethods(); for (Method method : ms) { //TODO what is a syntax that uses generics properly that this likes? it wants one that T t = (T) method.getAnnotation((Class) annotationClass);//annotationClass); if (t != null) { return t; } } return null; }
From source file:org.vaadin.spring.i18n.Translator.java
private void analyzeMethods(Class<?> clazz) { for (Method m : clazz.getDeclaredMethods()) { if (m.getParameterTypes().length == 0 && m.getReturnType() != Void.TYPE) { if (m.isAnnotationPresent(TranslatedProperty.class)) { translatedMethods.put(m.getAnnotation(TranslatedProperty.class), m); } else if (m.isAnnotationPresent(TranslatedProperties.class)) { for (TranslatedProperty annotation : m.getAnnotation(TranslatedProperties.class).value()) { translatedMethods.put(annotation, m); }/*from w ww. j av a 2 s . c o m*/ } } } }
From source file:controllerTas.config.xml.TasControllerConfigXmlParser.java
private Class getClassMethodIfExists(Class c, String method) { Method[] declared = c.getDeclaredMethods(); for (Method aDeclared : declared) { if (aDeclared.getName().equals(method)) { Class[] array = aDeclared.getParameterTypes(); if (array.length > 1) { throw new RuntimeException( "Ho trovato il metodo " + method + "ma non un setter con un solo parametro!"); } else return array[0]; }/* w w w . j av a 2s .com*/ } return null; }
From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.RequestAttributeResolver.java
private Set<String> getAttributesFromClassLoader(String clazzname) { final Set<String> ret = new LinkedHashSet<>(); try {/*w ww .j a v a2 s . co m*/ Class clazz = classPath.getClassLoader(true).loadClass(clazzname); for (Method method : clazz.getDeclaredMethods()) { for (Annotation annotation : method.getAnnotations()) { if (annotation.annotationType().getName().equals(REQUEST_ATTRIBUTE_CLASSNAME)) { ret.add(method.getName()); } } } for (Field field : clazz.getDeclaredFields()) { for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType().getName().equals(REQUEST_ATTRIBUTE_CLASSNAME)) { ret.add(field.getName()); } } } } catch (ClassNotFoundException cnfe) { LOGGER.log(Level.FINE, "Could not resolve class " + clazzname, cnfe); } return ret; }