IN PROGRESS - issue FELIX-507: properties and service names of extended components not always included
https://issues.apache.org/jira/browse/FELIX-507
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@633462 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 a986d01..977e04b 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
@@ -116,6 +116,14 @@
|| name.equals(ConfigurationAdmin.SERVICE_BUNDLELOCATION)
|| name.equals(ConfigurationAdmin.SERVICE_FACTORYPID);
+ // if this is an abstract component we store the extra info in the property
+ if ( component.isAbstract() ) {
+ prop.setPrivate(isPrivate);
+ prop.setLabel(tag.getNamedParameter(Constants.PROPERTY_LABEL));
+ prop.setDescription(tag.getNamedParameter(Constants.PROPERTY_DESCRIPTION));
+ prop.setCardinality(tag.getNamedParameter(Constants.PROPERTY_CARDINALITY));
+ }
+
// if this is a public property and the component is generating metatype info
// store the information!
if ( !isPrivate && ocd != null ) {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
index 65bae9b..122f162 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
@@ -242,7 +242,7 @@
issues.add(this.getMessage("Service interface information is missing for @scr.service tag"));
}
this.getService().validate(issues, warnings);
- isServiceFactory = Boolean.valueOf(this.getService().getServicefactory()).booleanValue();
+ isServiceFactory = this.getService().isServicefactory();
}
// serviceFactory must not be true for immediate of component factory
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
index 915a26b..1880d01 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
@@ -33,6 +33,11 @@
protected String type;
protected String[] multiValue;
+ protected boolean isPrivate;
+ protected String label;
+ protected String description;
+ protected String cardinality;
+
/**
* Default constructor.
*/
@@ -92,4 +97,37 @@
}
// might want to check type (and value)
}
+
+ public boolean isPrivate() {
+ return isPrivate;
+ }
+
+ public void setPrivate(boolean isPrivate) {
+ this.isPrivate = isPrivate;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCardinality() {
+ return cardinality;
+ }
+
+ public void setCardinality(String cardinality) {
+ this.cardinality = cardinality;
+ }
+
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
index afa7fd0..02a4435 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
@@ -28,7 +28,7 @@
*/
public class Service {
- protected String servicefactory;
+ protected boolean isServicefactory;
/** The list of implemented interfaces. */
protected final List interfaces = new ArrayList();
@@ -40,16 +40,18 @@
// nothing to do
}
- public String getServicefactory() {
- return this.servicefactory;
+ public boolean isServicefactory() {
+ return this.isServicefactory;
}
public void setServicefactory(String servicefactory) {
- this.servicefactory = servicefactory;
+ if ( servicefactory != null ) {
+ this.isServicefactory = Boolean.valueOf(servicefactory).booleanValue();
+ }
}
- public void setServicefactory(boolean servicefactory) {
- this.servicefactory = String.valueOf(servicefactory);
+ public void setServicefactory(boolean flag) {
+ this.isServicefactory = flag;
}
public List getInterfaces() {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
index 432be47..cb69ee2 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
@@ -22,8 +22,7 @@
import java.util.*;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.om.Component;
-import org.apache.felix.scrplugin.om.Reference;
+import org.apache.felix.scrplugin.om.*;
import org.apache.felix.scrplugin.tags.*;
import org.apache.maven.plugin.MojoExecutionException;
@@ -164,7 +163,8 @@
* @see org.apache.felix.scrplugin.tags.JavaClassDescription#getTagByName(java.lang.String)
*/
public JavaTag getTagByName(String name) {
- // TODO Auto-generated method stub
+ // this is only used to retrieve the component tag, so we can ignore it
+ // for classes from other bundles and simply return null
return null;
}
@@ -176,9 +176,21 @@
JavaTag[] javaTags = EMPTY_TAGS;
if ( this.component != null ) {
if ( Constants.SERVICE.equals(name) ) {
-
+ if ( this.component.getService() != null &&
+ this.component.getService().getInterfaces().size() > 0 ) {
+ javaTags = new JavaTag[this.component.getService().getInterfaces().size()];
+ for(int i=0; i<this.component.getService().getInterfaces().size(); i++) {
+ javaTags[i] = new ClassLoaderJavaTag(this, (Interface)this.component.getProperties().get(i),
+ this.component.getService().isServicefactory());
+ }
+ }
} else if ( Constants.PROPERTY.equals(name) ) {
-
+ if ( this.component.getProperties().size() > 0 ) {
+ javaTags = new JavaTag[this.component.getProperties().size()];
+ for(int i=0; i<this.component.getProperties().size(); i++) {
+ javaTags[i] = new ClassLoaderJavaTag(this, (Property)this.component.getProperties().get(i));
+ }
+ }
} else if ( Constants.REFERENCE.equals(name) ) {
if ( this.component.getReferences().size() > 0 ) {
javaTags = new JavaTag[this.component.getReferences().size()];
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
index 1071124..d53bec6 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
@@ -22,10 +22,8 @@
import java.util.Map;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.om.Reference;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.om.*;
+import org.apache.felix.scrplugin.tags.*;
/**
* <code>ClassLoaderJavaTag.java</code>...
@@ -35,10 +33,30 @@
protected final JavaClassDescription description;
protected final Reference reference;
+ protected final Property property;
+ protected final Interface interf;
+ protected boolean isServiceFactory;
public ClassLoaderJavaTag(JavaClassDescription desc, Reference reference) {
- this.reference = reference;
this.description = desc;
+ this.reference = reference;
+ this.interf = null;
+ this.property = null;
+ }
+
+ public ClassLoaderJavaTag(JavaClassDescription desc, Property property) {
+ this.description = desc;
+ this.property = property;
+ this.reference = null;
+ this.interf = null;
+ }
+
+ public ClassLoaderJavaTag(JavaClassDescription desc, Interface i, boolean isSF) {
+ this.interf = i;
+ this.description = desc;
+ this.property = null;
+ this.reference = null;
+ this.isServiceFactory = isSF;
}
/**
@@ -62,6 +80,10 @@
public String getName() {
if ( this.reference != null ) {
return Constants.REFERENCE;
+ } else if ( this.property != null ) {
+ return Constants.PROPERTY;
+ } else if ( this.interf != null ) {
+ return Constants.SERVICE;
}
return null;
}
@@ -91,6 +113,36 @@
map.put(Constants.REFERENCE_TARGET, this.reference.getTarget());
map.put(Constants.REFERENCE_UNDBIND, this.reference.getUnbind());
return map;
+ } else if ( this.property != null ) {
+ final Map map = new HashMap();
+ map.put(Constants.PROPERTY_TYPE, this.property.getType());
+ map.put(Constants.PROPERTY_NAME, this.property.getName());
+ final String[] values = this.property.getMultiValue();
+ if ( values != null ) {
+ for(int i=0; i<values.length;i++) {
+ map.put(Constants.PROPERTY_MULTIVALUE_PREFIX + '.' + i, values[i]);
+ }
+ } else {
+ map.put(Constants.PROPERTY_VALUE, this.property.getValue());
+ }
+ map.put(Constants.PROPERTY_PRIVATE, String.valueOf(property.isPrivate()));
+ if ( this.property.getLabel() != null ) {
+ map.put(Constants.PROPERTY_LABEL, this.property.getLabel());
+ }
+ if ( this.property.getDescription() != null ) {
+ map.put(Constants.PROPERTY_DESCRIPTION, this.property.getDescription());
+ }
+ if ( this.property.getCardinality() != null ) {
+ map.put(Constants.PROPERTY_CARDINALITY, this.property.getCardinality());
+ }
+ return map;
+ } else if ( this.interf != null ) {
+ final Map map = new HashMap();
+ map.put(Constants.SERVICE_INTERFACE, this.interf.getInterfacename());
+ if ( this.isServiceFactory ) {
+ map.put(Constants.SERVICE_FACTORY, "true");
+ }
+ return map;
}
return null;
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index af38c47..c5ab230 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -25,17 +25,9 @@
import javax.xml.transform.TransformerException;
-import org.apache.felix.scrplugin.om.Component;
-import org.apache.felix.scrplugin.om.Components;
-import org.apache.felix.scrplugin.om.Implementation;
-import org.apache.felix.scrplugin.om.Interface;
-import org.apache.felix.scrplugin.om.Property;
-import org.apache.felix.scrplugin.om.Reference;
-import org.apache.felix.scrplugin.om.Service;
+import org.apache.felix.scrplugin.om.*;
import org.apache.maven.plugin.MojoExecutionException;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
+import org.xml.sax.*;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
@@ -158,7 +150,7 @@
final Iterator i = component.getProperties().iterator();
while ( i.hasNext() ) {
final Property property = (Property)i.next();
- generateXML(property, contentHandler);
+ generateXML(property, contentHandler, component.isAbstract());
}
}
if ( component.getReferences() != null ) {
@@ -194,7 +186,7 @@
protected static void generateXML(Service service, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- IOUtils.addAttribute(ai, "servicefactory", service.getServicefactory());
+ IOUtils.addAttribute(ai, "servicefactory", String.valueOf(service.isServicefactory()));
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME, ai);
if ( service.getInterfaces() != null ) {
final Iterator i = service.getInterfaces().iterator();
@@ -226,12 +218,25 @@
* @param contentHandler
* @throws SAXException
*/
- protected static void generateXML(Property property, ContentHandler contentHandler)
+ protected static void generateXML(Property property, ContentHandler contentHandler, boolean isAbstract)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, "name", property.getName());
IOUtils.addAttribute(ai, "type", property.getType());
IOUtils.addAttribute(ai, "value", property.getValue());
+ // we have to write more information if the component is abstract
+ if ( isAbstract ) {
+ IOUtils.addAttribute(ai, "private", String.valueOf(property.isPrivate()));
+ if ( property.getLabel() != null ) {
+ IOUtils.addAttribute(ai, "label", String.valueOf(property.getLabel()));
+ }
+ if ( property.getDescription() != null ) {
+ IOUtils.addAttribute(ai, "description", String.valueOf(property.getDescription()));
+ }
+ if ( property.getCardinality() != null ) {
+ IOUtils.addAttribute(ai, "cardinality", String.valueOf(property.getCardinality()));
+ }
+ }
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.PROPERTY, ComponentDescriptorIO.PROPERTY_QNAME, ai);
if ( property.getMultiValue() != null && property.getMultiValue().length > 0 ) {
// generate a new line first
@@ -343,6 +348,14 @@
// hold the property pending as we have a multi value
this.pendingProperty = prop;
}
+ // check for abstract properties
+ prop.setLabel(attributes.getValue("label"));
+ prop.setDescription(attributes.getValue("description"));
+ prop.setCardinality(attributes.getValue("cardinality"));
+ final String pValue = attributes.getValue("private");
+ if ( pValue != null ) {
+ prop.setPrivate(Boolean.valueOf(pValue).booleanValue());
+ }
} else if (localName.equals("properties")) {