Example usage for javax.xml.bind Marshaller JAXB_FRAGMENT

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

Introduction

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

Prototype

String JAXB_FRAGMENT

To view the source code for javax.xml.bind Marshaller JAXB_FRAGMENT.

Click Source Link

Document

The name of the property used to specify whether or not the marshaller will generate document level events (ie calling startDocument or endDocument).

Usage

From source file:org.openmainframe.ade.ext.output.ExtJaxbAnalyzedIntervalV2XmlStorer.java

/**
 * Begin of Stream/*  ww w.j  a  va 2  s. c o m*/
 */
@Override
public void beginOfStream() throws AdeException, AdeFlowException {
    if (s_marshaller == null) {
        JAXBContext jaxbContext;
        try {
            jaxbContext = JAXBContext.newInstance(ADEEXT_JAXB_CONTEXT);
        } catch (JAXBException e) {
            throw new AdeInternalException(
                    "failed to create JAXBContext object for package " + Arrays.toString(ADEEXT_JAXB_CONTEXT),
                    e);
        }
        try {
            s_marshaller = jaxbContext.createMarshaller();
        } catch (JAXBException e) {
            throw new AdeInternalException("failed to create JAXB Marshaller object", e);
        }
        try {
            s_marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, m_formatXMLOutput);
            s_marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            s_marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, XML_INTERVAL_V2_XSD);

        } catch (PropertyException e) {
            throw new AdeInternalException("failed to set formatted output for JAXB Marshaller object", e);
        }

        SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

        File xmlParent = Ade.getAde().getConfigProperties().getXsltDir().getAbsoluteFile();
        xmlParent = xmlParent.getParentFile();
        File intervalSchema = new File(xmlParent, XML_INTERVAL_V2_XSD);

        Schema schema;
        try {
            URL analyzedIntervalSchema = intervalSchema.toURI().toURL();
            schema = sf.newSchema(analyzedIntervalSchema);
        } catch (SAXException e) {
            throw new AdeInternalException("failed to create XML Schemal for event log analysis results", e);
        } catch (MalformedURLException e) {
            throw new AdeInternalException(
                    "failed to create URL from Schema path: " + intervalSchema.getAbsolutePath(), e);
        }
        s_marshaller.setSchema(schema);
    }
    m_xmlMetaData = new XMLMetaDataRetriever();
}

From source file:org.openmainframe.ade.ext.output.ExtJaxbAnalyzedPeriodV2XmlStorer.java

/**
 * Begin of Stream/* w  w w.j a v  a2 s.  c  om*/
 */
@Override
public void beginOfStream() throws AdeException, AdeFlowException {
    if (s_marshaller == null) {
        JAXBContext jaxbContext;
        try {
            jaxbContext = JAXBContext.newInstance(ADEEXT_JAXB_CONTEXT);
        } catch (JAXBException e) {
            throw new AdeInternalException(
                    "failed to create JAXBContext object for package " + Arrays.toString(ADEEXT_JAXB_CONTEXT),
                    e);
        }
        try {
            s_marshaller = jaxbContext.createMarshaller();
        } catch (JAXBException e) {
            throw new AdeInternalException("failed to create JAXB Marshaller object", e);
        }
        try {
            s_marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, m_formatXMLOutput);
            s_marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            s_marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, XML_PLEX_V2_XSD);
        } catch (PropertyException e) {
            throw new AdeInternalException("failed to set formatted output for JAXB Marshaller object", e);
        }

        SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

        File xmlParent = Ade.getAde().getConfigProperties().getXsltDir().getAbsoluteFile();
        xmlParent = xmlParent.getParentFile();
        File systemSchema = new File(xmlParent, XML_PLEX_V2_XSD);

        Schema schema;
        try {
            URL systemSchemaURL = systemSchema.toURI().toURL();
            schema = sf.newSchema(systemSchemaURL);
        } catch (SAXException e) {
            throw new AdeInternalException("failed to create XML Schemal for event log analysis results", e);
        } catch (MalformedURLException e) {
            throw new AdeInternalException(
                    "failed to create URL from Schema path: " + systemSchema.getAbsolutePath(), e);
        }
        s_marshaller.setSchema(schema);
    }

    /* Retrieve the Model Data Here.  Force refresh, in case the Model's Analysis Group Change without impacting
     * the model internal ID. */
    m_xmlMetaData.retrieveXMLMetaData(m_lastKnownModelInternalID, true, m_framingFlowType.getDuration());

    /* Write out the period when it's begin of stream, within a period */
    if (m_inPeriod) {
        writePeriod();
    }
}

From source file:org.opennms.core.xml.JaxbUtils.java

public static Marshaller getMarshallerFor(final Object obj, final JAXBContext jaxbContext) {
    final Class<?> clazz = (Class<?>) (obj instanceof Class<?> ? obj : obj.getClass());

    Map<Class<?>, Marshaller> marshallers = m_marshallers.get();
    if (jaxbContext == null) {
        if (marshallers == null) {
            marshallers = new WeakHashMap<Class<?>, Marshaller>();
            m_marshallers.set(marshallers);
        }//from   ww w  .j a v a 2s  . co m
        if (marshallers.containsKey(clazz)) {
            LOG.trace("found unmarshaller for {}", clazz);
            return marshallers.get(clazz);
        }
    }
    LOG.trace("creating unmarshaller for {}", clazz);

    try {
        final JAXBContext context;
        if (jaxbContext == null) {
            context = getContextFor(clazz);
        } else {
            context = jaxbContext;
        }
        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        if (context.getClass().getName().startsWith("org.eclipse.persistence.jaxb")) {
            marshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER,
                    new EmptyNamespacePrefixMapper());
            marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, true);
        }
        final Schema schema = getValidatorFor(clazz);
        marshaller.setSchema(schema);
        if (jaxbContext == null)
            marshallers.put(clazz, marshaller);

        return marshaller;
    } catch (final JAXBException e) {
        throw EXCEPTION_TRANSLATOR.translate("creating XML marshaller", e);
    }
}

From source file:org.osate.atsv.integration.EngineConfigModel.ExplorationEngineModel.java

public void renderConfigurator() throws JAXBException, UnsatisfiableConstraint,
        ConfiguratorRepresentationException, UnsupportedFeatureException {
    if (cm.isEmpty()) {
        configurator = "";
        return;/*  ww  w . j a v a 2  s .  com*/
    }
    JAXBContext context = JAXBContext.newInstance(ConfiguratorsModel.class, SimpleConfiguratorModel.class,
            ImpliesConfiguratorModel.class, SetRestrictionConfiguratorModel.class);
    ConfiguratorModelAdapter configuratorAdapter = new ConfiguratorModelAdapter();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Marshaller marshal = context.createMarshaller();
    marshal.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
    marshal.setProperty(Marshaller.JAXB_FRAGMENT, true);
    marshal.setAdapter(configuratorAdapter);
    JAXBElement<ConfiguratorsModel> configuratorXML = new JAXBElement<ConfiguratorsModel>(
            new QName("Configurator"), ConfiguratorsModel.class, cm);
    marshal.marshal(configuratorXML, stream);
    configurator = stream.toString();
}

From source file:org.overlord.sramp.server.atom.workspaces.AbstractWorkspaceTest.java

/**
 * Marshalls the app service to XML./*  w ww  .jav  a2s.c  om*/
 * @param appService
 */
public static String marshall(AppService appService) throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(AppService.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
    StringWriter writer = new StringWriter();
    JAXBElement<AppService> element = new JAXBElement<AppService>(new QName("", "app:service", "app"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            AppService.class, appService);
    marshaller.marshal(element, writer);
    return writer.toString();
}

From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java

/**
 * Constructs a new exporting input stream with the default buffer size of 64KB.
 * /* ww w  .j av a2 s .c  o m*/
 * @param synchronizers the synchronizers to invoke when producing the export file
 * @param messagesPerExporter a reference to a map of messages that the exporters will use to produce additional info about the export
 * @param size the size in bytes of the intermediate buffer
 * @param zip whether to zip the export data
 * @throws IOException on failure
 */
public ExportingInputStream(Set<Synchronizer<?, ?>> synchronizers,
        Map<String, ExporterMessages> messagesPerExporter, int size, boolean zip) throws IOException {
    this.synchronizers = synchronizers;
    this.messagesPerExporter = messagesPerExporter;
    inputStream = new PipedInputStream(size);
    exportOutput = new PipedOutputStream(inputStream);
    zipOutput = zip;

    try {
        JAXBContext context = JAXBContext.newInstance(DefaultImportConfigurationDescriptor.class);

        configurationMarshaller = context.createMarshaller();
        configurationMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        configurationMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        configurationMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

    } catch (JAXBException e) {
        throw new IOException(e);
    }
}

From source file:org.springframework.ws.soap.PerformanceTest.java

public PerformanceTest(SoapMessageFactory messageFactory, StopWatch stopWatch) throws Exception {
    if (messageFactory instanceof InitializingBean) {
        ((InitializingBean) messageFactory).afterPropertiesSet();
    }//from w ww .  j  a  va 2  s . com
    this.messageFactory = messageFactory;
    JAXBContext jaxbContext = JAXBContext.newInstance(MyRootElement.class);
    marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

    jaxbElement = new MyRootElement();
    for (int i = 0; i < ELEMENTS; i++) {
        jaxbElement.getStrings().add(String.valueOf(i));
    }

    os = new NullOutputSteam();

    this.stopWatch = stopWatch;

    this.transformer = TransformerFactory.newInstance().newTransformer();
}

From source file:org.squidy.nodes.laserpointer.config.ConfigConnection.java

public ConfigConnection(ConfigManager configManager, Socket socket) {
    this.configManager = configManager;
    this.socket = socket;

    try {/*from  ww w  . j ava 2 s  . c  o m*/
        unmarshaller = ConfigManager.getJAXBContext().createUnmarshaller();
        marshaller = ConfigManager.getJAXBContext().createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

        start();
    } catch (JAXBException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Couldn't initiate JAXB: " + e.getMessage(), e);
        }
    }
}

From source file:org.squidy.nodes.laserpointer.configclient.service.comm.TcpIpCommService.java

@Override
protected void startupImpl() throws CommException {
    Object property = pService.getProperties().getProperty(JavaPropService.DEBUG_COMM);
    if (property != null) {
        debug = Boolean.parseBoolean((String) property);
    }//from ww  w .j  av a  2s  .  com
    if (debug)
        initDebugOutput();

    // init connection
    LOG.info("Creating connection: " + address);
    try {
        server = new Socket(address.getAddress(), address.getPort());
        LOG.info("Connection accepted");
        newConnection(server.getInputStream(), server.getOutputStream());
    } catch (ConnectException e) {
        String msg = "Connection to " + address + " refused.";
        LOG.error(msg);
        throw new CommException(msg);
    } catch (UnknownHostException e) {
        String msg = "Unknown host: " + address;
        LOG.error(msg);
        throw new CommException(msg);
    } catch (IOException e) {
        String msg = "Cannot read from: " + address;
        LOG.error(msg);
        throw new CommException(msg);
    }

    // init jaxb
    try {
        context = JAXBContext.newInstance("org.squidy.nodes.laserpointer.config.xml");
        unmarshaller = context.createUnmarshaller();
        marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    } catch (JAXBException e) {
        LOG.error(e.getMessage(), e);
        throw new CommException(CommService.INTERNAL_ERROR_MSG);
    }
}

From source file:org.squidy.nodes.tracking.configclient.service.comm.TcpIpCommService.java

@Override
protected void startupImpl() throws CommException {
    Object property = pService.getProperties().getProperty(JavaPropService.DEBUG_COMM);
    if (property != null) {
        debug = Boolean.parseBoolean((String) property);
    }//  w  w w  .  ja  v a2  s  . c om
    if (debug)
        initDebugOutput();

    // init connection
    LOG.info("Creating connection: " + address);
    try {
        server = new Socket(address.getAddress(), address.getPort());
        LOG.info("Connection accepted");
        newConnection(server.getInputStream(), server.getOutputStream());
    } catch (ConnectException e) {
        String msg = "Connection to " + address + " refused.";
        LOG.error(msg);
        throw new CommException(msg);
    } catch (UnknownHostException e) {
        String msg = "Unknown host: " + address;
        LOG.error(msg);
        throw new CommException(msg);
    } catch (IOException e) {
        String msg = "Cannot read from: " + address;
        LOG.error(msg);
        throw new CommException(msg);
    }

    // init jaxb
    try {
        context = JAXBContext.newInstance(Configuration.class.getPackage().getName());
        unmarshaller = context.createUnmarshaller();
        marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    } catch (JAXBException e) {
        LOG.error(e.getMessage(), e);
        throw new CommException(CommService.INTERNAL_ERROR_MSG);
    }
}