Search in sources :

Example 1 with IgnoredDiscovery

use of org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.IgnoredDiscovery 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;
}
Also used : NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) HandlerBinding(org.apache.felix.ipojo.annotations.HandlerBinding) GenericVisitorFactory(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory) AnnotationParser(org.apache.felix.ipojo.manipulator.metadata.annotation.model.parser.AnnotationParser) IgnoredDiscovery(org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.IgnoredDiscovery) ChainedAnnotationDiscovery(org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.ChainedAnnotationDiscovery) Element(org.apache.felix.ipojo.metadata.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AnnotationType(org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType) HandlerBindingDiscovery(org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.HandlerBindingDiscovery) StereotypeVisitorFactory(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory) NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) StereotypeDiscovery(org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.StereotypeDiscovery)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HandlerBinding (org.apache.felix.ipojo.annotations.HandlerBinding)1 AnnotationType (org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType)1 ChainedAnnotationDiscovery (org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.ChainedAnnotationDiscovery)1 HandlerBindingDiscovery (org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.HandlerBindingDiscovery)1 IgnoredDiscovery (org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.IgnoredDiscovery)1 StereotypeDiscovery (org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.StereotypeDiscovery)1 AnnotationParser (org.apache.felix.ipojo.manipulator.metadata.annotation.model.parser.AnnotationParser)1 GenericVisitorFactory (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory)1 NullBinding (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding)1 StereotypeVisitorFactory (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory)1 Element (org.apache.felix.ipojo.metadata.Element)1