List of usage examples for java.lang.reflect Method getDeclaredAnnotations
public Annotation[] getDeclaredAnnotations()
From source file:com.web.services.ExecutorServicesConstruct.java
/** * This method removes the configuration of the War file * @param servicesMap/*from ww w. j a v a 2 s . c o m*/ * @param exectorServicesXml * @param customClassLoader * @throws Exception */ public void removeExecutorServices(Hashtable servicesMap, File exectorServicesXml, WebClassLoader customClassLoader) throws Exception { DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/executorservices-config.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); ExecutorServices executorServices = (ExecutorServices) serverdigester .parse(new InputSource(new FileInputStream(exectorServicesXml))); CopyOnWriteArrayList<ExecutorService> executorServicesList = executorServices.getExecutorServices(); ExecutorServiceAnnot executorServiceAnnot; for (ExecutorService executorService : executorServicesList) { Class executorServiceClass = customClassLoader .loadClass(executorService.getExecutorserviceclass().toString()); //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); //System.out.println(); Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { executorServiceAnnot = (ExecutorServiceAnnot) annotation; //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception(); servicesMap.remove(executorServiceAnnot.servicename()); } } } } }
From source file:com.app.services.ExecutorServicesConstruct.java
/** * This method removes the configuration of the War file * @param servicesMap//from www .j a v a 2 s . c o m * @param exectorServicesXml * @param customClassLoader * @throws Exception */ public void removeExecutorServices(Hashtable servicesMap, File exectorServicesXml, WebClassLoader customClassLoader) throws Exception { DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/executorservices-config.xml"))); } catch (Exception e) { log.error("Could not able to load xml rules ./config/executorservices-config.xml", e); // TODO Auto-generated catch block //e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); ExecutorServices executorServices = (ExecutorServices) serverdigester .parse(new InputSource(new FileInputStream(exectorServicesXml))); CopyOnWriteArrayList<ExecutorService> executorServicesList = executorServices.getExecutorServices(); ExecutorServiceAnnot executorServiceAnnot; for (ExecutorService executorService : executorServicesList) { Class executorServiceClass = customClassLoader .loadClass(executorService.getExecutorserviceclass().toString()); //log.info("executor class in ExecutorServicesConstruct"+executorServiceClass); //log.info(); Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { executorServiceAnnot = (ExecutorServiceAnnot) annotation; //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception(); servicesMap.remove(executorServiceAnnot.servicename()); } } } } }
From source file:org.adscale.testtodoc.TestToDoc.java
void handleClass(List<String> res, Class<?> clazz) { Method[] methods = clazz.getMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation.annotationType().getName().endsWith(".Test")) { res.add(clazz.getName() + "::" + method.getName()); }/*from w ww. j a v a 2 s. c om*/ } } }
From source file:it.osm.gtfs.GTFSOSMImport.java
@Command(description = "Display available commands") public String help() { StringBuffer buffer = new StringBuffer(); buffer.append("Available commands:\n"); for (Method method : this.getClass().getMethods()) { for (Annotation annotation : method.getDeclaredAnnotations()) { if (annotation instanceof Command) { Command myAnnotation = (Command) annotation; buffer.append(method.getName() + "\t" + myAnnotation.description() + "\n"); }//from www .j a v a2 s.c o m } } buffer.append("exit\tExit from GTFSImport\n"); return buffer.toString(); }
From source file:org.omnaest.utils.beans.BeanUtils.java
/** * Returns a {@link Map} with all property names of the given Java Bean and a {@link Set} of all available annotations for the * properties, including the field, getter and setter methods. * //from ww w . j a v a 2 s. c o m * @param beanClass * @return */ public static <B> Map<String, Set<Annotation>> propertyNameToBeanPropertyAnnotationSetMap(Class<B> beanClass) { // Map<String, Set<Annotation>> retmap = new HashMap<String, Set<Annotation>>(); // Map<String, BeanPropertyAccessor<B>> propertyNameToBeanPropertyAccessorMap = BeanUtils .propertyNameToBeanPropertyAccessorMap(beanClass); for (String propertyName : propertyNameToBeanPropertyAccessorMap.keySet()) { // BeanPropertyAccessor<B> beanPropertyAccessor = propertyNameToBeanPropertyAccessorMap.get(propertyName); // Set<Annotation> annotationSet = new HashSet<Annotation>(); { // Field field = beanPropertyAccessor.getField(); if (field != null) { Annotation[] annotations = field.getDeclaredAnnotations(); if (annotations != null) { annotationSet.addAll(Arrays.asList(annotations)); } } } { // Method methodGetter = beanPropertyAccessor.getMethodGetter(); if (methodGetter != null) { Annotation[] annotations = methodGetter.getDeclaredAnnotations(); if (annotations != null) { annotationSet.addAll(Arrays.asList(annotations)); } } } { // Method methodSetter = beanPropertyAccessor.getMethodSetter(); if (methodSetter != null) { Annotation[] annotations = methodSetter.getDeclaredAnnotations(); if (annotations != null) { annotationSet.addAll(Arrays.asList(annotations)); } } } // retmap.put(propertyName, annotationSet); } // return retmap; }
From source file:org.gradle.model.internal.manage.schema.extract.ImplTypeSchemaExtractionStrategySupport.java
@Nullable private ModelProperty<?> extractPropertySchema(ModelSchemaExtractionContext<?> extractionContext, String propertyName, PropertyAccessorExtractionContext getterContext, PropertyAccessorExtractionContext setterContext, Set<Method> handledMethods) { // Take the most specific declaration of the getter Method mostSpecificGetter = getterContext.getMostSpecificDeclaration(); if (mostSpecificGetter.getParameterTypes().length != 0) { handleInvalidGetter(extractionContext, getterContext, "getter methods cannot take parameters"); return null; }/* w w w. ja v a 2 s .co m*/ if (!getterContext.isDeclaredInManagedType() && mostSpecificGetter.getReturnType().isPrimitive()) { handleInvalidGetter(extractionContext, getterContext, "managed properties cannot have primitive types"); return null; } boolean managedProperty = getterContext.isDeclaredInManagedType() && getterContext.isDeclaredAsAbstract(); ModelType<?> returnType = ModelType.returnType(mostSpecificGetter); boolean writable = setterContext != null; if (writable) { validateSetter(extractionContext, returnType, getterContext, setterContext); } Map<Class<? extends Annotation>, Annotation> annotations = Maps.newLinkedHashMap(); for (Method getterMethod : getterContext.getDeclaringMethods()) { for (Annotation annotation : getterMethod.getDeclaredAnnotations()) { // Make sure more specific annotation doesn't get overwritten with less specific one if (!annotations.containsKey(annotation.annotationType())) { annotations.put(annotation.annotationType(), annotation); } } } ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet.copyOf( Iterables.transform(getterContext.getDeclaringMethods(), new Function<Method, ModelType<?>>() { public ModelType<?> apply(Method input) { return ModelType.of(input.getDeclaringClass()); } })); return ModelProperty.of(returnType, propertyName, managedProperty, writable, declaringClasses, annotations); }
From source file:org.apache.axis2.jaxws.lifecycle.BaseLifecycleManager.java
protected boolean isPostConstruct(final Method method) { Annotation[] annotations = (Annotation[]) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return method.getDeclaredAnnotations(); }/* w w w . java 2 s . com*/ }); for (Annotation annotation : annotations) { return PostConstruct.class.isAssignableFrom(annotation.annotationType()); } return false; }
From source file:org.apache.axis2.jaxws.lifecycle.BaseLifecycleManager.java
protected boolean isPreDestroy(final Method method) { Annotation[] annotations = (Annotation[]) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return method.getDeclaredAnnotations(); }//from www .j av a 2 s . c o m }); for (Annotation annotation : annotations) { return PreDestroy.class.isAssignableFrom(annotation.annotationType()); } return false; }
From source file:ren.hankai.cordwood.web.breadcrumb.BreadCrumbInterceptor.java
/** * ?HTTPHandler// w w w. j ava 2 s .com * * @param handler HTTPHandler * @return * @author hankai * @since Nov 22, 2018 3:58:22 PM */ private Annotation[] getDeclaredAnnotationsForHandler(Object handler) { if (handler instanceof HandlerMethod) { final HandlerMethod handlerMethod = (HandlerMethod) handler; final Method method = handlerMethod.getMethod(); final Annotation[] declaredAnnotations = method.getDeclaredAnnotations(); return declaredAnnotations; } else { return null; } }
From source file:com.toolsverse.mvc.pojo.PojoWrapper.java
/** * Instantiate an obejct of the type P. Intersepts getters, setters, readres and writers. * * @param pojoClass the pojo class/*from w w w. j a v a2 s . c o m*/ */ @SuppressWarnings("unchecked") private void init(Class<?> pojoClass) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(pojoClass); enhancer.setCallback(this); _pojo = (P) enhancer.create(); Method[] methods = pojoClass.getMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); if (annotations != null) for (Annotation annotation : annotations) { if (annotation instanceof Getter && isGetterMethod(method)) { Attribute attr = getAttribute(((Getter) annotation).name()); Object attrParams = getAttrParams(((Getter) annotation).paramsClass()); if (attr == null) { attr = new Attribute(method.getReturnType(), method.getName(), null, attrParams); _attributes.put(((Getter) annotation).name(), attr); } else { attr.setGetter(method.getName()); attr.setAttributeClass(method.getReturnType()); if (attr.getParams() == null && attrParams != null) attr.setParams(attrParams); } } else if (annotation instanceof Setter && isSetterMethod(method)) { _setters.put(method, ((Setter) annotation).name()); Attribute attr = getAttribute(((Setter) annotation).name()); Object attrParams = getAttrParams(((Setter) annotation).paramsClass()); if (attr == null) { attr = new Attribute(method.getParameterTypes()[0], null, method.getName(), attrParams); _attributes.put(((Setter) annotation).name(), attr); } else { attr.setSetter(method.getName()); if (attr.getAttributeClass() == null) attr.setAttributeClass(method.getParameterTypes()[0]); if (attr.getParams() == null && attrParams != null) attr.setParams(attrParams); } } else if (annotation instanceof Reader && isReaderMethod(method)) { Attribute attr = getAttribute(((Reader) annotation).name()); Object attrParams = getAttrParams(((Reader) annotation).paramsClass()); if (attr == null) { attr = new Attribute(method.getParameterTypes()[0], null, null, attrParams, method.getName(), null); _attributes.put(((Reader) annotation).name(), attr); } else { attr.setReader(method.getName()); if (attr.getAttributeClass() == null) attr.setAttributeClass(method.getParameterTypes()[0]); if (attr.getParams() == null && attrParams != null) attr.setParams(attrParams); } } else if (annotation instanceof Writer && isWriterMethod(method)) { Attribute attr = getAttribute(((Writer) annotation).name()); Object attrParams = getAttrParams(((Writer) annotation).paramsClass()); if (attr == null) { attr = new Attribute(method.getParameterTypes()[0], null, null, attrParams, null, method.getName()); _attributes.put(((Writer) annotation).name(), attr); } else { attr.setWriter(method.getName()); if (attr.getAttributeClass() == null) attr.setAttributeClass(method.getParameterTypes()[0]); if (attr.getParams() == null && attrParams != null) attr.setParams(attrParams); } } } } }