Author: cziegeler
Date: Mon Jul 2 12:21:06 2012
New Revision: 1356203
URL: http://svn.apache.org/viewvc?rev=1356203&view=rev
Log:
FELIX-3550 : Reimplement the SCR Generator
Modified:
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
Modified:
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java?rev=1356203&r1=1356202&r2=1356203&view=diff
==============================================================================
---
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
(original)
+++
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
Mon Jul 2 12:21:06 2012
@@ -204,7 +204,7 @@ public class SlingAnnotationProcessor im
pd2.setName("sling.filter.scope");
pd2.setValue(scope);
pd2.setType(PropertyType.String);
- pd.setPrivate(true);
+ pd2.setPrivate(true);
classDescription.add(pd2);
}
}
Modified:
felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1356203&r1=1356202&r2=1356203&view=diff
==============================================================================
---
felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
(original)
+++
felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
Mon Jul 2 12:21:06 2012
@@ -480,70 +480,73 @@ public class SCRDescriptorGenerator {
final OCD ocd) {
for(final PropertyDescription pd :
current.getDescriptions(PropertyDescription.class)) {
- // metatype - is this property private?
- final boolean isPrivate;
- if ( pd.isPrivate() != null ) {
- isPrivate = pd.isPrivate();
- } else {
- final String name = pd.getName();
- if (org.osgi.framework.Constants.SERVICE_RANKING.equals(name)
- || org.osgi.framework.Constants.SERVICE_PID.equals(name)
- ||
org.osgi.framework.Constants.SERVICE_DESCRIPTION.equals(name)
- || org.osgi.framework.Constants.SERVICE_ID.equals(name)
- || org.osgi.framework.Constants.SERVICE_VENDOR.equals(name)
- || ConfigurationAdmin.SERVICE_BUNDLELOCATION.equals(name)
- || ConfigurationAdmin.SERVICE_FACTORYPID.equals(name) ) {
- isPrivate = true;
- } else {
- isPrivate = false;
- }
- }
- if ( !isPrivate && ocd != null ) {
- final AttributeDefinition ad = new AttributeDefinition();
- ocd.getProperties().add(ad);
- ad.setId(pd.getName());
- ad.setType(pd.getType().name());
+ if ( this.testProperty(current, component.getProperties(), pd,
current == component.getClassDescription()) && ocd != null) {
- if (pd.getLabel() != null ) {
- ad.setName(pd.getLabel());
+ // metatype - is this property private?
+ final boolean isPrivate;
+ if ( pd.isPrivate() != null ) {
+ isPrivate = pd.isPrivate();
} else {
- ad.setName("%" + pd.getName() + ".name");
- }
- if (pd.getDescription() != null ) {
- ad.setDescription(pd.getDescription());
- } else {
- ad.setDescription("%" + pd.getName() + ".description");
+ final String name = pd.getName();
+ if
(org.osgi.framework.Constants.SERVICE_RANKING.equals(name)
+ ||
org.osgi.framework.Constants.SERVICE_PID.equals(name)
+ ||
org.osgi.framework.Constants.SERVICE_DESCRIPTION.equals(name)
+ || org.osgi.framework.Constants.SERVICE_ID.equals(name)
+ ||
org.osgi.framework.Constants.SERVICE_VENDOR.equals(name)
+ ||
ConfigurationAdmin.SERVICE_BUNDLELOCATION.equals(name)
+ || ConfigurationAdmin.SERVICE_FACTORYPID.equals(name)
) {
+ isPrivate = true;
+ } else {
+ isPrivate = false;
+ }
}
+ if ( !isPrivate ) {
+ final AttributeDefinition ad = new AttributeDefinition();
+ ocd.getProperties().add(ad);
+ ad.setId(pd.getName());
+ ad.setType(pd.getType().name());
+
+ if (pd.getLabel() != null ) {
+ ad.setName(pd.getLabel());
+ } else {
+ ad.setName("%" + pd.getName() + ".name");
+ }
+ if (pd.getDescription() != null ) {
+ ad.setDescription(pd.getDescription());
+ } else {
+ ad.setDescription("%" + pd.getName() + ".description");
+ }
- if ( pd.getUnbounded() == PropertyUnbounded.DEFAULT ) {
- ad.setCardinality(pd.getCardinality());
- } else if ( pd.getUnbounded() == PropertyUnbounded.ARRAY ) {
- // unlimited array
- ad.setCardinality(new Integer(Integer.MAX_VALUE));
- } else {
- // unlimited vector
- ad.setCardinality(new Integer(Integer.MIN_VALUE));
- }
+ if ( pd.getUnbounded() == PropertyUnbounded.DEFAULT ) {
+ if ( pd.getCardinality() != 0 ) {
+ ad.setCardinality(pd.getCardinality());
+ }
+ } else if ( pd.getUnbounded() == PropertyUnbounded.ARRAY )
{
+ // unlimited array
+ ad.setCardinality(new Integer(Integer.MAX_VALUE));
+ } else {
+ // unlimited vector
+ ad.setCardinality(new Integer(Integer.MIN_VALUE));
+ }
- ad.setDefaultValue(pd.getValue());
- ad.setDefaultMultiValue(pd.getMultiValue());
+ ad.setDefaultValue(pd.getValue());
+ ad.setDefaultMultiValue(pd.getMultiValue());
- // check options
- final String[] parameters = pd.getOptions();
- if ( parameters != null && parameters.length > 0 ) {
- final Map<String, String> options = new
LinkedHashMap<String, String>();
- for (int j=0; j < parameters.length; j=j+2) {
- final String optionLabel = parameters[j];
- final String optionValue = (j < parameters.length-1) ?
parameters[j+1] : null;
- if (optionValue != null) {
- options.put(optionLabel, optionValue);
+ // check options
+ final String[] parameters = pd.getOptions();
+ if ( parameters != null && parameters.length > 0 ) {
+ final Map<String, String> options = new
LinkedHashMap<String, String>();
+ for (int j=0; j < parameters.length; j=j+2) {
+ final String optionLabel = parameters[j];
+ final String optionValue = (j <
parameters.length-1) ? parameters[j+1] : null;
+ if (optionValue != null) {
+ options.put(optionLabel, optionValue);
+ }
}
+ ad.setOptions(options);
}
- ad.setOptions(options);
}
-
}
- this.testProperty(current, component.getProperties(), pd, current
== component.getClassDescription());
}
}
@@ -574,7 +577,7 @@ public class SCRDescriptorGenerator {
/**
* Test a newly found property
*/
- private void testProperty(final ClassDescription current,
+ private boolean testProperty(final ClassDescription current,
final Map<String, PropertyDescription> allProperties,
final PropertyDescription newProperty,
final boolean isInspectedClass ) {
@@ -588,13 +591,15 @@ public class SCRDescriptorGenerator {
iLog.addError("Duplicate definition for property " +
propName + " in class "
+ current.getDescribedClass().getName(),
current.getSource() );
}
- } else {
- allProperties.put(propName, newProperty);
+ return false;
}
+ allProperties.put(propName, newProperty);
+
} else {
// no name - generate a unique one
allProperties.put(UUID.randomUUID().toString(), newProperty);
}
+ return true;
}
/**