Package org.apache.felix.scrplugin.description

Examples of org.apache.felix.scrplugin.description.PropertyDescription


    /** Generates a property descriptor of type {@link PropertyType#String[]} */
    private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription,
            final boolean metatype, final String propertyName, final String propertyDescriptorName, String label, String description, boolean isArray) {


        final PropertyDescription pd = new PropertyDescription(cad);
        pd.setName(propertyDescriptorName);
        pd.setLabel(label);
        pd.setDescription(description);
        pd.setType(PropertyType.String);

        if(isArray) {
            final String[] values = (String[]) cad.getValue(propertyName);
            pd.setMultiValue(values);
            pd.setUnbounded(PropertyUnbounded.ARRAY);
            pd.setCardinality(Integer.MAX_VALUE);
        } else {
            final String propertyVal = (String) cad.getValue(propertyName);
            pd.setValue(propertyVal);
            pd.setUnbounded(PropertyUnbounded.DEFAULT);
        }
       
        if (!metatype) {
            pd.setPrivate(true);
        }
        classDescription.add(pd);
    }
View Full Code Here


        final String[] values = (String[]) cad.getValue(annotationName);
        if (values == null) {
            return;
        }

        final PropertyDescription pd = new PropertyDescription(cad);
        pd.setName(propertyDescriptorName);
        pd.setMultiValue(values);
        pd.setType(PropertyType.String);
        if (metatype) {
            pd.setPrivate(true);
        }
        classDescription.add(pd);
    }
View Full Code Here

        }

        // generate PropertyDescriptions
        // property order = service.ranking
        final int order = cad.getIntegerValue("order", 0);
        final PropertyDescription pd = new PropertyDescription(cad);
        pd.setName("service.ranking");
        pd.setValue(String.valueOf(order));
        pd.setType(PropertyType.Integer);
        if (metatype) {
            pd.setPrivate(true);
        }
        classDescription.add(pd);

        // property scope
        final String[] scopes;
        final Object val = cad.getValue("scope");
        if ( val != null ) {
            if ( val instanceof String[] ) {
                final String[] arr = (String[])val;
                scopes = new String[arr.length / 2];
                int i = 0;
                int index = 0;
                while ( i < arr.length) {
                    scopes[index] = arr[i];
                    i+=2;
                    index++;
                }
            } else if ( val instanceof String[][] ) {
                final String[][] arr = (String[][])val;
                scopes = new String[arr.length];
                int index = 0;
                while ( index < arr.length) {
                    scopes[index] = arr[index][1];
                    index++;
                }
            } else {
                scopes = new String[] { val.toString()};
            }
        } else {
            scopes = new String[] {SlingFilterScope.REQUEST.getScope()};
        }

        final PropertyDescription pd2 = new PropertyDescription(cad);
        pd2.setName("sling.filter.scope");
        if ( scopes.length == 1 ) {
            pd2.setValue(scopes[0]);
        } else {
            pd2.setMultiValue(scopes);
        }
        pd2.setType(PropertyType.String);
        if (metatype) {
            pd2.setPrivate(true);
        }
        classDescription.add(pd2);
    }
View Full Code Here

     * @throws SCRDescriptorFailureException
     */
    private void createProperties(final List<? extends ScannedAnnotation> descs, final ClassDescription describedClass)
                    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());
                            }
                        }

                    }
                }
            }

            prop.setName(name);
            prop.setLabel(ad.getStringValue("label", null));
            prop.setDescription(ad.getStringValue("description", null));

            // check type
            if ( prop.getType() == null ) {
                prop.setType(PropertyType.String);
            }

            // private
            if ( ad.getValue("propertyPrivate") != null ) {
                prop.setPrivate(ad.getBooleanValue("propertyPrivate", false));
            }

            // cardinality handling
            final PropertyUnbounded pu = PropertyUnbounded
                            .valueOf(ad.getEnumValue("unbounded", PropertyUnbounded.DEFAULT.name()));
            prop.setUnbounded(pu);

            if (pu == PropertyUnbounded.DEFAULT) {
                prop.setCardinality(ad.getIntegerValue("cardinality", 0));
                if (prop.getMultiValue() != null && prop.getCardinality() == 0) {
                    prop.setUnbounded(PropertyUnbounded.ARRAY);
                }
            } else {
                prop.setCardinality(0);
            }

            if ( prop.getValue() != null ) {
                if ( prop.getUnbounded() == PropertyUnbounded.ARRAY || prop.getUnbounded() == PropertyUnbounded.VECTOR ) {
                    prop.setMultiValue(new String[] {prop.getValue()});
                } else if ( prop.getCardinality() < -1 || prop.getCardinality() > 1 ) {
                    prop.setMultiValue(new String[] {prop.getValue()});
                }
            }
            // options
            final ScannedAnnotation[] options = (ScannedAnnotation[])ad.getValue("options");
            if (options != null) {
                final List<String> propertyOptions = new ArrayList<String>();
                for(final ScannedAnnotation po : options) {
                    propertyOptions.add(po.getStringValue("name", ""));
                    propertyOptions.add(po.getStringValue("value", ""));
                }
                prop.setOptions(propertyOptions.toArray(new String[propertyOptions.size()]));
            }

            describedClass.add(prop);
        }
    }
View Full Code Here

        // global properties
        this.processGlobalProperties(desc, container.getProperties());

        // PID handling
        if ( componentDesc.isCreatePid() && !container.getProperties().containsKey(org.osgi.framework.Constants.SERVICE_PID)) {
            final PropertyDescription pid = new PropertyDescription(null);
            pid.setName( org.osgi.framework.Constants.SERVICE_PID );
            pid.setValue( componentDesc.getName() );
            pid.setType(PropertyType.String);

            container.getProperties().put(org.osgi.framework.Constants.SERVICE_PID, pid);
        }

        // check if component has spec version configured but requires a higher one
View Full Code Here

                final String propName = entry.getKey();
                final String value = entry.getValue();
                // check if the service already provides this property
                if ( value != null && !allProperties.containsKey(propName) ) {

                    final PropertyDescription p = new PropertyDescription(null);
                    p.setName(propName);
                    p.setValue(value);
                    p.setType(PropertyType.String);

                    allProperties.put(propName, p);
                }
            }
        }
View Full Code Here

                    // read the property, unless it is the service.pid
                    // property which must not be inherited
                    final String propName = attributes.getValue(ATTR_NAME);
                    if (!org.osgi.framework.Constants.SERVICE_PID.equals(propName)) {
                        final PropertyDescription prop = new PropertyDescription(null);

                        prop.setName(propName);
                        final String type = attributes.getValue(PROPERTY_ATTR_TYPE);
                        if ( type != null ) {
                            try {
                                prop.setType(PropertyType.valueOf(type));
                            } catch (final IllegalArgumentException iae) {
                                iLog.addWarning("Invalid value for attribute type : " + type, this.location);
                            }
                        }
                        if ( prop.getType() == null ) {
                            prop.setType(PropertyType.String);
                        }

                        if (attributes.getValue(PROPERTY_ATTR_VALUE) != null) {
                            if ( prop.getType() == PropertyType.Char || prop.getType() == PropertyType.Character ) {
                                final int val = Integer.valueOf(attributes.getValue(PROPERTY_ATTR_VALUE));
                                final Character c = Character.valueOf((char)val);
                                prop.setValue(c.toString());
                            } else {
                                prop.setValue(attributes.getValue(PROPERTY_ATTR_VALUE));
                            }
                            this.currentClass.add(prop);
                        } else {
                            // hold the property pending as we have a multi value
                            this.pendingProperty = prop;
                        }
                        // check for abstract properties
                        prop.setLabel(attributes.getValue(ATTR_LABEL));
                        prop.setDescription(attributes.getValue(ATTR_DESCRIPTION));
                        final String cardinality = attributes.getValue(ATTR_CARDINALITY);
                        prop.setUnbounded(PropertyUnbounded.DEFAULT);
                        if ( cardinality != null ) {
                            prop.setCardinality(Integer.valueOf(cardinality));
                            if ( prop.getCardinality() == Integer.MAX_VALUE ) {
                                prop.setCardinality(0);
                                prop.setUnbounded(PropertyUnbounded.ARRAY);
                            } else if ( prop.getCardinality() == Integer.MIN_VALUE ) {
                                prop.setCardinality(0);
                                prop.setUnbounded(PropertyUnbounded.VECTOR);
                            }
                        }
                        final String pValue = attributes.getValue(PROPERTY_ATTR_PRIVATE);
                        if (pValue != null) {
                            prop.setPrivate(Boolean.valueOf(pValue));
                        }
                    }

                } else if (localName.equals(PROPERTIES)) {
View Full Code Here

                    final String type = (typeSep == -1 ? PropertyType.String.name() : prefix.substring(typeSep + 1));

                    final PropertyType propType = PropertyType.valueOf(type);
                    // FELIX-4159 : check if this is a multi value prop
                    final List<PropertyDescription> existingProps = describedClass.getDescriptions(PropertyDescription.class);
                    PropertyDescription found = null;
                    for(final PropertyDescription current : existingProps) {
                        if ( current.getName().equals(key) ) {
                            found = current;
                            break;
                        }
                    }
                    if ( found == null ) {
                        final PropertyDescription pd = new PropertyDescription(cad);
                        describedClass.add(pd);
                        pd.setName(key);
                        pd.setValue(value);
                        pd.setType(propType);
                        pd.setUnbounded(PropertyUnbounded.DEFAULT);
                    } else {
                        if ( propType != found.getType() ) {
                            throw new SCRDescriptorException("Multi value property '" + key + "' has different types: "
                                    + found.getType() + " & " + propType,
                                    describedClass.getSource());
View Full Code Here

        final String[] values = (String[]) cad.getValue(annotationName);
        if (values == null) {
            return;
        }

        final PropertyDescription pd = new PropertyDescription(cad);
        pd.setName(propertyDescriptorName);
        pd.setMultiValue(values);
        pd.setType(PropertyType.String);
        if (metatype) {
            pd.setPrivate(true);
        }
        classDescription.add(pd);
    }
View Full Code Here

        }

        // generate PropertyDescriptions
        // property order = service.ranking
        final int order = cad.getIntegerValue("order", 0);
        final PropertyDescription pd = new PropertyDescription(cad);
        pd.setName("service.ranking");
        pd.setValue(String.valueOf(order));
        pd.setType(PropertyType.Integer);
        if (metatype) {
            pd.setPrivate(true);
        }
        classDescription.add(pd);

        // property scope
        final String scope = cad.getEnumValue("scope", SlingFilterScope.REQUEST.getScope());
        final PropertyDescription pd2 = new PropertyDescription(cad);
        pd2.setName("sling.filter.scope");
        pd2.setValue(scope);
        pd2.setType(PropertyType.String);
        if (metatype) {
            pd2.setPrivate(true);
        }
        classDescription.add(pd2);
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.scrplugin.description.PropertyDescription

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.