Example usage for javax.xml.bind Marshaller setProperty

List of usage examples for javax.xml.bind Marshaller setProperty

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller setProperty.

Prototype

public void setProperty(String name, Object value) throws PropertyException;

Source Link

Document

Set the particular property in the underlying implementation of Marshaller .

Usage

From source file:Main.java

/**
 *
 * @param obj//from  w ww .ja  v  a 2s  . c  om
 * @param os
 * @throws JAXBException
 */
public static void serialize(Object obj, OutputStream os) throws JAXBException {
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.setProperty(JAXB_FRAGMENT, TRUE);
    m.marshal(obj, os);
}

From source file:Main.java

/**
 *
 * @param obj//from  w  w  w  .  j av  a  2s.  c  om
 * @param filename
 * @throws JAXBException
 * @throws FileNotFoundException
 */
public static void serialize(Object obj, String filename) throws JAXBException, FileNotFoundException {
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.setProperty(JAXB_FRAGMENT, TRUE);
    m.setProperty(JAXB_FORMATTED_OUTPUT, TRUE);
    m.marshal(obj, new FileOutputStream(filename));
}

From source file:Main.java

/**
 *
 * @param obj//from www .  ja v  a 2s  .  c o  m
 * @param file
 * @throws JAXBException
 * @throws FileNotFoundException
 */
public static void serialize(Object obj, File file) throws JAXBException, FileNotFoundException {
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.setProperty(JAXB_FRAGMENT, TRUE);
    m.setProperty(JAXB_FORMATTED_OUTPUT, TRUE);
    m.marshal(obj, new FileOutputStream(file));
}

From source file:Main.java

/**
 *
 * @param obj//from w w w  .  j  a  v  a2  s.c  om
 * @param w
 * @throws JAXBException
 * @throws FileNotFoundException
 */
public static void serialize(Object obj, Writer w) throws JAXBException, FileNotFoundException {
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.setProperty(JAXB_FRAGMENT, TRUE);
    m.setProperty(JAXB_FORMATTED_OUTPUT, TRUE);
    m.marshal(obj, w);
}

From source file:eu.seaclouds.platform.planner.core.application.decorators.SeaCloudsManagementPolicyDecorator.java

private static String encodeBase64MonitoringRules(MonitoringInfo monitoringInfo) {
    StringWriter sw = new StringWriter();
    String encodeMonitoringRules;
    JAXBContext jaxbContext;//from www .  j  a  v  a 2 s . co  m
    String marshalledMonitoringRules = null;
    try {
        jaxbContext = JAXBContext.newInstance(MonitoringRules.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        jaxbMarshaller.marshal(monitoringInfo.getApplicationMonitoringRules(), sw);
        marshalledMonitoringRules = sw.toString();
    } catch (JAXBException e) {
        log.error("Monitoring rules {} can not be marshalled by addSeaCloudsPolicy in " + "DamGenerator",
                monitoringInfo.getApplicationMonitoringRules());
    }
    encodeMonitoringRules = Base64.encodeBase64String(marshalledMonitoringRules.getBytes());
    return encodeMonitoringRules;
}

From source file:de.iteratec.iteraplan.businesslogic.service.SavedQueryXmlHelper.java

private static Marshaller getMarshaller(Class<?> clazz, String schemaName) throws JAXBException, SAXException {
    JAXBContext context = JAXBContext.newInstance(clazz);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setSchema(getSchema(schemaName));//www  .j  av a2 s  .  c o m
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_URI + " " + SCHEMA_URI + schemaName);

    return m;
}

From source file:eu.planets_project.tb.impl.serialization.ExperimentViaJAXB.java

/**
 * @param exp// ww w  . jav  a2 s  .  com
 * @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:ee.ria.xroad.proxy.clientproxy.MetadataClientRequestProcessor.java

private static void marshal(Object object, OutputStream out) throws Exception {
    Marshaller marshaller = JAXB_CTX.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(object, out);/*w w w.j  a  v a2  s .c  o m*/
}

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.
 * /*w  w  w .j a  v  a 2 s  .  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:de.xirp.profile.ProfileGenerator.java

/**
 * Generates a BOT file with the given path from the given 
 * {@link de.xirp.profile.Robot robot} bean.
 * //w ww  .j a  va  2  s. c  om
 * @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));
}