FELIX-3641 : Option to generate separate descriptor files
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1379338 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
index b213968..4119428 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
@@ -42,11 +42,10 @@
import org.apache.felix.scrplugin.helper.ComponentContainer;
import org.apache.felix.scrplugin.helper.DescriptionContainer;
import org.apache.felix.scrplugin.helper.IssueLog;
+import org.apache.felix.scrplugin.helper.MetatypeAttributeDefinition;
+import org.apache.felix.scrplugin.helper.MetatypeContainer;
import org.apache.felix.scrplugin.helper.StringUtils;
import org.apache.felix.scrplugin.helper.Validator;
-import org.apache.felix.scrplugin.om.metatype.AttributeDefinition;
-import org.apache.felix.scrplugin.om.metatype.Designate;
-import org.apache.felix.scrplugin.om.metatype.OCD;
import org.apache.felix.scrplugin.xml.ComponentDescriptorIO;
import org.apache.felix.scrplugin.xml.MetaTypeIO;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -289,11 +288,11 @@
final ComponentContainer container = new ComponentContainer(desc, componentDesc);
// Create metatype (if required)
- final OCD ocd;
+ final MetatypeContainer ocd;
if ( !componentDesc.isAbstract() && componentDesc.isCreateMetatype() ) {
// OCD
- ocd = new OCD();
- container.setOCD( ocd );
+ ocd = new MetatypeContainer();
+ container.setMetatypeContainer( ocd );
ocd.setId( componentDesc.getName() );
if ( componentDesc.getLabel() != null ) {
ocd.setName( componentDesc.getLabel() );
@@ -306,15 +305,10 @@
ocd.setDescription( "%" + componentDesc.getName() + ".description");
}
- // Designate
- final Designate designate = new Designate();
- container.setDesignate( designate );
- designate.setPid( componentDesc.getName() );
-
// Factory pid
if ( componentDesc.isSetMetatypeFactoryPid() ) {
if ( componentDesc.getFactory() == null ) {
- designate.setFactoryPid( componentDesc.getName() );
+ ocd.setFactoryPid( componentDesc.getName() );
} else {
iLog.addWarning( "Component factory " + componentDesc.getName()
+ " should not set metatype factory pid.", desc.getSource() );
@@ -424,7 +418,7 @@
private void processProperties(
final ClassDescription current,
final ComponentContainer component,
- final OCD ocd) {
+ final MetatypeContainer ocd) {
for(final PropertyDescription pd : current.getDescriptions(PropertyDescription.class)) {
if ( this.testProperty(current, component.getProperties(), pd, current == component.getClassDescription()) && ocd != null) {
@@ -448,7 +442,7 @@
}
}
if ( !isPrivate ) {
- final AttributeDefinition ad = new AttributeDefinition();
+ final MetatypeAttributeDefinition ad = new MetatypeAttributeDefinition();
ocd.getProperties().add(ad);
ad.setId(pd.getName());
ad.setType(pd.getType().name());
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java
index cf524dc..4dc069e 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java
@@ -26,8 +26,6 @@
import org.apache.felix.scrplugin.description.PropertyDescription;
import org.apache.felix.scrplugin.description.ReferenceDescription;
import org.apache.felix.scrplugin.description.ServiceDescription;
-import org.apache.felix.scrplugin.om.metatype.Designate;
-import org.apache.felix.scrplugin.om.metatype.OCD;
/**
@@ -56,11 +54,8 @@
/** All properties. */
private final Map<String, PropertyDescription> allProperties = new LinkedHashMap<String, PropertyDescription>();
- /** Metatype: OCD. */
- private OCD ocd;
-
- /** Metatype: Designate. */
- private Designate designate;
+ /** Metatype container. */
+ private MetatypeContainer metatype;
/**
* Create a new component container
@@ -132,19 +127,11 @@
+ allProperties + "]";
}
- public OCD getOCD() {
- return ocd;
+ public MetatypeContainer getMetatypeContainer() {
+ return this.metatype;
}
- public void setOCD(final OCD ocd) {
- this.ocd = ocd;
- }
-
- public Designate getDesignate() {
- return designate;
- }
-
- public void setDesignate(final Designate designate) {
- this.designate = designate;
+ public void setMetatypeContainer(final MetatypeContainer ocd) {
+ this.metatype = ocd;
}
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/MetatypeAttributeDefinition.java
similarity index 85%
rename from scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java
rename to scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/MetatypeAttributeDefinition.java
index c32ccb1..0d096fe 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/MetatypeAttributeDefinition.java
@@ -16,29 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.scrplugin.om.metatype;
+package org.apache.felix.scrplugin.helper;
import java.util.Map;
-public class AttributeDefinition {
+public class MetatypeAttributeDefinition {
- public static final String DEFAULT_TYPE = "String";
+ private static final String DEFAULT_TYPE = "String";
- protected String id;
+ private String id;
- protected String type = DEFAULT_TYPE;
+ private String type = DEFAULT_TYPE;
- protected String defaultValue;
+ private String defaultValue;
- protected String name;
+ private String name;
- protected String[] defaultMultiValue;
+ private String[] defaultMultiValue;
- protected String description;
+ private String description;
- protected Integer cardinality;
+ private Integer cardinality;
- protected Map<String, String> options;
+ private Map<String, String> options;
public String getId() {
return this.id;
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/MetatypeContainer.java
similarity index 72%
rename from scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java
rename to scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/MetatypeContainer.java
index f167d49..08c18b9 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/MetatypeContainer.java
@@ -16,20 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.scrplugin.om.metatype;
+package org.apache.felix.scrplugin.helper;
import java.util.ArrayList;
import java.util.List;
-public class OCD {
+public class MetatypeContainer {
- protected String id;
+ private String id;
- protected String name;
+ private String name;
- protected String description;
+ private String description;
- protected List<AttributeDefinition> properties = new ArrayList<AttributeDefinition>();
+ private String factoryPid;
+
+ private final List<MetatypeAttributeDefinition> properties = new ArrayList<MetatypeAttributeDefinition>();
public String getId() {
return this.id;
@@ -55,11 +57,15 @@
this.description = description;
}
- public List<AttributeDefinition> getProperties() {
+ public List<MetatypeAttributeDefinition> getProperties() {
return this.properties;
}
- public void setProperties(List<AttributeDefinition> properties) {
- this.properties = properties;
+ public String getFactoryPid() {
+ return this.factoryPid;
+ }
+
+ public void setFactoryPid(String pid) {
+ this.factoryPid = pid;
}
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/Designate.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/Designate.java
deleted file mode 100644
index b2d86c4..0000000
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/metatype/Designate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.scrplugin.om.metatype;
-
-public class Designate {
-
- protected String pid;
-
- protected String factoryPid;
-
- public String getPid() {
- return this.pid;
- }
-
- public void setPid(String pid) {
- this.pid = pid;
- }
-
- public String getFactoryPid() {
- return this.factoryPid;
- }
-
- public void setFactoryPid(String pid) {
- this.factoryPid = pid;
- }
-}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
index 9d788ac..7fbe7dd 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
@@ -29,10 +29,9 @@
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.helper.ComponentContainer;
import org.apache.felix.scrplugin.helper.DescriptionContainer;
+import org.apache.felix.scrplugin.helper.MetatypeAttributeDefinition;
+import org.apache.felix.scrplugin.helper.MetatypeContainer;
import org.apache.felix.scrplugin.helper.StringUtils;
-import org.apache.felix.scrplugin.om.metatype.AttributeDefinition;
-import org.apache.felix.scrplugin.om.metatype.Designate;
-import org.apache.felix.scrplugin.om.metatype.OCD;
import org.osgi.service.metatype.MetaTypeService;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -77,7 +76,7 @@
throws SCRDescriptorException {
int metatypeCount = 0;
for(final ComponentContainer component : module.getComponents()) {
- if ( component.getOCD() != null ) {
+ if ( component.getMetatypeContainer() != null ) {
metatypeCount++;
}
}
@@ -134,9 +133,9 @@
IOUtils.newline(contentHandler);
for(final ComponentContainer comp : metaData.getComponents()) {
- if ( comp.getOCD() != null ) {
- generateXML(comp.getOCD(), contentHandler);
- generateXML(comp.getDesignate(), contentHandler);
+ if ( comp.getMetatypeContainer() != null ) {
+ generateOCDXML(comp.getMetatypeContainer(), contentHandler);
+ generateDesignateXML(comp.getMetatypeContainer(), contentHandler);
}
}
@@ -147,7 +146,7 @@
contentHandler.endDocument();
}
- private static void generateXML(OCD ocd, ContentHandler contentHandler)
+ private static void generateOCDXML(final MetatypeContainer ocd, final ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, "id", ocd.getId());
@@ -158,10 +157,10 @@
if ( ocd.getProperties().size() > 0 ) {
IOUtils.newline(contentHandler);
- final Iterator<AttributeDefinition> i = ocd.getProperties().iterator();
+ final Iterator<MetatypeAttributeDefinition> i = ocd.getProperties().iterator();
while ( i.hasNext() ) {
- final AttributeDefinition ad = i.next();
- generateXML(ad, contentHandler);
+ final MetatypeAttributeDefinition ad = i.next();
+ generateAttributeXML(ad, contentHandler);
}
IOUtils.indent(contentHandler, 1);
}
@@ -170,7 +169,7 @@
IOUtils.newline(contentHandler);
}
- private static void generateXML(AttributeDefinition ad, ContentHandler contentHandler)
+ private static void generateAttributeXML(final MetatypeAttributeDefinition ad, final ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, "id", ad.getId());
@@ -212,10 +211,10 @@
IOUtils.newline(contentHandler);
}
- private static void generateXML(final Designate designate, final ContentHandler contentHandler)
+ private static void generateDesignateXML(final MetatypeContainer designate, final ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- IOUtils.addAttribute(ai, "pid", designate.getPid());
+ IOUtils.addAttribute(ai, "pid", designate.getId());
IOUtils.addAttribute(ai, "factoryPid", designate.getFactoryPid());
IOUtils.indent(contentHandler, 1);
contentHandler.startElement(INNER_NAMESPACE_URI, DESIGNATE_ELEMENT, DESIGNATE_ELEMENT_QNAME, ai);
@@ -228,10 +227,10 @@
IOUtils.newline(contentHandler);
}
- private static void generateObjectXML(final Designate obj, final ContentHandler contentHandler)
+ private static void generateObjectXML(final MetatypeContainer obj, final ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- IOUtils.addAttribute(ai, "ocdref", obj.getPid());
+ IOUtils.addAttribute(ai, "ocdref", obj.getId());
IOUtils.indent(contentHandler, 2);
contentHandler.startElement(INNER_NAMESPACE_URI, OBJECT_ELEMENT, OBJECT_ELEMENT_QNAME, ai);
contentHandler.endElement(INNER_NAMESPACE_URI, OBJECT_ELEMENT, OBJECT_ELEMENT_QNAME);