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();
    }
示例#2
0
  public static ModifiableConnDef buildConnectionDefinitionObject(ModelNode operation)
      throws ValidateException {
    Map<String, String> configProperties = new HashMap<String, String>(0);
    //        if (operation.hasDefined(CONFIG_PROPERTIES.getName())) {
    //            configProperties = new HashMap<String,
    // String>(operation.get(CONFIG_PROPERTIES.getName()).asList().size());
    //            for (ModelNode property : operation.get(CONFIG_PROPERTIES.getName()).asList()) {
    //                configProperties.put(property.asProperty().getName(),
    // property.asProperty().getValue().asString());
    //            }
    //        }
    String className = getStringIfSetOrGetDefault(operation, CLASS_NAME.getName(), null);
    String jndiName = getStringIfSetOrGetDefault(operation, JNDINAME.getName(), null);
    String poolName = getStringIfSetOrGetDefault(operation, POOL_NAME.getName(), null);
    boolean enabled = getBooleanIfSetOrGetDefault(operation, ENABLED.getName(), Defaults.ENABLED);
    boolean useJavaContext =
        getBooleanIfSetOrGetDefault(
            operation, USE_JAVA_CONTEXT.getName(), Defaults.USE_JAVA_CONTEXT);
    boolean useCcm = getBooleanIfSetOrGetDefault(operation, USE_CCM.getName(), Defaults.USE_CCM);

    Integer maxPoolSize =
        getIntIfSetOrGetDefault(operation, MAX_POOL_SIZE.getName(), Defaults.MAX_POOL_SIZE);
    Integer minPoolSize =
        getIntIfSetOrGetDefault(operation, MIN_POOL_SIZE.getName(), Defaults.MIN_POOL_SIZE);
    boolean prefill =
        getBooleanIfSetOrGetDefault(operation, POOL_PREFILL.getName(), Defaults.PREFILL);
    boolean useStrictMin =
        getBooleanIfSetOrGetDefault(
            operation, POOL_USE_STRICT_MIN.getName(), Defaults.USE_STRICT_MIN);
    final FlushStrategy flushStrategy =
        operation.hasDefined(POOL_FLUSH_STRATEGY.getName())
            ? FlushStrategy.forName(operation.get(POOL_FLUSH_STRATEGY.getName()).asString())
            : Defaults.FLUSH_STRATEGY;

    Integer allocationRetry = getIntIfSetOrGetDefault(operation, ALLOCATION_RETRY.getName(), null);
    Long allocationRetryWaitMillis =
        getLongIfSetOrGetDefault(operation, ALLOCATION_RETRY_WAIT_MILLIS.getName(), null);
    Long blockingTimeoutMillis =
        getLongIfSetOrGetDefault(operation, BLOCKING_TIMEOUT_WAIT_MILLIS.getName(), null);
    Long idleTimeoutMinutes =
        getLongIfSetOrGetDefault(operation, IDLETIMEOUTMINUTES.getName(), null);
    Integer xaResourceTimeout =
        getIntIfSetOrGetDefault(operation, XA_RESOURCE_TIMEOUT.getName(), null);
    CommonTimeOut timeOut =
        new CommonTimeOutImpl(
            blockingTimeoutMillis,
            idleTimeoutMinutes,
            allocationRetry,
            allocationRetryWaitMillis,
            xaResourceTimeout);
    CommonPool pool =
        new CommonPoolImpl(minPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy);

    String securityDomain = getStringIfSetOrGetDefault(operation, SECURITY_DOMAIN.getName(), null);
    String securityDomainAndApplication =
        getStringIfSetOrGetDefault(operation, SECURITY_DOMAIN_AND_APPLICATION.getName(), null);
    Boolean application = getBooleanIfSetOrGetDefault(operation, APPLICATION.getName(), null);

    CommonSecurity security = null;

    if (securityDomain != null && securityDomainAndApplication != null && application != null) {
      if (application == null) application = Defaults.APPLICATION_MANAGED_SECURITY;
      security = new CommonSecurityImpl(securityDomain, securityDomainAndApplication, application);
    }

    Long backgroundValidationMillis =
        getLongIfSetOrGetDefault(operation, BACKGROUNDVALIDATIONMILLIS.getName(), null);
    boolean backgroundValidation =
        getBooleanIfSetOrGetDefault(
            operation, BACKGROUNDVALIDATION.getName(), Defaults.BACKGROUND_VALIDATION);
    boolean useFastFail =
        getBooleanIfSetOrGetDefault(operation, USE_FAST_FAIL.getName(), Defaults.USE_FAST_FAIl);
    CommonValidation validation =
        new CommonValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail);
    final String recoveryUsername =
        getStringIfSetOrGetDefault(operation, RECOVERY_USERNAME.getName(), null);
    String recoveryPassword =
        getStringIfSetOrGetDefault(operation, RECOVERY_PASSWORD.getName(), null);

    if (VaultUtil.isVaultFormat(recoveryPassword)) {
      try {
        recoveryPassword = VaultUtil.getValueAsString(recoveryPassword);
      } catch (SecurityVaultException e) {
        throw new RuntimeException(e); // TODO: use bundle from IJ
      }
    }
    final String recoverySecurityDomain =
        getStringIfSetOrGetDefault(operation, RECOVERY_SECURITY_DOMAIN.getName(), null);

    final Credential credential =
        new CredentialImpl(recoveryUsername, recoveryPassword, recoverySecurityDomain);

    final Extension recoverPlugin =
        extractExtension(
            operation, RECOVERLUGIN_CLASSNAME.getName(), RECOVERLUGIN_PROPERTIES.getName());
    final boolean noRecovery = getBooleanIfSetOrGetDefault(operation, NO_RECOVERY.getName(), false);
    Recovery recovery = new Recovery(credential, recoverPlugin, noRecovery);
    ModifiableConnDef connectionDefinition =
        new ModifiableConnDef(
            configProperties,
            className,
            jndiName,
            poolName,
            enabled,
            useJavaContext,
            useCcm,
            pool,
            timeOut,
            validation,
            security,
            recovery);

    return connectionDefinition;
  }
  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();
  }