Package org.apache.felix.scrplugin.annotations

Examples of org.apache.felix.scrplugin.annotations.FieldAnnotation


    private void createReferences(final List<? extends ScannedAnnotation> descs, final ClassDescription describedClass) {
        for (final ScannedAnnotation ad : descs) {
            final ReferenceDescription ref = new ReferenceDescription(ad);

            // check for field annotation
            final FieldAnnotation fieldAnnotation;
            if (ad instanceof FieldAnnotation) {
                fieldAnnotation = (FieldAnnotation) ad;
                ref.setField(fieldAnnotation.getAnnotatedField());
            } else {
                fieldAnnotation = null;
            }

            ref.setName(ad.getStringValue("name",
                            (fieldAnnotation != null ? fieldAnnotation.getAnnotatedField().getName() : null)));
            String defaultInterfaceName = null;
            if ( fieldAnnotation != null ) {
                if ( fieldAnnotation.getAnnotatedField().getType().isArray() ) {
                    defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getComponentType().getName();
                } else {
                    defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getName();
                }
            }
            ref.setInterfaceName(ad.getStringValue("referenceInterface", defaultInterfaceName));
            ref.setTarget(ad.getStringValue("target", null));
            ref.setCardinality(ReferenceCardinality.valueOf(ad.getEnumValue("cardinality",
View Full Code Here


                    throws SCRDescriptorFailureException, SCRDescriptorException {
        for (final ScannedAnnotation ad : descs) {
            final PropertyDescription prop = new PropertyDescription(ad);

            // check for field annotation
            final FieldAnnotation fieldAnnotation;
            if (ad instanceof FieldAnnotation) {
                fieldAnnotation = (FieldAnnotation) ad;
            } else {
                fieldAnnotation = null;
            }

            // Detect values from annotation
            String type = null;
            String[] values = null;
            int index = 0;
            while (type == null && index < PROPERTY_VALUE_PROCESSING.length) {
                final String propType = PROPERTY_VALUE_PROCESSING[index];
                final String propName = PROPERTY_VALUE_PROCESSING[index + 1];
                final Object propValue = ad.getValue(propName);
                if (propValue != null && propValue.getClass().isArray()) {
                    type = propType;
                    values = new String[Array.getLength(propValue)];
                    for (int i = 0; i < values.length; i++) {
                        values[i] = Array.get(propValue, i).toString();
                    }
                }
                index += 2;
            }

            String name = ad.getStringValue("name", null);

            if (values != null) {
                prop.setType(PropertyType.valueOf(type));
                if (values.length == 1) {
                    prop.setValue(values[0]);
                } else {
                    prop.setMultiValue(values);
                }
                if ( name == null ) {
                    final Object value = fieldAnnotation.getAnnotatedFieldValue();
                    if (value != null) {
                        name = value.toString();
                    }
                }

            } else if (fieldAnnotation != null) {
                // Detect values from field
                if ( name != null ) {
                    final Object value = fieldAnnotation.getAnnotatedFieldValue();
                    if (value != null) {
                        if (value.getClass().isArray()) {
                            final String[] newValues = new String[Array.getLength(value)];
                            for (int i = 0; i < newValues.length; i++) {
                                newValues[i] = Array.get(value, i).toString();
                            }
                            prop.setMultiValue(newValues);
                            prop.setType(PropertyType.from(fieldAnnotation.getAnnotatedField().getType().getComponentType()));
                        } else {
                            prop.setType(PropertyType.from(value.getClass()));
                            prop.setValue(value.toString());
                        }
                    }
                } else {
                    if ( Modifier.isStatic(fieldAnnotation.getAnnotatedField().getModifiers()) ) {
                        final Object value = fieldAnnotation.getAnnotatedFieldValue();
                        if (value != null) {
                            name = value.toString();
                        }
                    } else {
                        // non static, no name, no value (FELIX-4393)
                        name = fieldAnnotation.getAnnotatedField().getName();
                        final Object value = fieldAnnotation.getAnnotatedFieldValue();
                        if (value != null) {
                            if (value.getClass().isArray()) {
                                final String[] newValues = new String[Array.getLength(value)];
                                for (int i = 0; i < newValues.length; i++) {
                                    newValues[i] = Array.get(value, i).toString();
                                }
                                prop.setMultiValue(newValues);
                                prop.setType(PropertyType.from(fieldAnnotation.getAnnotatedField().getType().getComponentType()));
                            } else {
                                prop.setType(PropertyType.from(value.getClass()));
                                prop.setValue(value.toString());
                            }
                        }
View Full Code Here

        final ScannedAnnotation a;
        if (annotatedObject instanceof Method) {
            a = new MethodAnnotation(name, values, (Method) annotatedObject);
            ((Method) annotatedObject).setAccessible(true);
        } else if (annotatedObject instanceof Field) {
            a = new FieldAnnotation(name, values, (Field) annotatedObject);
            ((Field) annotatedObject).setAccessible(true);
        } else {
            a = new ClassAnnotation(name, values);
        }
        descriptions.add(a);
View Full Code Here

TOP

Related Classes of org.apache.felix.scrplugin.annotations.FieldAnnotation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.