private static void createXml(TestObjects testObjects) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(Characters.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); File file = new File("Characters.xml"); marshaller.marshal(testObjects.getCharacters(), file); file = new File("LearningObjectiveOut.xml"); jaxbContext = JAXBContext.newInstance(LearningAct.class); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(testObjects.getLearningAct(), file); file = new File("ThemeOut.xml"); jaxbContext = JAXBContext.newInstance(Theme.class); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(testObjects.getTheme(), file); file = new File("LocaleOut.xml"); jaxbContext = JAXBContext.newInstance(Locale.class); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(testObjects.getLocale(), file); }
public void testCreateContextWithPathAndBindings() throws Exception { String oxmString = "org/eclipse/persistence/testing/jaxb/jaxbcontext/eclipselink-oxm.xml"; InputStream oxm = ClassLoader.getSystemClassLoader().getResourceAsStream(oxmString); Map<String, Object> props = new HashMap<String, Object>(); props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, oxm); // Specify some other, unrelated context path -- we want to ensure that we don't fail // due to lack of ObjectFactory/jaxb.index JAXBContext ctx = JAXBContext.newInstance( "org.eclipse.persistence.testing.oxm.jaxb", ClassLoader.getSystemClassLoader(), props); Employee e = new Employee(); e.id = 6; e.name = "Jeeves Sobs"; e.put("tag", "tag-value"); Document marshalDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Marshaller m = ctx.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(e, marshalDoc); // Make sure OXM was picked up, "tag" property should have been added. Employee e2 = (Employee) ctx.createUnmarshaller().unmarshal(marshalDoc); assertEquals( "OXM file was not processed during context creation.", e.get("tag"), e2.get("tag")); }
private static void writeGameXml() throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(Game.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); File file = new File("Game.xml"); marshaller.marshal(game, file); }
@Override public String prepareResponse(String className, Object o) throws ParseException { try { Class clazz = Class.forName(className); JAXBContext jaxbContext = JAXBContext.newInstance(clazz.getPackage().getName()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); marshaller.marshal(clazz.cast(o), byteArrayOutputStream); return byteArrayOutputStream.toString(); } catch (JAXBException e) { throw new ParseException( "Error occured during the parsing of request's XML body. The details of the exception " + e.toString(), 0); } catch (ClassNotFoundException e) { throw new ParseException( "Error occured during the parsing of request's XML body. The details of the exception " + e.toString(), 0); } }
/** * Marshalls a scenario object and writes into output XML file * * @throws JAXBException, SiriusException */ public void marshallIntoXML(Scenario scenarioToWrite) throws JAXBException, FileNotFoundException, BeatsException { JAXBContext jaxbContext = JAXBContext.newInstance("edu.berkeley.path.beats.jaxb"); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setSchema(this.getSchema()); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.marshal(scenarioToWrite, new File(this.outputFileName)); }
Context(Class clazz) { try { jaxbContext = JAXBContext.newInstance(clazz); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setSchema(null); unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(null); } catch (JAXBException e) { e.printStackTrace(); } }
private static void test() throws JAXBException { Scene scene = new Scene(); List<Screen> screens = new ArrayList<Screen>(); // scene.setScreen(screens); JAXBContext jaxbContext = JAXBContext.newInstance(Scene.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); File file = new File("Scene.xml"); marshaller.marshal(scene, file); file = new File("Scene.xml"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Scene scene2 = (Scene) unmarshaller.unmarshal(file); System.out.println(scene2); }
@Override public void execute() { try { File file = new File(path); file.mkdir(); file = new File(path + config.getName() + extention); file.createNewFile(); JAXBContext jc = JAXBContext.newInstance(PrintConfiguration.class); JAXBElement<PrintConfiguration> je = new JAXBElement<PrintConfiguration>( new QName(xmlHeadName), PrintConfiguration.class, config); Marshaller marshaller = jc.createMarshaller(); OutputStream os = new FileOutputStream(path + config.getName() + extention); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(je, os); file = null; os = null; System.gc(); result = Boolean.TRUE; } catch (Exception ex) { Logger.getLogger(SavePrintConfigurationCommand.class.getName()).log(Level.SEVERE, null, ex); result = Boolean.FALSE; } }
@Override protected void setUp() throws Exception { JAXBContext jc = JAXBContextFactory.createContext(new Class[] {FlushRoot.class}, null); marshaller = jc.createMarshaller(); unmarshaller = jc.createUnmarshaller(); }