Search in sources :

Example 1 with XMLExtendedStreamWriter

use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.

the class PersistentResourceXMLParserTestCase method testORBSubsystem.

@Test
public void testORBSubsystem() throws Exception {
    IIOPSubsystemParser parser = new IIOPSubsystemParser();
    String xml = readResource("orb-subsystem.xml");
    StringReader strReader = new StringReader(xml);
    XMLMapper mapper = XMLMapper.Factory.create();
    mapper.registerRootElement(new QName("urn:jboss:domain:orb-test:1.0", "subsystem"), parser);
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
    List<ModelNode> operations = new ArrayList<>();
    mapper.parseDocument(operations, reader);
    Assert.assertEquals(1, operations.size());
    ModelNode subsystem = opsToModel(operations);
    StringWriter stringWriter = new StringWriter();
    XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
    SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
    mapper.deparseDocument(parser, context, xmlStreamWriter);
    String out = stringWriter.toString();
    Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) XMLMapper(org.jboss.staxmapper.XMLMapper) XMLExtendedStreamWriter(org.jboss.staxmapper.XMLExtendedStreamWriter) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 2 with XMLExtendedStreamWriter

use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.

the class ModuleConfigImpl method main.

// test
public static void main(String[] args) throws Exception {
    ModuleConfigImpl module = new ModuleConfigImpl("o.r.g");
    module.setProperty("jboss.api", "private");
    module.setProperty("prop", VALUE);
    module.setMainClass("o.r.g.MainClass");
    module.addResource(new ResourceRoot("a.jar"));
    module.addResource(new ResourceRoot("another.jar"));
    module.addDependency(new ModuleDependency("a.module"));
    module.addDependency(new ModuleDependency("another.module"));
    StringWriter strWriter = new StringWriter();
    XMLExtendedStreamWriter writer = create(XMLOutputFactory.newInstance().createXMLStreamWriter(strWriter));
    module.writeContent(writer, module);
    writer.flush();
    System.out.println(strWriter.toString());
}
Also used : XMLExtendedStreamWriter(org.jboss.staxmapper.XMLExtendedStreamWriter) StringWriter(java.io.StringWriter)

Example 3 with XMLExtendedStreamWriter

use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.

the class PersistentResourceXMLParserTestCase method testServerWithComplexAttributeParser.

@Test
public void testServerWithComplexAttributeParser() throws Exception {
    ServerParser parser = new ServerParser();
    String xml = readResource("server-complex-attribute.xml");
    StringReader strReader = new StringReader(xml);
    XMLMapper mapper = XMLMapper.Factory.create();
    mapper.registerRootElement(new QName(MyParser.NAMESPACE, "subsystem"), parser);
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
    List<ModelNode> operations = new ArrayList<>();
    mapper.parseDocument(operations, reader);
    Assert.assertEquals(5, operations.size());
    ModelNode subsystem = opsToModel(operations);
    StringWriter stringWriter = new StringWriter();
    XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
    SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
    mapper.deparseDocument(parser, context, xmlStreamWriter);
    String out = stringWriter.toString();
    Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) XMLMapper(org.jboss.staxmapper.XMLMapper) XMLExtendedStreamWriter(org.jboss.staxmapper.XMLExtendedStreamWriter) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 4 with XMLExtendedStreamWriter

use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.

the class PersistentResourceXMLParserTestCase method testElementParsers.

@Test
public void testElementParsers() throws Exception {
    MyParser parser = new MyParser();
    String xml = readResource("elements.xml");
    StringReader strReader = new StringReader(xml);
    XMLMapper mapper = XMLMapper.Factory.create();
    mapper.registerRootElement(new QName(MyParser.NAMESPACE, "subsystem"), parser);
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
    List<ModelNode> operations = new ArrayList<>();
    mapper.parseDocument(operations, reader);
    Assert.assertEquals(5, operations.size());
    ModelNode subsystem = opsToModel(operations);
    StringWriter stringWriter = new StringWriter();
    XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
    SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
    mapper.deparseDocument(parser, context, xmlStreamWriter);
    String out = stringWriter.toString();
    Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) XMLMapper(org.jboss.staxmapper.XMLMapper) XMLExtendedStreamWriter(org.jboss.staxmapper.XMLExtendedStreamWriter) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 5 with XMLExtendedStreamWriter

use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.

the class PersistentResourceXMLParserTestCase method testWrappersAndGroups.

@Test
public void testWrappersAndGroups() throws Exception {
    MyParser parser = new MyParser();
    String xml = readResource("groups-wrappers-subsystem.xml");
    StringReader strReader = new StringReader(xml);
    XMLMapper mapper = XMLMapper.Factory.create();
    mapper.registerRootElement(new QName(MyParser.NAMESPACE, "subsystem"), parser);
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
    List<ModelNode> operations = new ArrayList<>();
    mapper.parseDocument(operations, reader);
    ModelNode subsystem = opsToModel(operations);
    assertEquals("bar", subsystem.get("resource", "foo", "cluster-attr1").asString());
    assertEquals("baz", subsystem.get("resource", "foo", "cluster-attr2").asString());
    assertEquals("alice", subsystem.get("resource", "foo", "security-my-attr1").asString());
    assertEquals("bob", subsystem.get("resource", "foo", "security-my-attr2").asString());
    assertEquals("bar2", subsystem.get("resource", "foo2", "cluster-attr1").asString());
    assertEquals("baz2", subsystem.get("resource", "foo2", "cluster-attr2").asString());
    StringWriter stringWriter = new StringWriter();
    XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
    SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
    mapper.deparseDocument(parser, context, xmlStreamWriter);
    String out = stringWriter.toString();
    Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) XMLMapper(org.jboss.staxmapper.XMLMapper) XMLExtendedStreamWriter(org.jboss.staxmapper.XMLExtendedStreamWriter) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

XMLExtendedStreamWriter (org.jboss.staxmapper.XMLExtendedStreamWriter)15 ModelNode (org.jboss.dmr.ModelNode)13 StringWriter (java.io.StringWriter)12 StringReader (java.io.StringReader)10 ArrayList (java.util.ArrayList)10 QName (javax.xml.namespace.QName)10 XMLStreamReader (javax.xml.stream.XMLStreamReader)10 StreamSource (javax.xml.transform.stream.StreamSource)10 XMLMapper (org.jboss.staxmapper.XMLMapper)10 Test (org.junit.Test)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 DefaultFilenameTabCompleter (org.jboss.as.cli.handlers.DefaultFilenameTabCompleter)1 FilenameTabCompleter (org.jboss.as.cli.handlers.FilenameTabCompleter)1