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.ADD;
 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.SUBSYSTEM;
 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.CLASS;
 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.MODIFY_WSDL_ADDRESS;
 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 static org.jboss.as.webservices.dmr.Constants.VALUE;
 import static org.jboss.as.webservices.dmr.Constants.WSDL_HOST;
 import static org.jboss.as.webservices.dmr.Constants.WSDL_PORT;
 import static org.jboss.as.webservices.dmr.Constants.WSDL_SECURE_PORT;
 
 import java.util.List;
 
 

Author(s):
alessio.soldano@jboss.com
Jim Ma
 
 final class WSSubsystemLegacyReader implements XMLElementReader<List<ModelNode>> {
 
     private static final WSSubsystemLegacyReader INSTANCE = new WSSubsystemLegacyReader();
 
     private WSSubsystemLegacyReader() {
         // forbidden instantiation
     }
 
     static WSSubsystemLegacyReader getInstance() {
         return ;
     }
 
     @Override
     public void readElement(final XMLExtendedStreamReader readerfinal List<ModelNodelistthrows XMLStreamException {
         // no attributes
         requireNoAttributes(reader);
 
         final ModelNode subsystem = new ModelNode();
         subsystem.get().set();
         subsystem.get().add(.);
 
         final List<ModelNodeendpointConfigs = 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 : {
                             boolean b = Boolean.parseBoolean(parseElementNoAttributes(reader));
                             subsystem.get().set(b);
                             break;
                         }
                         case : {
                            subsystem.get().set(parseElementNoAttributes(reader));
                            break;
                        }
                        case : {
                            int port = Integer.valueOf(parseElementNoAttributes(reader));
                            subsystem.get().set(port);
                            break;
                        }
                        case : {
                            int port = Integer.valueOf(parseElementNoAttributes(reader));
                            subsystem.get().set(port);
                            break;
                        }
                        case : {
                            readEndpointConfig(readersubsystem.get(), endpointConfigs);
                            break;
                        }
                        default: {
                            throw unexpectedElement(reader);
                        }
                    }
                    break;
                }
            }
        }
        list.add(subsystem);
        list.addAll(endpointConfigs);
    }
        // no attributes
        requireNoAttributes(reader);
        return reader.getElementText().trim();
    }
    private void readEndpointConfig(final XMLExtendedStreamReader readerfinal ModelNode addressfinal List<ModelNodeoperationListthrows XMLStreamException {
        String configName = null;
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        while (reader.nextTag() != ) {
            final Element element = Element.forName(reader.getLocalName());
            if (element != .
                    && !encountered.add(element)) {
                throw unexpectedElement(reader);
            }
            switch (element) {
                case : {
                    configName = parseElementNoAttributes(reader);
                    final ModelNode node = new ModelNode();
                    node.get().set();
                    node.get().set(address).add(configName);
                    operationList.add(node);
                    break;
                }
                case : {
                    parseHandlerChains(readerconfigNameoperationListtrue);
                    break;
                }
                case : {
                    parseHandlerChains(readerconfigNameoperationListfalse);
                    break;
                }
                case  : {
                    final ModelNode operation = parseProperty(readerconfigName);
                    operationList.add(operation);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
    }
    private ModelNode parseProperty(final XMLExtendedStreamReader readerfinal String configNamethrows XMLStreamException {
        String propertyName = null;
        String propertyValue = null;
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        while (reader.nextTag() != ) {
            final Element element = Element.forName(reader.getLocalName());
            if (!encountered.add(element)) {
                throw unexpectedElement(reader);
            }
            switch (element) {
                case : {
                    propertyName = parseElementNoAttributes(reader);
                    break;
                }
                case  : {
                    propertyValue = parseElementNoAttributes(reader);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
        final ModelNode operation = new ModelNode();
        operation.get().set();
        operation.get().add(.).add(configName).add(propertyName);
        if (propertyValue != null) {
            operation.get().set(propertyValue);
        }
        return operation;
    }
    private ModelNode parseHandlerChains(final XMLExtendedStreamReader readerfinal String configNamefinal List<ModelNodeoperationListfinal boolean isPreHandlerChainthrows XMLStreamException {
        ModelNode chainsNode = new ModelNode();
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        while (reader.nextTag() != ) {
            final Element element = Element.forName(reader.getLocalName());
            if (element != . && !encountered.add(element)) {
                throw unexpectedElement(reader);
            }
            switch (element) {
                case : {
                    parseHandlerChain(readerconfigNameoperationListisPreHandlerChain);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
        return chainsNode;
    }
    private void parseHandlerChain(final XMLExtendedStreamReader readerfinal String configNamefinal List<ModelNodeoperationListfinal boolean isPreHandlerChainthrows XMLStreamException {
        String handlerChainId = null;
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        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;
            default:
                throw unexpectedAttribute(readeri);
            }
        }
        if (handlerChainId == null) {
            handlerChainId = "auto-generated-" + System.currentTimeMillis();
        }
        String protocolBindings = null;
        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 : {
                    protocolBindings = parseElementNoAttributes(reader);
                    break;
                }
                case : {
                    parseHandler(readerconfigNamehandlerChainIdisPreHandlerChainaddHandlerOperations);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
        final ModelNode operation = new ModelNode();
        final String handlerChainType = isPreHandlerChain ?  : ;
        operation.get().set();
        operation.get().add(.).add(configName).add(handlerChainTypehandlerChainId);
        if (protocolBindings != null) {
            operation.get(.).set(protocolBindings);
        }
        operationList.add(operation);
        operationList.addAll(addHandlerOperations);
    }
    private void parseHandler(final XMLExtendedStreamReader readerfinal String configNamefinal String handlerChainIdfinal boolean isPreHandlerChainfinal List<ModelNodeoperationsthrows XMLStreamException {
        String handlerName = null;
        String handlerClass = null;
        final EnumSet<Elementencountered = EnumSet.noneOf(Element.class);
        while (reader.nextTag() != ) {
            final Element element = Element.forName(reader.getLocalName());
            if (!encountered.add(element)) {
                throw unexpectedElement(reader);
            }
            switch (element) {
                case : {
                    handlerName = parseElementNoAttributes(reader);
                    break;
                }
                case : {
                    handlerClass = parseElementNoAttributes(reader);
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
            }
        }
        final ModelNode operation = new ModelNode();
        final String handlerChainType = isPreHandlerChain ?  : ;
        operation.get().set();
        operation.get().add(.).add(configName).add(handlerChainTypehandlerChainId).add(handlerName);
        operation.get().set(handlerClass);
        operations.add(operation);
    }
New to GrepCode? Check out our FAQ X