Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, 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.datasources;
 
 
 import static org.jboss.as.connector.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER;
 import static org.jboss.as.connector.ConnectorMessages.MESSAGES;
 import static org.jboss.as.connector.subsystems.datasources.Constants.JNDINAME;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLED;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 
 import java.util.List;
 
Operation handler responsible for disabling an existing data-source.

Author(s):
John Bailey
 
 public class DataSourceDisable implements OperationStepHandler {
     static final DataSourceDisable INSTANCE = new DataSourceDisable();
 
     public void execute(OperationContext contextModelNode operation) {
 
         final ModelNode model = context.readResourceForUpdate(.).getModel();
         model.get().set(false);
 
         if (context.getType() == ..) {
             context.addStep(new OperationStepHandler() {
                 public void execute(final OperationContext contextModelNode operationthrows OperationFailedException {
 
                     final ModelNode address = operation.require();
                     final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
                     final String jndiName = model.get(.getName()).asString();
 
                     final ServiceRegistry registry = context.getServiceRegistry(true);
 
                     final ServiceName dataSourceServiceName = ..append(jndiName);
                     final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName);
                     if (dataSourceController != null) {
                         if (...equals(dataSourceController.getState())) {
                             dataSourceController.setMode(..);
                         } else {
                             throw new OperationFailedException(new ModelNode().set(.serviceNotEnabled("Data-source"dsName)));
                         }
                     } else {
                         throw new OperationFailedException(new ModelNode().set(.serviceNotAvailable("Data-source"dsName)));
                     }
 
                     final ServiceName referenceServiceName = ..append(dsName);
                     final ServiceController<?> referenceController = registry.getService(referenceServiceName);
                     if (referenceController != null ) {
                         referenceController.setMode(..);
                     }
 
                     final ServiceName binderServiceName = ContextNames.bindInfoFor(jndiName).getBinderServiceName();
 
                     final ServiceController<?> binderController = registry.getService(binderServiceName);
                     if (binderController != null ) {
                         binderController.setMode(..);
                     }
 
                     final ServiceName dataSourceConfigServiceName = ..append(dsName);
                     final ServiceController<?> dataSourceConfigController = registry.getService(dataSourceConfigServiceName);
 
 
                     final List<ServiceNameserviceNames = registry.getServiceNames();
 
 
                     final ServiceName xaDataSourceConfigServiceName = ..append(dsName);
                    final ServiceController<?> xaDataSourceConfigController = registry.getService(xaDataSourceConfigServiceName);
                    for (ServiceName name : serviceNames) {
                        if (dataSourceConfigServiceName.append("connetion-properties").isParentOf(name)) {
                            final ServiceController<?> connProperyController = registry.getService(name);
                            if (connProperyController != null) {
                                if (...equals(connProperyController.getState())) {
                                    connProperyController.setMode(..);
                                } else {
                                    throw new OperationFailedException(new ModelNode().set(.serviceAlreadyStarted("Data-source.connectionProperty"name)));
                                }
                            } else {
                                throw new OperationFailedException(new ModelNode().set(.serviceNotAvailable("Data-source.connectionProperty"name)));
                            }
                        }
                        if (xaDataSourceConfigServiceName.append("xa-datasource-properties").isParentOf(name)) {
                            final ServiceController<?> xaConfigProperyController = registry.getService(name);
                            if (xaConfigProperyController != null) {
                                if (...equals(xaConfigProperyController.getState())) {
                                    xaConfigProperyController.setMode(..);
                                } else {
                                    throw new OperationFailedException(new ModelNode().set(.serviceAlreadyStarted("Data-source.xa-config-property"name)));
                                }
                            } else {
                                throw new OperationFailedException(new ModelNode().set(.serviceNotAvailable("Data-source.xa-config-property"name)));
                            }
                        }
                    }
                    if (xaDataSourceConfigController != null) {
                        xaDataSourceConfigController.setMode(..);
                    }
                    if (dataSourceConfigController != null) {
                        dataSourceConfigController.setMode(..);
                    }
                    context.completeStep();
                }
            }, ..);
        }
        context.completeStep();
    }
New to GrepCode? Check out our FAQ X