use of org.apache.felix.scrplugin.description.ReferenceDescription in project felix by apache.
the class ComponentDescriptorIO method generateXML.
/**
* Write the xml for a Component
*
* @param component
* @param contentHandler
* @throws SAXException
*/
private static void generateXML(final String namespace, final DescriptionContainer module, final ComponentContainer container, final ContentHandler contentHandler, final int indent) throws SAXException {
final ComponentDescription component = container.getComponentDescription();
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, COMPONENT_ATTR_ENABLED, component.getEnabled());
IOUtils.addAttribute(ai, COMPONENT_ATTR_IMMEDIATE, component.getImmediate());
IOUtils.addAttribute(ai, ATTR_NAME, component.getName());
IOUtils.addAttribute(ai, COMPONENT_ATTR_FACTORY, component.getFactory());
// attributes new in 1.1
if (module.getOptions().getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal()) {
if (component.getConfigurationPolicy() != null && component.getConfigurationPolicy() != ComponentConfigurationPolicy.OPTIONAL) {
IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name().toLowerCase());
}
IOUtils.addAttribute(ai, COMPONENT_ATTR_ACTIVATE, component.getActivate());
IOUtils.addAttribute(ai, COMPONENT_ATTR_DEACTIVATE, component.getDeactivate());
IOUtils.addAttribute(ai, COMPONENT_ATTR_MODIFIED, component.getModified());
}
// attributes new in 1.2
if (module.getOptions().getSpecVersion().ordinal() >= SpecVersion.VERSION_1_2.ordinal()) {
if (component.getConfigurationPid() != null && !component.getConfigurationPid().equals(component.getName())) {
IOUtils.addAttribute(ai, COMPONENT_ATTR_CONFIGURATION_PID, component.getConfigurationPid());
}
}
IOUtils.indent(contentHandler, indent);
contentHandler.startElement(namespace, ComponentDescriptorIO.COMPONENT, ComponentDescriptorIO.COMPONENT_QNAME, ai);
IOUtils.newline(contentHandler);
for (final PropertyDescription property : container.getProperties().values()) {
generatePropertyXML(property, contentHandler, indent + 1);
}
if (container.getServiceDescription() != null) {
generateServiceXML(container.getServiceDescription(), contentHandler, indent + 1);
}
for (final ReferenceDescription reference : container.getReferences().values()) {
generateReferenceXML(component, module, reference, contentHandler, indent + 1);
}
generateImplementationXML(container, contentHandler, indent + 1);
IOUtils.indent(contentHandler, indent);
contentHandler.endElement(namespace, ComponentDescriptorIO.COMPONENT, ComponentDescriptorIO.COMPONENT_QNAME);
IOUtils.newline(contentHandler);
}
Aggregations