use of org.eclipse.kura.core.configuration.XmlComponentConfigurations in project kura by eclipse.
the class XmlJavaComponentConfigurationsMapper method marshal.
@Override
public Element marshal(Document doc, Object object) throws Exception {
this.mashallDoc = doc;
Element configurations = doc.createElement(ESF_NAMESPACE + ":" + CONFIGURATIONS);
configurations.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:esf", "http://eurotech.com/esf/2.0");
configurations.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ocd", "http://www.osgi.org/xmlns/metatype/v1.2.0");
doc.appendChild(configurations);
XmlComponentConfigurations xmlCompConfig = (XmlComponentConfigurations) object;
List<ComponentConfigurationImpl> configsList = xmlCompConfig.getConfigurations();
if (configsList != null) {
for (ComponentConfigurationImpl config : configsList) {
Element configuration = marshallConfiguration(config);
configurations.appendChild(configuration);
}
}
return configurations;
}
use of org.eclipse.kura.core.configuration.XmlComponentConfigurations in project kura by eclipse.
the class XmlJavaComponentConfigurationsMapper method unmarshal.
@SuppressWarnings("unchecked")
@Override
public <T> T unmarshal(Document doc) throws Exception {
this.unmashallDoc = doc;
XmlComponentConfigurations xcc = new XmlComponentConfigurations();
// Get all configurations
NodeList configurationList = this.unmashallDoc.getElementsByTagName(ESF_NAMESPACE + ":" + CONFIGURATIONS_CONFIGURATION);
List<ComponentConfigurationImpl> compConfList = new ArrayList<ComponentConfigurationImpl>();
// Iterate through all the configuration elements inside configurations tag
for (int configIndex = 0; configIndex < configurationList.getLength(); configIndex++) {
Element configuration = (Element) configurationList.item(configIndex);
ComponentConfigurationImpl cci = parseConfiguration(configuration);
compConfList.add(cci);
}
xcc.setConfigurations(compConfList);
return (T) xcc;
}
use of org.eclipse.kura.core.configuration.XmlComponentConfigurations in project kura by eclipse.
the class XmlUtilTest method testXmlComponentConfigurationsUnmarshalling.
@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testXmlComponentConfigurationsUnmarshalling() {
try {
XmlComponentConfigurations xmlComponentConfigurations = getSampleXmlComponentConfigurationsObject();
// test String unmarshalling
String marshalledString = org.eclipse.kura.core.configuration.util.XmlUtil.marshal(xmlComponentConfigurations);
Object unmarshalledObjectFromString = org.eclipse.kura.core.configuration.util.XmlUtil.unmarshal(marshalledString, XmlComponentConfigurations.class);
Assert.assertTrue(String.format(differentInstanceMessage, XmlComponentConfigurations.class, unmarshalledObjectFromString.getClass()), unmarshalledObjectFromString instanceof XmlComponentConfigurations);
XmlComponentConfigurations outputXmlComponentConfigurations = (XmlComponentConfigurations) unmarshalledObjectFromString;
assertValuesForEquality(pid, xmlComponentConfigurations.getConfigurations().get(0).getPid(), outputXmlComponentConfigurations.getConfigurations().get(0).getPid(), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), false);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), false);
// test Reader unmarshalling
Reader marshalledStringReader = new StringReader(marshalledString);
Object unmarshalledObjectFromStringReader = org.eclipse.kura.core.configuration.util.XmlUtil.unmarshal(marshalledStringReader, XmlComponentConfigurations.class);
Assert.assertTrue(String.format(differentInstanceMessage, XmlComponentConfigurations.class, unmarshalledObjectFromStringReader.getClass()), unmarshalledObjectFromStringReader instanceof XmlComponentConfigurations);
outputXmlComponentConfigurations = (XmlComponentConfigurations) unmarshalledObjectFromStringReader;
assertValuesForEquality(pid, xmlComponentConfigurations.getConfigurations().get(0).getPid(), outputXmlComponentConfigurations.getConfigurations().get(0).getPid(), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), true);
assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), true);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.eclipse.kura.core.configuration.XmlComponentConfigurations in project kura by eclipse.
the class XmlUtilTest method getSampleXmlComponentConfigurationsObject.
private static XmlComponentConfigurations getSampleXmlComponentConfigurationsObject() {
Map<String, Object> sampleMap = new HashMap<String, Object>();
sampleMap.put("int", 1);
sampleMap.put("long", 2L);
sampleMap.put("string", "StringValue");
sampleMap.put("boolean", true);
sampleMap.put("double", 2.2d);
sampleMap.put("float", 2.3f);
sampleMap.put("char", 'a');
sampleMap.put("short", (short) 1);
sampleMap.put("byte", (byte) 90);
Password password = new Password("password".toCharArray());
// sampleMap.put("password", password);
ComponentConfigurationImpl componentConfigurationImpl = new ComponentConfigurationImpl();
componentConfigurationImpl.setPid("8236");
componentConfigurationImpl.setDefinition(getSampleTocdObject());
componentConfigurationImpl.setProperties(sampleMap);
XmlComponentConfigurations xmlComponentConfigurations = new XmlComponentConfigurations();
xmlComponentConfigurations.setConfigurations(new ArrayList<ComponentConfigurationImpl>(Arrays.asList(componentConfigurationImpl)));
return xmlComponentConfigurations;
}
use of org.eclipse.kura.core.configuration.XmlComponentConfigurations in project kura by eclipse.
the class ComponentConfigurationImplTest method testOCDMarshallUnmarshall.
@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testOCDMarshallUnmarshall() throws Exception {
String pid = "org.eclipse.kura.cloud.CloudService";
Tocd definition = ComponentUtil.readObjectClassDefinition(pid);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("prop.string", new String("prop.value"));
properties.put("prop.long", Long.MAX_VALUE);
properties.put("prop.double", Double.MAX_VALUE);
properties.put("prop.float", Float.MAX_VALUE);
properties.put("prop.integer", Integer.MAX_VALUE);
properties.put("prop.byte", Byte.MAX_VALUE);
properties.put("prop.character", 'a');
properties.put("prop.short", Short.MAX_VALUE);
XmlComponentConfigurations xcc = new XmlComponentConfigurations();
List<ComponentConfigurationImpl> ccis = new ArrayList<ComponentConfigurationImpl>();
ComponentConfigurationImpl config = new ComponentConfigurationImpl(pid, definition, properties);
ccis.add(config);
xcc.setConfigurations(ccis);
String s = XmlUtil.marshal(xcc);
System.err.println(s);
XmlComponentConfigurations config1 = XmlUtil.unmarshal(s, XmlComponentConfigurations.class);
String s1 = XmlUtil.marshal(config1);
System.err.println(s1);
Map<String, Object> properties1 = config1.getConfigurations().get(0).getConfigurationProperties();
assertEquals(properties, properties1);
}
Aggregations