List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:com.rabidgremlin.legalbeagle.util.HttpHelper.java
public HttpHelper() throws Exception { JAXBContext jc = JAXBContext.newInstance("com.rabidgremlin.legalbeagle.xmlbindings"); u = jc.createUnmarshaller(); // -Dhttp.proxyHost=prox -Dhttp.proxyPort=1234 // TODO: better error handling here if (System.getProperty("http.proxyHost") != null) { proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.getInteger("http.proxyPort")); }// ww w . j a v a 2 s . c om }
From source file:hydrograph.ui.dataviewer.utilities.ViewDataSchemaHelper.java
/** * This function will read schema file and return schema fields * @param schemaFilePath// ww w. java 2 s . com * @return Fields */ public Fields getFieldsFromSchema(String schemaFilePath) { Fields fields = null; if (StringUtils.isNotBlank(schemaFilePath)) { String filePath = ((IPath) new Path(schemaFilePath)).removeFileExtension() .addFileExtension(Constants.XML_EXTENSION_FOR_IPATH).toString(); File file = new File(filePath); if (file.exists()) { try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setExpandEntityReferences(false); builderFactory.setNamespaceAware(true); builderFactory.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION, true); DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Schema schema = (Schema) jaxbUnmarshaller.unmarshal(document); fields = schema.getFields(); for (Field field : fields.getField()) { logger.debug("Type:{}, Name:{}, Format:{}" + field.getType(), field.getName(), field.getFormat()); } } catch (JAXBException | ParserConfigurationException | SAXException | IOException exception) { logger.error("Invalid xml file: ", exception); } } } return fields; }
From source file:it.iit.genomics.cru.structures.bridges.eppic.client.EppicJaxbClient.java
private EppicAnalysisList getPdbInterfaces(String fileName) { try {// w w w . ja v a 2 s. c om XMLInputFactory xmlif = XMLInputFactory.newInstance(); XMLStreamReader xmler = xmlif.createXMLStreamReader(new FileReader(fileName)); JAXBContext jaxbContext = JAXBContext.newInstance(EppicAnalysisList.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); EppicAnalysisList result; result = (EppicAnalysisList) jaxbUnmarshaller.unmarshal(xmler); return result; } catch (JAXBException | IOException | XMLStreamException e) { logger.error(null, e); } return null; }
From source file:org.usd.edu.btl.cli.ConvertGalaxy.java
public void toBets(String inputS, String output) { System.out.println("Converting from GALAXY TO BETS"); File input = new File(inputS); InputStream infile = null;/* w w w . j ava2s . c o m*/ Tool myTool = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); //Unmarshalling Conversion XML content into a Java Object. infile = new FileInputStream(input); Tool test_tool = (Tool) unmarshaller.unmarshal(infile); myTool = test_tool; //System.out.println(test_tool.toString()); //print the test_tool } catch (FileNotFoundException | JAXBException e) { System.out.println(e.getMessage()); } finally { try { if (infile != null) { infile.close(); } } catch (IOException e) { System.out.println("You're rubbish, you can't even close a file"); System.out.println(e.getMessage()); } } //JAXB-Marshall Java back to XML // try { // JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class); // Marshaller marshaller = jaxbContext.createMarshaller(); //Marshalling Conversion a Java object into a XML file. // marshaller.marshal(myTool, System.out); //print XML out // } catch (JAXBException e) { // System.out.println("JAXB dun goofed"); // System.out.println(e.getMessage()); // } // RUN GALAXY TO BETS CONVERSION BETSV1 betsOutput = GalaxyConverter.toBETS(myTool); try { ObjectMapper mapper = new ObjectMapper(); System.out.println("************************************************\n" + "*********PRINTING OUT CONVERSION************\n" + "----------Galaxy --> Bets--------------\n" + "************************************************\n"); //print objects as Json using jackson ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter(); String betsJson = ow.writeValueAsString(betsOutput); //write Json as String System.out.println("=== GALAXY TO BETS JSON === \n" + betsJson); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:edu.harvard.i2b2.fhir.query.nonx.SearchParameterMap.java
public void init() throws JAXBException { JAXBContext context = JAXBContext.newInstance(SearchParameter.class); Unmarshaller um = context.createUnmarshaller(); SearchParameter p = null;/*from w ww . java 2 s . c o m*/ if (list == null) { list = new ArrayList<SearchParameter>(); String bundleString = null; try { bundleString = IOUtils .toString(SearchParameter.class.getResourceAsStream("/profiles/search-parameters.xml")); } catch (IOException e) { logger.error(e.getMessage(), e); } // logger.trace("bundleString:"+bundleString); Bundle b = JAXBUtil.fromXml(bundleString, Bundle.class); for (BundleEntry rc : b.getEntry()) { p = rc.getResource().getSearchParameter(); list.add(p); } } }
From source file:fr.fastconnect.factory.tibco.bw.codereview.CodeReviewInitialize.java
private ReviewResult loadReviewResult(File f) { try {//w w w . j a v a2s. co m JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Object o = jaxbUnmarshaller.unmarshal(f); return (ReviewResult) o; } catch (JAXBException e) { e.printStackTrace(); } return null; }
From source file:eu.europa.ec.fisheries.uvms.plugins.ais.TestStartupBean.java
private RegisterServiceRequest unmarshallMessage(String message) throws JAXBException { JAXBContext context = JAXBContext.newInstance(RegisterServiceRequest.class); return (RegisterServiceRequest) context.createUnmarshaller().unmarshal(new StringReader(message)); }
From source file:fr.mael.microrss.xml.AtomFeedParser.java
@Override public Feed parseFeedInfo(Feed feed) throws Exception { JAXBContext jc = JAXBContext.newInstance("fr.mael.microrss.xml.atom"); Unmarshaller unmarshaller = jc.createUnmarshaller(); Object o = unmarshaller.unmarshal(new URL(feed.getUrl()).openStream()); if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; FeedType feedType = (FeedType) element.getValue(); String link = XMLUtil.readLinkType("link", feedType.getAuthorOrCategoryOrContributor()); feed.setIcon(Tools.getImage(Tools.getBaseUrl(link) + "/favicon.ico")); feed.setTitle(XMLUtil.readTextType("title", feedType.getAuthorOrCategoryOrContributor())); }//w w w .j av a 2s. com return feed; }
From source file:ymanv.forex.provider.impl.EuropeanCentralBank.java
private List<RateEntity> getRates(String response, boolean usdBase) throws IOException { SimpleDateFormat sf = new SimpleDateFormat(DATE_FORMAT_STRNG); Calendar sfCalendar = sf.getCalendar(); sfCalendar.setTimeZone(TZ);/*from w ww .j a v a 2 s. co m*/ List<RateEntity> rates = new ArrayList<>(); String cleanResponse = response.substring(response.indexOf("<Cube>"), response.lastIndexOf("</Cube>") + 7); try { JAXBContext context = JAXBContext.newInstance(Result.class); Unmarshaller un = context.createUnmarshaller(); Result res = (Result) un.unmarshal(new StringReader(cleanResponse)); for (Day d : res.getDays()) { Date date = d.getDate(); sf.parse(sf.format(date)); sfCalendar.set(Calendar.HOUR, 15); date = sf.getCalendar().getTime(); if (!usdBase) { for (Rate r : d.getRates()) { rates.add(new RateEntity(BASE_CURRENCY, r.getTocur(), new BigDecimal(r.getValue()), date)); } } else { BigDecimal usdToEurValue = null; for (Rate r : d.getRates()) { if (USD.equals(r.getTocur())) { usdToEurValue = invert(new BigDecimal(r.getValue())); break; } } for (Rate r : d.getRates()) { if (USD.equals(r.getTocur())) { rates.add(new RateEntity(USD, BASE_CURRENCY, usdToEurValue, date)); } else { rates.add(new RateEntity(USD, r.getTocur(), new BigDecimal(r.getValue()).multiply(usdToEurValue), date)); } } } } return rates; } catch (ParseException | JAXBException e) { throw new IOException(e); } }
From source file:edu.wisc.cypress.dm.CypressJaxbTest.java
private <T> T unmarshall(String resource, Class<T> clazz) throws Exception { final JAXBContext context = JAXBContext.newInstance(clazz.getPackage().getName()); final Unmarshaller unmarshaller = context.createUnmarshaller(); final InputStream xmlStream = this.getClass().getResourceAsStream(resource); try {/*from w w w.j ava 2 s .c o m*/ assertNotNull(xmlStream); final JAXBElement<T> statements = unmarshaller.unmarshal(new StreamSource(xmlStream), clazz); return statements.getValue(); } finally { IOUtils.closeQuietly(xmlStream); } }