List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:edu.usc.goffish.gopher.impl.client.DeploymentTool.java
public void setup(String gofsConfig, String managerHost, String coordinatorHost, boolean persist) throws IOException, ConfigurationException { int numberOfProcessors = 0; PropertiesConfiguration gofs = new PropertiesConfiguration(gofsConfig); gofs.load();/*www .ja va 2 s. co m*/ String nameNodeRestAPI = gofs.getString(GoFSFormat.GOFS_NAMENODE_LOCATION_KEY); INameNode nameNode = new RemoteNameNode(URI.create(nameNodeRestAPI)); numberOfProcessors = nameNode.getDataNodes().size(); // generate flow graph. FloeGraphGenerator generator = new FloeGraphGenerator(); OMElement xmlOm = generator.createFloe(numberOfProcessors); xmlOm.build(); try { JAXBContext ctx = JAXBContext.newInstance(FloeGraph.class); Unmarshaller um = ctx.createUnmarshaller(); FloeGraph floe = (FloeGraph) um.unmarshal(xmlOm.getXMLStreamReader()); if (persist) { FileOutputStream fileOutputStream = new FileOutputStream(new File(FLOE_GRAPH_PATH)); ctx.createMarshaller().marshal(floe, fileOutputStream); } DefaultClientConfig config = new DefaultClientConfig(); config.getProperties().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true); config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true); Client c = Client.create(config); WebResource r = c .resource("http://" + coordinatorHost + ":" + COORDINATOR_PORT + "/Coordinator/createFloe"); c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); ClientResponse response; c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); response = r.post(ClientResponse.class, floe); StartFloeInfo startFloeInfo = response.getEntity(StartFloeInfo.class); createClientConfig(startFloeInfo, managerHost, coordinatorHost); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.healthcit.cacure.web.controller.FormExportController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView importForm(@RequestParam("file") MultipartFile file, @RequestParam("moduleId") long moduleId, HttpServletRequest request, HttpServletResponse response) { try {/*from ww w. j av a2 s. c om*/ if (file != null) { Map<String, String> existingForms = new HashMap<String, String>(); List<String> existingQuestions = new ArrayList<String>(); InputStream is = file.getInputStream(); JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model"); Unmarshaller m = jc.createUnmarshaller(); Cure cure = (Cure) m.unmarshal(is); dataImporter.importData(cure, moduleId, existingForms, existingQuestions); if (existingForms.size() > 0 || existingQuestions.size() > 0) { ModelAndView mav = new ModelAndView("formUploadStatus"); // initialize with view name ModelMap model = mav.getModelMap(); model.addAttribute("existingForms", existingForms); model.addAttribute("existingQuestions", existingQuestions); return mav; /* there had been errors */ // return new ModelAndView("formUploadStatus", "existingForms", existingForms); } } return new ModelAndView("formUploadStatus", "status", "OK"); } catch (Exception e) { log.error(e.getMessage(), e); return new ModelAndView("formUploadStatus", "status", "FAIL"); } }
From source file:org.apereo.services.persondir.support.xml.CachingJaxbLoaderImpl.java
/** * @param jaxbContext The context to get an unmarshaller for * @return An unmarshaller to use to generate object from the XML *///from w ww. j a va2s . c o m protected Unmarshaller getUnmarshaller(final JAXBContext jaxbContext) { try { return jaxbContext.createUnmarshaller(); } catch (final JAXBException e) { throw new RuntimeException( "Failed to create " + Unmarshaller.class + " to unmarshal " + this.loadedType, e); } }
From source file:dk.dma.epd.common.prototype.communication.webservice.ShoreHttp.java
public Object getXmlUnmarshalledContent(String contextPath) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(contextPath); Unmarshaller u = jc.createUnmarshaller(); return u.unmarshal(new ByteArrayInputStream(responseBody)); }
From source file:info.raack.appliancelabeler.service.OAuthRequestProcessor.java
@PostConstruct public void init() { try {/*from w w w .j av a 2s . co m*/ JAXBContext jc = JAXBContext.newInstance("edu.cmu.hcii.stepgreen.data.teds"); u1 = jc.createUnmarshaller(); SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); URL url = this.getClass().getClassLoader().getResource("teds.xsd"); Schema schema = sf.newSchema(url); u1.setSchema(schema); jc = JAXBContext.newInstance("edu.cmu.hcii.stepgreen.data.base"); u2 = jc.createUnmarshaller(); sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); url = this.getClass().getClassLoader().getResource("stepgreen.xsd"); schema = sf.newSchema(url); u2.setSchema(schema); } catch (Exception e) { throw new RuntimeException("Could not create JAXB unmarshaller", e); } }
From source file:in.gov.uidai.core.aua.client.BfdClient.java
private BfdRes parseBfdResponseXML(String xmlToParse) throws JAXBException { //Create an XMLReader to use with our filter try {/*from w ww . j a v a 2 s . c o m*/ //Prepare JAXB objects JAXBContext jc = JAXBContext.newInstance(BfdRes.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/auth/uid-bfd-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 BfdRes res = u.unmarshal(source, BfdRes.class).getValue(); return res; } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java
/** * * Reads and unmarshalls Digital Object/*from w w w.jav a 2s .c o m*/ * * @param path * @return */ public static DigitalObject readFoXML(String path) throws MetsExportException { DigitalObject foXMLObject; File file = new File(path); try { JAXBContext jaxbContext = JAXBContext.newInstance(DigitalObject.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); foXMLObject = (DigitalObject) unmarshaller.unmarshal(file); return foXMLObject; } catch (JAXBException e) { throw new MetsExportException("Unable to read FoXML document " + path, false, e); } }
From source file:eu.eco2clouds.accounting.bonfire.BFClientAccountingImpl.java
@Override public Experiment getExperiment(String userId, long experimentId) { this.userId = userId; Boolean exception = false;//from w ww. j a va 2 s .c o m 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:com.healthcit.cacure.web.controller.ModuleImportExportController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView importModule(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {//from ww w . j a v a 2s. co m try { if (file != null) { Map<String, String> existingForms = new HashMap<String, String>(); Map<String, String> existingModules = new HashMap<String, String>(); List<String> existingQuestions = new ArrayList<String>(); InputStream is = file.getInputStream(); JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model"); Unmarshaller m = jc.createUnmarshaller(); Cure cure = (Cure) m.unmarshal(is); dataImporter.importModule(cure, existingModules, existingForms, existingQuestions); if (existingModules.size() > 0 || existingForms.size() > 0 || existingQuestions.size() > 0) { ModelAndView mav = new ModelAndView("formUploadStatus"); // initialize with view name ModelMap model = mav.getModelMap(); model.addAttribute("existingModules", existingModules); model.addAttribute("existingForms", existingForms); model.addAttribute("existingQuestions", existingQuestions); return mav; /* there had been errors */ // return new ModelAndView("formUploadStatus", "existingForms", existingForms); } } return new ModelAndView("formUploadStatus", "status", "OK"); } catch (Exception e) { log.error(e.getMessage(), e); return new ModelAndView("formUploadStatus", "status", "FAIL"); } }
From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java
/** * * Reads and unmarshalls Digital Object from Fedora * * @param path// ww w .ja v a 2s . 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; }