List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.ibm.test.IBMImporterTest.java
@Test public void parse() throws JAXBException, JSONException { File xml = new File("resources\\IBM\\A\\s00000016\\s00000018\\s00000020\\s00000024\\s00000777.bpmn.xml"); 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); // List<Shape> shapes = new ArrayList<Shape>(); Map<String, Shape> shapes = new HashMap<String, Shape>(); for (FlowElement flowElement : p.getFlowElement()) { if (flowElement instanceof Edge) { Edge edge = (Edge) flowElement; if (edge.getSourceRef() != null) { //FIXME parse all nodes first and afterwards add edges. shapes.get(edge.getSourceRef().getId()).addOutgoing(new Shape(edge.getId())); }/*from w w w . jav a2s . co m*/ } Shape shape = new Shape(flowElement.getId()); Point lr = new Point(200d, 200d); Point ul = new Point(100d, 100d); Bounds bounds = new Bounds(lr, ul); shape.setBounds(bounds); flowElement.toShape(shape); if (flowElement.getName() != null) { shape.getProperties().put("name", flowElement.getName()); } shapes.put(flowElement.getId(), shape); } diagram.getChildShapes().addAll(shapes.values()); diagrams.add(diagram); } } //TODO use logger System.out.println(JSONBuilder.parseModeltoString(diagrams.get(0))); }
From source file:eu.learnpad.core.impl.me.XwikiController.java
@Override public Feedbacks getFeedbacks(String modelSetId) throws LpRestExceptionImpl { // Now send the package's path to the importer for XWiki HttpClient httpClient = RestResource.getClient(); String uri = String.format("%s/learnpad/cw/bridge/%s/feedbacks", RestResource.REST_URI, modelSetId); GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader("Accept", "application/xml"); try {//from w ww. j a v a2 s. c o m httpClient.executeMethod(getMethod); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } InputStream feedbacksStream = null; try { feedbacksStream = getMethod.getResponseBodyAsStream(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Feedbacks feedbacks = null; try { JAXBContext jc = JAXBContext.newInstance(Feedbacks.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); feedbacks = (Feedbacks) unmarshaller.unmarshal(feedbacksStream); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } return feedbacks; }
From source file:com.moss.appkeep.tools.MavenUploader.java
public List<Component> upload(File launchSpec, AppkeepService appkeep, IdProover idProver, boolean forceUpload) throws IdProovingException, SecurityException { // 1) select launch-spec Object o;/*from w ww. j a va 2s . c o m*/ try { JAXBContext jaxb = JAXBContext.newInstance(JavaAppSpec.class, JavaAppletSpec.class); o = jaxb.createUnmarshaller().unmarshal(launchSpec.toURL()); } catch (Throwable e) { throw new RuntimeException("Error reading file \"" + launchSpec + "\"", e); } final List<Component> components = new LinkedList<Component>(); if (o instanceof JavaAppSpec) { JavaAppSpec spec = (JavaAppSpec) o; { components.addAll(spec.components()); for (BundleSpec b : spec.bundles()) { components.addAll(b.components()); } for (AppProfile p : spec.profiles()) { components.addAll(p.components()); } } } else if (o instanceof JavaAppletSpec) { JavaAppletSpec spec = (JavaAppletSpec) o; { components.addAll(spec.components()); for (AppletProfile p : spec.profiles()) { components.addAll(p.components()); } } } // 2) for each component (in each profile): for (Component c : components) { // a) locate the component in the maven repo (local, remote?) MavenCoordinatesHandle m = MavenArtifactGrabber.getMavenArtifact(c.artifactHandles()); if (m == null) { throw new RuntimeException("Component has no maven handle: " + c); } final String logPrefix = c.type() + ": " + m; ComponentInfo info = appkeep.getInfo(new ComponentHandlesSelector(c.artifactHandles()), new UserAccountDownloadToken(idProver.giveProof())); // List<ComponentInfo> matches = appkeep.listByMavenInfo(m.groupId(), m.artifactId(), m.version(), idProver.giveProof()); if (forceUpload || info == null) { if (forceUpload) { log.info("[FORCING] " + logPrefix + " "); } else { log.info("[NOT IN KEEP] " + logPrefix + " "); } // b) download it SimpleArtifactFinder finder = new SimpleArtifactFinder(); File location = finder.findLocal(m.groupId(), m.artifactId(), m.version()); if (!location.exists()) { throw new RuntimeException("Cannot find " + m + " in local repository. I was expecting to find it at " + location.getAbsolutePath()); } log.info(" found in local repository: " + location.getAbsoluteFile()); InputStream data; try { data = new FileInputStream(location); } catch (FileNotFoundException e) { throw new RuntimeException(e); } try { log.info("uploading"); // c) upload it if necessary appkeep.post(c.artifactHandles().toArray(new ComponentHandle[] {}), c.type(), idProver.giveProof(), data); log.info("done"); } catch (SecurityException e) { throw new RuntimeException(e); } finally { try { data.close(); } catch (IOException e) { throw new RuntimeException(e); } } } else { log.info("[ALREADY IN KEEP] " + logPrefix + " "); } } /* * 3) upload the launch-spec itself? */ return components; }
From source file:com.agimatec.validation.jsr303.xml.ValidationParser.java
private ValidationConfigType parseXmlConfig() { try {/*w w w .j a v a 2s .c om*/ InputStream inputStream = getInputStream(validationXmlFile); if (inputStream == null) { if (log.isDebugEnabled()) log.debug("No " + validationXmlFile + " found. Using annotation based configuration only."); return null; } if (log.isDebugEnabled()) log.debug(validationXmlFile + " found."); Schema schema = getSchema(); JAXBContext jc = JAXBContext.newInstance(ValidationConfigType.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setSchema(schema); StreamSource stream = new StreamSource(inputStream); JAXBElement<ValidationConfigType> root = unmarshaller.unmarshal(stream, ValidationConfigType.class); return root.getValue(); } catch (JAXBException e) { throw new ValidationException("Unable to parse " + validationXmlFile, e); } catch (IOException e) { throw new ValidationException("Unable to parse " + validationXmlFile, e); } }
From source file:se.inera.intyg.intygstjanst.web.integration.RevokeMedicalCertificateResponderImplTest.java
private SendMedicalCertificateQuestionType expectedSendRequest() throws Exception { // read request from file JAXBContext jaxbContext = JAXBContext.newInstance(SendMedicalCertificateQuestionType.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<SendMedicalCertificateQuestionType> request = unmarshaller.unmarshal(new StreamSource( new ClassPathResource("revoke-medical-certificate/send-medical-certificate-question-request.xml") .getInputStream()),//w w w . j a v a2 s. com SendMedicalCertificateQuestionType.class); return request.getValue(); }
From source file:se.inera.intyg.intygstjanst.web.integration.RevokeMedicalCertificateResponderImplTest.java
protected RevokeMedicalCertificateRequestType revokeRequest() throws Exception { // read request from file JAXBContext jaxbContext = JAXBContext.newInstance(RevokeMedicalCertificateRequestType.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<RevokeMedicalCertificateRequestType> request = unmarshaller.unmarshal(new StreamSource( new ClassPathResource("revoke-medical-certificate/revoke-medical-certificate-request.xml") .getInputStream()),// w w w . j av a2 s .c o m RevokeMedicalCertificateRequestType.class); return request.getValue(); }
From source file:edu.htwm.vsp.phone.services.XmlMappingTest.java
@Before public void prepareXmlMarshalling() throws JAXBException { /*//from w ww.j a va2 s . c o m * Code Duplizierung vermeiden * (DRY -> http://de.wikipedia.org/wiki/Don%E2%80%99t_repeat_yourself) und * aufwndige, immer wieder verwendete Objekte nur einmal erzeugen * */ JAXBContext context = JAXBContext.newInstance(PhoneUser.class, PhoneNumber.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); unmarshaller = context.createUnmarshaller(); }
From source file:in.gov.uidai.auth.aua.httpclient.AuthClient.java
private AuthRes parseAuthResponseXML(String xmlToParse) throws JAXBException { //Create an XMLReader to use with our filter try {/*from www .j a v a2s . co m*/ //Prepare JAXB objects JAXBContext jc = JAXBContext.newInstance(AuthRes.class); Unmarshaller u = jc.createUnmarshaller(); XMLReader reader; reader = XMLReaderFactory.createXMLReader(); //Create the filter (to add namespace) and set the xmlReader as its parent. NamespaceFilter inFilter = new NamespaceFilter( "http://www.uidai.gov.in/authentication/uid-auth-response/1.0", true); inFilter.setParent(reader); //Prepare the input, in this case a java.io.File (output) InputSource is = new InputSource(new StringReader(xmlToParse)); //Create a SAXSource specifying the filter SAXSource source = new SAXSource(inFilter, is); //Do unmarshalling AuthRes res = u.unmarshal(source, AuthRes.class).getValue(); return res; } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:no.uis.fsws.proxy.StudInfoImportImpl.java
/** * @param studieinfoXml/*from w w w. jav a 2 s . co m*/ * the Reader is not closed in this method. */ @SneakyThrows protected FsStudieinfo unmarshalStudieinfo(@NonNull Reader studieinfoXml) { net.sf.saxon.TransformerFactoryImpl trFactory = new net.sf.saxon.TransformerFactoryImpl(); if (this.xmlSourceParser != null) { trFactory.setAttribute(FeatureKeys.SOURCE_PARSER_CLASS, this.xmlSourceParser); } @Cleanup InputStream transformerStream = transformerUrl.openStream(); Source schemaSource = new StreamSource(transformerStream); Transformer stylesheet = trFactory.newTransformer(schemaSource); Source input = new StreamSource(studieinfoXml); @Cleanup StringWriter resultWriter = new StringWriter(); Result result = new StreamResult(resultWriter); stylesheet.transform(input, result); @Cleanup Reader unmarshalSource = new StringReader(resultWriter.toString()); JAXBContext jc = JAXBContext.newInstance(FsStudieinfo.class); FsStudieinfo sinfo = (FsStudieinfo) jc.createUnmarshaller().unmarshal(unmarshalSource); return sinfo; }
From source file:be.fedict.eid.dss.model.bean.ServicesManagerSingletonBean.java
@SuppressWarnings("unchecked") public List<DigitalSignatureServiceProtocolType> getProtocolServices() { LOG.debug("getProtocolServices"); List<DigitalSignatureServiceProtocolType> protocolServices = new LinkedList<DigitalSignatureServiceProtocolType>(); Enumeration<URL> resources; try {/*from ww w . jav a 2 s .co m*/ resources = getResources("META-INF/eid-dss-protocol.xml"); } catch (IOException e) { LOG.error("I/O error: " + e.getMessage(), e); return protocolServices; } Unmarshaller unmarshaller; try { JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { LOG.error("JAXB error: " + e.getMessage(), e); return protocolServices; } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); LOG.debug("resource URL: " + resource.toString()); JAXBElement<DigitalSignatureServiceProtocolType> jaxbElement; try { jaxbElement = (JAXBElement<DigitalSignatureServiceProtocolType>) unmarshaller.unmarshal(resource); } catch (JAXBException e) { LOG.error("JAXB error: " + e.getMessage(), e); continue; } protocolServices.add(jaxbElement.getValue()); } return protocolServices; }