List of usage examples for java.lang.reflect AnnotatedElement isAnnotationPresent
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.opensymphony.xwork2.util.AnnotationUtils.java
/** * Varargs version of <code>AnnotatedElement.isAnnotationPresent()</code> * @param annotatedElement element to check * @param annotation the {@link Annotation}s to find * @return true is element is annotated by one of the annotation * @see AnnotatedElement//from www . j av a2 s. c o m */ public static boolean isAnnotatedBy(AnnotatedElement annotatedElement, Class<? extends Annotation>... annotation) { if (ArrayUtils.isEmpty(annotation)) { return false; } for (Class<? extends Annotation> c : annotation) { if (annotatedElement.isAnnotationPresent(c)) return true; } return false; }
From source file:acmi.l2.clientmod.xdat.Controller.java
private static List<PropertySheetItem> loadProperties(Object obj) { Class<?> objClass = obj.getClass(); List<PropertySheetItem> list = new ArrayList<>(); while (objClass != Object.class) { try {// w w w. ja va 2 s . c o m List<String> names = Arrays.stream(objClass.getDeclaredFields()) .map(field -> field.getName().replace("Prop", "")).collect(Collectors.toList()); BeanInfo beanInfo = Introspector.getBeanInfo(objClass, objClass.getSuperclass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); Arrays.sort(propertyDescriptors, (pd1, pd2) -> Integer.compare(names.indexOf(pd1.getName()), names.indexOf(pd2.getName()))); for (PropertyDescriptor descriptor : propertyDescriptors) { if ("metaClass".equals(descriptor.getName())) continue; if (Collection.class.isAssignableFrom(descriptor.getPropertyType())) continue; AnnotatedElement getter = descriptor.getReadMethod(); if (getter.isAnnotationPresent(Deprecated.class) || getter.isAnnotationPresent(Hide.class)) continue; String description = ""; if (getter.isAnnotationPresent(Description.class)) description = getter.getAnnotation(Description.class).value(); Class<? extends PropertyEditor<?>> propertyEditorClass = null; if (descriptor.getPropertyType() == Boolean.class || descriptor.getPropertyType() == Boolean.TYPE) { propertyEditorClass = BooleanPropertyEditor.class; } else if (getter.isAnnotationPresent(Tex.class)) { propertyEditorClass = TexturePropertyEditor.class; } else if (getter.isAnnotationPresent(Sysstr.class)) { propertyEditorClass = SysstringPropertyEditor.class; } BeanProperty property = new BeanProperty(descriptor, objClass.getSimpleName(), description, propertyEditorClass); list.add(property); } } catch (IntrospectionException e) { e.printStackTrace(); } objClass = objClass.getSuperclass(); } return list; }
From source file:com.adobe.acs.commons.models.injectors.impl.I18nInjector.java
@Override public Object getValue(Object adaptable, String name, Type type, AnnotatedElement annotatedElement, DisposalCallbackRegistry disposal) { if (annotatedElement.isAnnotationPresent(I18N.class) && canAdaptToString(adaptable, type)) { //skipping javax.Inject for performance reasons. Only supports direct injection. String key = getI18nKey(name, annotatedElement); if (adaptable instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) adaptable; return i18nProvider.translate(key, request); } else {//from w w w. j a v a2s . com Resource resource = getResource(adaptable); return i18nProvider.translate(key, resource); } } else if (canAdaptToObject(adaptable, type)) { if (adaptable instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) adaptable; return i18nProvider.i18n(request); } else { Resource resource = getResource(adaptable); return i18nProvider.i18n(resource); } } return null; }
From source file:com.adobe.acs.commons.models.injectors.impl.JsonValueMapValueInjector.java
@Override public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement element, DisposalCallbackRegistry callbackRegistry) { if (element.isAnnotationPresent(JsonValueMapValue.class)) { Resource resource = getResource(adaptable); JsonValueMapValue annotation = element.getAnnotation(JsonValueMapValue.class); String key = defaultIfEmpty(annotation.name(), name); String[] jsonStringArray = resource.getValueMap().get(key, String[].class); return parseValue(declaredType, jsonStringArray, key, resource); }//from w ww. java 2 s .c o m return null; }
From source file:com.wavemaker.tools.apidocs.tools.parser.impl.ReflectionModelParser.java
protected boolean isRequired(AnnotatedElement field) { return field.isAnnotationPresent(NotNull.class); }
From source file:com.haulmont.cuba.gui.CompanionDependencyInjector.java
private Class injectionAnnotation(AnnotatedElement element) { if (element.isAnnotationPresent(Named.class)) return Named.class; else if (element.isAnnotationPresent(Resource.class)) return Resource.class; else if (element.isAnnotationPresent(Inject.class)) return Inject.class; else/*from w w w . j a va 2 s . c o m*/ return null; }
From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java
private ReferenceDefinition updateReferenceDefinition(ReferenceDefinition definition, AnnotatedElement object) { if (object.isAnnotationPresent(Embedded.class)) { definition.setEmbedded(true);//from ww w. jav a 2 s. co m } return definition; }
From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java
private PropertyDefinition updatePropertyDefinition(PropertyDefinition definition, AnnotatedElement object) { if (object.isAnnotationPresent(Lob.class)) { definition.setLob(true);//w w w . j ava 2 s . co m } if (object.isAnnotationPresent(Enumerated.class)) { definition.setEnumerated(true); } //todo implement also lookup for @Table indexes if (object.isAnnotationPresent(Index.class)) { definition.setIndexed(true); } return definition; }
From source file:com.haulmont.cuba.gui.ControllerDependencyInjector.java
protected Class injectionAnnotation(AnnotatedElement element) { if (element.isAnnotationPresent(Named.class)) return Named.class; else if (element.isAnnotationPresent(Resource.class)) return Resource.class; else if (element.isAnnotationPresent(Inject.class)) return Inject.class; else if (element.isAnnotationPresent(WindowParam.class)) return WindowParam.class; else//w w w. j a va 2 s .c o m return null; }
From source file:com.medallia.spider.api.DynamicInputImpl.java
/** * Method used to parse values for the methods declared in {@link Input}. *//* w w w. j a v a 2 s .c om*/ public <X> X getInput(String name, Class<X> type, AnnotatedElement anno) { // Special case for file uploads if (type.isAssignableFrom(UploadedFile.class)) return type.cast(fileUploads.get(name)); // Also support just getting the bytes from a file without the name if (type.isArray() && type.getComponentType() == Byte.TYPE) { UploadedFile uploadedFile = fileUploads.get(name); return uploadedFile != null ? type.cast(uploadedFile.getBytes()) : null; } if (type.isArray() && anno.isAnnotationPresent(Input.MultiValued.class)) { // return type is an array; grab all Object o = inputParams.get(name); return type.cast(parseMultiValue(type, o, anno)); } String v = Strings.extract(inputParams.get(name)); // boolean is used for checkboxes, and false is encoded as a missing value if (type == Boolean.class || type == Boolean.TYPE) { @SuppressWarnings("unchecked") X x = (X) Boolean.valueOf(v != null && !"false".equalsIgnoreCase(v)); return x; } // the remaining types have proper null values if (v == null) return null; return cast(parseSingleValue(type, v, anno, inputArgParsers)); }