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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations