Package org.jboss.staxmapper

Examples of org.jboss.staxmapper.XMLMapper


        }
        return servers;
    }

    private static String writeModel(final String element, final XMLContentWriter content) throws Exception, FactoryConfigurationError {
        final XMLMapper mapper = XMLMapper.Factory.create();
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final BufferedOutputStream bos = new BufferedOutputStream(baos);
        final XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(bos);
        try {
            mapper.deparseDocument(new RootElementWriter(element, content), writer);
        }
        catch (XMLStreamException e) {
            // Dump some diagnostics
            stdout.println("XML Content that was written prior to exception:");
            stdout.println(writer.toString());
View Full Code Here


    private static final String namespace = "urn:jboss:domain:webservices:1.0";
    private static final WSSubsystemReader parser = WSSubsystemReader.getInstance();

    public void testParse() throws Exception {              
        final List<ModelNode> operations = new ArrayList<ModelNode>();
        XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "subsystem"), parser);

        URL configURL = getClass().getResource("ws-subsystem.xml");
        Assert.assertNotNull("url is not null", configURL);

        BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream()));
        mapper.parseDocument(operations, XMLInputFactory.newInstance().createXMLStreamReader(reader));
        assertEquals(9090, operations.get(0).get(Constants.WSDL_PORT).asInt());
        assertEquals(9443, operations.get(0).get(Constants.WSDL_SECURE_PORT).asInt());
        assertEquals("localhost", operations.get(0).get(Constants.WSDL_HOST).asString());
        assertTrue(operations.get(0).get(Constants.MODIFY_WSDL_ADDRESS).asBoolean());
    }
View Full Code Here

                + "      </subsystem>"; // +

        final Reader reader = new StringReader(xmlContent);
        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader);

        XMLMapper xmlMapper = XMLMapper.Factory.create();
        xmlMapper.registerRootElement(new QName(namespace.getUriString(), "subsystem"),
                ThreadsParser.INSTANCE);

        List<ModelNode> updates = new ArrayList<ModelNode>();
        xmlMapper.parseDocument(updates, xmlReader);

        // Process subsystems
        for (final ModelNode update : updates) {
            // Process relative subsystem path address
            final ModelNode subsystemAddress = profileAddress.clone();
View Full Code Here

        writer.flush();
        return strWriter.toString();
    }

    public static List<ModelNode> xmlToModelOperations(String xml, String nameSpaceUriString, XMLElementReader<List<ModelNode>> parser) throws Exception {
        XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(nameSpaceUriString, "subsystem"), parser);

        StringReader strReader = new StringReader(xml);

        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
        List<ModelNode> newList = new ArrayList<ModelNode>();
        mapper.parseDocument(newList, reader);

        return newList;
    }
View Full Code Here

                "    </deployments>" +
                "</server>";
        final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
        final StandaloneXml parser = new StandaloneXml(null, null, null);
        final List<ModelNode> operationList = new ArrayList<ModelNode>();
        final XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "server"), parser);
        mapper.parseDocument(operationList, reader);
        final ModelNode content = operationList.get(1).get("content");
        assertArrayEquals(new byte[] { 0x12, 0x34 }, content.get(0).get("hash").asBytes());
    }
View Full Code Here

                "    </deployments>" +
                "</server>";
        final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
        final StandaloneXml parser = new StandaloneXml(null, null, null);
        final List<ModelNode> operationList = new ArrayList<ModelNode>();
        final XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "server"), parser);
        mapper.parseDocument(operationList, reader);
        System.out.println(operationList.get(1));
        final ModelNode content = operationList.get(1).get("content");
        assertEquals(true, content.get(0).get("archive").asBoolean());
        assertEquals("${jboss.home}/content/welcome.jar", content.get(0).get("path").asString());
    }
View Full Code Here

                "    </deployments>" +
                "</server>";
        final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
        final StandaloneXml parser = new StandaloneXml(null, null, null);
        final List<ModelNode> operationList = new ArrayList<ModelNode>();
        final XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "server"), parser);
        mapper.parseDocument(operationList, reader);
        final ModelNode content = operationList.get(1).get("content");
        assertEquals(false, content.get(0).get("archive").asBoolean());
        assertEquals("deployments/test.jar", content.get(0).get("path").asString());
        assertEquals("jboss.server.base.dir", content.get(0).get("relative-to").asString());
    }
View Full Code Here

    }

    List<ModelNode> parse(final String name) throws XMLStreamException, IOException {
        final List<ModelNode> operations = new ArrayList<ModelNode>();

        XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "subsystem"), parser);

        URL configURL = getClass().getResource(name);
        Assert.assertNotNull(name + " url is not null", configURL);
        System.out.println("configURL = " + configURL);

        BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream()));
        mapper.parseDocument(operations, XMLInputFactory.newInstance().createXMLStreamReader(reader));

        return operations;
    }
View Full Code Here

        CliConfigImpl config = new CliConfigImpl();

        BufferedInputStream input = null;
        try {
            final XMLMapper mapper = XMLMapper.Factory.create();
            mapper.registerRootElement(new QName(NS, JBOSS_CLI), new XMLElementReader<CliConfigImpl>(){
                @Override
                public void readElement(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
                    boolean jbossCliEnded = false;
                    while (reader.hasNext() && jbossCliEnded == false) {
                        int tag = reader.nextTag();
                        if(tag == XMLStreamConstants.START_ELEMENT) {
                            final String localName = reader.getLocalName();
                            if(localName.equals(DEFAULT_CONTROLLER)) {
                                readDefaultController(reader, config);
                            } else if(localName.equals(HISTORY)) {
                                readHistory(reader, config);
                            } else if (localName.equals("ssl")) {
                                SslConfig sslConfig = new SslConfig();
                                readSSLElement(reader, sslConfig);
                                config.sslConfig = sslConfig;
                            } else {
                                throw new XMLStreamException("Unexpected element: " + localName);
                            }
                        } else if(tag == XMLStreamConstants.END_ELEMENT) {
                            final String localName = reader.getLocalName();
                            if (localName.equals(JBOSS_CLI)) {
                                jbossCliEnded = true;
                            }
                        }
                    }
                }

                private void readDefaultController(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        final String resolved = resolveString(reader.getElementText());
                        if (HOST.equals(localName)) {
                            config.defaultControllerHost = resolved;
                        } else if (PORT.equals(localName)) {
                            try {
                                config.defaultControllerPort = Integer.parseInt(resolved);
                            } catch(NumberFormatException e) {
                                throw new XMLStreamException("Failed to parse " + DEFAULT_CONTROLLER + " " + PORT + " value '" + resolved + "'", e);
                            }
                        } else {
                            throw new XMLStreamException("Unexpected child of " + DEFAULT_CONTROLLER + ": " + localName);
                        }
                    }
                }

                private void readHistory(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        final String resolved = resolveString(reader.getElementText());
                        if (ENABLED.equals(localName)) {
                            config.historyEnabled = Boolean.parseBoolean(resolved);
                        } else if (FILE_NAME.equals(localName)) {
                            config.historyFileName = resolved;
                        } else if (FILE_DIR.equals(localName)) {
                            config.historyFileDir = resolved;
                        } else if (MAX_SIZE.equals(localName)) {
                            try {
                                config.historyMaxSize = Integer.parseInt(resolved);
                            } catch(NumberFormatException e) {
                                throw new XMLStreamException("Failed to parse " + HISTORY + " " + MAX_SIZE + " value '" + resolved + "'", e);
                            }
                        } else {
                            throw new XMLStreamException("Unexpected child of " + DEFAULT_CONTROLLER + ": " + localName);
                        }
                    }
                }

                public void readSSLElement(XMLExtendedStreamReader reader, SslConfig config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        if ("keyStore".equals(localName)) {
                            config.setKeyStore(reader.getElementText());
                        } else if ("keyStorePassword".equals(localName)) {
                            config.setKeyStorePassword(reader.getElementText());
                        } else if ("trustStore".equals(localName)) {
                            config.setTrustStore(reader.getElementText());
                        } else if ("trustStorePassword".equals(localName)) {
                            config.setTrustStorePassword(reader.getElementText());
                        } else if ("modifyTrustStore".equals(localName)) {
                            config.setModifyTrustStore(Boolean.getBoolean(reader.getElementText()));
                        }
                    }
                }
            });

            FileInputStream is = new FileInputStream(f);
            input = new BufferedInputStream(is);
            XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
            mapper.parseDocument(config, streamReader);
            streamReader.close();
        } catch(Throwable t) {
            throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
        } finally {
            StreamUtils.safeClose(input);
View Full Code Here

    }

    /** {@inheritDoc} */
    @Override
    public void marshallAsXml(final ModelNode model, final OutputStream output) throws ConfigurationPersistenceException {
        final XMLMapper mapper = XMLMapper.Factory.create();
        try {
            XMLStreamWriter streamWriter = null;
            try {
                streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(output);
                ModelMarshallingContext extensibleModel = new ModelMarshallingContext() {

                    @Override
                    public ModelNode getModelNode() {
                        return model;
                    }

                    @Override
                    public XMLElementWriter<SubsystemMarshallingContext> getSubsystemWriter(String extensionName) {
                        synchronized (subsystemWriters) {
                            return subsystemWriters.get(extensionName);
                        }
                    }

                    @Override
                    public XMLElementWriter<SubsystemMarshallingContext> getSubsystemDeploymentWriter(String extensionName) {
                        synchronized (subsystemDeploymentWriters) {
                            return subsystemDeploymentWriters.get(extensionName);
                        }
                    }
                };
                mapper.deparseDocument(rootDeparser, extensibleModel, streamWriter);
                streamWriter.close();
            } finally {
                safeClose(streamWriter);
            }
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jboss.staxmapper.XMLMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.