Java Code Examples for org.jboss.as.controller.AttributeDefinition#marshallAsElement()

The following examples show how to use org.jboss.as.controller.AttributeDefinition#marshallAsElement() . 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: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void writeSecureDeployments(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(SecureDeploymentDefinition.TAG_NAME).isDefined()) {
        return;
    }
    for (Property deployment : context.getModelNode().get(SecureDeploymentDefinition.TAG_NAME).asPropertyList()) {
        writer.writeStartElement(SecureDeploymentDefinition.TAG_NAME);
        writer.writeAttribute("name", deployment.getName());
        ModelNode deploymentElements = deployment.getValue();
        for (AttributeDefinition element : SecureDeploymentDefinition.ALL_ATTRIBUTES) {
            element.marshallAsElement(deploymentElements, writer);
        }

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

        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: 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 4
Source File: BpmPlatformParser.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void writeJobExecutorContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
  ModelNode node = context.getModelNode();
  ModelNode jobExecutorNode = node.get(Element.JOB_EXECUTOR.getLocalName());
  
  if (jobExecutorNode.isDefined()) { 
    writer.writeStartElement(Element.JOB_EXECUTOR.getLocalName());
    
    for (Property property : jobExecutorNode.asPropertyList()) {
      ModelNode propertyValue = property.getValue();

      for (AttributeDefinition jobExecutorAttribute : SubsystemAttributeDefinitons.JOB_EXECUTOR_ATTRIBUTES) {
        if (jobExecutorAttribute.equals(SubsystemAttributeDefinitons.NAME)) {
          ((SimpleAttributeDefinition) jobExecutorAttribute).marshallAsAttribute(propertyValue, writer);
        } else {
          jobExecutorAttribute.marshallAsElement(propertyValue, writer);
        }
      }

      writeJobAcquisitionsContent(writer, context, propertyValue);
    }

    // end job-executor
    writer.writeEndElement();
  }
}
 
Example 5
Source File: BpmPlatformParser.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void writeJobAcquisitionsContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context, ModelNode parentNode) throws XMLStreamException {
  writer.writeStartElement(Element.JOB_AQUISITIONS.getLocalName());

  ModelNode jobAcquisitionConfigurations = parentNode.get(Element.JOB_AQUISITIONS.getLocalName());
  if (jobAcquisitionConfigurations.isDefined()) {
    for (Property property : jobAcquisitionConfigurations.asPropertyList()) {
      // write each child element to xml
      writer.writeStartElement(Element.JOB_AQUISITION.getLocalName());

      for (AttributeDefinition jobAcquisitionAttribute : SubsystemAttributeDefinitons.JOB_ACQUISITION_ATTRIBUTES) {
        if (jobAcquisitionAttribute.equals(SubsystemAttributeDefinitons.NAME)) {
          ((SimpleAttributeDefinition) jobAcquisitionAttribute).marshallAsAttribute(property.getValue(), writer);
        } else {
          jobAcquisitionAttribute.marshallAsElement(property.getValue(), writer);
        }
      }

      writer.writeEndElement();
    }
  }
  // end job-acquisitions
  writer.writeEndElement();
}
 
Example 6
Source File: CustomMarshaller.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {

  if (attribute instanceof ObjectListAttributeDefinition) {
    attribute = getValueType(attribute, ObjectListAttributeDefinition.class);
  }

  if (!(attribute instanceof ObjectTypeAttributeDefinition)) {
    throw new XMLStreamException(
      String.format("Attribute of class %s is expected, but %s received", "ObjectTypeAttributeDefinition", attribute.getClass().getSimpleName())
    );
  }

  AttributeDefinition[] valueTypes;
  valueTypes = CustomMarshaller.getValueTypes(attribute, ObjectTypeAttributeDefinition.class);

  writer.writeStartElement(attribute.getXmlName());
  for (AttributeDefinition valueType : valueTypes) {
    valueType.marshallAsElement(resourceModel, marshallDefault, writer);
  }
  writer.writeEndElement();
}
 
Example 7
Source File: BpmPlatformParser1_1.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void writeJobExecutorContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
  ModelNode node = context.getModelNode();
  ModelNode jobExecutorNode = node.get(Element.JOB_EXECUTOR.getLocalName());

  if (jobExecutorNode.isDefined()) {

    writer.writeStartElement(Element.JOB_EXECUTOR.getLocalName());

    for (Property property : jobExecutorNode.asPropertyList()) {
      ModelNode propertyValue = property.getValue();

      for (AttributeDefinition jobExecutorAttribute : SubsystemAttributeDefinitons.JOB_EXECUTOR_ATTRIBUTES) {
        if (jobExecutorAttribute.equals(SubsystemAttributeDefinitons.NAME)) {
          ((SimpleAttributeDefinition) jobExecutorAttribute).marshallAsAttribute(propertyValue, writer);
        } else {
          jobExecutorAttribute.marshallAsElement(propertyValue, writer);
        }
      }

      writeJobAcquisitionsContent(writer, context, propertyValue);
    }

    // end job-executor
    writer.writeEndElement();
  }
}
 
Example 8
Source File: BpmPlatformParser1_1.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void writeJobAcquisitionsContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context, ModelNode parentNode) throws XMLStreamException {
  writer.writeStartElement(Element.JOB_AQUISITIONS.getLocalName());

  ModelNode jobAcquisitionConfigurations = parentNode.get(Element.JOB_AQUISITIONS.getLocalName());
  if (jobAcquisitionConfigurations.isDefined()) {

    for (Property property : jobAcquisitionConfigurations.asPropertyList()) {
      // write each child element to xml
      writer.writeStartElement(Element.JOB_AQUISITION.getLocalName());

      for (AttributeDefinition jobAcquisitionAttribute : SubsystemAttributeDefinitons.JOB_ACQUISITION_ATTRIBUTES) {
        if (jobAcquisitionAttribute.equals(SubsystemAttributeDefinitons.NAME)) {
          ((SimpleAttributeDefinition) jobAcquisitionAttribute).marshallAsAttribute(property.getValue(), writer);
        } else {
          jobAcquisitionAttribute.marshallAsElement(property.getValue(), writer);
        }
      }

      writer.writeEndElement();
    }
  }
  // end job-acquisitions
  writer.writeEndElement();
}
 
Example 9
Source File: CustomMarshaller.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {

  if (attribute instanceof ObjectListAttributeDefinition) {
    attribute = getValueType(attribute, ObjectListAttributeDefinition.class);
  }

  if (!(attribute instanceof ObjectTypeAttributeDefinition)) {
    throw new XMLStreamException(
      String.format("Attribute of class %s is expected, but %s received", "ObjectTypeAttributeDefinition", attribute.getClass().getSimpleName())
    );
  }

  AttributeDefinition[] valueTypes;
  valueTypes = CustomMarshaller.getValueTypes(attribute, ObjectTypeAttributeDefinition.class);

  writer.writeStartElement(attribute.getXmlName());
  for (AttributeDefinition valueType : valueTypes) {
    valueType.marshallAsElement(resourceModel, marshallDefault, writer);
  }
  writer.writeEndElement();
}
 
Example 10
Source File: LoggingSubsystemWriter.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 SubsystemMarshallingContext context) throws XMLStreamException {
    context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);

    ModelNode model = context.getModelNode();

    // Marshall attributes
    for (AttributeDefinition attribute : LoggingResourceDefinition.ATTRIBUTES) {
        attribute.marshallAsElement(model, false, writer);
    }

    writeContent(writer, model);

    if (model.hasDefined(LOGGING_PROFILE)) {
        final List<Property> profiles = model.get(LOGGING_PROFILE).asPropertyList();
        if (!profiles.isEmpty()) {
            writer.writeStartElement(LOGGING_PROFILES);
            for (Property profile : profiles) {
                final String name = profile.getName();
                writer.writeStartElement(LOGGING_PROFILE);
                writer.writeAttribute(Attribute.NAME.getLocalName(), name);
                writeContent(writer, profile.getValue());
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
    }
    writer.writeEndElement();
}
 
Example 11
Source File: LoggingSubsystemWriter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeFormatters(final XMLExtendedStreamWriter writer, final String resourceName,
                             final AttributeDefinition attribute, final ModelNode model) throws XMLStreamException {
    if (model.hasDefined(resourceName)) {
        for (String name : model.get(resourceName).keys()) {
            writer.writeStartElement(Element.FORMATTER.getLocalName());
            writer.writeAttribute(NAME.getXmlName(), name);
            final ModelNode value = model.get(resourceName, name);
            attribute.marshallAsElement(value, writer);
            writer.writeEndElement();
        }
    }
}
 
Example 12
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void writeRealms(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(RealmDefinition.TAG_NAME).isDefined()) {
        return;
    }
    for (Property realm : context.getModelNode().get(RealmDefinition.TAG_NAME).asPropertyList()) {
        writer.writeStartElement(RealmDefinition.TAG_NAME);
        writer.writeAttribute("name", realm.getName());
        ModelNode realmElements = realm.getValue();
        for (AttributeDefinition element : RealmDefinition.ALL_ATTRIBUTES) {
            element.marshallAsElement(realmElements, writer);
        }

        writer.writeEndElement();
    }
}
 
Example 13
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void writeRealms(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    if (!context.getModelNode().get(RealmDefinition.TAG_NAME).isDefined()) {
        return;
    }
    for (Property realm : context.getModelNode().get(RealmDefinition.TAG_NAME).asPropertyList()) {
        writer.writeStartElement(RealmDefinition.TAG_NAME);
        writer.writeAttribute("name", realm.getName());
        ModelNode realmElements = realm.getValue();
        for (AttributeDefinition element : RealmDefinition.ALL_ATTRIBUTES) {
            element.marshallAsElement(realmElements, writer);
        }

        writer.writeEndElement();
    }
}
 
Example 14
Source File: BpmPlatformParser.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void writeProcessEnginesContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
  
  writer.writeStartElement(Element.PROCESS_ENGINES.getLocalName());

  ModelNode node = context.getModelNode();
  
  ModelNode processEngineConfigurations = node.get(Element.PROCESS_ENGINES.getLocalName());
  if (processEngineConfigurations.isDefined()) {
    for (Property property : processEngineConfigurations.asPropertyList()) {
      // write each child element to xml
      writer.writeStartElement(Element.PROCESS_ENGINE.getLocalName());
      
      ModelNode propertyValue = property.getValue();
      for (AttributeDefinition processEngineAttribute : SubsystemAttributeDefinitons.PROCESS_ENGINE_ATTRIBUTES) {
        if (processEngineAttribute.equals(SubsystemAttributeDefinitons.NAME) || processEngineAttribute.equals(SubsystemAttributeDefinitons.DEFAULT)) {
          ((SimpleAttributeDefinition) processEngineAttribute).marshallAsAttribute(propertyValue, writer);
        } else {
          processEngineAttribute.marshallAsElement(propertyValue, writer);
        }
      }


      writer.writeEndElement();
    }
  }
  // end process-engines
  writer.writeEndElement();
}
 
Example 15
Source File: BpmPlatformParser1_1.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void writeProcessEnginesContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {

      writer.writeStartElement(Element.PROCESS_ENGINES.getLocalName());

      ModelNode node = context.getModelNode();

      ModelNode processEngineConfigurations = node.get(Element.PROCESS_ENGINES.getLocalName());
      if (processEngineConfigurations.isDefined()) {
        for (Property property : processEngineConfigurations.asPropertyList()) {
          // write each child element to xml
          writer.writeStartElement(Element.PROCESS_ENGINE.getLocalName());

          ModelNode propertyValue = property.getValue();
          for (AttributeDefinition processEngineAttribute : SubsystemAttributeDefinitons.PROCESS_ENGINE_ATTRIBUTES) {
            if (processEngineAttribute.equals(SubsystemAttributeDefinitons.NAME) || processEngineAttribute.equals(SubsystemAttributeDefinitons.DEFAULT)) {
              ((SimpleAttributeDefinition) processEngineAttribute).marshallAsAttribute(propertyValue, writer);
            } else {
              processEngineAttribute.marshallAsElement(propertyValue, writer);
            }
          }

          writer.writeEndElement();
        }
      }
      // end process-engines
      writer.writeEndElement();
    }