Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, 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.webservices.dmr;
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
 import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
 import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
 import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
 import static org.jboss.as.webservices.dmr.Constants.CLIENT_CONFIG;
 import static org.jboss.as.webservices.dmr.Constants.ENDPOINT_CONFIG;
 import static org.jboss.as.webservices.dmr.Constants.HANDLER;
 import static org.jboss.as.webservices.dmr.Constants.POST_HANDLER_CHAIN;
 import static org.jboss.as.webservices.dmr.Constants.PRE_HANDLER_CHAIN;
 import static org.jboss.as.webservices.dmr.Constants.PROPERTY;
 
 import java.util.List;
 

Author(s):
Richard Opalka
Alessio Soldano
 
 final class WSSubsystemReader implements XMLElementReader<List<ModelNode>> {
 
     private static final WSSubsystemReader INSTANCE = new WSSubsystemReader();
 
     private WSSubsystemReader() {
         // forbidden instantiation
     }
 
     static WSSubsystemReader getInstance() {
         return ;
     }
 
     @Override
     public void readElement(final XMLExtendedStreamReader readerfinal List<ModelNodelistthrows XMLStreamException {
         // no attributes
         requireNoAttributes(reader);
 
         final PathAddress address = PathAddress.pathAddress(.);
         final ModelNode subsystem = Util.createAddOperation(address);
 
         final List<ModelNodeendpointConfigs = new ArrayList<ModelNode>();
         final List<ModelNodeclientConfigs = new ArrayList<ModelNode>();
 
         // elements
         final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
         while (reader.hasNext() && reader.nextTag() != ) {
             switch (Namespace.forUri(reader.getNamespaceURI())) {
                 case : {
                     final Element element = Element.forName(reader.getLocalName());
                     if (element != . && !encountered.add(element)) {
                         throw unexpectedElement(reader);
                     }
                     switch (element) {
                         case : {
                             final String value = parseElementNoAttributes(reader);
                             ..parseAndSetParameter(valuesubsystemreader);
                             break;
                         }
                         case : {
                             final String value = parseElementNoAttributes(reader);
                             ..parseAndSetParameter(valuesubsystemreader);
                             break;
                         }
                         case : {
                             final String value = parseElementNoAttributes(reader);
                             ..parseAndSetParameter(valuesubsystemreader);
                            break;
                        }
                        case : {
                            final String value = parseElementNoAttributes(reader);
                            ..parseAndSetParameter(valuesubsystemreader);
                            break;
                        }
                        case : {
                            readConfig(readeraddressendpointConfigsfalse);
                            break;
                        }
                        default: {
                            throw unexpectedElement(reader);
                        }
                    }
                    break;
                }
                case : {
                    final Element element = Element.forName(reader.getLocalName());
                    if (element != . && element != . && !encountered.add(element)) {
                        throw unexpectedElement(reader);
                    }
                    switch (element) {
                        case : {
                            final String value = parseElementNoAttributes(reader);
                            ..parseAndSetParameter(valuesubsystemreader);
                            break;
                        }
                        case : {
                            final String value = parseElementNoAttributes(reader);
                            ..parseAndSetParameter(valuesubsystemreader);
                            break;
                        }
                        case : {
                            final String value = parseElementNoAttributes(reader);
                            ..parseAndSetParameter(valuesubsystemreader);
                            break;
                        }
                        case : {
                            final String value = parseElementNoAttributes(reader);
                            ..parseAndSetParameter(valuesubsystemreader);
                            break;
                        }
                        case : {
                            readConfig(readeraddressendpointConfigsfalse);
                            break;
                        }
                        case : {
                            readConfig(readeraddressclientConfigstrue);
                            break;
                        }
                        default: {
                            throw unexpectedElement(reader);
                        }
                    }
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
        list.add(subsystem);
        list.addAll(endpointConfigs);
        list.addAll(clientConfigs);
    }
        // no attributes
        requireNoAttributes(reader);
        return reader.getElementText().trim();
    }
    private void readConfig(final XMLExtendedStreamReader readerfinal PathAddress parentAddressfinal List<ModelNodeoperationListfinal boolean clientthrows XMLStreamException {
        String configName = null;
        final int count = reader.getAttributeCount();
        for (int i = 0; i < counti++) {
            requireNoNamespaceAttribute(readeri);
            final String value = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case :
                    configName = value;
                    break;
                default:
                    throw unexpectedAttribute(readeri);
            }
        }
        final PathAddress address = parentAddress.append(client ?  : configName);
        final ModelNode node = Util.createAddOperation(address);
        operationList.add(node);
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        while (reader.nextTag() != ) {
            final Element element = Element.forName(reader.getLocalName());
            if (element != . && element != . && element != .
                    && !encountered.add(element)) {
                throw unexpectedElement(reader);
            }
            switch (element) {
                case : {
                    parseHandlerChain(readeroperationListtrueaddress);
                    break;
                }
                case : {
                    parseHandlerChain(readeroperationListfalseaddress);
                    break;
                }
                case : {
                    final ModelNode operation = parseProperty(readeraddress);
                    operationList.add(operation);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
    }
    private ModelNode parseProperty(final XMLExtendedStreamReader readerPathAddress parentAddressthrows XMLStreamException {
        final ModelNode operation = Util.createAddOperation(null);
        String propertyName = null;
        final int count = reader.getAttributeCount();
        for (int i = 0; i < counti++) {
            requireNoNamespaceAttribute(readeri);
            final String value = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case :
                    propertyName = value;
                    break;
                case :
                    ..parseAndSetParameter(valueoperationreader);
                    break;
                default:
                    throw unexpectedAttribute(readeri);
            }
        }
        ParseUtils.requireNoContent(reader);
        operation.get().set(parentAddress.append(propertyName).toModelNode());
        return operation;
    }
    private void parseHandlerChain(final XMLExtendedStreamReader readerfinal List<ModelNodeoperationListfinal boolean isPreHandlerChainPathAddress parentAddress)
            throws XMLStreamException {
        final ModelNode operation = Util.createAddOperation();
        String handlerChainId = null;
        final int count = reader.getAttributeCount();
        for (int i = 0; i < counti++) {
            requireNoNamespaceAttribute(readeri);
            final String value = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case :
                    handlerChainId = value;
                    break;
                case :
                    ..parseAndSetParameter(valueoperationreader);
                    break;
                default:
                    throw unexpectedAttribute(readeri);
            }
        }
        final String handlerChainType = isPreHandlerChain ?  : ;
        PathAddress address = parentAddress.append(handlerChainTypehandlerChainId);
        operation.get().set(address.toModelNode());
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        final List<ModelNodeaddHandlerOperations = new LinkedList<ModelNode>();
        while (reader.nextTag() != ) {
            final Element element = Element.forName(reader.getLocalName());
            if (element != . && !encountered.add(element)) {
                throw unexpectedElement(reader);
            }
            switch (element) {
                case : {
                    parseHandler(readeraddHandlerOperationsaddress);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
        operationList.add(operation);
        operationList.addAll(addHandlerOperations);
    }
    private void parseHandler(final XMLExtendedStreamReader readerfinal List<ModelNodeoperationsPathAddress parentAddressthrows XMLStreamException {
        String handlerName = null;
        final ModelNode operation = Util.createAddOperation();
        final int count = reader.getAttributeCount();
        for (int i = 0; i < counti++) {
            requireNoNamespaceAttribute(readeri);
            final String value = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case :
                    handlerName = value;
                    break;
                case :
                    ..parseAndSetParameter(valueoperationreader);
                    break;
                default:
                    throw unexpectedAttribute(readeri);
            }
        }
        ParseUtils.requireNoContent(reader);
        operation.get().set(parentAddress.append(handlerName).toModelNode());
        operations.add(operation);
    }
New to GrepCode? Check out our FAQ X