Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2008, Red Hat Middleware LLC, 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 static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ADMIN_OBJECTS_NAME;
 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.CONFIG_PROPERTIES;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTIONDEFINITIONS_NAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTER_NAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRANSACTIONSUPPORT;
 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 java.util.List;
 import java.util.Map;
 
 
A ResourceAdapterParserr.

Author(s):
Stefano Maestri
 
 public class ResourceAdapterParser extends CommonIronJacamarParser {
    
The bundle
 
     private static CommonBundle bundle = Messages.getBundle(CommonBundle.class);
 
 
     public void parse(final XMLExtendedStreamReader readerfinal List<ModelNodelistModelNode parentAddressthrows Exception {
 
         ResourceAdapters adapters = null;
 
         //iterate over tags
         int iterate;
         try {
             iterate = reader.nextTag();
         } catch (XMLStreamException e) {
             //founding a non tag..go on. Normally non-tag found at beginning are comments or DTD declaration
             iterate = reader.nextTag();
         }
         switch (iterate) {
             case : {
                 // should mean we're done, so ignore it.
                 break;
             }
             case : {
 
                 switch (Tag.forName(reader.getLocalName())) {
                     case : {
                         parseResourceAdapters(readerlistparentAddress);
                         break;
                     }
                     default:
                         throw new ParserException(.unexpectedElement(reader.getLocalName()));
                 }
 
                 break;
             }
             default:
                 throw new IllegalStateException();
         }
 
         return;
    }
    private void parseResourceAdapters(final XMLExtendedStreamReader readerfinal List<ModelNodelistModelNode parentAddressthrows XMLStreamExceptionParserException,
            ValidateException {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (Tag.forName(reader.getLocalName()) == .) {
                        return;
                    } else {
                        if (ResourceAdapters.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (ResourceAdapters.Tag.forName(reader.getLocalName())) {
                        case : {
                            parseResourceAdapter(readerlistparentAddress);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }
    private void parseResourceAdapter(final XMLExtendedStreamReader readerfinal List<ModelNodelistModelNode parentAddressthrows XMLStreamExceptionParserException,
            ValidateException {
        final ModelNode raAddress = parentAddress.clone();
        final ModelNode operation = new ModelNode();
        operation.get().set();
        String archiveName = null;
        HashMap<StringModelNodeconfigPropertiesOperations = new HashMap<StringModelNode>();
        HashMap<StringModelNodeconnectionDefinitionsOperations = new HashMap<StringModelNode>();
        HashMap<StringHashMap<StringModelNode>> cfConfigPropertiesOperations = new HashMap<StringHashMap<StringModelNode>>();
        HashMap<StringModelNodeadminObjectsOperations = new HashMap<StringModelNode>();
        HashMap<StringHashMap<StringModelNode>> aoConfigPropertiesOperations = new HashMap<StringHashMap<StringModelNode>>();
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case : {
                    if (ResourceAdapters.Tag.forName(reader.getLocalName()) == ..) {
                        if (archiveName != null) {
                            raAddress.add(archiveName);
                            raAddress.protect();
                            operation.get().set(raAddress);
                            list.add(operation);
                            for (Map.Entry<StringModelNodeentry : configPropertiesOperations.entrySet()) {
                                final ModelNode env = raAddress.clone();
                                env.add(.getName(), entry.getKey());
                                env.protect();
                                entry.getValue().get().set(env);
                                list.add(entry.getValue());
                            }
                            for (Map.Entry<StringModelNodeentry : connectionDefinitionsOperations.entrySet()) {
                                final ModelNode env = raAddress.clone();
                                env.add(entry.getKey());
                                env.protect();
                                entry.getValue().get().set(env);
                                list.add(entry.getValue());
                                final HashMap<StringModelNodeproperties = cfConfigPropertiesOperations.get(entry.getKey());
                                if (properties != null) {
                                    for (Map.Entry<StringModelNodeconfigEntry : properties.entrySet()) {
                                        final ModelNode configEnv = env.clone();
                                        configEnv.add(.getName(), configEntry.getKey());
                                        configEnv.protect();
                                        configEntry.getValue().get().set(configEnv);
                                        list.add(configEntry.getValue());
                                    }
                                }
                            }
                            for (Map.Entry<StringModelNodeentry : adminObjectsOperations.entrySet()) {
                                final ModelNode env = raAddress.clone();
                                env.add(entry.getKey());
                                env.protect();
                                entry.getValue().get().set(env);
                                list.add(entry.getValue());
                                final HashMap<StringModelNodeaoProperties = aoConfigPropertiesOperations.get(entry.getKey());
                                if (aoProperties != null) {
                                    for (Map.Entry<StringModelNodeconfigEntry : aoProperties.entrySet()) {
                                        final ModelNode configEnv = env.clone();
                                        configEnv.add(.getName(), configEntry.getKey());
                                        configEnv.protect();
                                        configEntry.getValue().get().set(configEnv);
                                        list.add(configEntry.getValue());
                                    }
                                }
                            }
                            return;
                        } else {
                            throw new ParserException(.requiredElementMissing(.getName(), ));
                        }
                    } else {
                        if (ResourceAdapter.Tag.forName(reader.getLocalName()) == ..) {
                            throw new ParserException(.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
                case : {
                    switch (ResourceAdapter.Tag.forName(reader.getLocalName())) {
                        case :
                        case :
                        case : {
                            //ignore it,we will parse bean-validation-group,admin_object and connection_definition directly
                            break;
                        }
                        case : {
                            parseAdminObjects(readeradminObjectsOperationsaoConfigPropertiesOperations);
                            break;
                        }
                        case : {
                            parseConnectionDefinitions(readerconnectionDefinitionsOperationscfConfigPropertiesOperations);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            operation.get(.getName()).add(.parse(valuereader));
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valueoperationreader);
                            break;
                        }
                        case : {
                            parseConfigProperties(readerconfigPropertiesOperations);
                            break;
                        }
                        case : {
                            String value = rawElementText(reader);
                            .parseAndSetParameter(valueoperationreader);
                            break;
                        }
                        case : {
                            archiveName = rawElementText(reader);
                            .parseAndSetParameter(archiveNameoperationreader);
                            break;
                        }
                        default:
                            throw new ParserException(.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
            }
        }
        throw new ParserException(.unexpectedEndOfDocument());
    }

    
A Tag.

Author(s):
Stefano Maestri
    public enum Tag {
        
always first
        UNKNOWN(null),

        
jboss-ra tag name
        RESOURCE_ADAPTERS("resource-adapters");
        private final String name;

        
Create a new Tag.

Parameters:
name a name
        Tag(final String name) {
            this. = name;
        }

        
Get the local name of this element.

Returns:
the local name
        public String getLocalName() {
            return ;
        }
        private static final Map<StringTagMAP;
        static {
            final Map<StringTagmap = new HashMap<StringTag>();
            for (Tag element : values()) {
                final String name = element.getLocalName();
                if (name != null)
                    map.put(nameelement);
            }
             = map;
        }

        
Static method to get enum instance given localName string

Parameters:
localName a string used as localname (typically tag name as defined in xsd)
Returns:
the enum instance
        public static Tag forName(String localName) {
            final Tag element = .get(localName);
            return element == null ?  : element;
        }
    }
New to GrepCode? Check out our FAQ X