use of java.lang.reflect.AnnotatedElement in project uPortal by Jasig.
the class ModelAttributeService method init.
@PostConstruct
public void init() {
/*
* Gather classes & methods that reference @SoffitMoldelAttribute
*/
final Map<AnnotatedElement, Object> map = new HashMap<>();
final String[] beanNames = applicationContext.getBeanDefinitionNames();
for (String name : beanNames) {
final Object bean = applicationContext.getBean(name);
final Class clazz = AopUtils.isAopProxy(bean) ? AopUtils.getTargetClass(bean) : bean.getClass();
if (clazz.isAnnotationPresent(SoffitModelAttribute.class)) {
// The bean itself is the model attribute
map.put(clazz, bean);
} else {
// Check the bean for annotated methods...
for (Method m : clazz.getMethods()) {
if (m.isAnnotationPresent(SoffitModelAttribute.class)) {
map.put(m, bean);
}
}
}
}
logger.debug("Found {} beans and/or methods referencing @SoffitModelAttribute", map.size());
modelAttributes = Collections.unmodifiableMap(map);
}
use of java.lang.reflect.AnnotatedElement in project uPortal by Jasig.
the class ModelAttributeService method gatherModelAttributes.
/* package-private */
Map<String, Object> gatherModelAttributes(String viewName, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) {
final Map<String, Object> rslt = new HashMap<>();
logger.debug("Processing model attributes for viewName='{}'", viewName);
for (Map.Entry<AnnotatedElement, Object> y : modelAttributes.entrySet()) {
final AnnotatedElement annotatedElement = y.getKey();
final Object bean = y.getValue();
final SoffitModelAttribute sma = annotatedElement.getAnnotation(SoffitModelAttribute.class);
if (attributeAppliesToView(sma, viewName)) {
logger.debug("The following SoffitModelAttribute applies to viewName='{}': {}", viewName, sma);
final String modelAttributeName = sma.value();
// Are we looking at a class or a method?
if (annotatedElement instanceof Class) {
// The bean itself is the model attribute
rslt.put(modelAttributeName, bean);
} else if (annotatedElement instanceof Method) {
final Method m = (Method) annotatedElement;
final Object modelAttribute = getModelAttributeFromMethod(bean, m, req, res, portalRequest, bearer, preferences, definition);
rslt.put(modelAttributeName, modelAttribute);
} else {
final String msg = "Unsupported AnnotatedElement type: " + AnnotatedElement.class.getName();
throw new UnsupportedOperationException(msg);
}
}
}
logger.debug("Calculated the following model attributes for viewName='{}': {}", viewName, rslt);
return rslt;
}
use of java.lang.reflect.AnnotatedElement in project hibernate-orm by hibernate.
the class Ejb3XmlTestCase method getReader.
protected JPAOverriddenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName) throws Exception {
AnnotatedElement el = getAnnotatedElement(entityClass, fieldName);
XMLContext xmlContext = getContext(ormResourceName);
return new JPAOverriddenAnnotationReader(el, xmlContext, ClassLoaderAccessTestingImpl.INSTANCE);
}
use of java.lang.reflect.AnnotatedElement in project jersey by jersey.
the class ParamInjectionResolver method hasEncodedAnnotation.
private boolean hasEncodedAnnotation(Injectee injectee) {
AnnotatedElement element = injectee.getParent();
final boolean isConstructor = element instanceof Constructor;
final boolean isMethod = element instanceof Method;
// if injectee is method or constructor, check its parameters
if (isConstructor || isMethod) {
Annotation[] annotations;
if (isMethod) {
annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()];
} else {
annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()];
}
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(Encoded.class)) {
return true;
}
}
}
// check injectee itself (method, constructor or field)
if (element.isAnnotationPresent(Encoded.class)) {
return true;
}
// check class which contains injectee
Class<?> clazz = injectee.getInjecteeClass();
return clazz.isAnnotationPresent(Encoded.class);
}
use of java.lang.reflect.AnnotatedElement in project newts by OpenNMS.
the class MergeSort method createCmdLineParser.
private CmdLineParser createCmdLineParser() {
return new CmdLineParser(this) {
@SuppressWarnings("rawtypes")
@Override
public void addArgument(final Setter setter, Argument a) {
Setter newSetter = setter;
if (setter instanceof MethodSetter) {
newSetter = new Setter() {
@SuppressWarnings("unchecked")
@Override
public void addValue(Object value) throws CmdLineException {
setter.addValue(value);
}
@Override
public Class getType() {
return setter.getType();
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public FieldSetter asFieldSetter() {
return setter.asFieldSetter();
}
@Override
public AnnotatedElement asAnnotatedElement() {
return setter.asAnnotatedElement();
}
};
}
super.addArgument(newSetter, a);
}
};
}
Aggregations