private void writeConDef(
        XMLExtendedStreamWriter streamWriter,
        ModelNode conDef,
        final String poolName,
        final boolean isXa)
        throws XMLStreamException {
      streamWriter.writeStartElement(ResourceAdapter.Tag.CONNECTION_DEFINITION.getLocalName());
      CLASS_NAME.marshallAsAttribute(conDef, streamWriter);
      JNDINAME.marshallAsAttribute(conDef, streamWriter);
      ENABLED.marshallAsAttribute(conDef, streamWriter);
      USE_JAVA_CONTEXT.marshallAsAttribute(conDef, streamWriter);
      streamWriter.writeAttribute("pool-name", poolName);
      USE_CCM.marshallAsAttribute(conDef, streamWriter);

      writeNewConfigProperties(streamWriter, conDef);

      if (conDef.hasDefined(MAX_POOL_SIZE.getName())
          || conDef.hasDefined(MIN_POOL_SIZE.getName())
          || conDef.hasDefined(POOL_USE_STRICT_MIN.getName())
          || conDef.hasDefined(POOL_PREFILL.getName())
          || conDef.hasDefined(POOL_FLUSH_STRATEGY.getName())) {
        if (isXa) {

          streamWriter.writeStartElement(CommonConnDef.Tag.XA_POOL.getLocalName());
          MIN_POOL_SIZE.marshallAsElement(conDef, streamWriter);
          MAX_POOL_SIZE.marshallAsElement(conDef, streamWriter);
          POOL_PREFILL.marshallAsElement(conDef, streamWriter);
          POOL_USE_STRICT_MIN.marshallAsElement(conDef, streamWriter);
          POOL_FLUSH_STRATEGY.marshallAsElement(conDef, streamWriter);

          SAME_RM_OVERRIDE.marshallAsElement(conDef, streamWriter);
          INTERLEAVING.marshallAsElement(conDef, streamWriter);
          NOTXSEPARATEPOOL.marshallAsElement(conDef, streamWriter);
          PAD_XID.marshallAsElement(conDef, streamWriter);
          WRAP_XA_RESOURCE.marshallAsElement(conDef, streamWriter);

          streamWriter.writeEndElement();
        } else {
          streamWriter.writeStartElement(CommonConnDef.Tag.POOL.getLocalName());
          MIN_POOL_SIZE.marshallAsElement(conDef, streamWriter);
          MAX_POOL_SIZE.marshallAsElement(conDef, streamWriter);
          POOL_PREFILL.marshallAsElement(conDef, streamWriter);
          POOL_USE_STRICT_MIN.marshallAsElement(conDef, streamWriter);
          POOL_FLUSH_STRATEGY.marshallAsElement(conDef, streamWriter);
          streamWriter.writeEndElement();
        }
      }

      if (conDef.hasDefined(APPLICATION.getName())
          || conDef.hasDefined(SECURITY_DOMAIN.getName())
          || conDef.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName())) {
        streamWriter.writeStartElement(CommonConnDef.Tag.SECURITY.getLocalName());
        APPLICATION.marshallAsElement(conDef, streamWriter);
        SECURITY_DOMAIN.marshallAsElement(conDef, streamWriter);
        SECURITY_DOMAIN_AND_APPLICATION.marshallAsElement(conDef, streamWriter);

        streamWriter.writeEndElement();
      }

      if (conDef.hasDefined(BLOCKING_TIMEOUT_WAIT_MILLIS.getName())
          || conDef.hasDefined(IDLETIMEOUTMINUTES.getName())
          || conDef.hasDefined(ALLOCATION_RETRY.getName())
          || conDef.hasDefined(ALLOCATION_RETRY_WAIT_MILLIS.getName())
          || conDef.hasDefined(XA_RESOURCE_TIMEOUT.getName())) {
        streamWriter.writeStartElement(CommonConnDef.Tag.TIMEOUT.getLocalName());
        BLOCKING_TIMEOUT_WAIT_MILLIS.marshallAsElement(conDef, streamWriter);
        IDLETIMEOUTMINUTES.marshallAsElement(conDef, streamWriter);
        ALLOCATION_RETRY.marshallAsElement(conDef, streamWriter);
        ALLOCATION_RETRY_WAIT_MILLIS.marshallAsElement(conDef, streamWriter);
        XA_RESOURCE_TIMEOUT.marshallAsElement(conDef, streamWriter);
        streamWriter.writeEndElement();
      }

      if (conDef.hasDefined(BACKGROUNDVALIDATION.getName())
          || conDef.hasDefined(BACKGROUNDVALIDATIONMILLIS.getName())
          || conDef.hasDefined(USE_FAST_FAIL.getName())) {
        streamWriter.writeStartElement(CommonConnDef.Tag.VALIDATION.getLocalName());
        BACKGROUNDVALIDATION.marshallAsElement(conDef, streamWriter);
        BACKGROUNDVALIDATIONMILLIS.marshallAsElement(conDef, streamWriter);
        USE_FAST_FAIL.marshallAsElement(conDef, streamWriter);
        streamWriter.writeEndElement();
      }

      if (conDef.hasDefined(RECOVERY_USERNAME.getName())
          || conDef.hasDefined(RECOVERY_PASSWORD.getName())
          || conDef.hasDefined(RECOVERY_SECURITY_DOMAIN.getName())
          || conDef.hasDefined(RECOVERLUGIN_CLASSNAME.getName())
          || conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())
          || conDef.hasDefined(NO_RECOVERY.getName())) {

        streamWriter.writeStartElement(CommonConnDef.Tag.RECOVERY.getLocalName());
        if (conDef.hasDefined(RECOVERY_USERNAME.getName())
            || conDef.hasDefined(RECOVERY_PASSWORD.getName())
            || conDef.hasDefined(RECOVERY_SECURITY_DOMAIN.getName())) {
          streamWriter.writeStartElement(Recovery.Tag.RECOVER_CREDENTIAL.getLocalName());
          RECOVERY_USERNAME.marshallAsElement(conDef, streamWriter);
          RECOVERY_PASSWORD.marshallAsElement(conDef, streamWriter);
          RECOVERY_SECURITY_DOMAIN.marshallAsElement(conDef, streamWriter);
          streamWriter.writeEndElement();
        }
        if (conDef.hasDefined(RECOVERLUGIN_CLASSNAME.getName())
            || conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())) {
          streamWriter.writeStartElement(Recovery.Tag.RECOVER_PLUGIN.getLocalName());
          RECOVERLUGIN_CLASSNAME.marshallAsAttribute(conDef, streamWriter);
          if (conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())) {
            for (Property property :
                conDef.get(RECOVERLUGIN_PROPERTIES.getName()).asPropertyList()) {
              writeProperty(
                  streamWriter,
                  conDef,
                  property.getName(),
                  property.getValue().asString(),
                  org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY
                      .getLocalName());
            }
          }
          streamWriter.writeEndElement();
        }
        NO_RECOVERY.marshallAsAttribute(conDef, streamWriter);
      }

      streamWriter.writeEndElement();
    }
  private void writeConDef(
      XMLExtendedStreamWriter streamWriter,
      ModelNode conDef,
      final String poolName,
      final boolean isXa)
      throws XMLStreamException {
    streamWriter.writeStartElement(Activation.Tag.CONNECTION_DEFINITION.getLocalName());
    CLASS_NAME.marshallAsAttribute(conDef, streamWriter);
    JNDINAME.marshallAsAttribute(conDef, streamWriter);
    ENABLED.marshallAsAttribute(conDef, streamWriter);
    CONNECTABLE.marshallAsAttribute(conDef, streamWriter);
    TRACKING.marshallAsAttribute(conDef, streamWriter);
    USE_JAVA_CONTEXT.marshallAsAttribute(conDef, streamWriter);
    streamWriter.writeAttribute("pool-name", poolName);
    USE_CCM.marshallAsAttribute(conDef, streamWriter);
    SHARABLE.marshallAsAttribute(conDef, streamWriter);
    ENLISTMENT.marshallAsAttribute(conDef, streamWriter);

    writeNewConfigProperties(streamWriter, conDef);

    boolean poolRequired =
        INITIAL_POOL_SIZE.isMarshallable(conDef)
            || MAX_POOL_SIZE.isMarshallable(conDef)
            || MIN_POOL_SIZE.isMarshallable(conDef)
            || POOL_USE_STRICT_MIN.isMarshallable(conDef)
            || POOL_PREFILL.isMarshallable(conDef)
            || POOL_FLUSH_STRATEGY.isMarshallable(conDef);
    final boolean capacityRequired =
        CAPACITY_INCREMENTER_CLASS.isMarshallable(conDef)
            || CAPACITY_INCREMENTER_PROPERTIES.isMarshallable(conDef)
            || CAPACITY_DECREMENTER_CLASS.isMarshallable(conDef)
            || CAPACITY_DECREMENTER_PROPERTIES.isMarshallable(conDef);
    poolRequired = poolRequired || capacityRequired;

    if (poolRequired) {
      if (isXa) {

        streamWriter.writeStartElement(ConnectionDefinition.Tag.XA_POOL.getLocalName());
        MIN_POOL_SIZE.marshallAsElement(conDef, streamWriter);
        INITIAL_POOL_SIZE.marshallAsElement(conDef, streamWriter);
        MAX_POOL_SIZE.marshallAsElement(conDef, streamWriter);
        POOL_PREFILL.marshallAsElement(conDef, streamWriter);
        POOL_USE_STRICT_MIN.marshallAsElement(conDef, streamWriter);
        POOL_FLUSH_STRATEGY.marshallAsElement(conDef, streamWriter);

        SAME_RM_OVERRIDE.marshallAsElement(conDef, streamWriter);
        if (conDef.hasDefined(INTERLEAVING.getName())
            && conDef.get(INTERLEAVING.getName()).asBoolean()) {
          streamWriter.writeEmptyElement(INTERLEAVING.getXmlName());
        } else {
          INTERLEAVING.marshallAsElement(conDef, streamWriter);
        }
        if (conDef.hasDefined(NOTXSEPARATEPOOL.getName())
            && conDef.get(NOTXSEPARATEPOOL.getName()).asBoolean()) {
          streamWriter.writeEmptyElement(NOTXSEPARATEPOOL.getXmlName());
        } else {
          NOTXSEPARATEPOOL.marshallAsElement(conDef, streamWriter);
        }
        PAD_XID.marshallAsElement(conDef, streamWriter);
        WRAP_XA_RESOURCE.marshallAsElement(conDef, streamWriter);

      } else {
        streamWriter.writeStartElement(ConnectionDefinition.Tag.POOL.getLocalName());
        MIN_POOL_SIZE.marshallAsElement(conDef, streamWriter);
        INITIAL_POOL_SIZE.marshallAsElement(conDef, streamWriter);
        MAX_POOL_SIZE.marshallAsElement(conDef, streamWriter);
        POOL_PREFILL.marshallAsElement(conDef, streamWriter);
        POOL_USE_STRICT_MIN.marshallAsElement(conDef, streamWriter);
        POOL_FLUSH_STRATEGY.marshallAsElement(conDef, streamWriter);
      }
      if (capacityRequired) {
        streamWriter.writeStartElement(Pool.Tag.CAPACITY.getLocalName());
        if (conDef.hasDefined(CAPACITY_INCREMENTER_CLASS.getName())) {
          streamWriter.writeStartElement(Capacity.Tag.INCREMENTER.getLocalName());
          CAPACITY_INCREMENTER_CLASS.marshallAsAttribute(conDef, streamWriter);
          CAPACITY_INCREMENTER_PROPERTIES.marshallAsElement(conDef, streamWriter);

          streamWriter.writeEndElement();
        }
        if (conDef.hasDefined(CAPACITY_DECREMENTER_CLASS.getName())) {
          streamWriter.writeStartElement(Capacity.Tag.DECREMENTER.getLocalName());
          CAPACITY_DECREMENTER_CLASS.marshallAsAttribute(conDef, streamWriter);
          CAPACITY_DECREMENTER_PROPERTIES.marshallAsElement(conDef, streamWriter);

          streamWriter.writeEndElement();
        }
        streamWriter.writeEndElement();
      }
      streamWriter.writeEndElement();
    }

    if (conDef.hasDefined(APPLICATION.getName())
        || conDef.hasDefined(SECURITY_DOMAIN.getName())
        || conDef.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName())) {
      streamWriter.writeStartElement(ConnectionDefinition.Tag.SECURITY.getLocalName());
      if (conDef.hasDefined(APPLICATION.getName())
          && conDef.get(APPLICATION.getName()).asBoolean()) {
        streamWriter.writeEmptyElement(APPLICATION.getXmlName());
      } else {
        APPLICATION.marshallAsElement(conDef, streamWriter);
      }
      SECURITY_DOMAIN.marshallAsElement(conDef, streamWriter);
      SECURITY_DOMAIN_AND_APPLICATION.marshallAsElement(conDef, streamWriter);

      streamWriter.writeEndElement();
    }

    if (conDef.hasDefined(BLOCKING_TIMEOUT_WAIT_MILLIS.getName())
        || conDef.hasDefined(IDLETIMEOUTMINUTES.getName())
        || conDef.hasDefined(ALLOCATION_RETRY.getName())
        || conDef.hasDefined(ALLOCATION_RETRY_WAIT_MILLIS.getName())
        || conDef.hasDefined(XA_RESOURCE_TIMEOUT.getName())) {
      streamWriter.writeStartElement(ConnectionDefinition.Tag.TIMEOUT.getLocalName());
      BLOCKING_TIMEOUT_WAIT_MILLIS.marshallAsElement(conDef, streamWriter);
      IDLETIMEOUTMINUTES.marshallAsElement(conDef, streamWriter);
      ALLOCATION_RETRY.marshallAsElement(conDef, streamWriter);
      ALLOCATION_RETRY_WAIT_MILLIS.marshallAsElement(conDef, streamWriter);
      XA_RESOURCE_TIMEOUT.marshallAsElement(conDef, streamWriter);
      streamWriter.writeEndElement();
    }

    if (conDef.hasDefined(BACKGROUNDVALIDATION.getName())
        || conDef.hasDefined(BACKGROUNDVALIDATIONMILLIS.getName())
        || conDef.hasDefined(USE_FAST_FAIL.getName())
        || conDef.hasDefined(VALIDATE_ON_MATCH.getName())) {
      streamWriter.writeStartElement(ConnectionDefinition.Tag.VALIDATION.getLocalName());
      BACKGROUNDVALIDATION.marshallAsElement(conDef, streamWriter);
      BACKGROUNDVALIDATIONMILLIS.marshallAsElement(conDef, streamWriter);
      USE_FAST_FAIL.marshallAsElement(conDef, streamWriter);
      VALIDATE_ON_MATCH.marshallAsElement(conDef, streamWriter);
      streamWriter.writeEndElement();
    }

    if (conDef.hasDefined(RECOVERY_USERNAME.getName())
        || conDef.hasDefined(RECOVERY_PASSWORD.getName())
        || conDef.hasDefined(RECOVERY_SECURITY_DOMAIN.getName())
        || conDef.hasDefined(RECOVERLUGIN_CLASSNAME.getName())
        || conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())
        || conDef.hasDefined(NO_RECOVERY.getName())) {

      streamWriter.writeStartElement(ConnectionDefinition.Tag.RECOVERY.getLocalName());
      NO_RECOVERY.marshallAsAttribute(conDef, streamWriter);

      if (conDef.hasDefined(RECOVERY_USERNAME.getName())
          || conDef.hasDefined(RECOVERY_PASSWORD.getName())
          || conDef.hasDefined(RECOVERY_SECURITY_DOMAIN.getName())) {
        streamWriter.writeStartElement(Recovery.Tag.RECOVER_CREDENTIAL.getLocalName());
        RECOVERY_USERNAME.marshallAsElement(conDef, streamWriter);
        RECOVERY_PASSWORD.marshallAsElement(conDef, streamWriter);
        RECOVERY_SECURITY_DOMAIN.marshallAsElement(conDef, streamWriter);
        streamWriter.writeEndElement();
      }
      if (conDef.hasDefined(RECOVERLUGIN_CLASSNAME.getName())
          || conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())) {
        streamWriter.writeStartElement(Recovery.Tag.RECOVER_PLUGIN.getLocalName());
        RECOVERLUGIN_CLASSNAME.marshallAsAttribute(conDef, streamWriter);
        if (conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())) {
          for (Property property : conDef.get(RECOVERLUGIN_PROPERTIES.getName()).asPropertyList()) {
            writeProperty(
                streamWriter,
                conDef,
                property.getName(),
                property.getValue().asString(),
                org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY
                    .getLocalName());
          }
        }
        streamWriter.writeEndElement();
      }
      streamWriter.writeEndElement();
    }

    streamWriter.writeEndElement();
  }