Search in sources :

Example 1 with XmlComponentConfigurations

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;
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) Element(org.w3c.dom.Element)

Example 2 with XmlComponentConfigurations

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;
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 3 with XmlComponentConfigurations

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());
    }
}
Also used : XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 4 with XmlComponentConfigurations

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;
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) HashMap(java.util.HashMap) Password(org.eclipse.kura.configuration.Password)

Example 5 with 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);
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Tocd(org.eclipse.kura.core.configuration.metatype.Tocd) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Aggregations

XmlComponentConfigurations (org.eclipse.kura.core.configuration.XmlComponentConfigurations)11 ComponentConfigurationImpl (org.eclipse.kura.core.configuration.ComponentConfigurationImpl)9 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 TestTarget (org.eclipse.kura.test.annotation.TestTarget)4 Test (org.junit.Test)4 ComponentConfiguration (org.eclipse.kura.configuration.ComponentConfiguration)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ServletException (javax.servlet.ServletException)2 ConfigurationService (org.eclipse.kura.configuration.ConfigurationService)2 XmlSnapshotIdResult (org.eclipse.kura.core.configuration.XmlSnapshotIdResult)2 Tocd (org.eclipse.kura.core.configuration.metatype.Tocd)2 ServiceLocator (org.eclipse.kura.web.server.util.ServiceLocator)2 GwtXSRFToken (org.eclipse.kura.web.shared.model.GwtXSRFToken)2 Element (org.w3c.dom.Element)2 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1