Search in sources :

Example 1 with ClassAnnotation

use of org.apache.felix.scrplugin.annotations.ClassAnnotation in project felix by apache.

the class SCRAnnotationProcessor method process.

/**
 * @throws SCRDescriptorException
 * @throws SCRDescriptorFailureException
 * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
 */
@Override
public void process(final ScannedClass scannedClass, final ClassDescription describedClass) throws SCRDescriptorFailureException, SCRDescriptorException {
    final List<ClassAnnotation> componentTags = scannedClass.getClassAnnotations(Component.class.getName());
    scannedClass.processed(componentTags);
    for (final ClassAnnotation cad : componentTags) {
        describedClass.add(createComponent(cad, scannedClass));
    }
    // search for the component descriptions and use the first one
    final List<ComponentDescription> componentDescs = describedClass.getDescriptions(ComponentDescription.class);
    ComponentDescription found = null;
    if (!componentDescs.isEmpty()) {
        found = componentDescs.get(0);
    }
    if (found != null) {
        final ComponentDescription cd = found;
        // search for methods
        final List<MethodAnnotation> methodTags = scannedClass.getMethodAnnotations(null);
        for (final MethodAnnotation m : methodTags) {
            if (m.getName().equals(Activate.class.getName())) {
                cd.setActivate(m.getAnnotatedMethod().getName());
                scannedClass.processed(m);
            } else if (m.getName().equals(Deactivate.class.getName())) {
                cd.setDeactivate(m.getAnnotatedMethod().getName());
                scannedClass.processed(m);
            } else if (m.getName().equals(Modified.class.getName())) {
                cd.setModified(m.getAnnotatedMethod().getName());
                scannedClass.processed(m);
            }
        }
    }
    // service tags
    final List<ClassAnnotation> allServiceTags = new ArrayList<ClassAnnotation>();
    final List<ClassAnnotation> serviceTags = scannedClass.getClassAnnotations(Service.class.getName());
    if (serviceTags.size() > 0) {
        scannedClass.processed(serviceTags);
        allServiceTags.addAll(serviceTags);
    }
    // services tags - class level
    final List<ClassAnnotation> servicesTags = scannedClass.getClassAnnotations(Services.class.getName());
    if (servicesTags.size() > 0) {
        scannedClass.processed(servicesTags);
        for (final ClassAnnotation cad : servicesTags) {
            final ClassAnnotation[] values = (ClassAnnotation[]) cad.getValue("value");
            if (values != null) {
                allServiceTags.addAll(Arrays.asList(values));
            }
        }
    }
    if (allServiceTags.size() > 0) {
        describedClass.add(createService(allServiceTags, scannedClass));
    }
    // references - class level
    final List<ClassAnnotation> referencesClassTags = scannedClass.getClassAnnotations(References.class.getName());
    scannedClass.processed(referencesClassTags);
    for (final ClassAnnotation cad : referencesClassTags) {
        final ClassAnnotation[] values = (ClassAnnotation[]) cad.getValue("value");
        if (values != null) {
            createReferences(Arrays.asList(values), describedClass);
        }
    }
    // reference - class level
    final List<ClassAnnotation> refClassTags = scannedClass.getClassAnnotations(Reference.class.getName());
    scannedClass.processed(refClassTags);
    createReferences(refClassTags, describedClass);
    // reference - field level
    final List<FieldAnnotation> refFieldTags = scannedClass.getFieldAnnotations(Reference.class.getName());
    scannedClass.processed(refFieldTags);
    createReferences(refFieldTags, describedClass);
    // properties - class level
    final List<ClassAnnotation> propsClassTags = scannedClass.getClassAnnotations(Properties.class.getName());
    scannedClass.processed(propsClassTags);
    for (final ClassAnnotation cad : propsClassTags) {
        final ClassAnnotation[] values = (ClassAnnotation[]) cad.getValue("value");
        if (values != null) {
            createProperties(Arrays.asList(values), describedClass);
        }
    }
    // property - class level
    final List<ClassAnnotation> propClassTags = scannedClass.getClassAnnotations(Property.class.getName());
    scannedClass.processed(propClassTags);
    createProperties(propClassTags, describedClass);
    // property - field level
    final List<FieldAnnotation> propFieldTags = scannedClass.getFieldAnnotations(Property.class.getName());
    scannedClass.processed(propFieldTags);
    createProperties(propFieldTags, describedClass);
}
Also used : ComponentDescription(org.apache.felix.scrplugin.description.ComponentDescription) Modified(org.apache.felix.scr.annotations.Modified) Reference(org.apache.felix.scr.annotations.Reference) ArrayList(java.util.ArrayList) ClassAnnotation(org.apache.felix.scrplugin.annotations.ClassAnnotation) Service(org.apache.felix.scr.annotations.Service) Properties(org.apache.felix.scr.annotations.Properties) Services(org.apache.felix.scr.annotations.Services) Activate(org.apache.felix.scr.annotations.Activate) References(org.apache.felix.scr.annotations.References) MethodAnnotation(org.apache.felix.scrplugin.annotations.MethodAnnotation) FieldAnnotation(org.apache.felix.scrplugin.annotations.FieldAnnotation) Component(org.apache.felix.scr.annotations.Component) Property(org.apache.felix.scr.annotations.Property)

Example 2 with ClassAnnotation

use of org.apache.felix.scrplugin.annotations.ClassAnnotation in project felix by apache.

the class SlingAnnotationProcessor method process.

/**
 * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
 */
@Override
public void process(final ScannedClass scannedClass, final ClassDescription describedClass) throws SCRDescriptorFailureException, SCRDescriptorException {
    final List<ClassAnnotation> servlets = scannedClass.getClassAnnotations(SlingServlet.class.getName());
    scannedClass.processed(servlets);
    for (final ClassAnnotation cad : servlets) {
        processSlingServlet(cad, describedClass);
    }
    final List<ClassAnnotation> filters = scannedClass.getClassAnnotations(SlingFilter.class.getName());
    scannedClass.processed(filters);
    for (final ClassAnnotation cad : filters) {
        processSlingFilter(cad, describedClass);
    }
}
Also used : SlingFilter(org.apache.felix.scr.annotations.sling.SlingFilter) ClassAnnotation(org.apache.felix.scrplugin.annotations.ClassAnnotation) SlingServlet(org.apache.felix.scr.annotations.sling.SlingServlet)

Example 3 with ClassAnnotation

use of org.apache.felix.scrplugin.annotations.ClassAnnotation in project sling by apache.

the class SlingHealthCheckProcessor method process.

@Override
public void process(final ScannedClass scannedClass, final ClassDescription classDescription) throws SCRDescriptorException, SCRDescriptorFailureException {
    final List<ClassAnnotation> healthChecks = scannedClass.getClassAnnotations(SlingHealthCheck.class.getName());
    scannedClass.processed(healthChecks);
    for (final ClassAnnotation cad : healthChecks) {
        processHealthCheck(cad, classDescription);
    }
}
Also used : ClassAnnotation(org.apache.felix.scrplugin.annotations.ClassAnnotation)

Example 4 with ClassAnnotation

use of org.apache.felix.scrplugin.annotations.ClassAnnotation in project felix by apache.

the class SCRAnnotationProcessor method createService.

/**
 * Create a service description
 *
 * @param descs
 *            The service annotations.
 * @param scannedClass
 *            The scanned class
 */
private ServiceDescription createService(final List<ClassAnnotation> descs, final ScannedClass scannedClass) {
    final ServiceDescription service = new ServiceDescription(descs.get(0));
    final List<String> listedInterfaces = new ArrayList<String>();
    for (final ClassAnnotation d : descs) {
        if (d.getBooleanValue("serviceFactory", false)) {
            service.setServiceFactory(true);
        }
        if (d.getValue("value") != null) {
            final String[] interfaces = (String[]) d.getValue("value");
            for (String t : interfaces) {
                listedInterfaces.add(t);
            }
        }
    }
    if (listedInterfaces.size() > 0 && !listedInterfaces.contains(AutoDetect.class.getName())) {
        for (final String i : listedInterfaces) {
            service.addInterface(i);
        }
    } else {
        // auto detection
        addInterfaces(service, scannedClass.getScannedClass());
    }
    return service;
}
Also used : AutoDetect(org.apache.felix.scr.annotations.AutoDetect) ServiceDescription(org.apache.felix.scrplugin.description.ServiceDescription) ArrayList(java.util.ArrayList) ClassAnnotation(org.apache.felix.scrplugin.annotations.ClassAnnotation)

Example 5 with ClassAnnotation

use of org.apache.felix.scrplugin.annotations.ClassAnnotation in project felix by apache.

the class DSAnnotationProcessor method process.

/**
 * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
 */
@Override
public void process(final ScannedClass scannedClass, final ClassDescription describedClass) throws SCRDescriptorFailureException, SCRDescriptorException {
    final List<ClassAnnotation> componentTags = scannedClass.getClassAnnotations(Component.class.getName());
    scannedClass.processed(componentTags);
    for (final ClassAnnotation cad : componentTags) {
        this.createComponent(cad, describedClass, scannedClass);
    }
    // search for the component descriptions and use the first one
    final List<ComponentDescription> componentDescs = describedClass.getDescriptions(ComponentDescription.class);
    ComponentDescription found = null;
    if (!componentDescs.isEmpty()) {
        found = componentDescs.get(0);
    }
    if (found != null) {
        final ComponentDescription cd = found;
        // search for methods
        final List<MethodAnnotation> methodTags = scannedClass.getMethodAnnotations(null);
        for (final MethodAnnotation m : methodTags) {
            if (m.getName().equals(Activate.class.getName())) {
                cd.setActivate(m.getAnnotatedMethod().getName());
                scannedClass.processed(m);
            } else if (m.getName().equals(Deactivate.class.getName())) {
                cd.setDeactivate(m.getAnnotatedMethod().getName());
                scannedClass.processed(m);
            } else if (m.getName().equals(Modified.class.getName())) {
                cd.setModified(m.getAnnotatedMethod().getName());
                scannedClass.processed(m);
            } else if (m.getName().equals(Reference.class.getName())) {
                this.processReference(describedClass, m);
                scannedClass.processed(m);
            }
        }
    }
}
Also used : ComponentDescription(org.apache.felix.scrplugin.description.ComponentDescription) Modified(org.osgi.service.component.annotations.Modified) Activate(org.osgi.service.component.annotations.Activate) MethodAnnotation(org.apache.felix.scrplugin.annotations.MethodAnnotation) ClassAnnotation(org.apache.felix.scrplugin.annotations.ClassAnnotation) Component(org.osgi.service.component.annotations.Component)

Aggregations

ClassAnnotation (org.apache.felix.scrplugin.annotations.ClassAnnotation)6 ArrayList (java.util.ArrayList)3 MethodAnnotation (org.apache.felix.scrplugin.annotations.MethodAnnotation)3 FieldAnnotation (org.apache.felix.scrplugin.annotations.FieldAnnotation)2 ComponentDescription (org.apache.felix.scrplugin.description.ComponentDescription)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Activate (org.apache.felix.scr.annotations.Activate)1 AutoDetect (org.apache.felix.scr.annotations.AutoDetect)1 Component (org.apache.felix.scr.annotations.Component)1 Modified (org.apache.felix.scr.annotations.Modified)1 Properties (org.apache.felix.scr.annotations.Properties)1 Property (org.apache.felix.scr.annotations.Property)1 Reference (org.apache.felix.scr.annotations.Reference)1 References (org.apache.felix.scr.annotations.References)1 Service (org.apache.felix.scr.annotations.Service)1 Services (org.apache.felix.scr.annotations.Services)1 SlingFilter (org.apache.felix.scr.annotations.sling.SlingFilter)1 SlingServlet (org.apache.felix.scr.annotations.sling.SlingServlet)1