Clean up implementation a little bit and move all property handling code into the property helper class.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@618307 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
index 88b92a1..6194c15 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
@@ -35,6 +35,11 @@
*/
public class PropertyHandler {
+ /** This is a map using the name as the key and {@link PropertyDescription}
+ * as values.
+ */
+ final private Map properties = new HashMap();
+
/**
* @param property
* @param name
@@ -220,7 +225,7 @@
throw new MojoExecutionException("Referencing values from foreign classes not supported yet.");
}
- public void testProperty(Map properties, JavaTag property, String defaultName, JavaField field, boolean isInspectedClass)
+ public void testProperty(JavaTag property, String defaultName, JavaField field, boolean isInspectedClass)
throws MojoExecutionException {
final String propName = this.getPropertyName(property, defaultName);
@@ -232,10 +237,44 @@
throw new MojoExecutionException("Duplicate definition for property " + propName + " in class " + property.getJavaClassDescription().getName());
}
} else {
- properties.put(propName, new Object[] {property, field});
+ properties.put(propName, new PropertyDescription(property, field));
}
}
}
+ public void handleField(JavaField javaField, boolean isInspectedClass)
+ throws MojoExecutionException {
+ final JavaTag tag = javaField.getTagByName(Constants.PROPERTY);
+ if (tag != null) {
+ String defaultName = null;
+ if ( "java.lang.String".equals(javaField.getType()) ) {
+ final String[] initValues = javaField.getInitializationExpression();
+ if ( initValues != null && initValues.length == 1 ) {
+ defaultName = initValues[0];
+ }
+ }
+ this.testProperty(tag, defaultName, javaField, isInspectedClass);
+ }
+ }
+ public void processProperties(final Component component, final OCD ocd)
+ throws MojoExecutionException {
+ final Iterator propIter = properties.entrySet().iterator();
+ while ( propIter.hasNext() ) {
+ final Map.Entry entry = (Map.Entry)propIter.next();
+ final String propName = entry.getKey().toString();
+ final PropertyDescription desc = (PropertyDescription)entry.getValue();
+ this.doProperty(desc.propertyTag, propName, component, ocd, desc.field);
+ }
+ }
+
+ protected static final class PropertyDescription {
+ public final JavaTag propertyTag;
+ public final JavaField field;
+
+ public PropertyDescription(final JavaTag p, final JavaField f) {
+ this.propertyTag = p;
+ this.field = f;
+ }
+ }
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index ad39889..b36bc95 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -224,8 +224,7 @@
boolean inherited = getBoolean(componentTag, Constants.COMPONENT_INHERIT, true);
this.doServices(description.getTagsByName(Constants.SERVICE, inherited), component, description);
- // collect properties and references from class tags and fields
- final Map properties = new HashMap();
+ // collect references from class tags and fields
final Map references = new HashMap();
JavaClassDescription currentDescription = description;
@@ -233,7 +232,7 @@
// properties
final JavaTag[] props = currentDescription.getTagsByName(Constants.PROPERTY, false);
for (int i=0; i < props.length; i++) {
- this.propertyHandler.testProperty(properties, props[i], null, null, description == currentDescription);
+ this.propertyHandler.testProperty(props[i], null, null, description == currentDescription);
}
// references
@@ -250,31 +249,14 @@
this.testReference(references, tag, fields[i].getName(), description == currentDescription);
}
- tag = fields[i].getTagByName(Constants.PROPERTY);
- if (tag != null) {
- String defaultName = null;
- if ( "java.lang.String".equals(fields[i].getType()) ) {
- final String[] initValues = fields[i].getInitializationExpression();
- if ( initValues != null && initValues.length == 1 ) {
- defaultName = initValues[0];
- }
- }
- this.propertyHandler.testProperty(properties, tag, defaultName, fields[i], description == currentDescription);
- }
+ this.propertyHandler.handleField(fields[i], description == currentDescription);
}
currentDescription = currentDescription.getSuperClass();
} while (inherited && currentDescription != null);
// process properties
- final Iterator propIter = properties.entrySet().iterator();
- while ( propIter.hasNext() ) {
- final Map.Entry entry = (Map.Entry)propIter.next();
- final String propName = entry.getKey().toString();
- final Object[] values = (Object[])entry.getValue();
- final JavaTag tag = (JavaTag)values[0];
- this.propertyHandler.doProperty(tag, propName, component, ocd, (JavaField)values[1]);
- }
+ this.propertyHandler.processProperties(component, ocd);
// process references
final Iterator refIter = references.entrySet().iterator();