Search in sources :

Example 1 with ComponentConfigurationImpl

use of org.eclipse.kura.core.configuration.ComponentConfigurationImpl in project kura by eclipse.

the class XmlJavaComponentConfigurationsMapper method parseConfiguration.

// 
// Unmarshaller's private methods
// 
private ComponentConfigurationImpl parseConfiguration(Element configuration) throws Exception {
    XmlConfigPropertiesAdapter xmlPropAdapter = new XmlConfigPropertiesAdapter();
    // get configuration's properties
    NodeList propertiesList = configuration.getChildNodes();
    // get effective elements
    Element[] propertiesArray = getElementNodes(propertiesList);
    XmlConfigPropertiesAdapted xmlPropertiesAdapted = new XmlConfigPropertiesAdapted();
    for (Element element : propertiesArray) {
        // parse property elements
        NodeList propertyList = element.getChildNodes();
        Element[] propertyArray = getElementNodes(propertyList);
        XmlConfigPropertyAdapted[] xmlConfigProperties = new XmlConfigPropertyAdapted[propertyArray.length];
        for (int propertyIndex = 0; propertyIndex < propertyArray.length; propertyIndex++) {
            XmlConfigPropertyAdapted xmlProperty = parseProperty(propertyArray[propertyIndex]);
            xmlConfigProperties[propertyIndex] = xmlProperty;
        }
        xmlPropertiesAdapted.setProperties(xmlConfigProperties);
    }
    Map<String, Object> propertiesMap = xmlPropAdapter.unmarshal(xmlPropertiesAdapted);
    String pid = configuration.getAttribute(CONFIGURATION_PID);
    return new ComponentConfigurationImpl(pid, null, propertiesMap);
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) XmlConfigPropertiesAdapted(org.eclipse.kura.core.configuration.XmlConfigPropertiesAdapted) XmlConfigPropertyAdapted(org.eclipse.kura.core.configuration.XmlConfigPropertyAdapted) XmlConfigPropertiesAdapter(org.eclipse.kura.core.configuration.XmlConfigPropertiesAdapter)

Example 2 with ComponentConfigurationImpl

use of org.eclipse.kura.core.configuration.ComponentConfigurationImpl 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 3 with ComponentConfigurationImpl

use of org.eclipse.kura.core.configuration.ComponentConfigurationImpl 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 4 with ComponentConfigurationImpl

use of org.eclipse.kura.core.configuration.ComponentConfigurationImpl 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 ComponentConfigurationImpl

use of org.eclipse.kura.core.configuration.ComponentConfigurationImpl 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

ComponentConfigurationImpl (org.eclipse.kura.core.configuration.ComponentConfigurationImpl)10 XmlComponentConfigurations (org.eclipse.kura.core.configuration.XmlComponentConfigurations)9 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 ComponentConfiguration (org.eclipse.kura.configuration.ComponentConfiguration)3 TestTarget (org.eclipse.kura.test.annotation.TestTarget)3 Test (org.junit.Test)3 Element (org.w3c.dom.Element)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 ConfigurationService (org.eclipse.kura.configuration.ConfigurationService)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 NodeList (org.w3c.dom.NodeList)2 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1