Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2008, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.connector.subsystems.resourceadapters;
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 import static org.jboss.as.connector.pool.Constants.BACKGROUNDVALIDATION;
 import static org.jboss.as.connector.pool.Constants.BACKGROUNDVALIDATIONMILLIS;
 import static org.jboss.as.connector.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS;
 import static org.jboss.as.connector.pool.Constants.IDLETIMEOUTMINUTES;
 import static org.jboss.as.connector.pool.Constants.MAX_POOL_SIZE;
 import static org.jboss.as.connector.pool.Constants.MIN_POOL_SIZE;
 import static org.jboss.as.connector.pool.Constants.POOL_FLUSH_STRATEGY;
 import static org.jboss.as.connector.pool.Constants.POOL_PREFILL;
 import static org.jboss.as.connector.pool.Constants.POOL_USE_STRICT_MIN;
 import static org.jboss.as.connector.pool.Constants.USE_FAST_FAIL;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTY_VALUE;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.JNDINAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.POOL_NAME_NAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERLUGIN_CLASSNAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERLUGIN_PROPERTIES;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_JAVA_CONTEXT;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
 
 import java.util.Map;
 
 
A CommonIronJacamarParser.

Author(s):
Stefano Maestri
 
 public abstract class CommonIronJacamarParser extends AbstractParser {
    
The bundle
 
     private static CommonBundle bundle = Messages.getBundle(CommonBundle.class);
 
 
    protected void parseConfigProperties(final XMLExtendedStreamReader readerfinal Map<String,ModelNodemapthrows XMLStreamException {
            String name = rawAttributeText(reader"name");
            final ModelNode operation = new ModelNode();
            operation.get().set();
            String value = rawElementText(reader);
            .parseAndSetParameter(value,operation,reader);
            map.put(nameoperation);
        }

    
parse a single connection-definition tag

    protected void parseConnectionDefinitions(final XMLExtendedStreamReader readerfinal Map<String,ModelNodemapfinal Map<String,HashMap<StringModelNode>> configMap)
            throws XMLStreamExceptionParserExceptionValidateException {
        final ModelNode connectionDefinitionNode = new ModelNode();
        connectionDefinitionNode.get().set();
        String poolName = null;
        String jndiName = null;
        int attributeSize = reader.getAttributeCount();
        boolean isXa = .;
        boolean poolDefined = .;
        for (int i = 0; i < attributeSizei++) {
            CommonConnDef.Attribute attribute = CommonConnDef.Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueconnectionDefinitionNodereader);
                    }
                    break;
                }
                case : {
                    jndiName = rawAttributeText(reader.getXmlName());
                    if(jndiName != null) {
                        .parseAndSetParameter(jndiNameconnectionDefinitionNodereader);
                    }
                    break;
                }
                case : {
                    poolName = rawAttributeText(reader);
                    break;
                }
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueconnectionDefinitionNodereader);
                    }
                    break;
                }
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueconnectionDefinitionNodereader);
                    }
                    break;
                }
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueconnectionDefinitionNodereader);
                    }
                    break;
                }
                default:
                    break;
            }
        }
        if (poolName == null || poolName.trim().equals("")) {
            if (jndiName != null && jndiName.trim().length() != 0) {
                if (jndiName.contains("/")) {
                    poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1);
                } else {
                    poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1);
                }
            } else {
               throw new ParserException(.missingValue(.getXmlName()));
            }
        }
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (ResourceAdapter.Tag.forName(reader.getLocalName()) == ..) {
                        map.put(poolNameconnectionDefinitionNode);
                        return;
                    } else {
                        if (CommonConnDef.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonConnDef.Tag.forName(reader.getLocalName())) {
                        case : {
                            if (! configMap.containsKey(poolName)) {
                                configMap.put(poolNamenew HashMap<StringModelNode>(0));
                            }
                            parseConfigProperties(readerconfigMap.get(poolName));
                            break;
                        }
                        case : {
                            parseSecuritySettings(readerconnectionDefinitionNode);
                            break;
                        }
                        case : {
                            parseTimeOut(readerisXaconnectionDefinitionNode);
                            break;
                        }
                        case : {
                            parseValidation(readerconnectionDefinitionNode);
                            break;
                        }
                        case : {
                            if (poolDefined)
                                throw new ParserException(.multiplePools());
                            parseXaPool(readerconnectionDefinitionNode);
                            isXa = true;
                            poolDefined = true;
                            break;
                        }
                        case : {
                            if (poolDefined)
                                throw new ParserException(.multiplePools());
                            parsePool(readerconnectionDefinitionNode);
                            poolDefined = true;
                            break;
                        }
                        case : {
                            parseRecovery(readerconnectionDefinitionNode);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
    private void parseValidation(XMLExtendedStreamReader readerModelNode nodethrows XMLStreamExceptionParserException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (CommonConnDef.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (CommonValidation.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonValidation.Tag.forName(reader.getLocalName())) {
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
    private void parseTimeOut(XMLExtendedStreamReader readerBoolean isXaModelNode nodethrows XMLStreamException,
            ParserExceptionValidateException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (CommonConnDef.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (CommonTimeOut.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonTimeOut.Tag.forName(reader.getLocalName())) {
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
    protected void parseAdminObjects(final XMLExtendedStreamReader readerfinal Map<String,ModelNodemapfinal Map<String,HashMap<StringModelNode>> configMap)
            throws XMLStreamExceptionParserExceptionValidateException {
        final ModelNode adminObjectNode = new ModelNode();
        adminObjectNode.get().set();
        int attributeSize = reader.getAttributeCount();
        String poolName = null;
        String jndiName = null;
        for (int i = 0; i < attributeSizei++) {
            CommonAdminObject.Attribute attribute = CommonAdminObject.Attribute.forName(reader
                    .getAttributeLocalName(i));
            switch (attribute) {
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueadminObjectNodereader);
                    }
                    break;
                }
                case : {
                    jndiName = rawAttributeText(reader.getXmlName());
                    if (jndiName != null) {
                        .parseAndSetParameter(jndiNameadminObjectNodereader);
                    }
                    break;
                }
                case : {
                    poolName = rawAttributeText(reader);
                    break;
                }
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueadminObjectNodereader);
                    }
                    break;
                }
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valueadminObjectNodereader);
                    }
                    break;
                }
                default:
                    throw new ParserException(.unexpectedAttribute(attribute.getLocalName(), reader.getLocalName()));
            }
        }
        if (poolName == null || poolName.trim().equals("")) {
            if (jndiName != null && jndiName.trim().length() != 0) {
                if (jndiName.contains("/")) {
                    poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1 );
                } else {
                    poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1);
                }
            } else {
               throw new ParserException(.missingValue(.getXmlName()));
            }
        }
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (ResourceAdapter.Tag.forName(reader.getLocalName()) == ..) {
                        map.put(poolNameadminObjectNode);
                        return;
                    } else {
                        if (CommonAdminObject.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonAdminObject.Tag.forName(reader.getLocalName())) {
                        case : {
                            if (! configMap.containsKey(poolName)) {
                                configMap.put(poolNamenew HashMap<StringModelNode>(0));
                            }
                            parseConfigProperties(readerconfigMap.get(poolName));
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }

    
    protected void parseXaPool(XMLExtendedStreamReader readerModelNode nodethrows XMLStreamExceptionParserException,
            ValidateException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (XaDataSource.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (CommonXaPool.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonXaPool.Tag.forName(reader.getLocalName())) {
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            //just presence means true
                            value = value == null ? "true" : value;
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            //just presence means true
                            value = value == null ? "true" : value;
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
    protected void parsePool(XMLExtendedStreamReader readerModelNode nodethrows XMLStreamExceptionParserException,
            ValidateException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (DataSource.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (CommonPool.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonPool.Tag.forName(reader.getLocalName())) {
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
    protected void parseRecovery(XMLExtendedStreamReader readerModelNode nodethrows XMLStreamExceptionParserException,
            ValidateException {
        for (Recovery.Attribute attribute : Recovery.Attribute.values()) {
            switch (attribute) {
                case : {
                    String value = rawAttributeText(reader.getXmlName());
                    if (value != null) {
                        .parseAndSetParameter(valuenodereader);
                    }
                    break;
                }
                default:
                    break;
            }
        }
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (XaDataSource.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (Recovery.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    Recovery.Tag tag = Recovery.Tag.forName(reader.getLocalName());
                    switch (tag) {
                        case : {
                            parseRecoveryCredential(readernode);
                            break;
                        }
                        case : {
                            parseExtension(readertag.getLocalName(), node);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
            ValidateException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (DataSource.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (CommonSecurity.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (CommonSecurity.Tag.forName(reader.getLocalName())) {
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            //just presence means true
                            value = value == null ? "true" : value;
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
            ValidateException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (DataSource.Tag.forName(reader.getLocalName()) == .. ||
                            Recovery.Tag.forName(reader.getLocalName()) == ..) {
                        return;
                    } else {
                        if (Credential.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (Credential.Tag.forName(reader.getLocalName())) {
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valuenodereader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
New to GrepCode? Check out our FAQ X