Search in sources :

Example 6 with ReferenceDescription

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);
}
Also used : PropertyDescription(org.apache.felix.scrplugin.description.PropertyDescription) ComponentDescription(org.apache.felix.scrplugin.description.ComponentDescription) AttributesImpl(org.xml.sax.helpers.AttributesImpl) ReferenceDescription(org.apache.felix.scrplugin.description.ReferenceDescription)

Aggregations

ReferenceDescription (org.apache.felix.scrplugin.description.ReferenceDescription)6 ComponentDescription (org.apache.felix.scrplugin.description.ComponentDescription)2 PropertyDescription (org.apache.felix.scrplugin.description.PropertyDescription)2 Constructor (java.lang.reflect.Constructor)1 FieldAnnotation (org.apache.felix.scrplugin.annotations.FieldAnnotation)1 ScannedAnnotation (org.apache.felix.scrplugin.annotations.ScannedAnnotation)1 ScannedClass (org.apache.felix.scrplugin.annotations.ScannedClass)1 Validator (org.apache.felix.scrplugin.helper.Validator)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1