Example usage for javax.xml.bind JAXBContext createUnmarshaller

List of usage examples for javax.xml.bind JAXBContext createUnmarshaller

Introduction

In this page you can find the example usage for javax.xml.bind JAXBContext createUnmarshaller.

Prototype

public abstract Unmarshaller createUnmarshaller() throws JAXBException;

Source Link

Document

Create an Unmarshaller object that can be used to convert XML data into a java content tree.

Usage

From source file:org.openwms.core.configuration.file.ApplicationPreferenceTest.java

/**
 * Just test to validate the given XML file against the schema declaration. If the XML file is not compliant with the schema, the test
 * will fail./* w ww.j a  v  a 2 s .c  om*/
 *
 * @throws Exception any error
 */
@Test
public void testReadPreferences() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(ResourceUtils.getFile("classpath:preferences.xsd"));
    // Schema schema = schemaFactory.newSchema(new
    // URL("http://www.openwms.org/schema/preferences.xsd"));
    JAXBContext ctx = JAXBContext.newInstance("org.openwms.core.configuration.file");
    Unmarshaller unmarshaller = ctx.createUnmarshaller();
    unmarshaller.setSchema(schema);
    unmarshaller.setEventHandler(new ValidationEventHandler() {
        @Override
        public boolean handleEvent(ValidationEvent event) {
            RuntimeException ex = new RuntimeException(event.getMessage(), event.getLinkedException());
            LOGGER.error(ex.getMessage());
            throw ex;
        }
    });

    Preferences prefs = Preferences.class.cast(unmarshaller
            .unmarshal(ResourceUtils.getFile("classpath:org/openwms/core/configuration/file/preferences.xml")));
    for (AbstractPreference pref : prefs.getApplications()) {
        LOGGER.info(pref.toString());
    }
    for (AbstractPreference pref : prefs.getModules()) {
        LOGGER.info(pref.toString());
    }
    for (AbstractPreference pref : prefs.getUsers()) {
        LOGGER.info(pref.toString());
    }
}

From source file:be.e_contract.mycarenet.certra.CertRAClient.java

public RevocableCertificatesDataResponse getRevocableCertificates(byte[] signedCms) throws Exception {

    GetRevocableCertificatesRequest request = this.protocolObjectFactory
            .createGetRevocableCertificatesRequest();
    request.setRevocableCertificatesDataRequest(signedCms);
    GetRevocableCertificatesResponse getRevocableCertificatesResponse = this.port
            .getRevocableCertificates(request);

    byte[] responseCmsData = getRevocableCertificatesResponse.getRevocableCertificatesDataResponse();

    byte[] responseData = getCmsData(responseCmsData);

    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    RevocableCertificatesDataResponse revocableCertificatesDataResponse = (RevocableCertificatesDataResponse) unmarshaller
            .unmarshal(new ByteArrayInputStream(responseData));
    return revocableCertificatesDataResponse;
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.MultimediaWSDaoTest.java

@SuppressWarnings("unchecked")
private JAXBElement<BlackboardMultimediaResponseCollection> getSingleMultimedia() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    JAXBElement<BlackboardMultimediaResponseCollection> response = (JAXBElement<BlackboardMultimediaResponseCollection>) unmarshaller
            .unmarshal(this.getClass()
                    .getResourceAsStream("/data/singleListRepositoryMultimediaResponseCollection.xml"));

    return response;
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.ibm.IBMModelImporter.java

public String parseIBMBPMN2Diagram(File xml) throws JAXBException, JSONException {
    JAXBContext context = JAXBContext.newInstance(Definitions.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    Definitions definitions = (Definitions) unmarshaller.unmarshal(xml);

    List<Diagram> diagrams = new ArrayList<Diagram>();
    for (RootElement e : definitions.getRootElement()) {
        if (e instanceof de.hpi.bpmn2_0.model.Process) {
            de.hpi.bpmn2_0.model.Process p = (de.hpi.bpmn2_0.model.Process) e;
            String resourceId = "oryx-canvas123";
            StencilType type = new StencilType("BPMNDiagram");
            String stencilSetNs = "http://b3mn.org/stencilset/bpmn2.0#";
            String url = "/oryx/stencilsets/bpmn2.0/bpmn2.0.json";
            StencilSet stencilSet = new StencilSet(url, stencilSetNs);
            Diagram diagram = new Diagram(resourceId, type, stencilSet);
            setStandardBounds(diagram);/*from  w w w.  j a  v  a2s  .  com*/
            //         List<Shape> shapes = new ArrayList<Shape>();
            Map<String, Shape> shapes = new HashMap<String, Shape>();
            for (FlowElement flowElement : p.getFlowElement()) {
                Shape shape = new Shape(flowElement.getId());
                setStandardBounds(shape);
                flowElement.toShape(shape);
                if (flowElement.getName() != null) {
                    shape.getProperties().put("name", flowElement.getName());
                }
                shapes.put(flowElement.getId(), shape);
            }
            for (FlowElement flowElement : p.getFlowElement()) {
                if (flowElement instanceof Edge) {
                    Edge edge = (Edge) flowElement;
                    if (edge.getSourceRef() != null) {
                        Shape current = shapes.get(edge.getSourceRef().getId());
                        current.addOutgoing(new Shape(edge.getId()));
                        shapes.get(edge.getId()).addIncoming(current);
                    }

                }
            }

            diagram.getChildShapes().addAll(shapes.values());

            diagrams.add(diagram);
        }
    }

    String parseModeltoString = JSONBuilder.parseModeltoString(diagrams.get(0));
    //      parseModeltoString = "{\"resourceId\":\"oryx-canvas123\",\"properties\":{\"name\":\"\",\"documentation\":\"\",\"auditing\":\"\",\"monitoring\":\"\",\"version\":\"\",\"author\":\"\",\"language\":\"English\",\"namespaces\":\"\",\"targetnamespace\":\"http://www.omg.org/bpmn20\",\"expressionlanguage\":\"http://www.w3.org/1999/XPath\",\"typelanguage\":\"http://www.w3.org/2001/XMLSchema\",\"creationdate\":\"\",\"modificationdate\":\"\"},\"stencil\":{\"id\":\"BPMNDiagram\"},\"childShapes\":[{\"resourceId\":\"oryx_7AD3C7F9-438D-4F61-9FBB-243027E573A9\",\"properties\":{\"name\":\"zrz\",\"documentation\":\"\",\"auditing\":\"\",\"monitoring\":\"\",\"categories\":\"\",\"startquantity\":1,\"completionquantity\":1,\"isforcompensation\":\"\",\"assignments\":\"\",\"callacitivity\":\"\",\"tasktype\":\"None\",\"implementation\":\"webService\",\"resources\":\"\",\"messageref\":\"\",\"operationref\":\"\",\"instantiate\":\"\",\"script\":\"\",\"script_language\":\"\",\"bgcolor\":\"#ffffcc\",\"looptype\":\"None\",\"testbefore\":\"\",\"loopcondition\":\"\",\"loopmaximum\":\"\",\"loopcardinality\":\"\",\"loopdatainput\":\"\",\"loopdataoutput\":\"\",\"inputdataitem\":\"\",\"outputdataitem\":\"\",\"behavior\":\"all\",\"complexbehaviordefinition\":\"\",\"completioncondition\":\"\",\"onebehavioreventref:\":\"signal\",\"nonebehavioreventref\":\"signal\",\"properties\":\"\",\"datainputset\":\"\",\"dataoutputset\":\"\"},\"stencil\":{\"id\":\"Task\"},\"childShapes\":[],\"outgoing\":[{\"resourceId\":\"oryx_F131DEFD-3632-4523-8A2A-18CCA592EA65\"}],\"bounds\":{\"lowerRight\":{\"x\":366,\"y\":163},\"upperLeft\":{\"x\":266,\"y\":83}},\"dockers\":[]},{\"resourceId\":\"oryx_FB713124-E16B-4325-9B87-AF7B91C21076\",\"properties\":{\"name\":\"zrz\",\"documentation\":\"\",\"auditing\":\"\",\"monitoring\":\"\",\"categories\":\"\",\"startquantity\":1,\"completionquantity\":1,\"isforcompensation\":\"\",\"assignments\":\"\",\"callacitivity\":\"\",\"tasktype\":\"None\",\"implementation\":\"webService\",\"resources\":\"\",\"messageref\":\"\",\"operationref\":\"\",\"instantiate\":\"\",\"script\":\"\",\"script_language\":\"\",\"bgcolor\":\"#ffffcc\",\"looptype\":\"None\",\"testbefore\":\"\",\"loopcondition\":\"\",\"loopmaximum\":\"\",\"loopcardinality\":\"\",\"loopdatainput\":\"\",\"loopdataoutput\":\"\",\"inputdataitem\":\"\",\"outputdataitem\":\"\",\"behavior\":\"all\",\"complexbehaviordefinition\":\"\",\"completioncondition\":\"\",\"onebehavioreventref:\":\"signal\",\"nonebehavioreventref\":\"signal\",\"properties\":\"\",\"datainputset\":\"\",\"dataoutputset\":\"\"},\"stencil\":{\"id\":\"Task\"},\"childShapes\":[],\"outgoing\":[],\"bounds\":{\"lowerRight\":{\"x\":511,\"y\":163},\"upperLeft\":{\"x\":411,\"y\":83}},\"dockers\":[]},{\"resourceId\":\"oryx_F131DEFD-3632-4523-8A2A-18CCA592EA65\",\"properties\":{\"name\":\"\",\"documentation\":\"\",\"auditing\":\"\",\"monitoring\":\"\",\"conditiontype\":\"None\",\"conditionexpression\":\"\",\"isimmediate\":\"\",\"showdiamondmarker\":\"\"},\"stencil\":{\"id\":\"SequenceFlow\"},\"childShapes\":[],\"outgoing\":[{\"resourceId\":\"oryx_FB713124-E16B-4325-9B87-AF7B91C21076\"}],\"bounds\":{\"lowerRight\":{\"x\":410.15625,\"y\":124},\"upperLeft\":{\"x\":366.84375,\"y\":122}},\"dockers\":[{\"x\":50,\"y\":40},{\"x\":50,\"y\":40}],\"target\":{\"resourceId\":\"oryx_FB713124-E16B-4325-9B87-AF7B91C21076\"}}],\"bounds\":{\"lowerRight\":{\"x\":1485,\"y\":1050},\"upperLeft\":{\"x\":0,\"y\":0}},\"stencilset\":{\"url\":\"/oryx//stencilsets/bpmn2.0/bpmn2.0.json\",\"namespace\":\"http://b3mn.org/stencilset/bpmn2.0#\"},\"ssextensions\":[]}";
    //      System.out.println(parseModeltoString);
    return parseModeltoString;

}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoTest.java

@SuppressWarnings("unchecked")
private JAXBElement<BlackboardSessionResponseCollection> mockSession(boolean isEmptyChair,
        boolean isEmptyNonChair) throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
    final Unmarshaller unmarshaller = context.createUnmarshaller();

    JAXBElement<BlackboardSessionResponseCollection> response;
    if (isEmptyChair && isEmptyNonChair) {
        response = (JAXBElement<BlackboardSessionResponseCollection>) unmarshaller
                .unmarshal(this.getClass().getResourceAsStream("/data/mockSessionEmptyLists.xml"));
    } else if (isEmptyChair) {
        response = (JAXBElement<BlackboardSessionResponseCollection>) unmarshaller
                .unmarshal(this.getClass().getResourceAsStream("/data/mockSessionEmptyChair.xml"));
    } else if (isEmptyNonChair) {
        response = (JAXBElement<BlackboardSessionResponseCollection>) unmarshaller
                .unmarshal(this.getClass().getResourceAsStream("/data/mockSessionEmptyNonChair.xml"));
    } else {// ww w .  j a v a2 s  . c  o m
        response = (JAXBElement<BlackboardSessionResponseCollection>) unmarshaller
                .unmarshal(this.getClass().getResourceAsStream("/data/mockSessionResponse.xml"));
    }

    return response;
}

From source file:gov.nih.nci.cabig.caaers.web.admin.StudyImporter.java

public void processEntities(File xmlFile, ImportCommand command) {
    boolean valid = validateAgainstSchema(xmlFile, command, getXSDLocation(STUDY_IMPORT));
    if (!valid) {
        return;/* www  .  j a v  a  2s .  c o m*/
    }

    Studies studies;

    try {
        JAXBContext jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.integration.schema.study");
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

        Object importObject = unmarshaller.unmarshal(xmlFile);
        if (!validRootElement(importObject, STUDY_IMPORT, command))
            return;

        studies = (Studies) importObject;
        if (studies != null) {
            for (gov.nih.nci.cabig.caaers.integration.schema.study.Study studyDto : studies.getStudy()) {
                DomainObjectImportOutcome<Study> studyImportOutcome = studyProcessorImpl.importStudy(studyDto);
                List<String> errors = domainObjectValidator
                        .validate(studyImportOutcome.getImportedDomainObject());
                if (studyImportOutcome.isSavable() && errors.size() == 0) {
                    command.addImportableStudy(studyImportOutcome);
                } else {
                    for (String errMsg : errors) {
                        studyImportOutcome.addErrorMessage(errMsg, Severity.ERROR);
                    }
                    command.addNonImportableStudy(studyImportOutcome);
                }
            }

            //Remove Duplicate Studies in the List.
            List<DomainObjectImportOutcome<Study>> dupList = new ArrayList<DomainObjectImportOutcome<Study>>();
            for (int i = 0; i < command.getImportableStudies().size() - 1; i++) {
                Study study1 = command.getImportableStudies().get(i).getImportedDomainObject();
                for (int j = i + 1; j < command.getImportableStudies().size(); j++) {
                    Study study2 = command.getImportableStudies().get(j).getImportedDomainObject();
                    if (study1.equals(study2)) {
                        command.getImportableStudies().get(j).addErrorMessage(
                                "Study Identifier already used in a different Study", Severity.ERROR);
                        command.addNonImportableStudy(command.getImportableStudies().get(j));
                        dupList.add(command.getImportableStudies().get(j));
                        logger.debug("Duplicate Study :: " + study2.getShortTitle());
                        break;
                    }
                }
            }
            for (DomainObjectImportOutcome<Study> obj : dupList) {
                command.getImportableStudies().remove(obj);
            }
        }
    } catch (JAXBException e) {
        throw new CaaersSystemException(
                "There was an error converting study data transfer object to study domain object", e);
    }
}

From source file:io.onedecision.engine.decisions.impl.DecisionModelFactory.java

@SuppressWarnings("unchecked")
protected final Definitions load(InputStream inputStream) throws IOException {
    JAXBContext context;
    try {/*from  w  w w  .  j a v a2 s  .c  om*/
        context = JAXBContext.newInstance(Definitions.class);
        Unmarshaller um = context.createUnmarshaller();

        Object dm = um.unmarshal(inputStream);
        if (dm instanceof JAXBElement<?>) {
            return ((JAXBElement<Definitions>) dm).getValue();
        } else {
            return (Definitions) dm;
        }
    } catch (JAXBException e) {
        String msg = "Unable to load decision model from stream";
        LOGGER.error(msg, e);
        throw new IOException(msg, e);
    }
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OPCKeySelector.java

public OPCKeySelector(URL opcUrl, String signatureResourceName) {
    this.opcUrl = opcUrl;
    this.signatureResourceName = signatureResourceName;

    try {//from   w w  w.ja v a 2  s . c om
        JAXBContext relationshipsJAXBContext = JAXBContext.newInstance(ObjectFactory.class);
        this.relationshipsUnmarshaller = relationshipsJAXBContext.createUnmarshaller();
    } catch (JAXBException e) {
        throw new RuntimeException("JAXB error: " + e.getMessage(), e);
    }

    try {
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException("CertificateFactory error: " + e.getMessage(), e);
    }
}

From source file:esg.node.components.registry.LasSistersGleaner.java

public synchronized LasSistersGleaner loadMyLasServers() {
    log.info("Loading my LAS LasServers info from " + sistersPath + sistersFile);
    try {//from  ww  w. j  a  v  a  2  s. c  om
        JAXBContext jc = JAXBContext.newInstance(LasServers.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement<LasServers> root = u.unmarshal(new StreamSource(new File(sistersPath + sistersFile)),
                LasServers.class);
        servers = root.getValue();
    } catch (Exception e) {
        log.error(e);
    }
    return this;
}

From source file:esg.node.components.registry.AzsWhitelistGleaner.java

public synchronized AzsWhitelistGleaner loadMyAzsWhitelist() {
    log.info("Loading my AZS Whitelist info from " + azsWhitelistPath + azsWhitelistFile);
    try {//w  ww  .  j av a 2 s  .  com
        JAXBContext jc = JAXBContext.newInstance(AzsWhitelist.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement<AzsWhitelist> root = u
                .unmarshal(new StreamSource(new File(azsWhitelistPath + azsWhitelistFile)), AzsWhitelist.class);
        azss = root.getValue();
    } catch (Exception e) {
        log.error(e);
    }
    return this;
}