List of usage examples for javax.xml.bind Unmarshaller unmarshal
public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;
From source file:eu.eco2clouds.accounting.bonfire.BFClientAccountingImpl.java
@Override public Experiment getExperiment(String userId, long experimentId) { this.userId = userId; Boolean exception = false;//www . ja v a 2 s. c om String experimentUrl = url + "/experiments/" + experimentId; String response = getMethod(experimentUrl, exception); logger.debug(response); Experiment experiment = new Experiment(); try { JAXBContext jaxbContext = JAXBContext.newInstance(Experiment.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); experiment = (Experiment) jaxbUnmarshaller.unmarshal(new StringReader(response)); } catch (JAXBException e) { logger.warn("Error trying to parse returned status of hosts: " + experimentUrl + " Exception: " + e.getMessage()); exception = true; } if (exception) return new Experiment(); return experiment; }
From source file:jails.http.converter.xml.Jaxb2RootElementHttpMessageConverter.java
@Override protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException { try {//from w ww .j a v a2s . c o m Unmarshaller unmarshaller = createUnmarshaller(clazz); if (clazz.isAnnotationPresent(XmlRootElement.class)) { return unmarshaller.unmarshal(source); } else { JAXBElement jaxbElement = unmarshaller.unmarshal(source, clazz); return jaxbElement.getValue(); } } catch (UnmarshalException ex) { throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex); } catch (JAXBException ex) { throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex); } }
From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java
/** * * Reads and unmarshalls Digital Object from Fedora * * @param path//from w w w . j ava 2 s .c o m * @return */ public static DigitalObject readFoXML(String uuid, FedoraClient client) throws MetsExportException { DigitalObject foXMLObject = null; if (uuid.startsWith("info:fedora/")) { uuid = uuid.substring(uuid.indexOf("/") + 1); } LOG.log(Level.FINE, "Reading document from Fedora:" + uuid); try { FedoraResponse response = FedoraClient.getObjectXML(uuid).execute(client); JAXBContext jaxbContext = JAXBContext.newInstance(DigitalObject.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); foXMLObject = (DigitalObject) unmarshaller.unmarshal(response.getEntityInputStream()); } catch (Exception e) { throw new MetsExportException("Unable to get " + uuid + " from Fedora", false, e); } return foXMLObject; }
From source file:br.eti.danielcamargo.backend.common.config.context.CoreConfig.java
@Bean public Unmarshaller unmarshaller() throws Exception { InputStream is = getClass().getResourceAsStream("/META-INF/hsnpts/programas.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(HsnPersonal.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); HsnPersonal hsnPersonal = (HsnPersonal) jaxbUnmarshaller.unmarshal(is); hsnPersonal.getProgramas();/* w ww .j ava2 s . c o m*/ return jaxbUnmarshaller; }
From source file:com.maxl.java.aips2xml.Aips2Xml.java
static List<MedicalInformations.MedicalInformation> readAipsFile() { List<MedicalInformations.MedicalInformation> med_list = null; try {// www. j av a 2 s .c o m JAXBContext context = JAXBContext.newInstance(MedicalInformations.class); // Validation SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(FILE_MEDICAL_INFOS_XSD)); Validator validator = schema.newValidator(); validator.setErrorHandler(new MyErrorHandler()); // Marshaller /* Marshaller ma = context.createMarshaller(); ma.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); MedicalInformations medi_infos = new MedicalInformations(); ma.marshal(medi_infos, System.out); */ // Unmarshaller long startTime = System.currentTimeMillis(); if (SHOW_LOGS) System.out.print("- Unmarshalling Swissmedic xml ... "); FileInputStream fis = new FileInputStream(new File(FILE_MEDICAL_INFOS_XML)); Unmarshaller um = context.createUnmarshaller(); MedicalInformations med_infos = (MedicalInformations) um.unmarshal(fis); med_list = med_infos.getMedicalInformation(); long stopTime = System.currentTimeMillis(); if (SHOW_LOGS) System.out.println(med_list.size() + " medis in " + (stopTime - startTime) / 1000.0f + " sec"); } catch (IOException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return med_list; }
From source file:ait.ffma.service.preservation.riskmanagement.api.riskanalysis.risk.RiskUtils.java
/** * This method initializes a set of risk properties loaded from XML file. * /*from w ww .ja va 2 s . c o m*/ * @param xmlFile * The XML file containing properties definitions * @return property set in risk analysis format */ public static RiskAnalysis loadRiskPropertiesFromXML(String xmlFile) { try { JAXBContext jc = JAXBContext.newInstance(RiskAnalysis.class); Unmarshaller u = jc.createUnmarshaller(); InputStream in = RiskUtils.class.getResourceAsStream(xmlFile); ra = (RiskAnalysis) u.unmarshal(in); } catch (JAXBException e) { LOG.log(Level.SEVERE, e.getMessage()); return null; } // resetProperties(ra.getRiskFactors()); return ra; }
From source file:at.ac.tuwien.dsg.cloud.utilities.messaging.discovery.LightweightSalsaDiscovery.java
public String discoverHost(String serviceName) { try {/*from w ww . j a va2s . c o m*/ URI statusUri = UriBuilder.fromPath(restCommand).build(serviceName); HttpGet method = new HttpGet(statusUri); HttpHost host = new HttpHost(this.config.getIp(), this.config.getPort()); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(host, method); if (response.getStatusLine().getStatusCode() == 200) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); response.getEntity().writeTo(outputStream); String serviceDescription = new String(outputStream.toByteArray()); JAXBContext a = JAXBContext.newInstance(DeploymentDescription.class); Unmarshaller u = a.createUnmarshaller(); if (!serviceDescription.equalsIgnoreCase("")) { Object object = u.unmarshal(new StringReader(serviceDescription)); DeploymentDescription deploymentInfo = (DeploymentDescription) object; for (DeploymentUnit unit : deploymentInfo.getDeployments()) { if (unit.getServiceUnitID().contains("RabbitServer")) { return unit.getAssociatedVM().get(0).getIp(); } } } } catch (JAXBException e) { //todo: log } } } catch (IOException ex) { //todo: log } return null; }
From source file:io.onedecision.engine.decisions.impl.DecisionModelFactory.java
@SuppressWarnings("unchecked") protected final Definitions load(InputStream inputStream) throws IOException { JAXBContext context;// w ww. ja v a 2s . c o m try { 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:org.jasig.services.persondir.support.xml.CachingJaxbLoaderImpl.java
/** * @param xmlInputStream InputStream to read the XML from * @param unmarshaller Unmarshaller to generate the object from the XML with * @return An unmarshalled object model of the XML *//* w w w. j a v a 2 s. c o m*/ @SuppressWarnings("unchecked") protected T unmarshal(final InputStream xmlInputStream, final Unmarshaller unmarshaller) { try { return (T) unmarshaller.unmarshal(xmlInputStream); } catch (JAXBException e) { throw new RuntimeException("Unexpected JAXB error while unmarshalling " + this.mappedXmlResource, e); } }
From source file:com.spend.spendService.DomainLearning.java
private SearchEngines getSearchEnginesFromXml() { try {// ww w . j a v a2 s . c om File file = new File("SearchEngines.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(SearchEngines.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); SearchEngines searchEngineList = (SearchEngines) jaxbUnmarshaller.unmarshal(file); return searchEngineList; } catch (JAXBException ex) { System.out.println("DomainLearning.java getSearchEnginesFromXml function ERROR " + ex.getMessage()); ex.printStackTrace(); } return null; }