Example usage for javax.xml.bind Unmarshaller setEventHandler

List of usage examples for javax.xml.bind Unmarshaller setEventHandler

Introduction

In this page you can find the example usage for javax.xml.bind Unmarshaller setEventHandler.

Prototype

public void setEventHandler(ValidationEventHandler handler) throws JAXBException;

Source Link

Document

Allow an application to register a ValidationEventHandler .

Usage

From source file:org.wso2.carbon.device.mgt.iot.common.config.devicetype.IotDeviceTypeConfigurationManager.java

public synchronized void initConfig() throws DeviceManagementException {

    try {//w w w.j  av  a 2s  .com
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new File(iotDeviceMgtConfigXSDPath));

        File iotDeviceMgtConfig = new File(iotDeviceMgtConfigXMLPath);
        Document doc = IotDeviceManagementUtil.convertToDocument(iotDeviceMgtConfig);
        JAXBContext iotDeviceMgmtContext = JAXBContext.newInstance(IoTDeviceTypeConfigManager.class);
        Unmarshaller unmarshaller = iotDeviceMgmtContext.createUnmarshaller();
        unmarshaller.setSchema(schema);
        unmarshaller.setEventHandler(new IotConfigValidationEventHandler());
        this.currentIoTDeviceTypeConfig = (IoTDeviceTypeConfigManager) unmarshaller.unmarshal(doc);

        List<IotDeviceTypeConfig> iotDeviceTypeConfigList = currentIoTDeviceTypeConfig.getIotDeviceTypeConfig();
        for (IotDeviceTypeConfig iotDeviceTypeConfig : iotDeviceTypeConfigList) {
            String applicationName = iotDeviceTypeConfig.getApiApplicationName();

            if (applicationName == null || applicationName.isEmpty()) {
                iotDeviceTypeConfig.setApiApplicationName(iotDeviceTypeConfig.getType());
            }
            iotDeviceTypeConfigMap.put(iotDeviceTypeConfig.getType(), iotDeviceTypeConfig);

        }
        ApisAppClient.getInstance().setBase64EncodedConsumerKeyAndSecret(iotDeviceTypeConfigList);

    } catch (Exception e) {
        String error = "Error occurred while initializing device configurations";
        log.error(error);
    }
}

From source file:org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager.java

public void initConfig() throws DeviceControllerException {
    try {//  ww w  . j  ava  2  s  .  c  o m
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new File(XSDCONFIGS_FILE_LOCATION));

        File deviceCloudMgtConfig = new File(XMLCONFIGS_FILE_LOCATION);
        Document doc = IotDeviceManagementUtil.convertToDocument(deviceCloudMgtConfig);
        JAXBContext deviceCloudContext = JAXBContext.newInstance(DeviceManagementConfiguration.class);
        Unmarshaller unmarshaller = deviceCloudContext.createUnmarshaller();
        unmarshaller.setSchema(schema);
        unmarshaller.setEventHandler(new IotConfigValidationEventHandler());
        this.currentDeviceManagementConfiguration = (DeviceManagementConfiguration) unmarshaller.unmarshal(doc);
    } catch (Exception e) {
        String error = "Error occurred while initializing DeviceController configurations";
        log.error(error);
        throw new DeviceControllerException(error, e);
    }
}

From source file:org.yccheok.jstock.engine.news.yahooRSSNewsEngine.java

public List<NewsItem> urlToBean(String ticker) throws XMLStreamException, MalformedURLException {

    try {/*  w w  w  . jav a 2s. c  o m*/

        JAXBContext jc = JAXBContext.newInstance(rss.class);
        Unmarshaller um = jc.createUnmarshaller();
        um.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
        StringBuilder sb = new StringBuilder();
        sb.append(yahooNewsURL);
        sb.append(ticker);
        URL url = new URL(sb.toString());
        rss r = (rss) um.unmarshal(url);

        channel c = r.getCh();

        listItems = c.getNi();

    } catch (JAXBException e) {
        log.error(null, e);
    }

    return listItems;
}