Author: cziegeler
Date: Mon Feb 4 07:47:16 2008
New Revision: 618307
URL: http://svn.apache.org/viewvc?rev=618307&view=rev
Log:
Clean up implementation a little bit and move all property handling code into
the property helper class.
Modified:
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
Modified:
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java?rev=618307&r1=618306&r2=618307&view=diff
==============================================================================
---
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
(original)
+++
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
Mon Feb 4 07:47:16 2008
@@ -35,6 +35,11 @@
*/
public class PropertyHandler {
+ /** This is a map using the name as the key and [EMAIL PROTECTED]
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;
+ }
+ }
}
Modified:
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java?rev=618307&r1=618306&r2=618307&view=diff
==============================================================================
---
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
(original)
+++
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
Mon Feb 4 07:47:16 2008
@@ -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();