org.jboss.staxmapper.XMLExtendedStreamWriter Java Examples

The following examples show how to use org.jboss.staxmapper.XMLExtendedStreamWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemotingSubsystemXMLPersister.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeOutboundConnection(final XMLExtendedStreamWriter writer, final String connectionName, final ModelNode model) throws XMLStreamException {
    // <outbound-connection>
    writer.writeStartElement(Element.OUTBOUND_CONNECTION.getLocalName());

    writer.writeAttribute(Attribute.NAME.getLocalName(), connectionName);

    final String uri = model.get(URI).asString();
    writer.writeAttribute(Attribute.URI.getLocalName(), uri);

    // write the connection-creation-options if any
    if (model.hasDefined(PROPERTY)) {
        writeProperties(writer, model.get(PROPERTY));
    }

    // </outbound-connection>
    writer.writeEndElement();
}
 
Example #2
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void writeSecureResource(String tagName, List<SimpleAttributeDefinition> attributes, XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(tagName).isDefined()) {
        return;
    }
    for (Property deployment : context.getModelNode().get(tagName).asPropertyList()) {
        writer.writeStartElement(tagName);
        writer.writeAttribute("name", deployment.getName());
        ModelNode deploymentElements = deployment.getValue();
        for (AttributeDefinition element : attributes) {
            element.marshallAsElement(deploymentElements, writer);
        }

        ModelNode credentials = deploymentElements.get(CredentialDefinition.TAG_NAME);
        if (credentials.isDefined()) {
            writeCredentials(writer, credentials);
        }

        ModelNode redirectRewriteRule = deploymentElements.get(RedirecRewritetRuleDefinition.TAG_NAME);
        if (redirectRewriteRule.isDefined()) {
            writeRedirectRules(writer, redirectRewriteRule);
        }

        writer.writeEndElement();
    }
}
 
Example #3
Source File: AuditLogXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeAuditLogger(XMLExtendedStreamWriter writer, ModelNode auditLog, String element) throws XMLStreamException {
    if (auditLog.hasDefined(element) && auditLog.get(element).hasDefined(ModelDescriptionConstants.AUDIT_LOG)){
        ModelNode config = auditLog.get(element, ModelDescriptionConstants.AUDIT_LOG);
        writer.writeStartElement(element);
        AuditLogLoggerResourceDefinition.LOG_BOOT.marshallAsAttribute(config, writer);
        AuditLogLoggerResourceDefinition.LOG_READ_ONLY.marshallAsAttribute(config, writer);
        AuditLogLoggerResourceDefinition.ENABLED.marshallAsAttribute(config, writer);
        if (config.hasDefined(ModelDescriptionConstants.HANDLER) && config.get(ModelDescriptionConstants.HANDLER).keys().size() > 0) {
            writer.writeStartElement(Element.HANDLERS.getLocalName());
            for (String name : config.get(ModelDescriptionConstants.HANDLER).keys()) {
                writer.writeStartElement(Element.HANDLER.getLocalName());
                writer.writeAttribute(Attribute.NAME.getLocalName(), name);
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }

        writer.writeEndElement();
    }
}
 
Example #4
Source File: StandaloneXml_8.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean writeNativeManagementProtocol(XMLExtendedStreamWriter writer, ModelNode protocol) throws XMLStreamException {

    writer.writeStartElement(Element.NATIVE_INTERFACE.getLocalName());
    NativeManagementResourceDefinition.SASL_AUTHENTICATION_FACTORY.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SSL_CONTEXT.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SECURITY_REALM.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SASL_PROTOCOL.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SERVER_NAME.marshallAsAttribute(protocol, writer);

    if (NativeManagementResourceDefinition.SOCKET_BINDING.isMarshallable(protocol)) {
        writer.writeEmptyElement(Element.SOCKET_BINDING.getLocalName());
        NativeManagementResourceDefinition.SOCKET_BINDING.marshallAsAttribute(protocol, writer);
    }

    writer.writeEndElement();

    return true;
}
 
Example #5
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void writeIdentityProvider(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }

    for (Property idp : model.asPropertyList()) {
        writer.writeStartElement(Constants.XML.IDENTITY_PROVIDER);
        writer.writeAttribute(Constants.XML.ENTITY_ID, idp.getName());

        ModelNode idpAttributes = idp.getValue();
        for (SimpleAttributeDefinition attr : IdentityProviderDefinition.ATTRIBUTES) {
            attr.getAttributeMarshaller().marshallAsAttribute(attr, idpAttributes, false, writer);
        }

        writeSingleSignOn(writer, idpAttributes.get(Constants.Model.SINGLE_SIGN_ON));
        writeSingleLogout(writer, idpAttributes.get(Constants.Model.SINGLE_LOGOUT));
        writeKeys(writer, idpAttributes.get(Constants.Model.KEY));
        writeHttpClient(writer, idpAttributes.get(Constants.Model.HTTP_CLIENT));
        writeAllowedClockSkew(writer, idpAttributes.get(Constants.Model.ALLOWED_CLOCK_SKEW));
        writer.writeEndElement();
    }
}
 
Example #6
Source File: RemotingSubsystemXMLPersister.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeSasl(final XMLExtendedStreamWriter writer, final ModelNode node) throws XMLStreamException {
    writer.writeStartElement(Element.SASL.getLocalName());
    SaslResource.INCLUDE_MECHANISMS_ATTRIBUTE.marshallAsElement(node, writer);
    SaslResource.QOP_ATTRIBUTE.marshallAsElement(node, writer);
    SaslResource.STRENGTH_ATTRIBUTE.marshallAsElement(node, writer);
    SaslResource.SERVER_AUTH_ATTRIBUTE.marshallAsElement(node, writer);
    SaslResource.REUSE_SESSION_ATTRIBUTE.marshallAsElement(node, writer);

    if (node.hasDefined(SASL_POLICY)) {
        writePolicy(writer, node.get(SASL_POLICY));
    }
    if (node.hasDefined(PROPERTY)) {
        writeProperties(writer, node.get(PROPERTY));
    }

    writer.writeEndElement();
}
 
Example #7
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void writeSps(final XMLExtendedStreamWriter writer, final ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    for (Property sp : model.get(Constants.Model.SERVICE_PROVIDER).asPropertyList()) {
        writer.writeStartElement(Constants.XML.SERVICE_PROVIDER);
        writer.writeAttribute(Constants.XML.ENTITY_ID, sp.getName());
        ModelNode spAttributes = sp.getValue();
        for (SimpleAttributeDefinition attr : ServiceProviderDefinition.ATTRIBUTES) {
            attr.getAttributeMarshaller().marshallAsAttribute(attr, spAttributes, false, writer);
        }
        writeKeys(writer, spAttributes.get(Constants.Model.KEY));
        writePrincipalNameMapping(writer, spAttributes);
        writeRoleIdentifiers(writer, spAttributes);
        writeRoleMappingsProvider(writer, spAttributes);
        writeIdentityProvider(writer, spAttributes.get(Constants.Model.IDENTITY_PROVIDER));

        writer.writeEndElement();
    }
}
 
Example #8
Source File: AccessControlXml.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writePrincipal(XMLExtendedStreamWriter writer, String alias, ModelNode principal) throws XMLStreamException {
    String elementName = principal.require(TYPE).asString().equalsIgnoreCase(GROUP) ? Element.GROUP.getLocalName() : Element.USER.getLocalName();
    writer.writeStartElement(elementName);

    String realm = principal.get(REALM).isDefined() ? principal.require(REALM).asString() : null;
    String name = principal.require(NAME).asString();

    String expectedAlias = AccessControlXml.generateAlias(elementName, name, realm);
    if (alias.equals(expectedAlias)==false) {
        writeAttribute(writer, Attribute.ALIAS, alias);
    }

    PrincipalResourceDefinition.REALM.marshallAsAttribute(principal, writer);

    PrincipalResourceDefinition.NAME.marshallAsAttribute(principal, writer);

    writer.writeEndElement();
}
 
Example #9
Source File: InterfacesXml.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Write the interfaces including the criteria elements.
 *
 * @param writer    the xml stream writer
 * @param modelNode the model
 * @throws XMLStreamException
 */
void writeInterfaces(final XMLExtendedStreamWriter writer, final ModelNode modelNode) throws XMLStreamException {
    writer.writeStartElement(Element.INTERFACES.getLocalName());
    final Set<String> interfaces = new TreeSet<>(modelNode.keys());
    for (String ifaceName : interfaces) {
        final ModelNode iface = modelNode.get(ifaceName);
        writer.writeStartElement(Element.INTERFACE.getLocalName());
        writeAttribute(writer, Attribute.NAME, ifaceName);
        // <any-* /> is just handled at the root
        if (iface.get(Element.ANY_ADDRESS.getLocalName()).asBoolean(false)) {
            writer.writeEmptyElement(Element.ANY_ADDRESS.getLocalName());
        } else {
            // Write the other criteria elements
            writeInterfaceCriteria(writer, iface, false);
        }
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
 
Example #10
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writePlugIn_Authentication(XMLExtendedStreamWriter writer, ModelNode plugIn) throws XMLStreamException {
    writer.writeStartElement(Element.PLUG_IN.getLocalName());
    AbstractPlugInAuthResourceDefinition.NAME.marshallAsAttribute(plugIn, writer);
    PlugInAuthenticationResourceDefinition.MECHANISM.marshallAsAttribute(plugIn, writer);
    if (plugIn.hasDefined(PROPERTY)) {
        writer.writeStartElement(PROPERTIES);
        ModelNode properties = plugIn.get(PROPERTY);
        for (String current : properties.keys()) {
            writer.writeEmptyElement(PROPERTY);
            writer.writeAttribute(Attribute.NAME.getLocalName(), current);
            PropertyResourceDefinition.VALUE.marshallAsAttribute(properties.get(current), writer);
        }
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
 
Example #11
Source File: PersistentResourceXMLParserTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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));
}
 
Example #12
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void writeRoleIdentifiers(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    ModelNode value = model.get(Constants.Model.ROLE_ATTRIBUTES);
    if (!value.isDefined()) {
        return;
    }

    List<ModelNode> items = value.asList();
    if (items.size() == 0) {
        return;
    }

    writer.writeStartElement(Constants.XML.ROLE_IDENTIFIERS);
    for (ModelNode item : items) {
        writer.writeStartElement(Constants.XML.ATTRIBUTE);
        writer.writeAttribute("name", item.asString());
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
 
Example #13
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void writeThemeDefaults(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(ThemeResourceDefinition.TAG_NAME).isDefined()) {
        return;
    }
    
    writer.writeStartElement(ThemeResourceDefinition.TAG_NAME);
    ModelNode themeElements = context.getModelNode().get(ThemeResourceDefinition.TAG_NAME, ThemeResourceDefinition.RESOURCE_NAME);
    for (AttributeDefinition def : ThemeResourceDefinition.ALL_ATTRIBUTES) {
        if (themeElements.hasDefined(def.getName())) {
            if (def == MODULES) {
                ModelNode themeContext = context.getModelNode().get("theme", "defaults");
                writeList(writer, themeContext, def, "module");
            } else {
                def.marshallAsElement(themeElements, writer);
            }
        }
    }
    writer.writeEndElement();
}
 
Example #14
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void writeIdentityProvider(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }

    for (Property idp : model.asPropertyList()) {
        writer.writeStartElement(Constants.XML.IDENTITY_PROVIDER);
        writer.writeAttribute(Constants.XML.ENTITY_ID, idp.getName());

        ModelNode idpAttributes = idp.getValue();
        for (SimpleAttributeDefinition attr : IdentityProviderDefinition.ATTRIBUTES) {
            attr.getAttributeMarshaller().marshallAsAttribute(attr, idpAttributes, false, writer);
        }

        writeSingleSignOn(writer, idpAttributes.get(Constants.Model.SINGLE_SIGN_ON));
        writeSingleLogout(writer, idpAttributes.get(Constants.Model.SINGLE_LOGOUT));
        writeKeys(writer, idpAttributes.get(Constants.Model.KEY));
        writeHttpClient(writer, idpAttributes.get(Constants.Model.HTTP_CLIENT));
        writeAllowedClockSkew(writer, idpAttributes.get(Constants.Model.ALLOWED_CLOCK_SKEW));
        writer.writeEndElement();
    }
}
 
Example #15
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeManagementInterfaces(XMLExtendedStreamWriter writer, ModelNode management) throws XMLStreamException {
    writer.writeStartElement(Element.MANAGEMENT_INTERFACES.getLocalName());
    ModelNode managementInterfaces = management.get(MANAGEMENT_INTERFACE);

    if (managementInterfaces.hasDefined(NATIVE_REMOTING_INTERFACE)) {
        writer.writeEmptyElement(Element.NATIVE_REMOTING_INTERFACE.getLocalName());
    }

    if (managementInterfaces.hasDefined(NATIVE_INTERFACE)) {
        if (delegate.writeNativeManagementProtocol(writer, managementInterfaces.get(NATIVE_INTERFACE)) == false) {
            throw ROOT_LOGGER.unsupportedResource(NATIVE_INTERFACE);
        }
    }

    if (managementInterfaces.hasDefined(HTTP_INTERFACE)) {
        if (delegate.writeHttpManagementProtocol(writer, managementInterfaces.get(HTTP_INTERFACE)) == false) {
            throw ROOT_LOGGER.unsupportedResource(HTTP_INTERFACE);
        }
    }

    writer.writeEndElement();
}
 
Example #16
Source File: HostXml_6.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean writeNativeManagementProtocol(XMLExtendedStreamWriter writer, ModelNode protocol) throws XMLStreamException {

    writer.writeStartElement(Element.NATIVE_INTERFACE.getLocalName());
    NativeManagementResourceDefinition.SASL_AUTHENTICATION_FACTORY.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SSL_CONTEXT.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SECURITY_REALM.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SASL_PROTOCOL.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SERVER_NAME.marshallAsAttribute(protocol, writer);

    writer.writeEmptyElement(Element.SOCKET.getLocalName());
    NativeManagementResourceDefinition.INTERFACE.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.NATIVE_PORT.marshallAsAttribute(protocol, writer);

    writer.writeEndElement();

    return true;
}
 
Example #17
Source File: StandaloneXml_7.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean writeNativeManagementProtocol(XMLExtendedStreamWriter writer, ModelNode protocol) throws XMLStreamException {

    writer.writeStartElement(Element.NATIVE_INTERFACE.getLocalName());
    NativeManagementResourceDefinition.SASL_AUTHENTICATION_FACTORY.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SSL_CONTEXT.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SECURITY_REALM.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SASL_PROTOCOL.marshallAsAttribute(protocol, writer);
    NativeManagementResourceDefinition.SERVER_NAME.marshallAsAttribute(protocol, writer);

    if (NativeManagementResourceDefinition.SOCKET_BINDING.isMarshallable(protocol)) {
        writer.writeEmptyElement(Element.SOCKET_BINDING.getLocalName());
        NativeManagementResourceDefinition.SOCKET_BINDING.marshallAsAttribute(protocol, writer);
    }

    writer.writeEndElement();

    return true;
}
 
Example #18
Source File: ModuleDependency.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void writeContent(XMLExtendedStreamWriter writer, Dependency value) throws XMLStreamException {

    if(value != null && this != value) {
        throw new IllegalStateException("Wrong target dependency.");
    }

    writer.writeStartElement(ModuleConfigImpl.MODULE);
    writer.writeAttribute(ModuleConfigImpl.NAME, name);
    if (export) {
        writer.writeAttribute(ModuleConfigImpl.EXPORT, "true");
    }
    writer.writeEndElement();
}
 
Example #19
Source File: RemotingSubsystemXMLPersister.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeRemoteOutboundConnection(final XMLExtendedStreamWriter writer, final String connectionName, final ModelNode model) throws XMLStreamException {
    // <remote-outbound-connection>
    writer.writeStartElement(Element.REMOTE_OUTBOUND_CONNECTION.getLocalName());

    writer.writeAttribute(Attribute.NAME.getLocalName(), connectionName);

    final String outboundSocketRef = model.get(OUTBOUND_SOCKET_BINDING_REF).asString();
    writer.writeAttribute(Attribute.OUTBOUND_SOCKET_BINDING_REF.getLocalName(), outboundSocketRef);

    if (model.hasDefined(CommonAttributes.USERNAME)) {
        writer.writeAttribute(Attribute.USERNAME.getLocalName(), model.require(CommonAttributes.USERNAME).asString());
    }

    if (model.hasDefined(CommonAttributes.SECURITY_REALM)) {
        writer.writeAttribute(Attribute.SECURITY_REALM.getLocalName(), model.require(SECURITY_REALM).asString());
    }

    if (model.hasDefined(CommonAttributes.PROTOCOL)) {
        writer.writeAttribute(Attribute.PROTOCOL.getLocalName(), model.require(PROTOCOL).asString());
    }
    if (model.hasDefined(CommonAttributes.AUTHENTICATION_CONTEXT)) {
        writer.writeAttribute(Attribute.AUTHENTICATION_CONTEXT.getLocalName(), model.require(AUTHENTICATION_CONTEXT).asString());
    }
    // write the connection-creation-options if any
    if (model.hasDefined(PROPERTY)) {
        writeProperties(writer, model.get(PROPERTY));
    }

    // </remote-outbound-connection>
    writer.writeEndElement();
}
 
Example #20
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void writeKeyStore(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    writer.writeStartElement(Constants.XML.KEY_STORE);
    for (SimpleAttributeDefinition attr : KeyStoreDefinition.ATTRIBUTES) {
        attr.getAttributeMarshaller().marshallAsAttribute(attr, model, false, writer);
    }
    writePrivateKey(writer, model);
    writeCertificate(writer, model);
    writer.writeEndElement();
}
 
Example #21
Source File: PatchXml_1_0.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void writeContent(final XMLExtendedStreamWriter writer, final Patch patch) throws XMLStreamException {

    // Get started ...
    writer.writeStartDocument();
    writer.writeStartElement(Element.PATCH.name);
    writer.writeDefaultNamespace(PatchXml.Namespace.PATCH_1_2.getNamespace());

    writePatch(writer, patch);

    // Done
    writer.writeEndElement();
    writer.writeEndDocument();
}
 
Example #22
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void writeScheduledTaskInterval(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(SCHEDULED_TASK_INTERVAL.getName()).isDefined()) {
        return;
    }

    SCHEDULED_TASK_INTERVAL.marshallAsElement(context.getModelNode(), writer);
}
 
Example #23
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void writeAdmin(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(MASTER_REALM_NAME.getName()).isDefined()) {
        return;
    }

    MASTER_REALM_NAME.marshallAsElement(context.getModelNode(), writer);
}
 
Example #24
Source File: ThreadsParser.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void writeThreadFactory(final XMLExtendedStreamWriter writer, final Property property, final String elementName, final boolean includeName) throws XMLStreamException {
    writer.writeStartElement(elementName);
    ModelNode node = property.getValue();
    if (includeName) {
        writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
    }
    PoolAttributeDefinitions.GROUP_NAME.marshallAsAttribute(node, writer);
    PoolAttributeDefinitions.THREAD_NAME_PATTERN.marshallAsAttribute(node, writer);
    PoolAttributeDefinitions.PRIORITY.marshallAsAttribute(node, writer);
    writer.writeEndElement();
}
 
Example #25
Source File: LoggingSubsystemWriter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeLogger(final XMLExtendedStreamWriter writer, String name, final ModelNode model) throws XMLStreamException {
    writer.writeStartElement(Element.LOGGER.getLocalName());
    writer.writeAttribute(CATEGORY.getXmlName(), name);
    USE_PARENT_HANDLERS.marshallAsAttribute(model, writer);
    writeCommonLogger(writer, model);
    writer.writeEndElement();
}
 
Example #26
Source File: PersistentResourceXMLParserTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testSimpleParser() throws Exception {

    MyParser parser = new MyParser();

    String xml = readResource("simple-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);

    Assert.assertEquals(4, operations.size());
    ModelNode subsystem = opsToModel(operations);
    ModelNode resource = subsystem.get("resource","foo");

    ModelNode complexMap = MyParser.COMPLEX_MAP.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, resource);
    Assert.assertEquals("Model type should be map", ModelType.OBJECT, complexMap.getType());
    Assert.assertEquals("Map should have 3 elements", 3, complexMap.asList().size());
    Assert.assertEquals("some.class1", complexMap.get("key1", "name").asString());
    Assert.assertEquals("some.class2", complexMap.get("key2", "name").asString());
    Assert.assertEquals("some.module3", complexMap.get("key3", "module").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));
}
 
Example #27
Source File: LoggingSubsystemWriter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeAsynchHandler(final XMLExtendedStreamWriter writer, final ModelNode model, final String name) throws XMLStreamException {
    writer.writeStartElement(Element.ASYNC_HANDLER.getLocalName());
    writer.writeAttribute(HANDLER_NAME.getXmlName(), name);
    ENABLED.marshallAsAttribute(model, false, writer);
    LEVEL.marshallAsElement(model, writer);
    AbstractHandlerDefinition.FILTER_SPEC.marshallAsElement(model, writer);
    FORMATTER.marshallAsElement(model, writer);
    QUEUE_LENGTH.marshallAsElement(model, writer);
    OVERFLOW_ACTION.marshallAsElement(model, writer);
    SUBHANDLERS.marshallAsElement(model, writer);

    writer.writeEndElement();
}
 
Example #28
Source File: StandaloneXml_6.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean writeHttpManagementProtocol(XMLExtendedStreamWriter writer, ModelNode protocol) throws XMLStreamException {

    writer.writeStartElement(Element.HTTP_INTERFACE.getLocalName());
    HttpManagementResourceDefinition.HTTP_AUTHENTICATION_FACTORY.marshallAsAttribute(protocol, writer);
    HttpManagementResourceDefinition.SSL_CONTEXT.marshallAsAttribute(protocol, writer);
    HttpManagementResourceDefinition.SECURITY_REALM.marshallAsAttribute(protocol, writer);
    HttpManagementResourceDefinition.SASL_PROTOCOL.marshallAsAttribute(protocol, writer);
    HttpManagementResourceDefinition.SERVER_NAME.marshallAsAttribute(protocol, writer);

    boolean consoleEnabled = protocol.get(ModelDescriptionConstants.CONSOLE_ENABLED).asBoolean(true);
    if (!consoleEnabled) {
        HttpManagementResourceDefinition.CONSOLE_ENABLED.marshallAsAttribute(protocol, writer);
    }

    HttpManagementResourceDefinition.ALLOWED_ORIGINS.getMarshaller().marshallAsAttribute(
            HttpManagementResourceDefinition.ALLOWED_ORIGINS, protocol, true, writer);

    if (HttpManagementResourceDefinition.HTTP_UPGRADE.isMarshallable(protocol)) {
        writer.writeEmptyElement(Element.HTTP_UPGRADE.getLocalName());
        HttpManagementResourceDefinition.ENABLED.marshallAsAttribute(protocol.require(HTTP_UPGRADE), writer);
        HttpManagementResourceDefinition.SASL_AUTHENTICATION_FACTORY.marshallAsAttribute(protocol.require(HTTP_UPGRADE), writer);
    }

    if (HttpManagementResourceDefinition.SOCKET_BINDING.isMarshallable(protocol)
            || HttpManagementResourceDefinition.SECURE_SOCKET_BINDING.isMarshallable(protocol)) {
        writer.writeEmptyElement(Element.SOCKET_BINDING.getLocalName());
        HttpManagementResourceDefinition.SOCKET_BINDING.marshallAsAttribute(protocol, writer);
        HttpManagementResourceDefinition.SECURE_SOCKET_BINDING.marshallAsAttribute(protocol, writer);
    }

    writer.writeEndElement();

    return true;
}
 
Example #29
Source File: LoggingSubsystemWriter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeConsoleHandler(final XMLExtendedStreamWriter writer, final ModelNode model, final String name)
        throws XMLStreamException {
    writer.writeStartElement(Element.CONSOLE_HANDLER.getLocalName());
    writer.writeAttribute(HANDLER_NAME.getXmlName(), name);
    AUTOFLUSH.marshallAsAttribute(model, writer);
    ENABLED.marshallAsAttribute(model, false, writer);
    writeCommonHandler(writer, model);
    TARGET.marshallAsElement(model, writer);
    writer.writeEndElement();
}
 
Example #30
Source File: PatchXmlUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static void writeAppliesToVersions(XMLExtendedStreamWriter writer, List<String> appliesTo) throws XMLStreamException {
        for (String version : appliesTo) {
//            writer.writeStartElement(Element.APPLIES_TO_VERSION.name);
            writer.writeCharacters(version);
            writer.writeEndElement();
        }
    }