Search in sources :

Example 6 with Annotation

use of aQute.bnd.osgi.Annotation in project bnd by bndtools.

the class Target method testSimple.

public void testSimple() throws Exception {
    Analyzer analyzer = new Analyzer();
    Clazz clazz = new Clazz(analyzer, "", null);
    ClassDataCollector cd = new ClassDataCollector() {

        @Override
        public void addReference(TypeRef token) {
        }

        @Override
        public void annotation(Annotation annotation) {
            System.err.println("Annotation " + annotation);
        }

        @Override
        public void classBegin(int access, TypeRef name) {
            System.err.println("Class " + name);
        }

        @Override
        public void classEnd() {
            System.err.println("Class end ");
        }

        @Override
        public void extendsClass(TypeRef name) {
            System.err.println("extends " + name);
        }

        @Override
        public void implementsInterfaces(TypeRef[] name) {
            System.err.println("implements " + Arrays.toString(name));
        }

        @Override
        public void parameter(int p) {
            System.err.println("parameter " + p);
        }
    };
    clazz.parseClassFile(getClass().getResourceAsStream("Target.class"), cd);
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) Annotation(aQute.bnd.osgi.Annotation)

Example 7 with Annotation

use of aQute.bnd.osgi.Annotation in project felix by apache.

the class AnnotationCollector method parseMetaTypes.

/**
 * Parse optional meta types annotation attributes
 * @param annotation
 */
private void parseMetaTypes(Annotation annotation, String pid, boolean factory) {
    if (annotation.get("metadata") != null) {
        String propertiesHeading = annotation.get("heading");
        String propertiesDesc = annotation.get("description");
        MetaType.OCD ocd = new MetaType.OCD(pid, propertiesHeading, propertiesDesc);
        for (Object p : (Object[]) annotation.get("metadata")) {
            Annotation property = (Annotation) p;
            String heading = property.get("heading");
            String id = property.get("id");
            String type = parseClassAttrValue(property.get("type"));
            Object[] defaults = (Object[]) property.get("defaults");
            String description = property.get("description");
            Integer cardinality = property.get("cardinality");
            Boolean required = property.get("required");
            MetaType.AD ad = new MetaType.AD(id, type, defaults, heading, description, cardinality, required);
            Object[] optionLabels = property.get("optionLabels");
            Object[] optionValues = property.get("optionValues");
            if (optionLabels == null && optionValues != null || optionLabels != null && optionValues == null || (optionLabels != null && optionValues != null && optionLabels.length != optionValues.length)) {
                throw new IllegalArgumentException("invalid option labels/values specified for property " + id + " in PropertyMetadata annotation from class " + m_currentClassName);
            }
            if (optionValues != null) {
                for (int i = 0; i < optionValues.length; i++) {
                    ad.add(new MetaType.Option(optionValues[i].toString(), optionLabels[i].toString()));
                }
            }
            ocd.add(ad);
        }
        m_metaType.add(ocd);
        MetaType.Designate designate = new MetaType.Designate(pid, factory);
        m_metaType.add(designate);
        m_logger.info("Parsed MetaType Properties from class " + m_componentClassName);
    }
}
Also used : Annotation(aQute.bnd.osgi.Annotation)

Aggregations

Annotation (aQute.bnd.osgi.Annotation)7 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)4 Clazz (aQute.bnd.osgi.Clazz)3 Analyzer (aQute.bnd.osgi.Analyzer)2 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)2 Map (java.util.Map)2 XMLAttribute (aQute.bnd.annotation.xml.XMLAttribute)1 DeclarativeServicesAnnotationError (aQute.bnd.component.error.DeclarativeServicesAnnotationError)1 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)1 Instructions (aQute.bnd.osgi.Instructions)1 Delta (aQute.bnd.service.diff.Delta)1 Type (aQute.bnd.service.diff.Type)1 MultiMap (aQute.lib.collections.MultiMap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Reference (org.osgi.service.component.annotations.Reference)1