use of org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding in project felix by apache.
the class MetaAnnotationBindingRegistry method createBindings.
@Override
protected List<Binding> createBindings(final Type type) {
// Parse the annotation
byte[] bytes;
try {
bytes = m_store.read(type.getInternalName().concat(".class"));
} catch (IOException e) {
// Annotation type cannot be read
m_reporter.trace("Could not read bytecode for @%s.", type.getClassName());
return emptyList();
} catch (IllegalStateException e) {
m_reporter.trace("Could not read bytecode for @%s because the bundle is not in a state allowing read " + "operations.", type.getClassName());
return emptyList();
}
AnnotationParser parser = new AnnotationParser();
AnnotationType annotationType = parser.read(bytes);
// Search meta-annotations
ChainedAnnotationDiscovery chain = new ChainedAnnotationDiscovery();
StereotypeDiscovery stereotypeDiscovery = new StereotypeDiscovery();
HandlerBindingDiscovery handlerBindingDiscovery = new HandlerBindingDiscovery();
IgnoredDiscovery ignoredDiscovery = new IgnoredDiscovery();
chain.getDiscoveries().add(stereotypeDiscovery);
chain.getDiscoveries().add(handlerBindingDiscovery);
chain.getDiscoveries().add(ignoredDiscovery);
annotationType.traverse(chain);
// Produced Bindings
List<Binding> bindings = new ArrayList<Binding>();
// @Stereotype support
if (stereotypeDiscovery.isStereotype()) {
m_reporter.trace("@Stereotype detected: @%s", type.getClassName());
Binding binding = new Binding();
binding.setAnnotationType(type);
binding.setPredicate(alwaysTrue());
binding.setFactory(new StereotypeVisitorFactory(annotationType));
bindings.add(binding);
}
// @HandlerBinding support
if (handlerBindingDiscovery.isHandlerBinding()) {
m_reporter.trace("@HandlerBinding detected: @%s", type.getClassName());
Binding binding = new Binding();
binding.setAnnotationType(type);
binding.setPredicate(alwaysTrue());
final Element element = buildElement(handlerBindingDiscovery, type);
binding.setFactory(new GenericVisitorFactory(element.getName(), element.getNameSpace()));
bindings.add(binding);
}
// Its IMPORTANT that the @Ignore is processed last since it removes existing bindings
if (ignoredDiscovery.isIgnore()) {
m_reporter.trace("@Ignore detected: @%s", type.getClassName());
Binding binding = new NullBinding(type);
bindings.clear();
bindings.add(binding);
// just in case of ...
bindings = unmodifiableList(bindings);
}
return bindings;
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding in project felix by apache.
the class MetaAnnotationBindingRegistry method nullBindingsForMetaAnnotations.
protected Iterable<Binding> nullBindingsForMetaAnnotations() {
// Do not re-apply meta-annotations
ArrayList<Binding> bindings = new ArrayList<Binding>();
bindings.add(new NullBinding(Type.getType(Stereotype.class)));
bindings.add(new NullBinding(Type.getType(HandlerBinding.class)));
bindings.add(new NullBinding(Type.getType(Ignore.class)));
return bindings;
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding in project felix by apache.
the class MetaAnnotationBindingRegistryTestCase method testIgnoreAnnotation.
public void testIgnoreAnnotation() throws Exception {
when(store.read(anyString())).thenReturn(from(Ignored.class));
MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
Binding binding = registry.getBindings(Type.getDescriptor(Ignored.class)).get(0);
assertTrue(binding instanceof NullBinding);
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding in project felix by apache.
the class AbsBindingModuleTestCase method testIgnoreBindings.
public void testIgnoreBindings() throws Exception {
AbsBindingModule module = new AbsBindingModule() {
public void configure() {
bindIgnore(Bound.class);
}
};
module.configure();
Iterator<Binding> i = module.iterator();
Binding one = i.next();
assertEquals(getType(Bound.class), one.getAnnotationType());
assertTrue(one instanceof NullBinding);
}
Aggregations