List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:org.apache.axis2.transport.http.AbstractAgent.java
private void preloadMethods() { Class clazz = getClass(); while (clazz != null && !clazz.equals(Object.class)) { examineMethods(clazz.getDeclaredMethods()); clazz = clazz.getSuperclass();//ww w. ja v a2 s. c o m } }
From source file:com.github.tddts.jet.config.spring.postprocessor.MessageAnnotationBeanPostProcessor.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(); Method[] methods = type.getDeclaredMethods(); Field[] fields = type.getDeclaredFields(); for (Method method : methods) { if (checkMethod(method, type)) processMethod(target, method); }// www . ja va2s . co m for (Field field : fields) { if (checkField(field, type)) processField(target, field); } return bean; }
From source file:org.apache.hadoop.hbase.ipc.HBaseRpcMetrics.java
private void initMethods(Class<? extends VersionedProtocol> protocol) { for (Method m : protocol.getDeclaredMethods()) { if (get(m.getName()) == null) create(m.getName());/*from w w w. j av a2 s. co m*/ } }
From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java
private Object getValueFromMethods(String path, Class<?> type, Object inst) throws Exception { Method[] methods = type.getDeclaredMethods(); for (Method method : methods) { JsonProperty ann = method.getAnnotation(JsonProperty.class); if (ann != null) { String annName = ann.value(); if (StringUtils.isBlank(annName)) { annName = ann.defaultValue(); }/*w w w. j a v a 2 s. c o m*/ if (StringUtils.isBlank(annName)) { annName = getNameFromMethod(method); } if (StringUtils.equals(path, annName)) { boolean accessible = method.isAccessible(); if (!accessible) { method.setAccessible(true); } Object value = method.invoke(inst); if (!accessible) { method.setAccessible(false); } return value; } } } return null; }
From source file:ei.ne.ke.cassandra.cql3.EntitySpecificationUtils.java
/** * Constructs a map of {@link String}S representing column names to {@link * Field}S.//w w w. j ava 2 s. c o m * * @param entityClazz * @return */ public static <T> Map<String, AttributeAccessor> createAccessors(Class<T> entityClazz) { Preconditions.checkNotNull(entityClazz); Map<String, AttributeAccessor> map = Maps.newLinkedHashMap(); for (Field f : entityClazz.getDeclaredFields()) { javax.persistence.Column c = f.getAnnotation(javax.persistence.Column.class); if (c == null) { continue; } String normalizedName = normalizeCqlElementName(c.name()); if (map.containsKey(normalizedName)) { throw new IllegalStateException(String.format("Duplicate column name '%s'", normalizedName)); } AttributeAccessor accessor = new AttributeAccessorFieldIntrospection(f); map.put(normalizedName, accessor); } for (Method firstMethod : entityClazz.getDeclaredMethods()) { javax.persistence.Column c = firstMethod.getAnnotation(javax.persistence.Column.class); if (c == null) { continue; } String normalizedName = normalizeCqlElementName(c.name()); /* * For bean getters and setters, we allow to annotate either the * getter or the setter and will find the corresponding counterpart. * If the column name is already mapped, then there's either a * @Column-annotated field, or the previous reversed pair of getters * and setters was found. Either way, ignore this annotated method. */ if (map.containsKey(normalizedName)) { continue; } String firstMethodName = firstMethod.getName(); AttributeAccessor accessor = null; if (firstMethodName.startsWith("set")) { String attributeName = firstMethodName.substring(NON_BOOLEAN_BEAN_PROPERTY_ACCESSOR_PREFIX_LENGTH); Method secondMethod = findGetterMethod(entityClazz, attributeName); if (secondMethod == null) { throw new IllegalArgumentException(String.format("No counterpart to %s", firstMethodName)); } accessor = new AttributeAccessorBeanMethods(secondMethod, firstMethod); } else if (firstMethodName.startsWith("is")) { String attributeName = firstMethodName.substring(BOOLEAN_BEAN_PROPERTY_ACCESSOR_PREFIX_LENGTH); Method secondMethod = findSetterMethod(entityClazz, attributeName); if (secondMethod == null) { throw new IllegalArgumentException(String.format("No counterpart to %s", firstMethodName)); } accessor = new AttributeAccessorBeanMethods(firstMethod, secondMethod); } else if (firstMethodName.startsWith("get")) { String attributeName = firstMethodName.substring(NON_BOOLEAN_BEAN_PROPERTY_ACCESSOR_PREFIX_LENGTH); /* * Find the corresponding setter. */ Method secondMethod = findSetterMethod(entityClazz, attributeName); if (secondMethod == null) { throw new IllegalArgumentException(String.format("No counterpart to %s", firstMethodName)); } accessor = new AttributeAccessorBeanMethods(firstMethod, secondMethod); } map.put(normalizedName, accessor); } return map; }
From source file:com.zc.util.refelect.Reflector.java
/** * * ?annotationClass/*from w ww . j ava2s. c o m*/ * * @param targetClass * Class * @param annotationClass * Class * * @return List */ public static <T extends Annotation> List<T> getAnnotations(Class targetClass, Class annotationClass) { List<T> result = new ArrayList<T>(); Annotation annotation = targetClass.getAnnotation(annotationClass); if (annotation != null) { result.add((T) annotation); } Constructor[] constructors = targetClass.getDeclaredConstructors(); // ? CollectionUtils.addAll(result, getAnnotations(constructors, annotationClass).iterator()); Field[] fields = targetClass.getDeclaredFields(); // ? CollectionUtils.addAll(result, getAnnotations(fields, annotationClass).iterator()); Method[] methods = targetClass.getDeclaredMethods(); // ? CollectionUtils.addAll(result, getAnnotations(methods, annotationClass).iterator()); for (Class<?> superClass = targetClass.getSuperclass(); superClass == null || superClass == Object.class; superClass = superClass.getSuperclass()) { List<T> temp = (List<T>) getAnnotations(superClass, annotationClass); if (CollectionUtils.isNotEmpty(temp)) { CollectionUtils.addAll(result, temp.iterator()); } } return result; }
From source file:it.cosenonjaviste.alfresco.annotations.processors.runtime.BehaviourConfigurer.java
private List<Method> discoverEventsMethods(ClassPolicy bean) { List<Method> methods = new ArrayList<>(); Class<?>[] interfaces = bean.getClass().getInterfaces(); if (interfaces != null && interfaces.length > 0) { for (Class<?> anInterface : interfaces) { if (ClassPolicy.class.isAssignableFrom(anInterface)) { methods.addAll(Arrays.asList(anInterface.getDeclaredMethods())); }//from ww w . j av a2 s . c o m } } return methods; }
From source file:it.unibas.spicy.persistence.object.operators.AnalyzeFields.java
private boolean findPublicMethodInClass(Class currentClass, String methodName) { Method[] methods = currentClass.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(methodName) && Modifier.isPublic(method.getModifiers())) { return true; }/*from w ww. ja v a 2 s . c om*/ } return false; }
From source file:net.jselby.pc.bukkit.BukkitLoader.java
@SuppressWarnings("unchecked") public void loadPlugin(File file) throws ZipException, IOException, InvalidPluginException, InvalidDescriptionException { if (file.getName().endsWith(".jar")) { JarFile jarFile = new JarFile(file); URL[] urls = { new URL("jar:file:" + file + "!/") }; URLClassLoader cl = URLClassLoader.newInstance(urls); ZipEntry bukkit = jarFile.getEntry("plugin.yml"); String bukkitClass = ""; PluginDescriptionFile reader = null; if (bukkit != null) { reader = new PluginDescriptionFile(new InputStreamReader(jarFile.getInputStream(bukkit))); bukkitClass = reader.getMain(); System.out.println("Loading plugin " + reader.getName() + "..."); }//from w w w .j a v a 2s . co m jarFile.close(); try { //addToClasspath(file); JavaPluginLoader pluginLoader = new JavaPluginLoader(PoweredCube.getInstance().getBukkitServer()); Plugin plugin = pluginLoader.loadPlugin(file); Class<JavaPlugin> pluginClass = (Class<JavaPlugin>) plugin.getClass().getSuperclass(); for (Method method : pluginClass.getDeclaredMethods()) { if (method.getName().equalsIgnoreCase("init") || method.getName().equalsIgnoreCase("initialize")) { method.setAccessible(true); method.invoke(plugin, null, PoweredCube.getInstance().getBukkitServer(), reader, new File("plugins" + File.separator + reader.getName()), file, cl); } } // Load the plugin, using its default methods BukkitPluginManager mgr = (BukkitPluginManager) Bukkit.getPluginManager(); mgr.registerPlugin((JavaPlugin) plugin); plugin.onLoad(); plugin.onEnable(); } catch (Exception e1) { e1.printStackTrace(); } catch (Error e1) { e1.printStackTrace(); } jarFile.close(); } }
From source file:com.netflix.hystrix.contrib.javanica.utils.MethodProvider.java
/** * Gets method by name and parameters types using reflection, * if the given type doesn't contain required method then continue applying this method for all super classes up to Object class. * * @param type the type to search method * @param name the method name * @param parameterTypes the parameters types * @return Some if method exists otherwise None *///from w w w . j ava2 s. c o m public Optional<Method> getMethod(Class<?> type, String name, Class<?>... parameterTypes) { Method[] methods = type.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(name) && Arrays.equals(method.getParameterTypes(), parameterTypes)) { return Optional.of(method); } } Class<?> superClass = type.getSuperclass(); if (superClass != null && !superClass.equals(Object.class)) { return getMethod(superClass, name, parameterTypes); } else { return Optional.absent(); } }