Search in sources :

Example 41 with Marshaller

use of javax.xml.bind.Marshaller in project opennms by OpenNMS.

the class ShowHistoryCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    final SavedHistory savedHistory = historyManager.getHistoryByUserId(user);
    if (savedHistory == null) {
        System.out.println("No History for user '" + user + "' found.");
    } else {
        System.out.println("History for user '" + user + "':");
        JAXBContext jaxbContext = JAXBContext.newInstance(SavedHistory.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.marshal(savedHistory, System.out);
    }
    return null;
}
Also used : Marshaller(javax.xml.bind.Marshaller) SavedHistory(org.opennms.features.topology.api.support.SavedHistory) JAXBContext(javax.xml.bind.JAXBContext)

Example 42 with Marshaller

use of javax.xml.bind.Marshaller in project zm-mailbox by Zimbra.

the class JaxbUtil method jaxbToNamedElement.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Element jaxbToNamedElement(String name, String namespace, Object o, Element.ElementFactory factory) throws ServiceException {
    if (Element.JSONElement.mFactory.equals(factory)) {
        return JacksonUtil.jaxbToJSONElement(o, org.dom4j.QName.get(name, namespace));
    }
    try {
        Marshaller marshaller = createMarshaller(o.getClass());
        // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        DocumentResult dr = new DocumentResult();
        marshaller.marshal(new JAXBElement(new QName(namespace, name), o.getClass(), o), dr);
        Document theDoc = dr.getDocument();
        org.dom4j.Element rootElem = theDoc.getRootElement();
        return Element.convertDOM(rootElem, factory);
    } catch (Exception e) {
        throw ServiceException.FAILURE("Unable to convert " + o.getClass().getName() + " to Element", e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) DocumentResult(org.dom4j.io.DocumentResult) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Document(org.dom4j.Document) ServiceException(com.zimbra.common.service.ServiceException) JAXBException(javax.xml.bind.JAXBException)

Example 43 with Marshaller

use of javax.xml.bind.Marshaller in project voltdb by VoltDB.

the class DeploymentBuilder method getXML.

/**
     * Writes deployment.xml file to a temporary file. It is constructed from the passed parameters and the m_users
     * field.
     *
     * @param voltRoot
     * @param dinfo an instance {@link DeploymentInfo}
     * @return deployment path
     * @throws IOException
     * @throws JAXBException
     */
public String getXML() {
    // make sure voltroot exists
    new File(m_voltRootPath).mkdirs();
    org.voltdb.compiler.deploymentfile.ObjectFactory factory = new org.voltdb.compiler.deploymentfile.ObjectFactory();
    // <deployment>
    DeploymentType deployment = factory.createDeploymentType();
    JAXBElement<DeploymentType> doc = factory.createDeployment(deployment);
    // <cluster>
    ClusterType cluster = factory.createClusterType();
    deployment.setCluster(cluster);
    cluster.setHostcount(m_hostCount);
    cluster.setSitesperhost(m_sitesPerHost);
    cluster.setKfactor(m_replication);
    cluster.setSchema(m_useDDLSchema ? SchemaType.DDL : SchemaType.CATALOG);
    // <paths>
    PathsType paths = factory.createPathsType();
    deployment.setPaths(paths);
    Voltdbroot voltdbroot = factory.createPathsTypeVoltdbroot();
    paths.setVoltdbroot(voltdbroot);
    voltdbroot.setPath(m_voltRootPath);
    if (m_snapshotPath != null) {
        PathsType.Snapshots snapshotPathElement = factory.createPathsTypeSnapshots();
        snapshotPathElement.setPath(m_snapshotPath);
        paths.setSnapshots(snapshotPathElement);
    }
    if (m_commandLogPath != null) {
        PathsType.Commandlog commandLogPathElement = factory.createPathsTypeCommandlog();
        commandLogPathElement.setPath(m_commandLogPath);
        paths.setCommandlog(commandLogPathElement);
    }
    if (m_internalSnapshotPath != null) {
        PathsType.Commandlogsnapshot commandLogSnapshotPathElement = factory.createPathsTypeCommandlogsnapshot();
        commandLogSnapshotPathElement.setPath(m_internalSnapshotPath);
        paths.setCommandlogsnapshot(commandLogSnapshotPathElement);
    }
    if (m_snapshotPrefix != null) {
        SnapshotType snapshot = factory.createSnapshotType();
        deployment.setSnapshot(snapshot);
        snapshot.setFrequency(m_snapshotFrequency);
        snapshot.setPrefix(m_snapshotPrefix);
        snapshot.setRetain(m_snapshotRetain);
    }
    SecurityType security = factory.createSecurityType();
    deployment.setSecurity(security);
    security.setEnabled(m_securityEnabled);
    SecurityProviderString provider = SecurityProviderString.HASH;
    if (m_securityEnabled)
        try {
            provider = SecurityProviderString.fromValue(m_securityProvider);
        } catch (IllegalArgumentException shouldNotHappenSeeSetter) {
        }
    security.setProvider(provider);
    if (m_commandLogSync != null || m_commandLogEnabled != null || m_commandLogFsyncInterval != null || m_commandLogMaxTxnsBeforeFsync != null || m_commandLogSize != null) {
        CommandLogType commandLogType = factory.createCommandLogType();
        if (m_commandLogSync != null) {
            commandLogType.setSynchronous(m_commandLogSync.booleanValue());
        }
        if (m_commandLogEnabled != null) {
            commandLogType.setEnabled(m_commandLogEnabled);
        }
        if (m_commandLogSize != null) {
            commandLogType.setLogsize(m_commandLogSize);
        }
        if (m_commandLogFsyncInterval != null || m_commandLogMaxTxnsBeforeFsync != null) {
            CommandLogType.Frequency frequency = factory.createCommandLogTypeFrequency();
            if (m_commandLogFsyncInterval != null) {
                frequency.setTime(m_commandLogFsyncInterval);
            }
            if (m_commandLogMaxTxnsBeforeFsync != null) {
                frequency.setTransactions(m_commandLogMaxTxnsBeforeFsync);
            }
            commandLogType.setFrequency(frequency);
        }
        deployment.setCommandlog(commandLogType);
    }
    // <partition-detection>/<snapshot>
    PartitionDetectionType ppd = factory.createPartitionDetectionType();
    deployment.setPartitionDetection(ppd);
    ppd.setEnabled(m_ppdEnabled);
    // <systemsettings>
    SystemSettingsType systemSettingType = factory.createSystemSettingsType();
    Temptables temptables = factory.createSystemSettingsTypeTemptables();
    temptables.setMaxsize(m_maxTempTableMemory);
    systemSettingType.setTemptables(temptables);
    if (m_snapshotPriority != null) {
        SystemSettingsType.Snapshot snapshot = factory.createSystemSettingsTypeSnapshot();
        snapshot.setPriority(m_snapshotPriority);
        systemSettingType.setSnapshot(snapshot);
    }
    deployment.setSystemsettings(systemSettingType);
    // <users>
    if (m_users.size() > 0) {
        UsersType users = factory.createUsersType();
        deployment.setUsers(users);
        // <user>
        for (final UserInfo info : m_users) {
            User user = factory.createUsersTypeUser();
            users.getUser().add(user);
            user.setName(info.name);
            user.setPassword(info.password);
            // build up user/roles.
            if (info.roles.length > 0) {
                final StringBuilder roles = new StringBuilder();
                for (final String role : info.roles) {
                    if (roles.length() > 0)
                        roles.append(",");
                    roles.append(role.toLowerCase());
                }
                user.setRoles(roles.toString());
            }
        }
    }
    SslType ssl = factory.createSslType();
    deployment.setSsl(ssl);
    ssl.setEnabled(false);
    // <httpd>. Disabled unless port # is configured by a testcase
    HttpdType httpd = factory.createHttpdType();
    deployment.setHttpd(httpd);
    httpd.setEnabled(m_httpdPortNo != -1);
    httpd.setPort(m_httpdPortNo);
    Jsonapi json = factory.createHttpdTypeJsonapi();
    httpd.setJsonapi(json);
    json.setEnabled(m_jsonApiEnabled);
    // <export>
    ExportType export = factory.createExportType();
    deployment.setExport(export);
    // <dr>
    if (m_drRole != DrRoleType.NONE) {
        final DrType drType = factory.createDrType();
        deployment.setDr(drType);
        drType.setRole(m_drRole);
        drType.setId(1);
    }
    // Have some yummy boilerplate!
    String xml = null;
    try {
        JAXBContext context = JAXBContext.newInstance(DeploymentType.class);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        StringWriter writer = new StringWriter();
        marshaller.marshal(doc, writer);
        xml = writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }
    return xml;
}
Also used : SecurityType(org.voltdb.compiler.deploymentfile.SecurityType) User(org.voltdb.compiler.deploymentfile.UsersType.User) SecurityProviderString(org.voltdb.compiler.deploymentfile.SecurityProviderString) Jsonapi(org.voltdb.compiler.deploymentfile.HttpdType.Jsonapi) JAXBContext(javax.xml.bind.JAXBContext) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) SecurityProviderString(org.voltdb.compiler.deploymentfile.SecurityProviderString) PathsType(org.voltdb.compiler.deploymentfile.PathsType) CommandLogType(org.voltdb.compiler.deploymentfile.CommandLogType) SystemSettingsType(org.voltdb.compiler.deploymentfile.SystemSettingsType) StringWriter(java.io.StringWriter) PartitionDetectionType(org.voltdb.compiler.deploymentfile.PartitionDetectionType) Marshaller(javax.xml.bind.Marshaller) ExportType(org.voltdb.compiler.deploymentfile.ExportType) Voltdbroot(org.voltdb.compiler.deploymentfile.PathsType.Voltdbroot) ClusterType(org.voltdb.compiler.deploymentfile.ClusterType) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) DrType(org.voltdb.compiler.deploymentfile.DrType) Temptables(org.voltdb.compiler.deploymentfile.SystemSettingsType.Temptables) HttpdType(org.voltdb.compiler.deploymentfile.HttpdType) UsersType(org.voltdb.compiler.deploymentfile.UsersType) SslType(org.voltdb.compiler.deploymentfile.SslType) SnapshotType(org.voltdb.compiler.deploymentfile.SnapshotType) File(java.io.File)

Example 44 with Marshaller

use of javax.xml.bind.Marshaller in project Activiti by Activiti.

the class AlfrescoArtifactExporter method writeShareExtensionModule.

/**
	 * Write the Share module XML in the given conversion to the given stream. 
	 */
public void writeShareExtensionModule(OutputStream out, WorkflowDefinitionConversion conversion) throws IOException {
    Extension extension = AlfrescoConversionUtil.getExtension(conversion);
    try {
        ModuleDeployment toMarshall = new ModuleDeployment();
        toMarshall.setModule(extension.getModules().get(0).getId());
        // In case the configuration should NOT be exported as a module, wrap the configurations
        // in a "alfresco-configuration" element instead
        Marshaller marshaller = moduleJaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(toMarshall, out);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    }
}
Also used : Extension(org.activiti.workflow.simple.alfresco.model.config.Extension) ModuleDeployment(org.activiti.workflow.simple.alfresco.model.config.ModuleDeployment) Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 45 with Marshaller

use of javax.xml.bind.Marshaller in project Activiti by Activiti.

the class AlfrescoArtifactExporter method writeBeans.

protected void writeBeans(OutputStream out, Beans beans) throws IOException {
    try {
        Marshaller marshaller = beansJaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd");
        marshaller.marshal(beans, out);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Aggregations

Marshaller (javax.xml.bind.Marshaller)280 JAXBContext (javax.xml.bind.JAXBContext)162 JAXBException (javax.xml.bind.JAXBException)100 StringWriter (java.io.StringWriter)82 Test (org.junit.Test)33 JAXBElement (javax.xml.bind.JAXBElement)32 ByteArrayOutputStream (java.io.ByteArrayOutputStream)31 File (java.io.File)29 Unmarshaller (javax.xml.bind.Unmarshaller)21 IOException (java.io.IOException)20 FileOutputStream (java.io.FileOutputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)15 QName (javax.xml.namespace.QName)14 Element (org.w3c.dom.Element)14 HashMap (java.util.HashMap)12 Writer (java.io.Writer)11 Document (org.w3c.dom.Document)11 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7