Search in sources :

Example 16 with ParserException

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

the class DsParser method parseDriver.

private void parseDriver(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException {
    final ModelNode driverAddress = parentAddress.clone();
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(ADD);
    String driverName = null;
    for (org.jboss.jca.common.api.metadata.ds.Driver.Attribute attribute : Driver.Attribute.values()) {
        switch(attribute) {
            case NAME:
                {
                    driverName = rawAttributeText(reader, DRIVER_NAME.getXmlName());
                    DRIVER_NAME.parseAndSetParameter(driverName, operation, reader);
                    break;
                }
            case MAJOR_VERSION:
                {
                    String value = rawAttributeText(reader, DRIVER_MAJOR_VERSION.getXmlName());
                    DRIVER_MAJOR_VERSION.parseAndSetParameter(value, operation, reader);
                    break;
                }
            case MINOR_VERSION:
                {
                    String value = rawAttributeText(reader, DRIVER_MINOR_VERSION.getXmlName());
                    DRIVER_MINOR_VERSION.parseAndSetParameter(value, operation, reader);
                    break;
                }
            case MODULE:
                {
                    String moduleName = rawAttributeText(reader, DRIVER_MODULE_NAME.getXmlName());
                    String slot = null;
                    if (moduleName.contains(":")) {
                        slot = moduleName.substring(moduleName.indexOf(":") + 1);
                        moduleName = moduleName.substring(0, moduleName.indexOf(":"));
                    }
                    DRIVER_MODULE_NAME.parseAndSetParameter(moduleName, operation, reader);
                    if (slot != null) {
                        MODULE_SLOT.parseAndSetParameter(slot, operation, reader);
                    }
                    break;
                }
            default:
                break;
        }
    }
    driverAddress.add(JDBC_DRIVER_NAME, driverName);
    driverAddress.protect();
    operation.get(OP_ADDR).set(driverAddress);
    boolean driverClassMatched = false;
    boolean xaDatasourceClassMatched = false;
    boolean datasourceClassMatched = false;
    //elements reading
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DRIVER) {
                        list.add(operation);
                        return;
                    } else {
                        if (Driver.Tag.forName(reader.getLocalName()) == Driver.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(Driver.Tag.forName(reader.getLocalName())) {
                        case DATASOURCE_CLASS:
                            {
                                if (datasourceClassMatched) {
                                    throw new ParserException(bundle.unexpectedElement(DRIVER_DATASOURCE_CLASS_NAME.getXmlName()));
                                }
                                String value = rawElementText(reader);
                                DRIVER_DATASOURCE_CLASS_NAME.parseAndSetParameter(value, operation, reader);
                                datasourceClassMatched = true;
                                break;
                            }
                        case XA_DATASOURCE_CLASS:
                            {
                                if (xaDatasourceClassMatched) {
                                    throw new ParserException(bundle.unexpectedElement(DRIVER_XA_DATASOURCE_CLASS_NAME.getXmlName()));
                                }
                                String value = rawElementText(reader);
                                DRIVER_XA_DATASOURCE_CLASS_NAME.parseAndSetParameter(value, operation, reader);
                                xaDatasourceClassMatched = true;
                                break;
                            }
                        case DRIVER_CLASS:
                            {
                                if (driverClassMatched) {
                                    throw new ParserException(bundle.unexpectedElement(DRIVER_CLASS_NAME.getXmlName()));
                                }
                                String value = rawElementText(reader);
                                DRIVER_CLASS_NAME.parseAndSetParameter(value, operation, reader);
                                driverClassMatched = 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) Driver(org.jboss.jca.common.api.metadata.ds.Driver) ModelNode(org.jboss.dmr.ModelNode)

Example 17 with ParserException

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

the class DsParser method parseXaPool.

private void parseXaPool(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException {
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.XA_POOL) {
                        return;
                    //it's fine. Do nothing
                    } else {
                        if (DsXaPool.Tag.forName(reader.getLocalName()) == DsXaPool.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(DsXaPool.Tag.forName(reader.getLocalName())) {
                        case MAX_POOL_SIZE:
                            {
                                String value = rawElementText(reader);
                                MAX_POOL_SIZE.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case INITIAL_POOL_SIZE:
                            {
                                String value = rawElementText(reader);
                                INITIAL_POOL_SIZE.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case MIN_POOL_SIZE:
                            {
                                String value = rawElementText(reader);
                                MIN_POOL_SIZE.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case PREFILL:
                            {
                                String value = rawElementText(reader);
                                POOL_PREFILL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case FAIR:
                            {
                                String value = rawElementText(reader);
                                POOL_FAIR.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case USE_STRICT_MIN:
                            {
                                String value = rawElementText(reader);
                                POOL_USE_STRICT_MIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case FLUSH_STRATEGY:
                            {
                                String value = rawElementText(reader);
                                POOL_FLUSH_STRATEGY.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case ALLOW_MULTIPLE_USERS:
                            {
                                String value = rawElementText(reader);
                                ALLOW_MULTIPLE_USERS.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case CONNECTION_LISTENER:
                            {
                                parseExtension(reader, reader.getLocalName(), operation, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES);
                                break;
                            }
                        case INTERLEAVING:
                            {
                                //tag presence is sufficient to set it to true
                                String value = rawElementText(reader);
                                value = value == null ? "true" : value;
                                INTERLEAVING.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case IS_SAME_RM_OVERRIDE:
                            {
                                String value = rawElementText(reader);
                                SAME_RM_OVERRIDE.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case NO_TX_SEPARATE_POOLS:
                            {
                                //tag presence is sufficient to set it to true
                                String value = rawElementText(reader);
                                value = value == null ? "true" : value;
                                NO_TX_SEPARATE_POOL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case PAD_XID:
                            {
                                String value = rawElementText(reader);
                                PAD_XID.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case WRAP_XA_RESOURCE:
                            {
                                String value = rawElementText(reader);
                                WRAP_XA_RESOURCE.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case CAPACITY:
                            {
                                parseCapacity(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)

Example 18 with ParserException

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

the class DsParser method parseCredential.

private void parseCredential(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException {
    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;
                    } 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:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_PASSWORD.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case USER_NAME:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_USERNAME.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case SECURITY_DOMAIN:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException)

Example 19 with ParserException

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

the class DsParser method parseCredential_5_0.

private void parseCredential_5_0(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException {
    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;
                    } 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:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_PASSWORD.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case USER_NAME:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_USERNAME.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case SECURITY_DOMAIN:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case ELYTRON_ENABLED:
                            {
                                String value = rawElementText(reader);
                                value = value == null ? "true" : value;
                                RECOVERY_ELYTRON_ENABLED.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case AUTHENTICATION_CONTEXT:
                            {
                                String value = rawElementText(reader);
                                RECOVERY_AUTHENTICATION_CONTEXT.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case CREDENTIAL_REFERENCE:
                            RECOVERY_CREDENTIAL_REFERENCE.getParser().parseElement(RECOVERY_CREDENTIAL_REFERENCE, 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)

Example 20 with ParserException

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

the class DsParser method parseDataSource_1_2.

private void parseDataSource_1_2(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);
    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 DataSource.Attribute attribute = DataSource.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;
                }
            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;
                }
            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);
                        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 (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)

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