List of usage examples for javax.xml.bind JAXBContext createMarshaller
public abstract Marshaller createMarshaller() throws JAXBException;
From source file:de.xirp.profile.ProfileGenerator.java
/** * Generates a BOT file with the given path from the given * {@link de.xirp.profile.Robot robot} bean. * //from w w w . j a va2s. co m * @param robot * The robot to generate the XML for. * @param botFile * The file to write the result to. Must be the full path. * * @throws JAXBException if the given robot was null, or something * went wrong generating the xml. * @throws FileNotFoundException if something went wrong generating the xml. */ public static void generateBOT(Robot robot, File botFile) throws FileNotFoundException, JAXBException { if (robot == null) { throw new JAXBException(I18n.getString("ProfileGenerator.exception.robotNull")); //$NON-NLS-1$ } String fileName = FilenameUtils.getBaseName(botFile.getName()); JAXBContext jc = JAXBContext.newInstance(Robot.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(robot, new FileOutputStream( Constants.CONF_ROBOTS_DIR + File.separator + fileName + Constants.ROBOT_POSTFIX)); }
From source file:eu.planets_project.tb.impl.serialization.ExperimentViaJAXB.java
/** * @param exp//from w w w. java 2 s . c om * @param out */ private static void writeToOutputStream(ExperimentImpl exp, OutputStream out) { try { JAXBContext jc = JAXBContext.newInstance(PACKAGE_CONTEXT); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(exp, out); } catch (JAXBException e) { log.fatal("Writing Experiment to XML failed: " + e); } }
From source file:de.xirp.profile.ProfileGenerator.java
/** * Generates a PRO file with the given path from the given * {@link de.xirp.profile.Profile profile} bean. * //from w w w . j a va2s .c om * @param profile * The profile to generate the XML for. * @param proFile * The file to write the result to. Must be the full path. * * @throws JAXBException if the given profile was null, or something * went wrong generating the xml. * @throws FileNotFoundException if something went wrong generating the xml. * * @see de.xirp.profile.Profile */ public static void generatePRO(Profile profile, File proFile) throws JAXBException, FileNotFoundException { if (profile == null) { throw new JAXBException(I18n.getString("ProfileGenerator.exception.profileNull")); //$NON-NLS-1$ } String fileName = FilenameUtils.getBaseName(proFile.getName()); JAXBContext jc = JAXBContext.newInstance(Profile.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(profile, new FileOutputStream( Constants.CONF_PROFILES_DIR + File.separator + fileName + Constants.PROFILE_POSTFIX)); }
From source file:com.netflix.imfutility.dpp.audio.AudioMapHelper.java
public static void writeAudioMapToFile(File outputFile, AudioMapType audioMap) { JAXBContext jaxbContext; try {/*w ww .jav a2 s .c o m*/ jaxbContext = JAXBContext.newInstance(AudioMapType.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); JAXBElement<AudioMapType> audioMapJaxb = new ObjectFactory().createAudioMap(audioMap); jaxbMarshaller.marshal(audioMapJaxb, outputFile); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:com.topsem.common.mapper.JaxbMapper.java
/** * Marshallerencoding(?null)./*from w w w . j a v a 2 s . c om*/ * ???pooling */ public static Marshaller createMarshaller(Class clazz, String encoding) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (StringUtils.isNotBlank(encoding)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); } return marshaller; } catch (JAXBException e) { throw Throwables.propagate(e); } }
From source file:com.wsun.seap.common.mapper.JaxbMapper.java
/** * Marshallerencoding(?null)./* w w w . jav a 2 s .co m*/ * ???pooling */ public static Marshaller createMarshaller(Class clazz, String encoding) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (StringUtils.isNotBlank(encoding)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); } return marshaller; } catch (JAXBException e) { throw ExceptionUtil.unchecked(e); } }
From source file:com.androidwhy.modules.mapper.JaxbMapper.java
/** * Marshallerencoding(?null).// ww w. jav a 2 s . co m * ???pooling */ public static Marshaller createMarshaller(Class clazz, String encoding) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (StringUtils.isNotBlank(encoding)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); } return marshaller; } catch (JAXBException e) { throw Exceptions.unchecked(e); } }
From source file:com.plateform.common.util.JaxbMapper.java
/** * Marshallerencoding(?null)./*www . ja va2s . c om*/ * ???pooling */ public static Marshaller createMarshaller(Class clazz, String encoding) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (StringUtils.isNotBlank(encoding)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); } return marshaller; } catch (JAXBException e) { throw ExceptionUtils.unchecked(e); } }
From source file:at.ac.tuwien.dsg.comot.m.common.Utils.java
public static String asXmlString(Object obj, String contextPath) throws JAXBException { StringWriter w = new StringWriter(); JAXBContext context = JAXBContext.newInstance(contextPath); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(obj, w);/* www. ja v a 2 s.c o m*/ return w.toString(); }
From source file:eu.seaclouds.platform.dashboard.util.ObjectMapperHelpers.java
/** * Transforms an annotated Object to a XML string using javax.xml.bind.Marshaller * * @param object to transform to a XML String * @return a XML string representing the object * @throws IOException if is not possible to parse the object *//*from ww w .j a va2s . co m*/ public static String ObjectToXml(Object object) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(object, sw); return sw.toString(); }