Search in sources :

Example 1 with ParserException

use of org.jboss.as.connector.util.ParserException in project wildfly by wildfly.

the class ResourceAdapterParser method parseResourceAdapter.

private void parseResourceAdapter(final XMLExtendedStreamReader reader, final List<ModelNode> list, ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException {
    final ModelNode raAddress = parentAddress.clone();
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(ADD);
    String archiveOrModuleName = null;
    HashMap<String, ModelNode> configPropertiesOperations = new HashMap<String, ModelNode>();
    HashMap<String, ModelNode> connectionDefinitionsOperations = new HashMap<String, ModelNode>();
    HashMap<String, HashMap<String, ModelNode>> cfConfigPropertiesOperations = new HashMap<String, HashMap<String, ModelNode>>();
    HashMap<String, ModelNode> adminObjectsOperations = new HashMap<String, ModelNode>();
    HashMap<String, HashMap<String, ModelNode>> aoConfigPropertiesOperations = new HashMap<String, HashMap<String, ModelNode>>();
    boolean archiveOrModuleMatched = false;
    boolean txSupportMatched = false;
    boolean isXa = false;
    String id = null;
    int attributeSize = reader.getAttributeCount();
    for (int i = 0; i < attributeSize; i++) {
        Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        String value = reader.getAttributeValue(i);
        switch(attribute) {
            case ID:
                {
                    id = value;
                    break;
                }
            case STATISTICS_ENABLED:
                STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader);
                break;
            default:
                break;
        }
    }
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (Activations.Tag.forName(reader.getLocalName()) == Activations.Tag.RESOURCE_ADAPTER) {
                        if (!archiveOrModuleMatched) {
                            throw new ParserException(bundle.requiredElementMissing(ARCHIVE.getName(), RESOURCEADAPTER_NAME));
                        }
                        if (id != null) {
                            raAddress.add(RESOURCEADAPTER_NAME, id);
                        } else {
                            raAddress.add(RESOURCEADAPTER_NAME, archiveOrModuleName);
                        }
                        raAddress.protect();
                        operation.get(OP_ADDR).set(raAddress);
                        list.add(operation);
                        for (Map.Entry<String, ModelNode> entry : configPropertiesOperations.entrySet()) {
                            final ModelNode env = raAddress.clone();
                            env.add(CONFIG_PROPERTIES.getName(), entry.getKey());
                            env.protect();
                            entry.getValue().get(OP_ADDR).set(env);
                            list.add(entry.getValue());
                        }
                        for (Map.Entry<String, ModelNode> entry : connectionDefinitionsOperations.entrySet()) {
                            final ModelNode env = raAddress.clone();
                            env.add(CONNECTIONDEFINITIONS_NAME, entry.getKey());
                            env.protect();
                            entry.getValue().get(OP_ADDR).set(env);
                            list.add(entry.getValue());
                            final HashMap<String, ModelNode> properties = cfConfigPropertiesOperations.get(entry.getKey());
                            if (properties != null) {
                                for (Map.Entry<String, ModelNode> configEntry : properties.entrySet()) {
                                    final ModelNode configEnv = env.clone();
                                    configEnv.add(CONFIG_PROPERTIES.getName(), configEntry.getKey());
                                    configEnv.protect();
                                    configEntry.getValue().get(OP_ADDR).set(configEnv);
                                    list.add(configEntry.getValue());
                                }
                            }
                        }
                        for (Map.Entry<String, ModelNode> entry : adminObjectsOperations.entrySet()) {
                            final ModelNode env = raAddress.clone();
                            env.add(ADMIN_OBJECTS_NAME, entry.getKey());
                            env.protect();
                            entry.getValue().get(OP_ADDR).set(env);
                            list.add(entry.getValue());
                            final HashMap<String, ModelNode> aoProperties = aoConfigPropertiesOperations.get(entry.getKey());
                            if (aoProperties != null) {
                                for (Map.Entry<String, ModelNode> configEntry : aoProperties.entrySet()) {
                                    final ModelNode configEnv = env.clone();
                                    configEnv.add(CONFIG_PROPERTIES.getName(), configEntry.getKey());
                                    configEnv.protect();
                                    configEntry.getValue().get(OP_ADDR).set(configEnv);
                                    list.add(configEntry.getValue());
                                }
                            }
                        }
                        return;
                    } else {
                        if (AS7ResourceAdapterTags.forName(reader.getLocalName()) == AS7ResourceAdapterTags.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(AS7ResourceAdapterTags.forName(reader.getLocalName())) {
                        case ADMIN_OBJECTS:
                        case CONNECTION_DEFINITIONS:
                        case BEAN_VALIDATION_GROUPS:
                            {
                                // ignore it,we will parse bean-validation-group,admin_object and connection_definition directly
                                break;
                            }
                        case ADMIN_OBJECT:
                            {
                                parseAdminObjects(reader, adminObjectsOperations, aoConfigPropertiesOperations);
                                break;
                            }
                        case CONNECTION_DEFINITION:
                            {
                                switch(org.jboss.as.connector.subsystems.resourceadapters.Namespace.forUri(reader.getNamespaceURI())) {
                                    case RESOURCEADAPTERS_1_0:
                                    case RESOURCEADAPTERS_1_1:
                                    case RESOURCEADAPTERS_2_0:
                                        parseConnectionDefinitions_1_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa);
                                        break;
                                    case RESOURCEADAPTERS_3_0:
                                        parseConnectionDefinitions_3_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa);
                                        break;
                                    case RESOURCEADAPTERS_4_0:
                                        parseConnectionDefinitions_4_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa);
                                        break;
                                    default:
                                        parseConnectionDefinitions_5_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa);
                                        break;
                                }
                                break;
                            }
                        case BEAN_VALIDATION_GROUP:
                            {
                                String value = rawElementText(reader);
                                operation.get(BEANVALIDATION_GROUPS.getName()).add(BEANVALIDATIONGROUP.parse(value, reader));
                                break;
                            }
                        case BOOTSTRAP_CONTEXT:
                            {
                                String value = rawElementText(reader);
                                BOOTSTRAP_CONTEXT.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case CONFIG_PROPERTY:
                            {
                                parseConfigProperties(reader, configPropertiesOperations);
                                break;
                            }
                        case TRANSACTION_SUPPORT:
                            {
                                if (txSupportMatched) {
                                    throw new ParserException(bundle.unexpectedElement(TRANSACTION_SUPPORT.getXmlName()));
                                }
                                String value = rawElementText(reader);
                                TRANSACTION_SUPPORT.parseAndSetParameter(value, operation, reader);
                                ModelNode transactionSupport = TRANSACTION_SUPPORT.parse(value, reader);
                                // so we need to know the transaction support level to give a chance to throw XMLStreamException for
                                // unexpectedElement when parsing connection-definitions in CommonIronJacamarParser ?
                                String transactionSupportResolved = transactionSupport.resolve().asString();
                                isXa = value != null && TransactionSupportEnum.valueOf(transactionSupportResolved) == TransactionSupportEnum.XATransaction;
                                txSupportMatched = true;
                                break;
                            }
                        case WORKMANAGER:
                            {
                                parseWorkManager(operation, reader);
                                break;
                            }
                        case ARCHIVE:
                            {
                                if (archiveOrModuleMatched) {
                                    throw new ParserException(bundle.unexpectedElement(ARCHIVE.getXmlName()));
                                }
                                archiveOrModuleName = rawElementText(reader);
                                ARCHIVE.parseAndSetParameter(archiveOrModuleName, operation, reader);
                                archiveOrModuleMatched = true;
                                break;
                            }
                        case MODULE:
                            {
                                if (archiveOrModuleMatched) {
                                    throw new ParserException(bundle.unexpectedElement(MODULE.getXmlName()));
                                }
                                String moduleId = rawAttributeText(reader, "id");
                                String moduleSlot = rawAttributeText(reader, "slot", "main");
                                archiveOrModuleName = moduleId + ":" + moduleSlot;
                                MODULE.parseAndSetParameter(archiveOrModuleName, operation, reader);
                                archiveOrModuleMatched = true;
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) HashMap(java.util.HashMap) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with ParserException

use of org.jboss.as.connector.util.ParserException in project wildfly by wildfly.

the class ResourceAdapterParser method parseWorkManagerSecurity.

protected WorkManagerSecurity parseWorkManagerSecurity(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException {
    boolean mappingRequired = false;
    String domain = null;
    String defaultPrincipal = null;
    List<String> defaultGroups = null;
    Map<String, String> userMappings = null;
    Map<String, String> groupMappings = null;
    boolean userMappingEnabled = false;
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (WorkManager.Tag.forName(reader.getLocalName()) == WorkManager.Tag.SECURITY) {
                        return new WorkManagerSecurityImpl(mappingRequired, domain, false, defaultPrincipal, defaultGroups, userMappings, groupMappings);
                    } else {
                        if (WorkManagerSecurity.Tag.forName(reader.getLocalName()) == WorkManagerSecurity.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(WorkManagerSecurity.Tag.forName(reader.getLocalName())) {
                        case DEFAULT_GROUPS:
                        case MAPPINGS:
                            {
                                // Skip
                                break;
                            }
                        case MAPPING_REQUIRED:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_MAPPING_REQUIRED.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DOMAIN:
                            {
                                String value = domain = rawElementText(reader);
                                WM_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DEFAULT_PRINCIPAL:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_DEFAULT_PRINCIPAL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case GROUP:
                            {
                                String value = rawElementText(reader);
                                operation.get(WM_SECURITY_DEFAULT_GROUPS.getName()).add(WM_SECURITY_DEFAULT_GROUP.parse(value, reader));
                                break;
                            }
                        case USERS:
                            {
                                userMappingEnabled = true;
                                break;
                            }
                        case GROUPS:
                            {
                                userMappingEnabled = false;
                                break;
                            }
                        case MAP:
                            {
                                if (userMappingEnabled) {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_USERS.getName()).add(object);
                                } else {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_GROUPS.getName()).add(object);
                                }
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) WorkManagerSecurityImpl(org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with ParserException

use of org.jboss.as.connector.util.ParserException in project wildfly by wildfly.

the class CommonIronJacamarParser method parseConnectionDefinitions_4_0.

/**
 * parse a single connection-definition tag
 *
 * @param reader the reader
 * @throws javax.xml.stream.XMLStreamException
 *                         XMLStreamException
 * @throws ParserException ParserException
 * @throws org.jboss.jca.common.api.validator.ValidateException
 *                         ValidateException
 */
protected void parseConnectionDefinitions_4_0(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap, final boolean isXa) throws XMLStreamException, ParserException, ValidateException {
    final ModelNode connectionDefinitionNode = new ModelNode();
    connectionDefinitionNode.get(OP).set(ADD);
    String poolName = null;
    String jndiName = null;
    int attributeSize = reader.getAttributeCount();
    boolean poolDefined = Boolean.FALSE;
    for (int i = 0; i < attributeSize; i++) {
        ConnectionDefinition.Attribute attribute = ConnectionDefinition.Attribute.forName(reader.getAttributeLocalName(i));
        String value = reader.getAttributeValue(i);
        switch(attribute) {
            case ENABLED:
                {
                    ENABLED.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case CONNECTABLE:
                {
                    CONNECTABLE.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case TRACKING:
                {
                    TRACKING.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case JNDI_NAME:
                {
                    jndiName = value;
                    JNDINAME.parseAndSetParameter(jndiName, connectionDefinitionNode, reader);
                    break;
                }
            case POOL_NAME:
                {
                    poolName = value;
                    break;
                }
            case USE_JAVA_CONTEXT:
                {
                    USE_JAVA_CONTEXT.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case USE_CCM:
                {
                    USE_CCM.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case SHARABLE:
                {
                    SHARABLE.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case ENLISTMENT:
                {
                    ENLISTMENT.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case CLASS_NAME:
                {
                    CLASS_NAME.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case MCP:
                {
                    MCP.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case ENLISTMENT_TRACE:
                ENLISTMENT_TRACE.parseAndSetParameter(value, connectionDefinitionNode, reader);
                break;
            default:
                throw ParseUtils.unexpectedAttribute(reader, i);
        }
    }
    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 ParseUtils.missingRequired(reader, EnumSet.of(ConnectionDefinition.Attribute.JNDI_NAME));
        }
    }
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.CONNECTION_DEFINITION) {
                        map.put(poolName, connectionDefinitionNode);
                        return;
                    } else {
                        if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) {
                            throw ParseUtils.unexpectedEndElement(reader);
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(ConnectionDefinition.Tag.forName(reader.getLocalName())) {
                        case CONFIG_PROPERTY:
                            {
                                if (!configMap.containsKey(poolName)) {
                                    configMap.put(poolName, new HashMap<String, ModelNode>(0));
                                }
                                parseConfigProperties(reader, configMap.get(poolName));
                                break;
                            }
                        case SECURITY:
                            {
                                parseSecuritySettings(reader, connectionDefinitionNode);
                                break;
                            }
                        case TIMEOUT:
                            {
                                parseTimeOut(reader, connectionDefinitionNode);
                                break;
                            }
                        case VALIDATION:
                            {
                                parseValidation(reader, connectionDefinitionNode);
                                break;
                            }
                        case XA_POOL:
                            {
                                if (!isXa) {
                                    throw ParseUtils.unexpectedElement(reader);
                                }
                                if (poolDefined) {
                                    throw new ParserException(bundle.multiplePools());
                                }
                                parseXaPool(reader, connectionDefinitionNode);
                                poolDefined = true;
                                break;
                            }
                        case POOL:
                            {
                                if (isXa) {
                                    throw ParseUtils.unexpectedElement(reader);
                                }
                                if (poolDefined) {
                                    throw new ParserException(bundle.multiplePools());
                                }
                                parsePool(reader, connectionDefinitionNode);
                                poolDefined = true;
                                break;
                            }
                        case RECOVERY:
                            {
                                parseRecovery(reader, connectionDefinitionNode);
                                break;
                            }
                        default:
                            throw ParseUtils.unexpectedElement(reader);
                    }
                    break;
                }
        }
    }
    throw ParseUtils.unexpectedEndElement(reader);
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) ConnectionDefinition(org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 4 with ParserException

use of org.jboss.as.connector.util.ParserException in project wildfly by wildfly.

the class DsParser method parseDataSource_3_0.

private void parseDataSource_3_0(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException {
    String poolName = null;
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(ADD);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        }
        final DataSource.Attribute attribute = DataSource.Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case ENABLED:
                {
                    final String value = rawAttributeText(reader, ENABLED.getXmlName());
                    if (value != null) {
                        ENABLED.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case JNDI_NAME:
                {
                    final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName());
                    JNDI_NAME.parseAndSetParameter(jndiName, operation, reader);
                    break;
                }
            case POOL_NAME:
                {
                    poolName = rawAttributeText(reader, POOLNAME_NAME);
                    break;
                }
            case USE_JAVA_CONTEXT:
                {
                    final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName());
                    if (value != null) {
                        USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case SPY:
                {
                    final String value = rawAttributeText(reader, SPY.getXmlName());
                    if (value != null) {
                        SPY.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case USE_CCM:
                {
                    final String value = rawAttributeText(reader, USE_CCM.getXmlName());
                    if (value != null) {
                        USE_CCM.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case JTA:
                {
                    final String value = rawAttributeText(reader, JTA.getXmlName());
                    if (value != null) {
                        JTA.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case CONNECTABLE:
                {
                    final String value = rawAttributeText(reader, CONNECTABLE.getXmlName());
                    if (value != null) {
                        CONNECTABLE.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case TRACKING:
                {
                    final String value = rawAttributeText(reader, TRACKING.getXmlName());
                    if (value != null) {
                        TRACKING.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            default:
                if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) {
                    final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName());
                    if (value != null) {
                        Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                } else {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
        }
    }
    final ModelNode dsAddress = parentAddress.clone();
    dsAddress.add(DATA_SOURCE, poolName);
    dsAddress.protect();
    operation.get(OP_ADDR).set(dsAddress);
    List<ModelNode> configPropertiesOperations = new ArrayList<ModelNode>(0);
    // elements reading
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE) {
                        list.add(operation);
                        list.addAll(configPropertiesOperations);
                        return;
                    } else {
                        if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(DataSource.Tag.forName(reader.getLocalName())) {
                        case CONNECTION_PROPERTY:
                            {
                                String name = rawAttributeText(reader, "name");
                                String value = rawElementText(reader);
                                final ModelNode configOperation = new ModelNode();
                                configOperation.get(OP).set(ADD);
                                final ModelNode configAddress = dsAddress.clone();
                                configAddress.add(CONNECTION_PROPERTIES.getName(), name);
                                configAddress.protect();
                                configOperation.get(OP_ADDR).set(configAddress);
                                CONNECTION_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader);
                                configPropertiesOperations.add(configOperation);
                                break;
                            }
                        case CONNECTION_URL:
                            {
                                String value = rawElementText(reader);
                                CONNECTION_URL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DRIVER_CLASS:
                            {
                                String value = rawElementText(reader);
                                DRIVER_CLASS.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DATASOURCE_CLASS:
                            {
                                String value = rawElementText(reader);
                                DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DRIVER:
                            {
                                String value = rawElementText(reader);
                                DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case POOL:
                            {
                                parsePool(reader, operation);
                                break;
                            }
                        case NEW_CONNECTION_SQL:
                            {
                                String value = rawElementText(reader);
                                NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case URL_DELIMITER:
                            {
                                String value = rawElementText(reader);
                                URL_DELIMITER.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case URL_SELECTOR_STRATEGY_CLASS_NAME:
                            {
                                String value = rawElementText(reader);
                                URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case TRANSACTION_ISOLATION:
                            {
                                String value = rawElementText(reader);
                                TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case SECURITY:
                            {
                                parseDsSecurity(reader, operation);
                                break;
                            }
                        case STATEMENT:
                            {
                                parseStatementSettings(reader, operation);
                                break;
                            }
                        case TIMEOUT:
                            {
                                parseTimeOutSettings(reader, operation);
                                break;
                            }
                        case VALIDATION:
                            {
                                parseValidationSetting(reader, operation);
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource)

Example 5 with ParserException

use of org.jboss.as.connector.util.ParserException in project wildfly by wildfly.

the class DsParser method parseXADataSource_1_2.

private void parseXADataSource_1_2(XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException {
    String poolName = null;
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(ADD);
    boolean enabled = Defaults.ENABLED.booleanValue();
    // Persist the enabled flag because xml default is != from DMR default
    boolean persistEnabled = true;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        }
        final XaDataSource.Attribute attribute = XaDataSource.Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case ENABLED:
                {
                    final String value = rawAttributeText(reader, ENABLED.getXmlName());
                    if (value != null) {
                        enabled = Boolean.parseBoolean(value);
                        // ENABLED.parseAndSetParameter(value, operation, reader);
                        persistEnabled = true;
                    }
                    break;
                }
            case JNDI_NAME:
                {
                    final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName());
                    JNDI_NAME.parseAndSetParameter(jndiName, operation, reader);
                    break;
                }
            case POOL_NAME:
                {
                    poolName = rawAttributeText(reader, POOLNAME_NAME);
                    break;
                }
            case USE_JAVA_CONTEXT:
                {
                    final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName());
                    if (value != null) {
                        USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case SPY:
                {
                    final String value = rawAttributeText(reader, SPY.getXmlName());
                    if (value != null) {
                        SPY.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            case USE_CCM:
                {
                    final String value = rawAttributeText(reader, USE_CCM.getXmlName());
                    if (value != null) {
                        USE_CCM.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                }
            default:
                if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) {
                    final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName());
                    if (value != null) {
                        Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader);
                    }
                    break;
                } else {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
        }
    }
    final ModelNode dsAddress = parentAddress.clone();
    dsAddress.add(XA_DATASOURCE, poolName);
    dsAddress.protect();
    operation.get(OP_ADDR).set(dsAddress);
    List<ModelNode> xadatasourcePropertiesOperations = new ArrayList<ModelNode>(0);
    // elements reading
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.XA_DATASOURCE) {
                        list.add(operation);
                        list.addAll(xadatasourcePropertiesOperations);
                        if (enabled) {
                            final ModelNode enableOperation = new ModelNode();
                            enableOperation.get(OP).set(ENABLE);
                            enableOperation.get(OP_ADDR).set(dsAddress);
                            enableOperation.get(PERSISTENT).set(persistEnabled);
                            list.add(enableOperation);
                        }
                        return;
                    } else {
                        if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(XaDataSource.Tag.forName(reader.getLocalName())) {
                        case XA_DATASOURCE_PROPERTY:
                            {
                                String name = rawAttributeText(reader, "name");
                                String value = rawElementText(reader);
                                final ModelNode configOperation = new ModelNode();
                                configOperation.get(OP).set(ADD);
                                final ModelNode configAddress = dsAddress.clone();
                                configAddress.add(XADATASOURCE_PROPERTIES.getName(), name);
                                configAddress.protect();
                                configOperation.get(OP_ADDR).set(configAddress);
                                XADATASOURCE_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader);
                                xadatasourcePropertiesOperations.add(configOperation);
                                break;
                            }
                        case XA_DATASOURCE_CLASS:
                            {
                                String value = rawElementText(reader);
                                XA_DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DRIVER:
                            {
                                String value = rawElementText(reader);
                                DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case XA_POOL:
                            {
                                parseXaPool(reader, operation);
                                break;
                            }
                        case NEW_CONNECTION_SQL:
                            {
                                String value = rawElementText(reader);
                                NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case URL_DELIMITER:
                            {
                                String value = rawElementText(reader);
                                URL_DELIMITER.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case URL_SELECTOR_STRATEGY_CLASS_NAME:
                            {
                                String value = rawElementText(reader);
                                URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case TRANSACTION_ISOLATION:
                            {
                                String value = rawElementText(reader);
                                TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case SECURITY:
                            {
                                parseDsSecurity(reader, operation);
                                break;
                            }
                        case STATEMENT:
                            {
                                parseStatementSettings(reader, operation);
                                break;
                            }
                        case TIMEOUT:
                            {
                                parseTimeOutSettings(reader, operation);
                                break;
                            }
                        case VALIDATION:
                            {
                                parseValidationSetting(reader, operation);
                                break;
                            }
                        case RECOVERY:
                            {
                                parseRecovery(reader, operation);
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource)

Aggregations

ParserException (org.jboss.as.connector.util.ParserException)25 ModelNode (org.jboss.dmr.ModelNode)16 ArrayList (java.util.ArrayList)8 XaDataSource (org.jboss.jca.common.api.metadata.ds.XaDataSource)8 DataSource (org.jboss.jca.common.api.metadata.ds.DataSource)4 ConnectionDefinition (org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition)3 WorkManagerSecurityImpl (org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl)2 HashMap (java.util.HashMap)1 Driver (org.jboss.jca.common.api.metadata.ds.Driver)1