Search in sources :

Example 21 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project openhab1-addons by openhab.

the class SmarthomaticBinding method activate.

/**
     * activate binding
     *
     */
@Override
public void activate() {
    // log activate of binding
    if (baseStation != null) {
        logger.info("Smarthomatic Binding activated. BaseStation= {}", baseStation.toString());
    }
    Bundle bundle = SmarthomaticActivator.getContext().getBundle();
    URL fileURL = bundle.getEntry("packet_layout.xml");
    Packet packet = null;
    try {
        InputStream inputStream = fileURL.openConnection().getInputStream();
        JAXBContext jaxbContext = JAXBContext.newInstance(Packet.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        packet = (Packet) jaxbUnmarshaller.unmarshal(inputStream);
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    this.packet = packet;
}
Also used : Packet(org.openhab.binding.smarthomatic.internal.packetData.Packet) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL)

Example 22 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project openhab1-addons by openhab.

the class TestSHCMessage method setUp.

/**
     * common setup
     *
     * @throws Exception
     */
@Before
public void setUp() throws Exception {
    File file = new File("src/main/resources/packet_layout.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(Packet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    packet = (Packet) jaxbUnmarshaller.unmarshal(file);
}
Also used : JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) Before(org.junit.Before)

Example 23 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project openhab1-addons by openhab.

the class LgTvAppSet method loadapps.

/**
     * read applications out of string into a list
     * 
     * @param s
     * @throws JAXBException
     */
public void loadapps(String s) throws JAXBException {
    JAXBContext jc;
    jc = JAXBContext.newInstance(envelope.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    int start = s.indexOf("<envelope>");
    int stop = s.indexOf("</envelope>") + "</envelope>".length();
    String t = s.substring(start, stop);
    StringReader reader = new StringReader(t);
    envel = null;
    envel = (envelope) unmarshaller.unmarshal(reader);
}
Also used : StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 24 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project openhab1-addons by openhab.

the class LgTvEventChannelChanged method readevent.

public String readevent(String s) throws JAXBException {
    JAXBContext jc;
    jc = JAXBContext.newInstance(envelope.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    int start = s.indexOf("<envelope>");
    int stop = s.indexOf("</envelope>") + "</envelope>".length();
    String t = s.substring(start, stop);
    // System.out.println(t);
    StringReader reader = new StringReader(t);
    envel = null;
    envel = (envelope) unmarshaller.unmarshal(reader);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter sw = new StringWriter();
    marshaller.marshal(envel, sw);
    return new String(sw.toString());
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 25 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project openhab1-addons by openhab.

the class CommonIdHandler method loadMapping.

/**
     * Load predefined common id mappings from an XML file.
     */
public void loadMapping() throws Exception {
    Unmarshaller um = JAXBContext.newInstance(CommonIdList.class).createUnmarshaller();
    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("weather/common-id-mappings.xml");
    CommonIdList mappings = (CommonIdList) um.unmarshal(stream);
    for (CommonId commonId : mappings.getCommonIds()) {
        for (CommonIdProvider commonIdProvider : commonId.getProviders()) {
            Map<String, CommonId> commonIds = providerCommonIds.get(commonIdProvider.getName());
            if (commonIds == null) {
                commonIds = new HashMap<String, CommonId>();
                providerCommonIds.put(commonIdProvider.getName(), commonIds);
            }
            addCommonId(commonIdProvider.getIds(), "id", commonIdProvider, commonIds, commonId);
            addCommonId(commonIdProvider.getIcons(), "icon", commonIdProvider, commonIds, commonId);
        }
    }
}
Also used : CommonId(org.openhab.binding.weather.internal.model.common.CommonId) CommonIdList(org.openhab.binding.weather.internal.model.common.CommonIdList) InputStream(java.io.InputStream) CommonIdProvider(org.openhab.binding.weather.internal.model.common.CommonIdProvider) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

Unmarshaller (javax.xml.bind.Unmarshaller)292 JAXBContext (javax.xml.bind.JAXBContext)240 JAXBException (javax.xml.bind.JAXBException)97 InputStream (java.io.InputStream)91 Test (org.junit.Test)79 StringReader (java.io.StringReader)40 BaseTest (org.orcid.core.BaseTest)39 V2Convertible (org.orcid.core.version.V2Convertible)39 File (java.io.File)33 InputSource (org.xml.sax.InputSource)22 IOException (java.io.IOException)21 JAXBElement (javax.xml.bind.JAXBElement)18 Marshaller (javax.xml.bind.Marshaller)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParserFactory (javax.xml.parsers.SAXParserFactory)13 XMLInputFactory (javax.xml.stream.XMLInputFactory)13 XMLStreamException (javax.xml.stream.XMLStreamException)13 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Schema (javax.xml.validation.Schema)13