List of usage examples for javax.xml.bind JAXBContext newInstance
public static JAXBContext newInstance(Class<?>... classesToBeBound) throws JAXBException
From source file:com.ponysdk.spring.ProxyBuilderGenerator.java
public static List<Root> getDefinitions(final String directories) throws JAXBException { final JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); final List<Root> definitions = new ArrayList<Root>(); final String[] split = directories.split(","); for (final String d : split) { final List<File> files = read(new File(d)); for (final File file : files) { System.out.println("file = " + file); final Root root = (Root) unmarshaller.unmarshal(file); definitions.add(root);// w ww . j a va2 s . co m } } return definitions; }
From source file:org.bremersee.comparator.test.ComparatorItemTests.java
@Before public void createJAXBContext() throws JAXBException { this.jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()); }
From source file:io.apiman.test.common.util.TestUtil.java
/** * Loads a test plan from a file resource. * @param planFile//from ww w.j a va 2 s .c om */ public static final TestPlan loadTestPlan(File planFile) { try { if (!planFile.isFile()) throw new RuntimeException("Test Plan not found: " + planFile.getCanonicalPath()); //$NON-NLS-1$ JAXBContext jaxbContext = JAXBContext.newInstance(TestPlan.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); TestPlan plan = (TestPlan) jaxbUnmarshaller.unmarshal(planFile); return plan; } catch (Throwable e) { throw new RuntimeException(e); } }
From source file:org.javelin.sws.ext.bind.SweJaxbContextFactoryTest.java
@Test(expected = JAXBException.class) public void nonExistingPackageForJaxbRi() throws Exception { JAXBContext.newInstance("a.b.c"); }
From source file:net.sf.dynamicreports.report.defaults.Defaults.java
private static XmlDynamicReports load() { String resource = "dynamicreports-defaults.xml"; InputStream is = null;// w ww . j av a 2s.c o m ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader != null) { is = classLoader.getResourceAsStream(resource); } if (is == null) { classLoader = Defaults.class.getClassLoader(); if (classLoader != null) { is = classLoader.getResourceAsStream(resource); } if (is == null) { is = Defaults.class.getResourceAsStream("/" + resource); } } if (is == null) { return null; } try { Unmarshaller unmarshaller = JAXBContext.newInstance(XmlDynamicReports.class).createUnmarshaller(); JAXBElement<XmlDynamicReports> root = unmarshaller.unmarshal(new StreamSource(is), XmlDynamicReports.class); return root.getValue(); } catch (JAXBException e) { log.error("Could not load dynamic reports defaults", e); return null; } }
From source file:org.osmsurround.ae.osmrequest.SchemaService.java
public Marshaller createOsmMarshaller() { try {//from w w w .java2 s. c o m return JAXBContext.newInstance(OsmRoot.class).createMarshaller(); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:ejava.projects.edmv.xml.EDmvBindingTest.java
public void setUp() throws Exception { JAXBContext jaxbc = JAXBContext.newInstance(Dmv.class); m = jaxbc.createMarshaller();/* w w w.ja v a2 s . com*/ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); }
From source file:labr_client.xml.ObjToXML.java
public static void jaxbObjectToXML(LabrRequest request, HashMap<String, String> patient) { try {/*from w ww. j av a 2s. c o m*/ JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); //----------PATIENT---------------------------- request.patient.name.setValue("De Mey"); request.patient.name.setX(20); request.patient.name.setY(50); request.patient.firstName.setValue("Matthias"); request.patient.firstName.setX(150); request.patient.firstName.setY(50); request.patient.birthDate.setValue("07/06/1990"); request.patient.birthDate.setX(20); request.patient.birthDate.setY(80); request.patient.gender.setValue("M"); request.patient.gender.setX(150); request.patient.gender.setY(80); request.patient.straatAndNumber.setValue("Hemelbeekstraat 16"); request.patient.straatAndNumber.setX(20); request.patient.straatAndNumber.setY(110); request.patient.zip.setValue("8000"); request.patient.zip.setX(20); request.patient.zip.setY(140); request.patient.city.setValue("Brugge"); request.patient.city.setX(120); request.patient.city.setY(140); request.patient.country.setValue("Belgie"); request.patient.country.setX(20); request.patient.country.setY(170); request.patient.nationalNumber.setValue("001-12345-223"); request.patient.nationalNumber.setX(120); request.patient.nationalNumber.setY(210); //----------ATTRIBUTEN------------------------- request.attributes.setAge(26); //----------LABELS----------------------------- LabrXMLLabel l = new LabrXMLLabel(); l.setColor("#110000"); l.setSize(12); l.setId("1"); l.setValue("Hematologie"); request.labels.getLabel().add(l); //---------KNOPPEN----------------------------- request.buttons.save.setX(300); request.buttons.save.setY(100); request.buttons.save.setColor(-65536); request.buttons.save.setWidth(100); request.buttons.save.setValue("Save"); //----------AANVRAGEN-------------------------- LabrXMLRequest r = new LabrXMLRequest(); r.setComment("Dit is commentaar"); r.setLoinc("Kalium"); request.requests.getRequest().add(r); r.setLoinc("Natrium"); request.requests.getRequest().add(r); //----------AANVRAGEN-------------------------- // Write to System.out for debugging // m.marshal(emp, System.out); // Write to File m.marshal(request, new File("C:\\Users\\labbl\\Documents\\test.xml")); } catch (JAXBException e) { e.printStackTrace(); } }
From source file:com.px100systems.util.XmlParser.java
/** * XML parser// ww w . j a v a 2 s .co m * @param xmlClass class to parse into */ public XmlParser(Class<T> xmlClass) { try { jaxb = JAXBContext.newInstance(xmlClass); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:org.fcrepo.integration.auth.oauth.api.TestBinding.java
@Test public void testBinding() throws JAXBException { LOGGER.trace("Executing testBinding()"); final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class); final Unmarshaller u = context.createUnmarshaller(); final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResourceAsStream("/web.xml")); Assert.assertEquals("Fedora-on-ModeShape", o.displayName()); Assert.assertTrue(o.contextParams()//from ww w. j ava 2 s .c o m .contains(new ContextParam("contextConfigLocation", "classpath:spring-test/rest.xml; " + "classpath:spring-test/repo.xml; " + "classpath:spring-test/security.xml"))); Assert.assertTrue(o.listeners() .contains(new Listener(null, "org.springframework.web.context.ContextLoaderListener"))); final ServletMapping sm = o.servletMappings("jersey-servlet").iterator().next(); Assert.assertNotNull(sm); Assert.assertEquals("/*", sm.urlPattern()); FilterMapping fm = o.filterMappings("TokenFilter").iterator().next(); Assert.assertNotNull(fm); Assert.assertEquals("/token", fm.urlPattern()); fm = o.filterMappings("OpFilter").iterator().next(); Assert.assertNotNull(fm); Assert.assertEquals("/rest/objects/authenticated/*", fm.urlPattern()); }