Search in sources :

Example 1 with Tocd

use of org.eclipse.kura.core.configuration.metatype.Tocd in project kura by eclipse.

the class XmlJavaComponentConfigurationsMapper method marshallConfiguration.

// 
// Marshaller's private methods
// 
private Element marshallConfiguration(ComponentConfigurationImpl config) throws Exception {
    // get ComponentConfigurationImpl Object data
    String configPid = config.getPid();
    Map<String, Object> configProperty = config.getConfigurationProperties();
    Tocd configOCD = config.getDefinition();
    // create configuration element
    Element configurationElement = this.mashallDoc.createElement(ESF_NAMESPACE + ":" + CONFIGURATIONS_CONFIGURATION);
    Attr propertiesAttribute = this.mashallDoc.createAttribute(CONFIGURATION_PID);
    propertiesAttribute.setNodeValue(configPid);
    configurationElement.setAttributeNode(propertiesAttribute);
    // Add OCD node and marshall definitions
    if (configOCD != null) {
        Element ocd = new XmlJavaMetadataMapper().marshal(this.mashallDoc, configOCD);
        configurationElement.appendChild(ocd);
    }
    // Add properties Node and marshall properties
    if (configProperty != null) {
        Element properties = this.mashallDoc.createElement(ESF_NAMESPACE + ":" + PROPERTIES);
        marshallProperties(configProperty, properties);
        configurationElement.appendChild(properties);
    }
    return configurationElement;
}
Also used : Element(org.w3c.dom.Element) Tocd(org.eclipse.kura.core.configuration.metatype.Tocd) Attr(org.w3c.dom.Attr)

Example 2 with Tocd

use of org.eclipse.kura.core.configuration.metatype.Tocd in project kura by eclipse.

the class XmlJavaMetadataMapper method unmarshal.

@SuppressWarnings("unchecked")
@Override
public <T> T unmarshal(Document doc) {
    Element metadata = doc.getDocumentElement();
    Tmetadata tMetadata = parseMetadataAttributes(metadata);
    NodeList metadataChilds = metadata.getChildNodes();
    Element[] metadataChildsArray = getElementNodes(metadataChilds);
    for (Element node : metadataChildsArray) {
        String localName = node.getNodeName();
        if (localName.equals("OCD")) {
            Tocd tocd = parseOCD(node);
            tMetadata.setOCD(tocd);
        } else if (localName.equals("Designate")) {
            Tdesignate tDesignate = parseDesignate(node);
            tMetadata.setDesignate(tDesignate);
        }
    }
    return (T) tMetadata;
}
Also used : Tmetadata(org.eclipse.kura.core.configuration.metatype.Tmetadata) Tdesignate(org.eclipse.kura.core.configuration.metatype.Tdesignate) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Tocd(org.eclipse.kura.core.configuration.metatype.Tocd)

Example 3 with Tocd

use of org.eclipse.kura.core.configuration.metatype.Tocd in project kura by eclipse.

the class XmlJavaMetadataMapper method marshal.

// 
// Public methods
// 
@Override
public Element marshal(Document doc, Object o) throws Exception {
    this.mashallDoc = doc;
    if (o instanceof Tocd) {
        Tocd configOCD = (Tocd) o;
        String ocdName = configOCD.getName();
        String ocdDescription = configOCD.getDescription();
        String ocdID = configOCD.getId();
        List<Icon> ocdIcons = configOCD.getIcon();
        List<AD> ocdADs = configOCD.getAD();
        configOCD.getAny();
        configOCD.getOtherAttributes();
        Element ocd = this.mashallDoc.createElement(OCD_NAMESPACE + ":" + METADATA_OCD);
        if (ocdName != null && !ocdName.trim().isEmpty()) {
            Attr ocdAttrName = this.mashallDoc.createAttribute(METADATA_OCD_NAME);
            ocdAttrName.setNodeValue(ocdName);
            ocd.setAttributeNode(ocdAttrName);
        }
        if (ocdDescription != null && !ocdDescription.trim().isEmpty()) {
            Attr ocdAttrDescription = this.mashallDoc.createAttribute(METADATA_OCD_DESCRIPTION);
            ocdAttrDescription.setNodeValue(ocdDescription);
            ocd.setAttributeNode(ocdAttrDescription);
        }
        if (ocdID != null && !ocdID.trim().isEmpty()) {
            Attr ocdAttrId = this.mashallDoc.createAttribute(METADATA_OCD_ID);
            ocdAttrId.setNodeValue(ocdID);
            ocd.setAttributeNode(ocdAttrId);
        }
        if (ocdADs != null) {
            for (AD ocdAD : ocdADs) {
                Element ad = this.mashallDoc.createElement(OCD_NAMESPACE + ":" + METADATA_AD);
                marshallAD(ocdAD, ad);
                ocd.appendChild(ad);
            }
        }
        if (ocdIcons != null) {
            for (Icon ocdIcon : ocdIcons) {
                Element icon = this.mashallDoc.createElement(OCD_NAMESPACE + ":" + METADATA_ICON);
                marshallIcon(ocdIcon, icon);
                ocd.appendChild(icon);
            }
        }
        return ocd;
    }
    return null;
}
Also used : AD(org.eclipse.kura.configuration.metatype.AD) Element(org.w3c.dom.Element) Tocd(org.eclipse.kura.core.configuration.metatype.Tocd) Icon(org.eclipse.kura.configuration.metatype.Icon) Attr(org.w3c.dom.Attr)

Example 4 with Tocd

use of org.eclipse.kura.core.configuration.metatype.Tocd in project kura by eclipse.

the class XmlJavaMetadataMapper method parseOCD.

private Tocd parseOCD(Element ocd) {
    String ocdName = ocd.getAttribute(METADATA_OCD_NAME);
    String ocdID = ocd.getAttribute(METADATA_OCD_ID);
    String ocdDescription = ocd.getAttribute(METADATA_OCD_DESCRIPTION);
    Tocd tocd = new Tocd();
    if (ocdID != null && !ocdID.trim().isEmpty()) {
        tocd.setId(ocdID);
    }
    if (ocdName != null && !ocdName.trim().isEmpty()) {
        tocd.setName(ocdName);
    }
    if (ocdDescription != null && !ocdDescription.trim().isEmpty()) {
        tocd.setDescription(ocdDescription);
    }
    NodeList ocdChilds = ocd.getChildNodes();
    Element[] ocdChildElements = getElementNodes(ocdChilds);
    for (Element node : ocdChildElements) {
        String localName = node.getNodeName();
        if (localName.equals(METADATA_ICON)) {
            // parse Icon
            Ticon tIcon = parseIcon(node);
            tocd.setIcon(tIcon);
        } else if (localName.equals(METADATA_AD)) {
            // parse AD
            Tad tad = parseAD(node);
            tocd.addAD(tad);
        }
    }
    return tocd;
}
Also used : Tad(org.eclipse.kura.core.configuration.metatype.Tad) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Tocd(org.eclipse.kura.core.configuration.metatype.Tocd) Ticon(org.eclipse.kura.core.configuration.metatype.Ticon)

Example 5 with Tocd

use of org.eclipse.kura.core.configuration.metatype.Tocd in project kura by eclipse.

the class ComponentUtil method readObjectClassDefinition.

/**
 * Returned the ObjectClassDefinition as parsed from the XML file.
 * The returned OCD is just an object representation of the OCD
 * element contained in the XML MetaData file and it does not
 * contain any extra post-processing of the loaded information.
 *
 * @param ctx
 * @param pid
 *            ID of the service whose OCD should be loaded
 * @return
 * @throws IOException
 * @throws JAXBException
 * @throws XMLStreamException
 * @throws FactoryConfigurationError
 */
public static Tocd readObjectClassDefinition(Bundle bundle, String pid) throws IOException, Exception, XMLStreamException, FactoryConfigurationError {
    Tocd ocd = null;
    StringBuilder sbMetatypeXmlName = new StringBuilder();
    sbMetatypeXmlName.append("OSGI-INF/metatype/").append(pid).append(".xml");
    String metatypeXmlName = sbMetatypeXmlName.toString();
    String metatypeXml = IOUtil.readResource(bundle, metatypeXmlName);
    if (metatypeXml != null) {
        Tmetadata metaData = XmlUtil.unmarshal(metatypeXml, Tmetadata.class);
        if (metaData.getOCD() != null && metaData.getOCD().size() > 0) {
            ocd = (Tocd) metaData.getOCD().get(0);
        }
    }
    return ocd;
}
Also used : Tmetadata(org.eclipse.kura.core.configuration.metatype.Tmetadata) Tocd(org.eclipse.kura.core.configuration.metatype.Tocd)

Aggregations

Tocd (org.eclipse.kura.core.configuration.metatype.Tocd)15 Tad (org.eclipse.kura.core.configuration.metatype.Tad)4 Element (org.w3c.dom.Element)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 KuraException (org.eclipse.kura.KuraException)3 Tmetadata (org.eclipse.kura.core.configuration.metatype.Tmetadata)3 IOException (java.io.IOException)2 ComponentConfiguration (org.eclipse.kura.configuration.ComponentConfiguration)2 ComponentConfigurationImpl (org.eclipse.kura.core.configuration.ComponentConfigurationImpl)2 XmlComponentConfigurations (org.eclipse.kura.core.configuration.XmlComponentConfigurations)2 ObjectFactory (org.eclipse.kura.core.configuration.metatype.ObjectFactory)2 TestTarget (org.eclipse.kura.test.annotation.TestTarget)2 Test (org.junit.Test)2 Attr (org.w3c.dom.Attr)2 NodeList (org.w3c.dom.NodeList)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 KuraPartialSuccessException (org.eclipse.kura.KuraPartialSuccessException)1