use of java.lang.annotation.Annotation in project morphia by mongodb.
the class MappedField method discoverConstructor.
private Constructor discoverConstructor() {
Class<?> type = null;
// get the first annotation with a concreteClass that isn't Object.class
for (final Annotation an : foundAnnotations.values()) {
try {
final Method m = an.getClass().getMethod("concreteClass");
m.setAccessible(true);
final Object o = m.invoke(an);
//noinspection EqualsBetweenInconvertibleTypes
if (o != null && !(o.equals(Object.class))) {
type = (Class) o;
break;
}
} catch (NoSuchMethodException e) {
// do nothing
} catch (IllegalArgumentException e) {
if (LOG.isWarningEnabled()) {
LOG.warning("There should not be an argument", e);
}
} catch (Exception e) {
if (LOG.isWarningEnabled()) {
LOG.warning("", e);
}
}
}
if (type != null) {
try {
constructor = type.getDeclaredConstructor();
constructor.setAccessible(true);
} catch (NoSuchMethodException e) {
if (!hasAnnotation(ConstructorArgs.class)) {
if (LOG.isWarningEnabled()) {
LOG.warning("No usable constructor for " + type.getName(), e);
}
}
}
} else {
// see if we can create instances of the type used for declaration
type = getType();
// short circuit to avoid wasting time throwing an exception trying to get a constructor we know doesnt exist
if (type == List.class || type == Map.class) {
return null;
}
if (type != null) {
try {
constructor = type.getDeclaredConstructor();
constructor.setAccessible(true);
} catch (NoSuchMethodException e) {
// never mind.
} catch (SecurityException e) {
// never mind.
}
}
}
return constructor;
}
use of java.lang.annotation.Annotation in project netty-socketio by mrniko.
the class ScannerEngine method scan.
public void scan(Namespace namespace, Object object, Class<?> clazz) throws IllegalArgumentException {
Method[] methods = clazz.getDeclaredMethods();
if (!clazz.isAssignableFrom(object.getClass())) {
for (Method method : methods) {
for (AnnotationScanner annotationScanner : annotations) {
Annotation ann = method.getAnnotation(annotationScanner.getScanAnnotation());
if (ann != null) {
annotationScanner.validate(method, clazz);
Method m = findSimilarMethod(object.getClass(), method);
if (m != null) {
annotationScanner.addListener(namespace, object, m, ann);
} else {
log.warn("Method similar to " + method.getName() + " can't be found in " + object.getClass());
}
}
}
}
} else {
for (Method method : methods) {
for (AnnotationScanner annotationScanner : annotations) {
Annotation ann = method.getAnnotation(annotationScanner.getScanAnnotation());
if (ann != null) {
annotationScanner.validate(method, clazz);
makeAccessible(method);
annotationScanner.addListener(namespace, object, method, ann);
}
}
}
if (clazz.getSuperclass() != null) {
scan(namespace, object, clazz.getSuperclass());
} else if (clazz.isInterface()) {
for (Class<?> superIfc : clazz.getInterfaces()) {
scan(namespace, object, superIfc);
}
}
}
}
use of java.lang.annotation.Annotation in project netty-socketio by mrniko.
the class SpringAnnotationScanner method postProcessBeforeInitialization.
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
final AtomicBoolean add = new AtomicBoolean();
ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
add.set(true);
}
}, new MethodFilter() {
@Override
public boolean matches(Method method) {
for (Class<? extends Annotation> annotationClass : annotations) {
if (method.isAnnotationPresent(annotationClass)) {
return true;
}
}
return false;
}
});
if (add.get()) {
originalBeanClass = bean.getClass();
}
return bean;
}
use of java.lang.annotation.Annotation in project ninja by ninjaframework.
the class JaxyRoutes method findControllerMethods.
/**
* Searches for Methods that have either a Path Annotation or a HTTP-Method Annotation
*/
@SuppressWarnings("unchecked")
private Set<Method> findControllerMethods() {
Set<Method> methods = Sets.newLinkedHashSet();
methods.addAll(reflections.getMethodsAnnotatedWith(Path.class));
Reflections annotationReflections = new Reflections("", new TypeAnnotationsScanner(), new SubTypesScanner());
for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) {
if (httpMethod.isAnnotation()) {
methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod));
}
}
return methods;
}
use of java.lang.annotation.Annotation in project neo4j by neo4j.
the class PluginPointFactoryImpl method createFrom.
public PluginPoint createFrom(ServerPlugin plugin, Method method, Class<?> discovery) {
ResultConverter result = ResultConverter.get(method.getGenericReturnType());
Type[] types = method.getGenericParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
SourceExtractor sourceExtractor = null;
DataExtractor[] extractors = new DataExtractor[types.length];
for (int i = 0; i < types.length; i++) {
Description description = null;
Parameter param = null;
Source source = null;
for (Annotation annotation : annotations[i]) {
if (annotation instanceof Description) {
description = (Description) annotation;
} else if (annotation instanceof Parameter) {
param = (Parameter) annotation;
} else if (annotation instanceof Source) {
source = (Source) annotation;
}
}
if (param != null && source != null) {
throw new IllegalStateException(String.format("Method parameter %d of %s cannot be retrieved as both Parameter and Source", Integer.valueOf(i), method));
} else if (source != null) {
if (types[i] != discovery) {
throw new IllegalStateException("Source parameter type (" + types[i] + ") must equal the discovery type (" + discovery.getName() + ").");
}
if (sourceExtractor != null) {
throw new IllegalStateException("Server Extension methods may have at most one Source parameter.");
}
extractors[i] = sourceExtractor = new SourceExtractor(source, description);
} else if (param != null) {
extractors[i] = parameterExtractor(types[i], param, description);
} else {
throw new IllegalStateException("Parameters of Server Extension methods must be annotated as either Source or Parameter.");
}
}
return new PluginMethod(nameOf(method), discovery, plugin, result, method, extractors, method.getAnnotation(Description.class));
}
Aggregations