/**
   * {@inheritDoc}
   *
   * @see
   *     org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader,
   *     java.lang.Object)
   */
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations)
      throws XMLStreamException {

    ModelNode subsystemAddress = new ModelNode();
    subsystemAddress.add(ModelDescriptionConstants.SUBSYSTEM, InfinispanExtension.SUBSYSTEM_NAME);
    subsystemAddress.protect();

    ModelNode subsystem = Util.getEmptyOperation(ModelDescriptionConstants.ADD, subsystemAddress);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      ParseUtils.requireNoNamespaceAttribute(reader, i);
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case DEFAULT_CACHE_CONTAINER:
          {
            subsystem.get(ModelKeys.DEFAULT_CACHE_CONTAINER).set(value);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    if (!subsystem.hasDefined(ModelKeys.DEFAULT_CACHE_CONTAINER)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.DEFAULT_CACHE_CONTAINER));
    }

    // command to add the subsystem
    operations.add(subsystem);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      switch (Namespace.forUri(reader.getNamespaceURI())) {
        case INFINISPAN_1_0:
        case INFINISPAN_1_1:
          {
            Element element = Element.forName(reader.getLocalName());
            switch (element) {
              case CACHE_CONTAINER:
                {
                  parseContainer(reader, subsystemAddress, operations);
                  break;
                }
              default:
                {
                  throw ParseUtils.unexpectedElement(reader);
                }
            }
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
 static ModelNode parseCustomLoadMetric(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode load = new ModelNode();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case CAPACITY:
         load.get(CAPACITY).set(value);
         break;
       case WEIGHT:
         load.get(WEIGHT).set(value);
         break;
       case CLASS:
         load.get(CLASS).set(value);
         break;
       default:
         unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case PROPERTY:
         final Property property = parseProperty(reader);
         load.get("property").add(property.getName(), property.getValue());
         break;
       default:
         unexpectedElement(reader);
     }
   }
   return load;
 }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader,
   *     Object)
   */
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations)
      throws XMLStreamException {

    PathAddress subsystemAddress = PathAddress.pathAddress(InfinispanExtension.SUBSYSTEM_PATH);
    ModelNode subsystem = Util.createAddOperation(subsystemAddress);

    // command to add the subsystem
    operations.add(subsystem);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CACHE_CONTAINER:
          {
            parseContainer(reader, subsystemAddress, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
Example #4
0
    /** {@inheritDoc} */
    @Override
    public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list)
        throws XMLStreamException {
      ModelNode subsystemAdd = null;

      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
          case JPA:
            {
              subsystemAdd = parseJPA(reader);
              break;
            }
          default:
            {
              throw ParseUtils.unexpectedElement(reader);
            }
        }
      }
      if (subsystemAdd == null) {
        throw ParseUtils.missingRequiredElement(
            reader, Collections.singleton(Element.JPA.getLocalName()));
      }
      list.add(subsystemAdd);
    }
 private void parseProtocolElement(
     XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations)
     throws XMLStreamException {
   XMLElement element = XMLElement.forName(reader.getLocalName());
   switch (element) {
     case PROPERTY:
       {
         this.parseProperty(reader, address, operations);
         break;
       }
     case DEFAULT_THREAD_POOL:
       parseThreadPool(ThreadPoolResourceDefinition.DEFAULT, reader, address, operations);
       break;
     case INTERNAL_THREAD_POOL:
       parseThreadPool(ThreadPoolResourceDefinition.INTERNAL, reader, address, operations);
       break;
     case OOB_THREAD_POOL:
       parseThreadPool(ThreadPoolResourceDefinition.OOB, reader, address, operations);
       break;
     case TIMER_THREAD_POOL:
       parseThreadPool(ThreadPoolResourceDefinition.TIMER, reader, address, operations);
       break;
     default:
       {
         throw ParseUtils.unexpectedElement(reader);
       }
   }
 }
 static ModelNode parseModClusterConfig(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode config = new ModelNode();
   // Parse the attributes.
   parsePropConf(reader, config);
   // Parse the elements
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case SIMPLE_LOAD_PROVIDER:
         final ModelNode load = parseSimpleLoadProvider(reader);
         config.get(SIMPLE_LOAD_PROVIDER).set(load);
         break;
       case DYNAMIC_LOAD_PROVIDER:
         final ModelNode dynload = parseDynamicLoadProvider(reader);
         config.get(DYNAMIC_LOAD_PROVIDER).set(dynload);
         break;
       case SSL:
         final ModelNode ssl = parseSSL(reader);
         config.get(SSL).set(ssl);
         break;
       default:
         unexpectedElement(reader);
     }
   }
   return config;
 }
 private void parseCacheElement(
     XMLExtendedStreamReader reader, Element element, ModelNode cache, List<ModelNode> operations)
     throws XMLStreamException {
   switch (element) {
     case LOCKING:
       {
         this.parseLocking(reader, cache, operations);
         break;
       }
     case TRANSACTION:
       {
         this.parseTransaction(reader, cache, operations);
         break;
       }
     case EVICTION:
       {
         this.parseEviction(reader, cache, operations);
         break;
       }
     case EXPIRATION:
       {
         this.parseExpiration(reader, cache, operations);
         break;
       }
     case STORE:
       {
         this.parseCustomStore(reader, cache, operations);
         break;
       }
     case FILE_STORE:
       {
         this.parseFileStore(reader, cache, operations);
         break;
       }
     case STRING_KEYED_JDBC_STORE:
       {
         this.parseStringKeyedJDBCStore(reader, cache, operations);
         break;
       }
     case BINARY_KEYED_JDBC_STORE:
       {
         this.parseBinaryKeyedJDBCStore(reader, cache, operations);
         break;
       }
     case MIXED_KEYED_JDBC_STORE:
       {
         this.parseMixedKeyedJDBCStore(reader, cache, operations);
         break;
       }
     case REMOTE_STORE:
       {
         this.parseRemoteStore(reader, cache, operations);
         break;
       }
     default:
       {
         throw ParseUtils.unexpectedElement(reader);
       }
   }
 }
  private void parseSequencer(
      XMLExtendedStreamReader reader, String repositoryName, final List<ModelNode> sequencers)
      throws XMLStreamException {

    final ModelNode sequencer = new ModelNode();
    sequencer.get(OP).set(ADD);
    String name = null;

    sequencers.add(sequencer);

    if (reader.getAttributeCount() > 0) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attrName = reader.getAttributeLocalName(i);
        String attrValue = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(attrName);
        switch (attribute) {
          case NAME:
            name = attrValue;
            break;
          case PATH_EXPRESSION:
            ModelAttributes.PATH_EXPRESSIONS.parseAndAddParameterElement(
                attrValue, sequencer, reader);
            break;
          case CLASSNAME:
            ModelAttributes.SEQUENCER_CLASSNAME.parseAndSetParameter(attrValue, sequencer, reader);
            if (name == null) name = attrValue;
            break;
          case MODULE:
            ModelAttributes.MODULE.parseAndSetParameter(attrValue, sequencer, reader);
            break;
          default:
            // extra attributes are allowed to set sequencer-specific properties ...
            sequencer.get(ModelKeys.PROPERTIES).add(attrName, attrValue);
            break;
        }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case PATH_EXPRESSION:
          String value = reader.getElementText();
          ModelAttributes.PATH_EXPRESSIONS.parseAndAddParameterElement(value, sequencer, reader);
          break;
        default:
          throw ParseUtils.unexpectedElement(reader);
      }
    }

    sequencer
        .get(OP_ADDR)
        .add(SUBSYSTEM, ModeShapeExtension.SUBSYSTEM_NAME)
        .add(ModelKeys.REPOSITORY, repositoryName)
        .add(ModelKeys.SEQUENCER, name);
  }
Example #9
0
    /** {@inheritDoc} */
    @Override
    public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list)
        throws XMLStreamException {
      // no attributes
      if (reader.getAttributeCount() > 0) {
        throw ParseUtils.unexpectedAttribute(reader, 0);
      }

      final ModelNode subsystem = createEmptyAddOperation();
      list.add(subsystem);

      // elements
      final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case XTS_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              if (!encountered.add(element)) {
                throw ParseUtils.unexpectedElement(reader);
              }
              switch (element) {
                case XTS_ENVIRONMENT:
                  {
                    final ModelNode model = parseXTSEnvironmentElement(reader);
                    subsystem.get(CommonAttributes.XTS_ENVIRONMENT).set(model);
                    break;
                  }
                default:
                  {
                    throw ParseUtils.unexpectedElement(reader);
                  }
              }
              break;
            }
          default:
            {
              throw ParseUtils.unexpectedElement(reader);
            }
        }
      }
    }
  private void parseJDBCStoreTable(XMLExtendedStreamReader reader, ModelNode table)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case PREFIX:
          {
            table.get(ModelKeys.PREFIX).set(value);
            break;
          }
        case FETCH_SIZE:
          {
            table.get(ModelKeys.FETCH_SIZE).set(Integer.parseInt(value));
            break;
          }
        case BATCH_SIZE:
          {
            table.get(ModelKeys.BATCH_SIZE).set(Integer.parseInt(value));
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case ID_COLUMN:
          {
            this.parseJDBCStoreColumn(reader, table.get(ModelKeys.ID_COLUMN).setEmptyObject());
            break;
          }
        case DATA_COLUMN:
          {
            this.parseJDBCStoreColumn(reader, table.get(ModelKeys.DATA_COLUMN).setEmptyObject());
            break;
          }
        case TIMESTAMP_COLUMN:
          {
            this.parseJDBCStoreColumn(
                reader, table.get(ModelKeys.TIMESTAMP_COLUMN).setEmptyObject());
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  @Override
  public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list)
      throws XMLStreamException {

    final ModelNode subsystem = new ModelNode();
    subsystem.add(SUBSYSTEM, ModeShapeExtension.SUBSYSTEM_NAME);
    subsystem.protect();

    final ModelNode bootServices = new ModelNode();
    bootServices.get(OP).set(ADD);
    bootServices.get(OP_ADDR).set(subsystem);
    list.add(bootServices);

    // no attributes
    requireNoAttributes(reader);

    final List<ModelNode> repositories = new ArrayList<ModelNode>();

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      if (reader.isStartElement()) {
        // elements
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case MODESHAPE_1_0:
            Element element = Element.forName(reader.getLocalName());
            switch (element) {
              case REPOSITORY:
                parseRepository(reader, subsystem, repositories);
                break;
              default:
                throw ParseUtils.unexpectedElement(reader);
            }
            break;
          case UNKNOWN:
            throw ParseUtils.unexpectedElement(reader);
        }
      }
    }

    list.addAll(repositories);
  }
 @SuppressWarnings("deprecation")
 private void parseCacheElement(
     XMLExtendedStreamReader reader, Element element, ModelNode cache, List<ModelNode> operations)
     throws XMLStreamException {
   switch (element) {
     case LOCKING:
       {
         this.parseLocking(reader, cache, operations);
         break;
       }
     case TRANSACTION:
       {
         this.parseTransaction(reader, cache, operations);
         break;
       }
     case EVICTION:
       {
         this.parseEviction(reader, cache, operations);
         break;
       }
     case EXPIRATION:
       {
         this.parseExpiration(reader, cache, operations);
         break;
       }
     case STORE:
       {
         this.parseCustomStore(reader, cache.get(), operations);
         break;
       }
     case FILE_STORE:
       {
         this.parseFileStore(reader, cache, operations);
         break;
       }
     case JDBC_STORE:
       {
         this.parseJDBCStore(reader, cache, operations);
         break;
       }
     case REMOTE_STORE:
       {
         this.parseRemoteStore(reader, cache, operations);
         break;
       }
     default:
       {
         throw ParseUtils.unexpectedElement(reader);
       }
   }
 }
  private void parseChannel(
      XMLExtendedStreamReader reader,
      PathAddress subsystemAddress,
      Map<PathAddress, ModelNode> operations)
      throws XMLStreamException {
    String name = require(reader, XMLAttribute.NAME);
    PathAddress address = subsystemAddress.append(ChannelResourceDefinition.pathElement(name));
    ModelNode operation = Util.createAddOperation(address);
    operations.put(address, operation);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      ParseUtils.requireNoNamespaceAttribute(reader, i);
      XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case NAME:
          {
            // Already parsed
            break;
          }
        case STACK:
          {
            readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.STACK);
            break;
          }
        case MODULE:
          {
            readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.MODULE);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      XMLElement element = XMLElement.forName(reader.getLocalName());
      switch (element) {
        case FORK:
          {
            this.parseFork(reader, address, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  private void parseIndexing(XMLExtendedStreamReader reader, ModelNode node)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      if (attribute == Attribute.INDEX) {
        CacheResource.INDEXING.parseAndSetParameter(value, node, reader);
      } else {
        throw ParseUtils.unexpectedAttribute(reader, i);
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case PROPERTY:
          {
            int attributes = reader.getAttributeCount();
            String property = null;
            for (int i = 0; i < attributes; i++) {
              String value = reader.getAttributeValue(i);
              Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
              switch (attribute) {
                case NAME:
                  {
                    property = value;
                    break;
                  }
                default:
                  {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                  }
              }
            }
            if (property == null) {
              throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.NAME));
            }
            String value = reader.getElementText();
            CacheResource.INDEXING_PROPERTIES.parseAndAddParameterElement(
                property, value, node, reader);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
    // ParseUtils.requireNoContent(reader);
  }
 @Override
 public void parse(
     final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list)
     throws XMLStreamException {
   if (getXmlWrapperElement() != null) {
     if (reader.getLocalName().equals(getXmlWrapperElement())) {
       if (reader.hasNext()) {
         if (reader.nextTag() == END_ELEMENT) {
           return;
         }
       }
     } else {
       throw ParseUtils.unexpectedElement(reader);
     }
   }
   boolean wildcard = getPathElement().isWildcard();
   String name = null;
   ModelNode op = Util.createAddOperation();
   Map<String, AttributeDefinition> attributes = getAttributeMap();
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     String attributeName = reader.getAttributeLocalName(i);
     String value = reader.getAttributeValue(i);
     if (wildcard && NAME.equals(attributeName)) {
       name = value;
     } else if (attributes.containsKey(attributeName)) {
       AttributeDefinition def = attributes.get(attributeName);
       if (def instanceof SimpleAttributeDefinition) {
         ((SimpleAttributeDefinition) def).parseAndSetParameter(value, op, reader);
       } else if (def instanceof StringListAttributeDefinition) {
         ((StringListAttributeDefinition) def).parseAndSetParameter(value, op, reader);
       } else {
         throw new IllegalArgumentException("we should know how to handle " + def);
       }
     } else {
       throw ParseUtils.unexpectedAttribute(reader, i);
     }
   }
   if (wildcard && name == null) {
     throw MESSAGES.missingRequiredAttributes(new StringBuilder(NAME), reader.getLocation());
   }
   PathElement path =
       wildcard ? PathElement.pathElement(getPathElement().getKey(), name) : getPathElement();
   PathAddress address = parentAddress.append(path);
   op.get(ADDRESS).set(address.toModelNode());
   list.add(op);
   parseChildren(reader, address, list);
   if (getXmlWrapperElement() != null) {
     ParseUtils.requireNoContent(reader);
   }
 }
 private void parseCacheElement(XMLExtendedStreamReader reader, Element element, ModelNode cache)
     throws XMLStreamException {
   switch (element) {
     case LOCKING:
       {
         this.parseLocking(reader, cache.get(ModelKeys.LOCKING).setEmptyObject());
         break;
       }
     case TRANSACTION:
       {
         this.parseTransaction(reader, cache.get(ModelKeys.TRANSACTION).setEmptyObject());
         break;
       }
     case EVICTION:
       {
         this.parseEviction(reader, cache.get(ModelKeys.EVICTION).setEmptyObject());
         break;
       }
     case EXPIRATION:
       {
         this.parseExpiration(reader, cache.get(ModelKeys.EXPIRATION).setEmptyObject());
         break;
       }
     case STORE:
       {
         this.parseCustomStore(reader, cache.get(ModelKeys.STORE).setEmptyObject());
         break;
       }
     case FILE_STORE:
       {
         this.parseFileStore(reader, cache.get(ModelKeys.FILE_STORE).setEmptyObject());
         break;
       }
     case JDBC_STORE:
       {
         this.parseJDBCStore(reader, cache.get(ModelKeys.JDBC_STORE).setEmptyObject());
         break;
       }
     case REMOTE_STORE:
       {
         this.parseRemoteStore(reader, cache.get(ModelKeys.REMOTE_STORE).setEmptyObject());
         break;
       }
     default:
       {
         throw ParseUtils.unexpectedElement(reader);
       }
   }
 }
  private void parseRelay(
      XMLExtendedStreamReader reader,
      PathAddress stackAddress,
      Map<PathAddress, ModelNode> operations)
      throws XMLStreamException {
    PathAddress address = stackAddress.append(RelayResourceDefinition.PATH);
    ModelNode operation = Util.createAddOperation(address);
    operations.put(address, operation);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case SITE:
          {
            readAttribute(reader, i, operation, RelayResourceDefinition.Attribute.SITE);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    if (!operation.hasDefined(RelayResourceDefinition.Attribute.SITE.getDefinition().getName())) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(XMLAttribute.SITE));
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      XMLElement element = XMLElement.forName(reader.getLocalName());
      switch (element) {
        case REMOTE_SITE:
          {
            this.parseRemoteSite(reader, address, operations);
            break;
          }
        case PROPERTY:
          {
            this.parseProperty(reader, address, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
 public void parse(final XMLExtendedStreamReader reader, final ModelNode operation)
     throws XMLStreamException {
   while (reader.hasNext() && reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
     if (reader.getLocalName().equals(getXmlName())) {
       final String[] array =
           requireAttributes(
               reader,
               org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(),
               org.jboss.as.controller.parsing.Attribute.VALUE.getLocalName());
       parseAndAddParameterElement(array[0], array[1], operation, reader);
       ParseUtils.requireNoContent(reader);
     } else {
       throw ParseUtils.unexpectedElement(reader);
     }
   }
 }
 public void parseChildren(
     final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list)
     throws XMLStreamException {
   if (getChildren().size() == 0) {
     ParseUtils.requireNoContent(reader);
   } else {
     Map<String, PersistentResourceDefinition> children = getChildrenMap();
     while (reader.hasNext() && reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
       PersistentResourceDefinition child = children.get(reader.getLocalName());
       if (child != null) {
         child.parse(reader, parentAddress, list);
       } else {
         throw ParseUtils.unexpectedElement(reader);
       }
     }
   }
 }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader,
   *     java.lang.Object)
   */
  @SuppressWarnings("deprecation")
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations)
      throws XMLStreamException {

    ModelNode subsystemAddress = new ModelNode();
    subsystemAddress.add(ModelDescriptionConstants.SUBSYSTEM, InfinispanExtension.SUBSYSTEM_NAME);
    subsystemAddress.protect();

    ModelNode subsystem = Util.getEmptyOperation(ModelDescriptionConstants.ADD, subsystemAddress);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      ParseUtils.requireNoNamespaceAttribute(reader, i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case DEFAULT_CACHE_CONTAINER:
          {
            // Ignore
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    // command to add the subsystem
    operations.add(subsystem);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CACHE_CONTAINER:
          {
            parseContainer(reader, subsystemAddress, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  private List<ModelNode> parseTextExtracting(
      final XMLExtendedStreamReader reader, final String repositoryName) throws XMLStreamException {
    requireNoAttributes(reader);

    List<ModelNode> extractors = new ArrayList<ModelNode>();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case TEXT_EXTRACTOR:
          parseTextExtractor(reader, repositoryName, extractors);
          break;
        default:
          throw ParseUtils.unexpectedElement(reader);
      }
    }

    return extractors;
  }
  private List<ModelNode> parseSequencers(
      final XMLExtendedStreamReader reader,
      final ModelNode parentAddress,
      final String repositoryName)
      throws XMLStreamException {
    requireNoAttributes(reader);

    List<ModelNode> sequencers = new ArrayList<ModelNode>();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case SEQUENCER:
          parseSequencer(reader, repositoryName, sequencers);
          break;
        default:
          throw ParseUtils.unexpectedElement(reader);
      }
    }

    return sequencers;
  }
 private void parseStoreElements(
     XMLExtendedStreamReader reader, ModelNode store, List<ModelNode> operations)
     throws XMLStreamException {
   while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
     Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case WRITE_BEHIND:
         {
           parseStoreWriteBehind(reader, store, operations);
           break;
         }
       case PROPERTY:
         {
           parseStoreProperty(reader, store, operations);
           break;
         }
       default:
         throw ParseUtils.unexpectedElement(reader);
     }
   }
 }
  private void parseWorkspaces(
      final XMLExtendedStreamReader reader,
      final ModelNode parentAddress,
      final ModelNode repository)
      throws XMLStreamException {
    if (reader.getAttributeCount() > 0) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attrName = reader.getAttributeLocalName(i);
        String attrValue = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(attrName);
        switch (attribute) {
            // Set these as properties on the repository ModelNode ...
          case ALLOW_WORKSPACE_CREATION:
            ModelAttributes.ALLOW_WORKSPACE_CREATION.parseAndSetParameter(
                attrValue, repository, reader);
            break;
          case DEFAULT_WORKSPACE:
            ModelAttributes.DEFAULT_WORKSPACE.parseAndSetParameter(attrValue, repository, reader);
            break;
          default:
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
      }
    }

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case WORKSPACE:
          {
            parseWorkspace(reader, repository);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  @SuppressWarnings("deprecation")
  private void parseStacks(
      XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations)
      throws XMLStreamException {

    ModelNode operation = operations.get(address);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      ParseUtils.requireNoNamespaceAttribute(reader, i);
      XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case DEFAULT:
          {
            readAttribute(
                reader, i, operation, JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      XMLElement element = XMLElement.forName(reader.getLocalName());
      switch (element) {
        case STACK:
          {
            this.parseStack(reader, address, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  private void parseAuthenticators(
      final XMLExtendedStreamReader reader,
      final ModelNode parentAddress,
      final ModelNode repository)
      throws XMLStreamException {
    requireNoAttributes(reader);

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case AUTHENTICATOR:
          {
            parseAuthenticator(reader, repository);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  static ModelNode parseDynamicLoadProvider(XMLExtendedStreamReader reader)
      throws XMLStreamException {
    final ModelNode load = new ModelNode();
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      requireNoNamespaceAttribute(reader, i);
      final String value = reader.getAttributeValue(i);
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case HISTORY:
          load.get(HISTORY).set(value);
          break;
        case DECAY:
          load.get(DECAY).set(value);
          break;
        default:
          unexpectedAttribute(reader, i);
      }
    }
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      // read the load-metric and the custom-load-metric
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case LOAD_METRIC:
          final ModelNode loadmetric = parseLoadMetric(reader);
          load.get(LOAD_METRIC).add(loadmetric);
          break;
        case CUSTOM_LOAD_METRIC:
          final ModelNode customloadmetric = parseCustomLoadMetric(reader);
          load.get(CUSTOM_LOAD_METRIC).add(customloadmetric);
          break;
        default:
          unexpectedElement(reader);
      }
    }

    return load;
  }
  private void parseStack(
      XMLExtendedStreamReader reader,
      PathAddress subsystemAddress,
      Map<PathAddress, ModelNode> operations)
      throws XMLStreamException {
    String name = require(reader, XMLAttribute.NAME);
    PathAddress address = subsystemAddress.append(StackResourceDefinition.pathElement(name));
    ModelNode operation = Util.createAddOperation(address);
    operations.put(address, operation);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      XMLElement element = XMLElement.forName(reader.getLocalName());
      switch (element) {
        case TRANSPORT:
          {
            this.parseTransport(reader, address, operations);
            break;
          }
        case PROTOCOL:
          {
            this.parseProtocol(reader, address, operations);
            break;
          }
        case RELAY:
          {
            if (this.schema.since(JGroupsSchema.VERSION_2_0)) {
              this.parseRelay(reader, address, operations);
              break;
            }
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
 private void parseStoreProperty(XMLExtendedStreamReader reader, ModelNode node)
     throws XMLStreamException {
   Element element = Element.forName(reader.getLocalName());
   switch (element) {
     case PROPERTY:
       {
         int attributes = reader.getAttributeCount();
         String property = null;
         for (int i = 0; i < attributes; i++) {
           String value = reader.getAttributeValue(i);
           Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
           switch (attribute) {
             case NAME:
               {
                 property = value;
                 break;
               }
             default:
               {
                 throw ParseUtils.unexpectedAttribute(reader, i);
               }
           }
         }
         if (property == null) {
           throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.NAME));
         }
         String value = reader.getElementText();
         node.get(ModelKeys.PROPERTY).add(property, value);
         break;
       }
     default:
       {
         throw ParseUtils.unexpectedElement(reader);
       }
   }
 }
  private void parseRepository(
      final XMLExtendedStreamReader reader,
      final ModelNode address,
      final List<ModelNode> repositories)
      throws XMLStreamException {

    final ModelNode repositoryAddress = address.clone();
    final ModelNode repository =
        Util.getEmptyOperation(ModelDescriptionConstants.ADD, repositoryAddress);

    String repositoryName = null;
    if (reader.getAttributeCount() > 0) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attrName = reader.getAttributeLocalName(i);
        String attrValue = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(attrName);
        switch (attribute) {
          case NAME:
            repositoryName = attrValue;
            repositoryAddress.add("repository", attrValue); // $NON-NLS-1$
            repositoryAddress.protect();
            repository.get(OP).set(ADD);
            repository.get(OP_ADDR).set(repositoryAddress);
            repositories.add(repository);
            break;
          case CACHE_NAME:
            ModelAttributes.CACHE_NAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          case CACHE_CONTAINER:
            ModelAttributes.CACHE_CONTAINER.parseAndSetParameter(attrValue, repository, reader);
            break;
          case JNDI_NAME:
            ModelAttributes.JNDI_NAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          case ENABLE_MONITORING:
            ModelAttributes.ENABLE_MONITORING.parseAndSetParameter(attrValue, repository, reader);
            break;
          case SECURITY_DOMAIN:
            ModelAttributes.SECURITY_DOMAIN.parseAndSetParameter(attrValue, repository, reader);
            break;
          case ANONYMOUS_ROLES:
            for (String role : reader.getListAttributeValue(i)) {
              repository.get(ModelKeys.ANONYMOUS_ROLES).add(role);
            }
            break;
          case ANONYMOUS_USERNAME:
            ModelAttributes.ANONYMOUS_USERNAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          case USE_ANONYMOUS_IF_AUTH_FAILED:
            ModelAttributes.USE_ANONYMOUS_IF_AUTH_FAILED.parseAndSetParameter(
                attrValue, repository, reader);
            break;
          case CLUSTER_STACK:
            ModelAttributes.CLUSTER_STACK.parseAndSetParameter(attrValue, repository, reader);
            break;
          case CLUSTER_NAME:
            ModelAttributes.CLUSTER_NAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          default:
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
      }
    }

    ModelNode indexStorage = null;
    ModelNode binaryStorage = null;
    List<ModelNode> sequencers = new ArrayList<ModelNode>();
    List<ModelNode> textExtractors = new ArrayList<ModelNode>();
    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case WORKSPACES:
          parseWorkspaces(reader, address, repository);
          break;
        case INDEXING:
          parseIndexing(reader, address, repository);
          break;

          // Index storage ...
        case RAM_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage = parseRamIndexStorage(reader, repositoryName);
          break;
        case LOCAL_FILE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage =
              parseFileIndexStorage(reader, repositoryName, ModelKeys.LOCAL_FILE_INDEX_STORAGE);
          break;
        case MASTER_FILE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage =
              parseFileIndexStorage(reader, repositoryName, ModelKeys.MASTER_FILE_INDEX_STORAGE);
          break;
        case SLAVE_FILE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage =
              parseFileIndexStorage(reader, repositoryName, ModelKeys.SLAVE_FILE_INDEX_STORAGE);
          break;
        case CACHE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage = parseCacheIndexStorage(reader, repositoryName);
          break;
        case CUSTOM_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage = parseCustomIndexStorage(reader, repositoryName);
          break;

          // Binary storage ...
        case FILE_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseFileBinaryStorage(reader, repositoryName);
          break;
        case DB_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseDatabaseBinaryStorage(reader, repositoryName);
          break;
        case CACHE_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseCacheBinaryStorage(reader, repositoryName);
          break;
        case CUSTOM_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseCustomBinaryStorage(reader, repositoryName);
          break;

          // Sequencing ...
        case AUTHENTICATORS:
          parseAuthenticators(reader, address, repository);
          break;

          // Sequencing ...
        case SEQUENCERS:
          sequencers = parseSequencers(reader, address, repositoryName);
          break;

          // Text extracting ...
        case TEXT_EXTRACTORS:
          textExtractors = parseTextExtracting(reader, repositoryName);
          break;

        default:
          throw ParseUtils.unexpectedElement(reader);
      }
    }

    if (indexStorage != null) repositories.add(indexStorage);
    if (binaryStorage != null) repositories.add(binaryStorage);
    repositories.addAll(sequencers);
    repositories.addAll(textExtractors);
  }