Example #1
0
  /**
   * Parse recovery tag
   *
   * @param reader reader
   * @return the parsed recovery object
   * @throws XMLStreamException in case of error
   * @throws ParserException in case of error
   * @throws ValidateException in case of error
   */
  protected Recovery parseRecovery(XMLStreamReader reader)
      throws XMLStreamException, ParserException, ValidateException {

    Boolean noRecovery = null;
    Credential security = null;
    Extension plugin = null;

    for (Recovery.Attribute attribute : Recovery.Attribute.values()) {
      switch (attribute) {
        case NO_RECOVERY:
          {
            noRecovery = attributeAsBoolean(reader, attribute.getLocalName(), Boolean.FALSE);
            break;
          }
        default:
          break;
      }
    }

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.RECOVERY) {
              return new Recovery(security, plugin, noRecovery);
            } else {
              if (Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            Recovery.Tag tag = Recovery.Tag.forName(reader.getLocalName());
            switch (tag) {
              case RECOVER_CREDENTIAL:
                {
                  security = parseCredential(reader);
                  break;
                }
              case RECOVER_PLUGIN:
                {
                  plugin = parseExtension(reader, tag.getLocalName());
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }
Example #2
0
  /**
   * parse the Extension tag
   *
   * @param reader reader
   * @param enclosingTag enclosingTag
   * @return the parsed extension object
   * @throws XMLStreamException in case of error
   * @throws ParserException in case of error
   * @throws ValidateException in case of error
   */
  protected Extension parseExtension(XMLStreamReader reader, String enclosingTag)
      throws XMLStreamException, ParserException, ValidateException {

    String className = null;
    Map<String, String> properties = null;

    for (Extension.Attribute attribute : Extension.Attribute.values()) {
      switch (attribute) {
        case CLASS_NAME:
          {
            className = attributeAsString(reader, attribute.getLocalName());
            break;
          }
        default:
          break;
      }
    }

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (reader.getLocalName().equals(enclosingTag)) {
              if (className == null) {
                throw new ParserException(bundle.missingClassName(enclosingTag));
              }

              return new Extension(className, properties);
            } else {
              if (Extension.Tag.forName(reader.getLocalName()) == Extension.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            switch (Extension.Tag.forName(reader.getLocalName())) {
              case CONFIG_PROPERTY:
                {
                  if (properties == null) properties = new HashMap<String, String>();
                  properties.put(attributeAsString(reader, "name"), elementAsString(reader));
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }
Example #3
0
  /**
   * parse a {@link CommonSecurity} element
   *
   * @param reader reader
   * @return a {@link CommonSecurity} object
   * @throws XMLStreamException XMLStreamException
   * @throws ParserException ParserException
   * @throws ValidateException ValidateException
   */
  protected CommonSecurity parseSecuritySettings(XMLStreamReader reader)
      throws XMLStreamException, ParserException, ValidateException {

    String securityDomain = null;
    String securityDomainAndApplication = null;
    boolean application = false;

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY) {

              return new CommonSecurityImpl(
                  securityDomain, securityDomainAndApplication, application);
            } else {
              if (CommonSecurity.Tag.forName(reader.getLocalName()) == CommonSecurity.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            switch (CommonSecurity.Tag.forName(reader.getLocalName())) {
              case SECURITY_DOMAIN:
                {
                  securityDomain = elementAsString(reader);
                  break;
                }
              case SECURITY_DOMAIN_AND_APPLICATION:
                {
                  securityDomainAndApplication = elementAsString(reader);
                  break;
                }
              case APPLICATION:
                {
                  application = elementAsBoolean(reader);
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }
Example #4
0
  /**
   * parse credential tag
   *
   * @param reader reader
   * @return the parse Object
   * @throws XMLStreamException in case of error
   * @throws ParserException in case of error
   * @throws ValidateException in case of error
   */
  protected Credential parseCredential(XMLStreamReader reader)
      throws XMLStreamException, ParserException, ValidateException {

    String userName = null;
    String password = null;
    String securityDomain = null;

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY
                || Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.RECOVER_CREDENTIAL) {

              return new CredentialImpl(userName, password, securityDomain);
            } else {
              if (Credential.Tag.forName(reader.getLocalName()) == Credential.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            switch (Credential.Tag.forName(reader.getLocalName())) {
              case PASSWORD:
                {
                  password = elementAsString(reader);
                  break;
                }
              case USER_NAME:
                {
                  userName = elementAsString(reader);
                  break;
                }
              case SECURITY_DOMAIN:
                {
                  securityDomain = elementAsString(reader);
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }
Example #5
0
  /**
   * convert an xml element in FlushStrategy value
   *
   * @param reader the StAX reader
   * @return the flush strategy represention
   * @throws XMLStreamException StAX exception
   * @throws ParserException in case it isn't a number
   */
  protected FlushStrategy elementAsFlushStrategy(XMLStreamReader reader)
      throws XMLStreamException, ParserException {
    String elementtext = rawElementText(reader);
    FlushStrategy result = FlushStrategy.forName(getSubstitutionValue(elementtext));

    if (result != FlushStrategy.UNKNOWN) return result;

    throw new ParserException(bundle.notValidFlushStrategy(elementtext));
  }
Example #6
0
 /**
  * convert an xml element in Integer value
  *
  * @param reader the StAX reader
  * @return the integer representing element
  * @throws XMLStreamException StAX exception
  * @throws ParserException in case it isn't a number
  */
 protected Integer elementAsInteger(XMLStreamReader reader)
     throws XMLStreamException, ParserException {
   Integer integerValue;
   integerValue = null;
   String elementtext = rawElementText(reader);
   try {
     integerValue = Integer.valueOf(getSubstitutionValue(elementtext));
   } catch (NumberFormatException nfe) {
     throw new ParserException(bundle.notValidNumber(elementtext, reader.getLocalName()));
   }
   return integerValue;
 }
Example #7
0
  /**
   * convert an xml element in Long value
   *
   * @param reader the StAX reader
   * @return the long representing element
   * @throws XMLStreamException StAX exception
   * @throws ParserException in case it isn't a number
   */
  protected Long elementAsLong(XMLStreamReader reader) throws XMLStreamException, ParserException {
    Long longValue;
    longValue = null;
    String elementtext = rawElementText(reader);

    try {
      longValue = Long.valueOf(getSubstitutionValue(elementtext));
    } catch (NumberFormatException nfe) {
      throw new ParserException(bundle.notValidNumber(elementtext, reader.getLocalName()));
    }

    return longValue;
  }
Example #8
0
  /**
   * convert an xml element in boolean value. Empty elements results with true (tag presence is
   * sufficient condition)
   *
   * @param reader the StAX reader
   * @return the boolean representing element
   * @throws XMLStreamException StAX exception
   * @throws ParserException in case of non valid boolean for given element value
   */
  protected Boolean elementAsBoolean(XMLStreamReader reader)
      throws XMLStreamException, ParserException {
    String elementtext = rawElementText(reader);
    String stringValue = getSubstitutionValue(elementtext);
    if (stringValue == null
        || stringValue.length() == 0
        || stringValue.trim().equalsIgnoreCase("true")
        || stringValue.trim().equalsIgnoreCase("false")) {

      return stringValue == null || stringValue.length() == 0
          ? true
          : Boolean.valueOf(stringValue.trim());
    } else {
      throw new ParserException(bundle.elementAsBoolean(elementtext, reader.getLocalName()));
    }
  }
Example #9
0
  /**
   * convert an xml attribute in boolean value. Empty elements results with false
   *
   * @param reader the StAX reader
   * @param attributeName the name of the attribute
   * @param defaultValue defaultValue
   * @return the boolean representing element
   * @throws XMLStreamException StAX exception
   * @throws ParserException in case of not valid boolena for given attribute
   */
  protected Boolean attributeAsBoolean(
      XMLStreamReader reader, String attributeName, Boolean defaultValue)
      throws XMLStreamException, ParserException {
    String attributeString = rawAttributeText(reader, attributeName);
    String stringValue = getSubstitutionValue(attributeString);
    if (stringValue == null
        || stringValue.length() == 0
        || stringValue.trim().equalsIgnoreCase("true")
        || stringValue.trim().equalsIgnoreCase("false")) {

      return attributeString == null
          ? defaultValue
          : Boolean.valueOf(reader.getAttributeValue("", attributeName).trim());
    } else {
      throw new ParserException(bundle.attributeAsBoolean(attributeString, reader.getLocalName()));
    }
  }
Example #10
0
  /**
   * parse a {@link CommonXaPool} object
   *
   * @param reader reader
   * @return the parsed {@link CommonXaPool} object
   * @throws XMLStreamException XMLStreamException
   * @throws ParserException ParserException
   * @throws ValidateException ValidateException
   */
  protected CommonXaPool parseXaPool(XMLStreamReader reader)
      throws XMLStreamException, ParserException, ValidateException {
    Integer minPoolSize = null;
    Integer maxPoolSize = null;
    Boolean prefill = Boolean.FALSE;
    FlushStrategy flushStrategy = FlushStrategy.FAILING_CONNECTION_ONLY;
    Boolean interleaving = Boolean.FALSE;
    Boolean isSameRmOverride = Boolean.FALSE;
    Boolean padXid = Boolean.FALSE;
    Boolean noTxSeparatePool = Boolean.FALSE;
    Boolean wrapXaDataSource = Boolean.TRUE;
    Boolean useStrictMin = Boolean.FALSE;

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.XA_POOL) {

              return new CommonXaPoolImpl(
                  minPoolSize,
                  maxPoolSize,
                  prefill,
                  useStrictMin,
                  flushStrategy,
                  isSameRmOverride,
                  interleaving,
                  padXid,
                  wrapXaDataSource,
                  noTxSeparatePool);

            } else {
              if (CommonXaPool.Tag.forName(reader.getLocalName()) == CommonXaPool.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            switch (CommonXaPool.Tag.forName(reader.getLocalName())) {
              case MAX_POOL_SIZE:
                {
                  maxPoolSize = elementAsInteger(reader);
                  break;
                }
              case MIN_POOL_SIZE:
                {
                  minPoolSize = elementAsInteger(reader);
                  break;
                }
              case INTERLEAVING:
                {
                  interleaving = elementAsBoolean(reader);
                  break;
                }
              case IS_SAME_RM_OVERRIDE:
                {
                  isSameRmOverride = elementAsBoolean(reader);
                  break;
                }
              case NO_TX_SEPARATE_POOLS:
                {
                  noTxSeparatePool = elementAsBoolean(reader);
                  break;
                }
              case PAD_XID:
                {
                  padXid = elementAsBoolean(reader);
                  break;
                }
              case WRAP_XA_RESOURCE:
                {
                  wrapXaDataSource = elementAsBoolean(reader);
                  break;
                }
              case PREFILL:
                {
                  prefill = elementAsBoolean(reader);
                  break;
                }
              case USE_STRICT_MIN:
                {
                  useStrictMin = elementAsBoolean(reader);
                  break;
                }
              case FLUSH_STRATEGY:
                {
                  flushStrategy = elementAsFlushStrategy(reader);
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }
Example #11
0
  /**
   * parse a {@link CommonPool} object
   *
   * @param reader reader
   * @return the parsed {@link CommonPool} object
   * @throws XMLStreamException XMLStreamException
   * @throws ParserException ParserException
   * @throws ValidateException ValidateException
   */
  protected CommonPool parsePool(XMLStreamReader reader)
      throws XMLStreamException, ParserException, ValidateException {
    Integer minPoolSize = null;
    Integer maxPoolSize = null;
    Boolean prefill = Boolean.FALSE;
    Boolean useStrictMin = Boolean.FALSE;
    FlushStrategy flushStrategy = FlushStrategy.FAILING_CONNECTION_ONLY;

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.POOL) {

              return new CommonPoolImpl(
                  minPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy);

            } else {
              if (CommonPool.Tag.forName(reader.getLocalName()) == CommonPool.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            switch (CommonPool.Tag.forName(reader.getLocalName())) {
              case MAX_POOL_SIZE:
                {
                  maxPoolSize = elementAsInteger(reader);
                  break;
                }
              case MIN_POOL_SIZE:
                {
                  minPoolSize = elementAsInteger(reader);
                  break;
                }

              case PREFILL:
                {
                  prefill = elementAsBoolean(reader);
                  break;
                }
              case USE_STRICT_MIN:
                {
                  useStrictMin = elementAsBoolean(reader);
                  break;
                }
              case FLUSH_STRATEGY:
                {
                  flushStrategy = elementAsFlushStrategy(reader);
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }
Example #12
0
 /**
  * Validation
  *
  * @throws ValidateException in case of error
  */
 private void partialCommonValidate() throws ValidateException {
   if (this.backgroundValidationMillis != null && this.backgroundValidationMillis < 0)
     throw new ValidateException(
         bundle.invalidNegative(Tag.BACKGROUND_VALIDATION_MILLIS.getLocalName()));
 }