Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2010, Red Hat, Inc., 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 java.util.List;
 import java.util.Map;
 
 
 
 import static org.jboss.as.connector.ConnectorLogger.SUBSYSTEM_RA_LOGGER;
 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.ADMIN_OBJECTS_NAME;
 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.ARCHIVE;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATIONGROUPS;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BOOTSTRAPCONTEXT;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTIES;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTIONDEFINITIONS_NAME;
 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.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.RESOURCEADAPTERS_NAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTER_NAME;
 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.TRANSACTIONSUPPORT;
 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.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.ADD_ADMIN_OBJECT_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.ADD_CONFIG_PROPERTIES_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.ADD_CONNECTION_DEFINITION_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.ADD_RESOURCEADAPTER_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.ADMIN_OBJECT_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.CONFIG_PROPERTIES_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.CONNECTION_DEFINITION_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.FLUSH_ALL_CONNECTION_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.FLUSH_IDLE_CONNECTION_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.REMOVE_ADMIN_OBJECT_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.REMOVE_CONFIG_PROPERTIES_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.REMOVE_CONNECTION_DEFINITION_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.REMOVE_RESOURCEADAPTER_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.RESOURCEADAPTER_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.SUBSYSTEM;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.SUBSYSTEM_ADD_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.SUBSYSTEM_REMOVE_DESC;
import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemProviders.TEST_CONNECTION_DESC;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;

Author(s):
Stefano Maestri
Jeff Zhang
public class ResourceAdaptersExtension implements Extension {
    public static final String SUBSYSTEM_NAME = ;
    @Override
    public void initialize(final ExtensionContext context) {
        .debugf("Initializing ResourceAdapters Extension");
        // Register the remoting subsystem
        final SubsystemRegistration registration = context.registerSubsystem();
        ReloadRequiredWriteAttributeHandler reloadRequiredWriteAttributeHandler = new ReloadRequiredWriteAttributeHandler();
        // Remoting subsystem description and operation handlers
        final ManagementResourceRegistration subsystem = registration.registerSubsystemModel();
        final ManagementResourceRegistration resourceadapter = subsystem.registerSubModel(PathElement.pathElement(),
                );
        resourceadapter.registerOperationHandler(.false);
        for (final String attribute : .) {
            resourceadapter.registerReadWriteAttribute(attributenull,
                    reloadRequiredWriteAttributeHandler.);
        }
        final ManagementResourceRegistration configAdapter = resourceadapter.registerSubModel(PathElement.pathElement(.getName()), );
        final ManagementResourceRegistration connectionDefinition = resourceadapter.registerSubModel(PathElement.pathElement(), );
        final ManagementResourceRegistration configCF = connectionDefinition.registerSubModel(PathElement.pathElement(.getName()), );
            connectionDefinition.registerReadWriteAttribute(attribute.getName(), null,
                    reloadRequiredWriteAttributeHandler.);
        }
        final ManagementResourceRegistration adminObject = resourceadapter.registerSubModel(PathElement.pathElement(), );
        final ManagementResourceRegistration configAO = adminObject.registerSubModel(PathElement.pathElement(.getName()), );
            adminObject.registerReadWriteAttribute(attribute.getName(), null,
                    reloadRequiredWriteAttributeHandler.);
        }
        connectionDefinition.registerOperationHandler("flush-idle-connection-in-pool",
        connectionDefinition.registerOperationHandler("flush-all-connection-in-pool",
        connectionDefinition.registerOperationHandler("test-connection-in-pool"..,
                false);
    }
    @Override
    public void initializeParsers(final ExtensionParsingContext context) {
    }
    public static final class ResourceAdapterSubsystemParser implements XMLStreamConstantsXMLElementReader<List<ModelNode>>,
        static final ResourceAdapterSubsystemParser INSTANCE = new ResourceAdapterSubsystemParser();

        
        @Override
        public void writeContent(XMLExtendedStreamWriter writerSubsystemMarshallingContext contextthrows XMLStreamException {
            ModelNode node = context.getModelNode();
            boolean hasChildren = node.hasDefined() && node.get().asPropertyList().size() > 0;
            context.startSubsystemElement(..getUriString(), !hasChildren);
            if (hasChildren) {
                writer.writeStartElement(..getLocalName());
                for (Property property : node.get().asPropertyList()) {
                    final ModelNode ra = property.getValue();
                    writeRaElement(writerra);
                }
                writer.writeEndElement();
                // Close the subsystem element
                writer.writeEndElement();
            }
        }
        private void writeRaElement(XMLExtendedStreamWriter streamWriterModelNode rathrows XMLStreamException {
            streamWriter.writeStartElement(...getLocalName());
            .marshallAsElement(rastreamWriter);
            .marshallAsElement(rastreamWriter);
            if (ra.hasDefined(.getName())) {
                streamWriter.writeStartElement(...getLocalName());
                for (ModelNode bvg : ra.get(.getName()).asList()) {
                    streamWriter.writeStartElement(.getXmlName());
                    streamWriter.writeCharacters(bvg.asString());
                    streamWriter.writeEndElement();
                }
                streamWriter.writeEndElement();
            }
            .marshallAsElement(rastreamWriter);
            writeNewConfigProperties(streamWriterra);
            TransactionSupportEnum transactionSupport = ra.hasDefined(.getName()) ? TransactionSupportEnum
                .valueOf(ra.get(.getName()).asString()) : null;
            boolean isXa = false;
            if (transactionSupport == .) {
                isXa = true;
            }
            if (ra.hasDefined()) {
                streamWriter.writeStartElement(...getLocalName());
                for (Property conDef : ra.get().asPropertyList()) {
                    writeConDef(streamWriterconDef.getValue(), conDef.getName(), isXa);
                }
                streamWriter.writeEndElement();
            }
            if (ra.hasDefined()) {
                streamWriter.writeStartElement(...getLocalName());
                for (Property adminObject : ra.get().asPropertyList()) {
                    writeAdminObject(streamWriteradminObject.getValue(), adminObject.getName());
                }
                streamWriter.writeEndElement();
            }
            streamWriter.writeEndElement();
        }
        private void writeConfigProperties(XMLExtendedStreamWriter streamWriterModelNode rathrows XMLStreamException {
            if (ra.hasDefined(.getName())) {
                for (Property connectionProperty : ra.get(.getName()).asPropertyList()) {
                    writeProperty(streamWriterraconnectionProperty.getName(), connectionProperty
                            .getValue().asString(), ...getLocalName());
                }
            }
        }
        private void writeNewConfigProperties(XMLExtendedStreamWriter streamWriterModelNode rathrows XMLStreamException {
            if (ra.hasDefined(.getName())) {
                for (Property connectionProperty : ra.get(.getName()).asPropertyList()) {
                    writeProperty(streamWriterraconnectionProperty.getName(), connectionProperty
                            .getValue().get("value").asString(), ...getLocalName());
                }
            }
        }
        private void writeProperty(XMLExtendedStreamWriter writerModelNode nodeString nameString valueString localName)
                throws XMLStreamException {
            writer.writeStartElement(localName);
            writer.writeAttribute("name"name);
            writer.writeCharacters(value);
            writer.writeEndElement();
        }
        private void writeAdminObject(XMLExtendedStreamWriter streamWriterModelNode adminObjectfinal String poolNamethrows XMLStreamException {
            streamWriter.writeStartElement(...getLocalName());
            .marshallAsAttribute(adminObjectstreamWriter);
            .marshallAsAttribute(adminObjectstreamWriter);
            .marshallAsAttribute(adminObjectstreamWriter);
            .marshallAsAttribute(adminObjectstreamWriter);
            streamWriter.writeAttribute("pool-name"poolName);
            writeNewConfigProperties(streamWriteradminObject);
            streamWriter.writeEndElement();
        }
        private void writeConDef(XMLExtendedStreamWriter streamWriterModelNode conDeffinal String poolNamefinal boolean isXathrows XMLStreamException {
            .marshallAsAttribute(conDefstreamWriter);
            .marshallAsAttribute(conDefstreamWriter);
            .marshallAsAttribute(conDefstreamWriter);
            .marshallAsAttribute(conDefstreamWriter);
            streamWriter.writeAttribute("pool-name"poolName);
            .marshallAsAttribute(conDefstreamWriter);
            writeNewConfigProperties(streamWriterconDef);
            if (conDef.hasDefined(.getName()) || conDef.hasDefined(.getName()) ||
                conDef.hasDefined(.getName()) || conDef.hasDefined(.getName()) ||
                conDef.hasDefined(.getName())) {
                if (isXa) {
                    streamWriter.writeStartElement(...getLocalName());
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    if (conDef.get(.getName()).asBoolean()) {
                        streamWriter.writeEmptyElement(.getXmlName());
                    } else {
                        .marshallAsElement(conDefstreamWriter);
                    }
                    if (conDef.get(.getName()).asBoolean()) {
                        streamWriter.writeEmptyElement(.getXmlName());
                    } else {
                        .marshallAsElement(conDefstreamWriter);
                    }
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    streamWriter.writeEndElement();
                } else {
                    streamWriter.writeStartElement(...getLocalName());
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    streamWriter.writeEndElement();
                }
            }
            if (conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())
                    || conDef.hasDefined(.getName())) {
                streamWriter.writeStartElement(...getLocalName());
                if (conDef.hasDefined(.getName()) && conDef.get(.getName()).asBoolean()) {
                    streamWriter.writeEmptyElement(.getXmlName());
                } else {
                    .marshallAsElement(conDefstreamWriter);
                }
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                streamWriter.writeEndElement();
            }
                    || conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())) {
                streamWriter.writeStartElement(...getLocalName());
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                streamWriter.writeEndElement();
            }
            if (conDef.hasDefined(.getName()) || conDef.hasDefined(.getName()) || conDef.hasDefined(.getName()) ) {
                streamWriter.writeStartElement(...getLocalName());
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                .marshallAsElement(conDefstreamWriter);
                streamWriter.writeEndElement();
            }
            if (conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())
                    || conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())
                    || conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())) {
                streamWriter.writeStartElement(...getLocalName());
                .marshallAsAttribute(conDefstreamWriter);
                if (conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())
                        || conDef.hasDefined(.getName())) {
                    streamWriter.writeStartElement(...getLocalName());
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    .marshallAsElement(conDefstreamWriter);
                    streamWriter.writeEndElement();
                }
                if (conDef.hasDefined(.getName()) || conDef.hasDefined(.getName())) {
                    streamWriter.writeStartElement(...getLocalName());
                    .marshallAsAttribute(conDefstreamWriter);
                    if (conDef.hasDefined(.getName())) {
                        for (Property property : conDef.get(.getName()).asPropertyList()) {
                            writeProperty(streamWriterconDefproperty.getName(), property
                                        .getValue().asString(), ..........getLocalName());
                        }
                    }
                    streamWriter.writeEndElement();
                }
                streamWriter.writeEndElement();
            }
            streamWriter.writeEndElement();
        }
        @Override
        public void readElement(final XMLExtendedStreamReader readerfinal List<ModelNodelistthrows XMLStreamException {
            final ModelNode address = new ModelNode();
            address.protect();
            final ModelNode subsystem = new ModelNode();
            subsystem.get().set();
            subsystem.get().set(address);
            list.add(subsystem);
            try {
                String localName = null;
                switch (Namespace.forUri(reader.getNamespaceURI())) {
                    case : {
                        localName = reader.getLocalName();
                        final Element element = Element.forName(reader.getLocalName());
                        .tracef("%s -> %s"localNameelement);
                        switch (element) {
                            case : {
                                ResourceAdapterParser parser = new ResourceAdapterParser();
                                parser.parse(readerlistaddress);
                                ParseUtils.requireNoContent(reader);
                                break;
                            }
                        }
                    }
                }
            } catch (Exception e) {
                throw new XMLStreamException(e);
            }
        }
    }
    private static void setStringIfNotNull(final ModelNode nodefinal String identifierfinal String value) {
        if (value != null) {
            node.get(identifier).set(value);
        }
    }
    private static void setExtensionIfNotNull(final ModelNode dsModelfinal String extensionclassname,
            final String extensionPropertiesfinal org.jboss.jca.common.api.metadata.common.Extension extension) {
        if (extension != null) {
            setStringIfNotNull(dsModelextensionclassnameextension.getClassName());
            if (extension.getConfigPropertiesMap() != null) {
                for (Map.Entry<StringStringentry : extension.getConfigPropertiesMap().entrySet()) {
                    dsModel.get(extensionPropertiesentry.getKey()).set(entry.getValue());
                }
            }
        }
    }
    private static void setBooleanIfNotNull(final ModelNode nodefinal String identifierfinal Boolean value) {
        if (value != null) {
            node.get(identifier).set(value);
        }
    }
    private static void setBooleanIfNotNull(final ModelNode nodefinal String identifier,
                                            final Boolean valuefinal Boolean defaultValue) {
        if (value != null) {
            node.get(identifier).set(value);
        } else if (defaultValue != null) {
            node.get(identifier).set(defaultValue);
        }
    }
    private static void setIntegerIfNotNull(final ModelNode nodefinal String identifierfinal Integer value) {
        if (value != null) {
            node.get(identifier).set(value);
        }
    }
    private static void setLongIfNotNull(final ModelNode nodefinal String identifierfinal Long value) {
        if (value != null) {
            node.get(identifier).set(value);
        }
    }
New to GrepCode? Check out our FAQ X