throws SCRDescriptorFailureException, SCRDescriptorException { for (final ScannedAnnotation ad : descs) { final PropertyDescription prop = new PropertyDescription(ad); prop.setType(PropertyType.valueOf(type)); if (values.length == 1) { prop.setValue(values[0]); } else { prop.setMultiValue(values); prop.setMultiValue(newValues); prop.setType(PropertyType.from(fieldAnnotation.getAnnotatedField().getType().getComponentType())); } else { prop.setType(PropertyType.from(value.getClass())); prop.setValue(value.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)); if ( prop.getType() == null ) { prop.setType(PropertyType.String);
/** * Generates a property descriptor of type {@link PropertyType#String} */ private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, final boolean metatype, String annotationName, String propertyDescriptorName) { 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); }
@Override public AbstractDescription clone() { final PropertyDescription cd = new PropertyDescription(this.annotation); cd.setName(this.getName()); cd.setLabel(this.getLabel()); cd.setDescription(this.getDescription()); if ( this.getValue() != null ) { cd.setValue(this.getValue()); } else { cd.setMultiValue(this.getMultiValue()); } cd.setType(this.getType()); cd.setUnbounded(this.getUnbounded()); cd.setCardinality(this.getCardinality()); cd.setPrivate(this.isPrivate()); cd.setOptions(this.getOptions()); return cd; } }
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 ( 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)); 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);
/** Generates a property descriptor of type {@link PropertyType} */ private void generatePropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, final boolean metatype, final String propertyName, final String propertyDescriptorName, PropertyType propertyType, String label, String description, boolean isArray) { final PropertyDescription pd = new PropertyDescription(cad); pd.setName(propertyDescriptorName); pd.setLabel(label); pd.setDescription(description); pd.setType(propertyType); if(isArray) { final String[] values = (String[]) cad.getValue(propertyName); pd.setMultiValue(values); pd.setUnbounded(PropertyUnbounded.ARRAY); pd.setCardinality(Integer.MAX_VALUE); } else { final Object propertyVal = cad.getValue(propertyName); String pdValue = (propertyVal instanceof String) ? (String) propertyVal : propertyVal!=null ? propertyVal.toString() : null; pd.setValue(pdValue); pd.setUnbounded(PropertyUnbounded.DEFAULT); } if (!metatype) { pd.setPrivate(true); } classDescription.add(pd); }
PropertyDescription found = null; for(final PropertyDescription current : existingProps) { if ( current.getName().equals(key) ) { found = current; break; 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()); if ( found.getValue() != null ) { final String[] values = new String[2]; values[0] = found.getValue(); values[1] = value; found.setMultiValue(values); } else { final String[] oldValues = found.getMultiValue(); final String[] newValues = new String[oldValues.length + 1]; System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); newValues[oldValues.length] = value; found.setMultiValue(newValues);
if (property.getName() == null || property.getName().trim().length() == 0) { this.logError(property, "Property name can not be empty."); if (property.getType() != null) { if (this.options.getSpecVersion() == SpecVersion.VERSION_1_0 && property.getType() == PropertyType.Character) { property.setType(PropertyType.Char); && property.getType() == PropertyType.Char) { property.setType(PropertyType.Character); if ( property.getType() == PropertyType.Char || property.getType() == PropertyType.Character ) { if ( property.getValue() != null ) { if ( property.getValue().length() != 1 ) { this.logError(property, "Value is not a character: " + property.getValue()); if ( property.getMultiValue() != null ) { for(final String value : property.getMultiValue() ) { if ( value.length() != 1 ) { this.logError(property, "Value is not a character: " + value);
final String name = pd.getName(); if ( org.osgi.framework.Constants.SERVICE_ID.equals(name) ) { iLog.addError("Class " + current.getDescribedClass().getName() + " is declaring " + if ( pd.isPrivate() != null ) { isPrivate = pd.isPrivate(); } else { if (isPrivateProperty(name) ) { final MetatypeAttributeDefinition ad = new MetatypeAttributeDefinition(); ocd.getProperties().add(ad); ad.setId(pd.getName()); ad.setType(pd.getType().name()); if (pd.getLabel() != null ) { ad.setName(pd.getLabel()); if (pd.getDescription() != null ) { ad.setDescription(pd.getDescription()); if ( pd.getUnbounded() == PropertyUnbounded.DEFAULT ) { if ( pd.getCardinality() != 0 ) { ad.setCardinality(pd.getCardinality()); } else if ( pd.getUnbounded() == PropertyUnbounded.ARRAY ) { ad.setDefaultValue(pd.getValue()); ad.setDefaultMultiValue(pd.getMultiValue());
/** * Add global properties (if not already defined in the component) */ private void processGlobalProperties(final ClassDescription desc, final Map<String, PropertyDescription> allProperties) { // apply pre configured global properties if ( this.options.getProperties() != null ) { for(final Map.Entry<String, String> entry : this.options.getProperties().entrySet()) { 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); } } } }
} else if (localName.equals(PROPERTY) && this.pendingProperty != null) { final String text = this.pendingProperty.getValue(); if (text != null) { final StringTokenizer st = new StringTokenizer(text); while (st.hasMoreTokens()) { values[index] = st.nextToken(); if ( this.pendingProperty.getType() == PropertyType.Char || this.pendingProperty.getType() == PropertyType.Character ) { final int val = Integer.valueOf(values[index]); final Character c = Character.valueOf((char)val); this.pendingProperty.setMultiValue(values);
/** * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int) */ @Override public void characters(char[] ch, int start, int length) throws SAXException { if (this.pendingProperty != null) { final String text = new String(ch, start, length); if (this.pendingProperty.getValue() == null) { this.pendingProperty.setValue(text); } else { this.pendingProperty.setValue(this.pendingProperty.getValue() + text); } } } }
final PropertyDescription pd = new PropertyDescription(cad); pd.setName("service.ranking"); pd.setValue(String.valueOf(order)); pd.setType(PropertyType.Integer); if (metatype) { pd.setPrivate(true); final PropertyDescription pdPattern = new PropertyDescription(cad); pdPattern.setName("sling.filter.pattern"); pdPattern.setValue(pattern); pdPattern.setType(PropertyType.String); if (metatype) { pdPattern.setPrivate(true); 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);
throws SAXException { final AttributesImpl ai = new AttributesImpl(); IOUtils.addAttribute(ai, ATTR_NAME, property.getName()); if ( property.getType() != PropertyType.String && property.getType() != PropertyType.Password) { IOUtils.addAttribute(ai, PROPERTY_ATTR_TYPE, property.getType()); String value = property.getValue(); if ( value != null ) { if ( property.getType() == PropertyType.Character || property.getType() == PropertyType.Char ) { value = String.valueOf((int)value.charAt(0)); if (property.getMultiValue() != null && property.getMultiValue().length > 0) { for (int i = 0; i < property.getMultiValue().length; i++) { IOUtils.indent(contentHandler, indent + 1); value = property.getMultiValue()[i]; if ( property.getType() == PropertyType.Character || property.getType() == PropertyType.Char ) { value = String.valueOf((int)value.charAt(0));