Close Option tag (fix FELIX-349) and move utility methods to IOUtils.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@570458 13f79535-47bb-0310-9956-ffa450edef68
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 c0d9d8d..b9a1f43 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
@@ -144,10 +144,10 @@
protected static void generateXML(Component component, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "enabled", component.isEnabled());
- addAttribute(ai, "immediate",component.isImmediate());
- addAttribute(ai, "name", component.getName());
- addAttribute(ai, "factory", component.getFactory());
+ IOUtils.addAttribute(ai, "enabled", component.isEnabled());
+ IOUtils.addAttribute(ai, "immediate",component.isImmediate());
+ IOUtils.addAttribute(ai, "name", component.getName());
+ IOUtils.addAttribute(ai, "factory", component.getFactory());
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.COMPONENT, ComponentDescriptorIO.COMPONENT_QNAME, ai);
generateXML(component.getImplementation(), contentHandler);
@@ -180,7 +180,7 @@
protected static void generateXML(Implementation implementation, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "class", implementation.getClassame());
+ IOUtils.addAttribute(ai, "class", implementation.getClassame());
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, ComponentDescriptorIO.IMPLEMENTATION_QNAME, ai);
contentHandler.endElement(NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, ComponentDescriptorIO.IMPLEMENTATION_QNAME);
}
@@ -194,7 +194,7 @@
protected static void generateXML(Service service, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "servicefactory", service.getServicefactory());
+ IOUtils.addAttribute(ai, "servicefactory", service.getServicefactory());
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME, ai);
if ( service.getInterfaces() != null ) {
final Iterator i = service.getInterfaces().iterator();
@@ -215,7 +215,7 @@
protected static void generateXML(Interface interf, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "interface", interf.getInterfacename());
+ IOUtils.addAttribute(ai, "interface", interf.getInterfacename());
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME, ai);
contentHandler.endElement(NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME);
}
@@ -229,15 +229,15 @@
protected static void generateXML(Property property, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "name", property.getName());
- addAttribute(ai, "type", property.getType());
- addAttribute(ai, "value", property.getValue());
+ IOUtils.addAttribute(ai, "name", property.getName());
+ IOUtils.addAttribute(ai, "type", property.getType());
+ IOUtils.addAttribute(ai, "value", property.getValue());
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.PROPERTY, ComponentDescriptorIO.PROPERTY_QNAME, ai);
if ( property.getMultiValue() != null && property.getMultiValue().length > 0 ) {
for(int i=0; i<property.getMultiValue().length; i++) {
- text(contentHandler, " ");
- text(contentHandler, property.getMultiValue()[i]);
- text(contentHandler, "\n");
+ IOUtils.text(contentHandler, " ");
+ IOUtils.text(contentHandler, property.getMultiValue()[i]);
+ IOUtils.text(contentHandler, "\n");
}
}
contentHandler.endElement(NAMESPACE_URI, ComponentDescriptorIO.PROPERTY, ComponentDescriptorIO.PROPERTY_QNAME);
@@ -252,46 +252,18 @@
protected static void generateXML(Reference reference, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "name", reference.getName());
- addAttribute(ai, "interface", reference.getInterfacename());
- addAttribute(ai, "cardinality", reference.getCardinality());
- addAttribute(ai, "policy", reference.getPolicy());
- addAttribute(ai, "target", reference.getTarget());
- addAttribute(ai, "bind", reference.getBind());
- addAttribute(ai, "unbind", reference.getUnbind());
+ IOUtils.addAttribute(ai, "name", reference.getName());
+ IOUtils.addAttribute(ai, "interface", reference.getInterfacename());
+ IOUtils.addAttribute(ai, "cardinality", reference.getCardinality());
+ IOUtils.addAttribute(ai, "policy", reference.getPolicy());
+ IOUtils.addAttribute(ai, "target", reference.getTarget());
+ IOUtils.addAttribute(ai, "bind", reference.getBind());
+ IOUtils.addAttribute(ai, "unbind", reference.getUnbind());
contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME, ai);
contentHandler.endElement(NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME);
}
/**
- * Helper method to add an attribute.
- * This implementation adds a new attribute with the given name
- * and value. Before adding the value is checked for non-null.
- * @param ai The attributes impl receiving the additional attribute.
- * @param name The name of the attribute.
- * @param value The value of the attribute.
- */
- protected static void addAttribute(AttributesImpl ai, String name, Object value) {
- if ( value != null ) {
- ai.addAttribute("", name, name, "CDATA", value.toString());
- }
- }
-
- /**
- * Helper method writing out a string.
- * @param ch
- * @param text
- * @throws SAXException
- */
- protected static void text(ContentHandler ch, String text)
- throws SAXException {
- if ( text != null ) {
- final char[] c = text.toCharArray();
- ch.characters(c, 0, c.length);
- }
- }
-
- /**
* A content handler for parsing the component descriptions.
*
*/
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java
index 40cbe5c..c199090 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java
@@ -375,4 +375,31 @@
}
}
+ /**
+ * Helper method to add an attribute.
+ * This implementation adds a new attribute with the given name
+ * and value. Before adding the value is checked for non-null.
+ * @param ai The attributes impl receiving the additional attribute.
+ * @param name The name of the attribute.
+ * @param value The value of the attribute.
+ */
+ protected static void addAttribute(AttributesImpl ai, String name, Object value) {
+ if ( value != null ) {
+ ai.addAttribute("", name, name, "CDATA", value.toString());
+ }
+ }
+
+ /**
+ * Helper method writing out a string.
+ * @param ch
+ * @param text
+ * @throws SAXException
+ */
+ protected static void text(ContentHandler ch, String text)
+ throws SAXException {
+ if ( text != null ) {
+ final char[] c = text.toCharArray();
+ ch.characters(c, 0, c.length);
+ }
+ }
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
index bfc3058..7e84dac 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
@@ -63,6 +63,9 @@
protected static final String AD_ELEMENT = "AD";
protected static final String AD_ELEMENT_QNAME = PREFIX + ':' + AD_ELEMENT;
+ protected static final String OPTION_ELEMENT = "Option";
+ protected static final String OPTION_ELEMENT_QNAME = PREFIX + ':' + OPTION_ELEMENT;
+
public static void write(MetaData metaData, File file)
throws MojoExecutionException {
try {
@@ -89,7 +92,7 @@
contentHandler.startPrefixMapping(PREFIX, NAMESPACE_URI);
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "localization", metaData.getLocalization());
+ IOUtils.addAttribute(ai, "localization", metaData.getLocalization());
contentHandler.startElement(NAMESPACE_URI, METADATA_ELEMENT, METADATA_ELEMENT_QNAME, ai);
@@ -111,9 +114,9 @@
protected static void generateXML(OCD ocd, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "id", ocd.getId());
- addAttribute(ai, "name", ocd.getName());
- addAttribute(ai, "description", ocd.getDescription());
+ IOUtils.addAttribute(ai, "id", ocd.getId());
+ IOUtils.addAttribute(ai, "name", ocd.getName());
+ IOUtils.addAttribute(ai, "description", ocd.getDescription());
contentHandler.startElement(NAMESPACE_URI, OCD_ELEMENT, OCD_ELEMENT_QNAME, ai);
final Iterator i = ocd.getProperties().iterator();
@@ -128,8 +131,8 @@
protected static void generateXML(AttributeDefinition ad, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "id", ad.getId());
- addAttribute(ai, "type", ad.getType());
+ IOUtils.addAttribute(ai, "id", ad.getId());
+ IOUtils.addAttribute(ai, "type", ad.getType());
if ( ad.getDefaultMultiValue() != null ) {
final StringBuffer buf = new StringBuffer();
for(int i=0; i<ad.getDefaultMultiValue().length; i++) {
@@ -138,22 +141,23 @@
}
buf.append(ad.getDefaultMultiValue()[i]);
}
- addAttribute(ai, "default", buf);
+ IOUtils.addAttribute(ai, "default", buf);
} else {
- addAttribute(ai, "default", ad.getDefaultValue());
+ IOUtils.addAttribute(ai, "default", ad.getDefaultValue());
}
- addAttribute(ai, "name", ad.getName());
- addAttribute(ai, "description", ad.getDescription());
- addAttribute(ai, "cardinality", ad.getCardinality());
+ IOUtils.addAttribute(ai, "name", ad.getName());
+ IOUtils.addAttribute(ai, "description", ad.getDescription());
+ IOUtils.addAttribute(ai, "cardinality", ad.getCardinality());
contentHandler.startElement(NAMESPACE_URI, AD_ELEMENT, AD_ELEMENT_QNAME, ai);
if (ad.getOptions() != null) {
for (Iterator oi=ad.getOptions().entrySet().iterator(); oi.hasNext(); ) {
final Map.Entry entry = (Map.Entry) oi.next();
ai.clear();
- addAttribute(ai, "value", String.valueOf(entry.getKey()));
- addAttribute(ai, "label", String.valueOf(entry.getValue()));
- contentHandler.startElement(NAMESPACE_URI, "Option", PREFIX + ':' + "Option", ai);
+ IOUtils.addAttribute(ai, "value", String.valueOf(entry.getKey()));
+ IOUtils.addAttribute(ai, "label", String.valueOf(entry.getValue()));
+ contentHandler.startElement(NAMESPACE_URI, OPTION_ELEMENT, OPTION_ELEMENT_QNAME, ai);
+ contentHandler.endElement(NAMESPACE_URI, OPTION_ELEMENT, OPTION_ELEMENT_QNAME);
}
}
@@ -163,7 +167,7 @@
protected static void generateXML(Designate designate, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "pid", designate.getPid());
+ IOUtils.addAttribute(ai, "pid", designate.getPid());
contentHandler.startElement(NAMESPACE_URI, DESIGNATE_ELEMENT, DESIGNATE_ELEMENT_QNAME, ai);
generateXML(designate.getObject(), contentHandler);
@@ -174,23 +178,8 @@
protected static void generateXML(MTObject obj, ContentHandler contentHandler)
throws SAXException {
final AttributesImpl ai = new AttributesImpl();
- addAttribute(ai, "ocdref", obj.getOcdref());
+ IOUtils.addAttribute(ai, "ocdref", obj.getOcdref());
contentHandler.startElement(NAMESPACE_URI, OBJECT_ELEMENT, OBJECT_ELEMENT_QNAME, ai);
contentHandler.endElement(NAMESPACE_URI, OBJECT_ELEMENT, OBJECT_ELEMENT_QNAME);
}
-
- /**
- * Helper method to add an attribute.
- * This implementation adds a new attribute with the given name
- * and value. Before adding the value is checked for non-null.
- * @param ai The attributes impl receiving the additional attribute.
- * @param name The name of the attribute.
- * @param value The value of the attribute.
- */
- protected static void addAttribute(AttributesImpl ai, String name, Object value) {
- if ( value != null ) {
- ai.addAttribute("", name, name, "CDATA", value.toString());
- }
- }
-
}