Example #1
0
    ModelNode parseModulesElement(XMLExtendedStreamReader reader) throws XMLStreamException {

      // Handle attributes
      requireNoAttributes(reader);

      ModelNode modules = new ModelNode();

      // Handle elements
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case OSGI_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              if (element == Element.MODULE) {
                String identifier = null;
                String start = null;
                final int count = reader.getAttributeCount();
                for (int i = 0; i < count; i++) {
                  requireNoNamespaceAttribute(reader, i);
                  final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                  switch (attribute) {
                    case IDENTIFIER:
                      {
                        identifier = reader.getAttributeValue(i);
                        break;
                      }
                    case START:
                      {
                        start = reader.getAttributeValue(i);
                        break;
                      }
                    default:
                      throw unexpectedAttribute(reader, i);
                  }
                }
                if (identifier == null)
                  throw missingRequired(reader, Collections.singleton(Attribute.IDENTIFIER));
                if (modules.has(identifier))
                  throw new XMLStreamException(
                      element.getLocalName() + " already declared", reader.getLocation());

                ModelNode module = new ModelNode();
                if (start != null) {
                  module.get(START).set(start);
                }
                modules.get(identifier).set(module);

                requireNoContent(reader);
              } else {
                throw unexpectedElement(reader);
              }
              break;
            }
          default:
            throw unexpectedElement(reader);
        }
      }

      return modules;
    }
  /**
   * {@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);
          }
      }
    }
  }
Example #3
0
    private void parseActivationAttribute(XMLExtendedStreamReader reader, ModelNode addOperation)
        throws XMLStreamException {

      switch (Namespace.forUri(reader.getNamespaceURI())) {
        case OSGI_1_0:
          {
            // Handle attributes
            int count = reader.getAttributeCount();
            for (int i = 0; i < count; i++) {
              requireNoNamespaceAttribute(reader, i);
              final String attrValue = reader.getAttributeValue(i);
              final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
              switch (attribute) {
                case ACTIVATION:
                  {
                    addOperation.get(ACTIVATION).set(attrValue);
                    break;
                  }
                default:
                  throw unexpectedAttribute(reader, i);
              }
            }
            break;
          }
        default:
          throw unexpectedElement(reader);
      }
    }
Example #4
0
    private String parseRef(XMLExtendedStreamReader reader) throws XMLStreamException {
      final int attrCount = reader.getAttributeCount();
      String refName = null;
      for (int i = 0; i < attrCount; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch (attribute) {
          case NAME:
            {
              refName = value;
              break;
            }
          default:
            throw unexpectedAttribute(reader, i);
        }
      }

      if (refName == null) {
        throw missingRequired(reader, Collections.singleton(NAME));
      }
      if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        throw unexpectedElement(reader);
      }

      return refName;
    }
 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;
 }
  /** Adds the worker thread pool attributes to the subysystem add method */
  void parseWorkerThreadPool(final XMLExtendedStreamReader reader, final ModelNode subsystemAdd)
      throws XMLStreamException {
    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 WORKER_READ_THREADS:
          if (subsystemAdd.hasDefined(CommonAttributes.WORKER_READ_THREADS)) {
            throw duplicateAttribute(reader, CommonAttributes.WORKER_READ_THREADS);
          }
          RemotingSubsystemRootResource.WORKER_READ_THREADS.parseAndSetParameter(
              value, subsystemAdd, reader);
          break;
        case WORKER_TASK_CORE_THREADS:
          if (subsystemAdd.hasDefined(CommonAttributes.WORKER_TASK_CORE_THREADS)) {
            throw duplicateAttribute(reader, CommonAttributes.WORKER_TASK_CORE_THREADS);
          }
          RemotingSubsystemRootResource.WORKER_TASK_CORE_THREADS.parseAndSetParameter(
              value, subsystemAdd, reader);
          break;
        case WORKER_TASK_KEEPALIVE:
          if (subsystemAdd.hasDefined(CommonAttributes.WORKER_TASK_KEEPALIVE)) {
            throw duplicateAttribute(reader, CommonAttributes.WORKER_TASK_KEEPALIVE);
          }
          RemotingSubsystemRootResource.WORKER_TASK_KEEPALIVE.parseAndSetParameter(
              value, subsystemAdd, reader);
          break;
        case WORKER_TASK_LIMIT:
          if (subsystemAdd.hasDefined(CommonAttributes.WORKER_TASK_LIMIT)) {
            throw duplicateAttribute(reader, CommonAttributes.WORKER_TASK_LIMIT);
          }
          RemotingSubsystemRootResource.WORKER_TASK_LIMIT.parseAndSetParameter(
              value, subsystemAdd, reader);
          break;
        case WORKER_TASK_MAX_THREADS:
          if (subsystemAdd.hasDefined(CommonAttributes.WORKER_TASK_MAX_THREADS)) {
            throw duplicateAttribute(reader, CommonAttributes.WORKER_TASK_MAX_THREADS);
          }
          RemotingSubsystemRootResource.WORKER_TASK_MAX_THREADS.parseAndSetParameter(
              value, subsystemAdd, reader);
          break;
        case WORKER_WRITE_THREADS:
          if (subsystemAdd.hasDefined(CommonAttributes.WORKER_WRITE_THREADS)) {
            throw duplicateAttribute(reader, CommonAttributes.WORKER_WRITE_THREADS);
          }
          RemotingSubsystemRootResource.WORKER_WRITE_THREADS.parseAndSetParameter(
              value, subsystemAdd, reader);
          break;
        default:
          throw unexpectedAttribute(reader, i);
      }
    }

    requireNoContent(reader);
  }
Example #7
0
    ModelNode parsePropertiesElement(XMLExtendedStreamReader reader) throws XMLStreamException {

      // Handle attributes
      requireNoAttributes(reader);

      ModelNode properties = new ModelNode();

      // Handle elements
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case OSGI_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              if (element == Element.PROPERTY) {
                // Handle attributes
                String name = null;
                String value = null;
                int count = reader.getAttributeCount();
                for (int i = 0; i < count; i++) {
                  requireNoNamespaceAttribute(reader, i);
                  final String attrValue = reader.getAttributeValue(i);
                  final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                  switch (attribute) {
                    case NAME:
                      {
                        name = attrValue;
                        if (properties.has(name)) {
                          throw new XMLStreamException(
                              "Property " + name + " already exists", reader.getLocation());
                        }
                        break;
                      }
                    default:
                      throw unexpectedAttribute(reader, i);
                  }
                }
                if (name == null) {
                  throw missingRequired(reader, Collections.singleton(Attribute.NAME));
                }
                value = reader.getElementText().trim();
                if (value == null || value.length() == 0) {
                  throw new XMLStreamException(
                      "Value for property " + name + " is null", reader.getLocation());
                }
                properties.get(name).set(value);
                break;
              } else {
                throw unexpectedElement(reader);
              }
            }
          default:
            throw unexpectedElement(reader);
        }
      }

      return properties;
    }
Example #8
0
 static ModelNode parseSsl(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode ssl = new ModelNode();
   ssl.setEmptyObject();
   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 NAME:
         ssl.get(NAME).set(value);
         break;
       case KEY_ALIAS:
         ssl.get(KEY_ALIAS).set(value);
         break;
       case PASSWORD:
         ssl.get(PASSWORD).set(value);
         break;
       case CERTIFICATE_KEY_FILE:
         ssl.get(CERTIFICATE_KEY_FILE).set(value);
         break;
       case CIPHER_SUITE:
         ssl.get(CIPHER_SUITE).set(value);
         break;
       case PROTOCOL:
         ssl.get(PROTOCOL).set(value);
         break;
       case VERIFY_CLIENT:
         ssl.get(VERIFY_CLIENT).set(value);
         break;
       case VERIFY_DEPTH:
         ssl.get(VERIFY_DEPTH).set(Integer.valueOf(value));
         break;
       case CERTIFICATE_FILE:
         ssl.get(CERTIFICATE_FILE).set(value);
         break;
       case CA_CERTIFICATE_FILE:
         ssl.get(CA_CERTIFICATE_FILE).set(value);
         break;
       case CA_REVOCATION_URL:
         ssl.get(CA_REVOCATION_URL).set(value);
         break;
       case SESSION_CACHE_SIZE:
         ssl.get(SESSION_CACHE_SIZE).set(value);
         break;
       case SESSION_TIMEOUT:
         ssl.get(SESSION_TIMEOUT).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   requireNoContent(reader);
   return ssl;
 }
Example #9
0
    private ModelNode parseScaledCount(final XMLExtendedStreamReader reader)
        throws XMLStreamException {
      final int attrCount = reader.getAttributeCount();
      BigDecimal count = null;
      BigDecimal perCpu = null;
      for (int i = 0; i < attrCount; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch (attribute) {
          case COUNT:
            {
              try {
                count = new BigDecimal(value);
              } catch (NumberFormatException e) {
                throw invalidAttributeValue(reader, i);
              }
              break;
            }
          case PER_CPU:
            {
              try {
                perCpu = new BigDecimal(value);
              } catch (NumberFormatException e) {
                throw invalidAttributeValue(reader, i);
              }
              break;
            }
          default:
            throw unexpectedAttribute(reader, i);
        }
      }

      if (count == null || perCpu == null) {
        Set<Attribute> missing = new HashSet<Attribute>();
        if (count == null) {
          missing.add(Attribute.COUNT);
        }
        if (perCpu == null) {
          missing.add(Attribute.PER_CPU);
        }
        throw missingRequired(reader, missing);
      }

      if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        throw unexpectedElement(reader);
      }

      ModelNode node = new ModelNode();
      node.get(COUNT).set(count);
      node.get(PER_CPU).set(perCpu);

      return node;
    }
  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);
          }
      }
    }
  }
Example #11
0
 /**
  * Require that the current element have only a single attribute with the given name.
  *
  * @param reader the reader
  * @param attributeName the attribute name
  * @throws javax.xml.stream.XMLStreamException if an error occurs
  */
 public static void requireSingleAttribute(
     final XMLExtendedStreamReader reader, final String attributeName) throws XMLStreamException {
   final int count = reader.getAttributeCount();
   if (count == 0) {
     throw missingRequired(reader, Collections.singleton(attributeName));
   }
   requireNoNamespaceAttribute(reader, 0);
   if (!attributeName.equals(reader.getAttributeLocalName(0))) {
     throw unexpectedAttribute(reader, 0);
   }
   if (count > 1) {
     throw unexpectedAttribute(reader, 1);
   }
 }
Example #12
0
    private ModelNode parseProperties(final XMLExtendedStreamReader reader)
        throws XMLStreamException {
      ModelNode node = new ModelNode();
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Element.forName(reader.getLocalName())) {
          case PROPERTY:
            {
              final int attrCount = reader.getAttributeCount();
              String propName = null;
              String propValue = null;
              for (int i = 0; i < attrCount; i++) {
                requireNoNamespaceAttribute(reader, i);
                final String value = reader.getAttributeValue(i);
                final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                switch (attribute) {
                  case NAME:
                    {
                      propName = value;
                      break;
                    }
                  case VALUE:
                    {
                      propValue = value;
                    }
                    break;
                  default:
                    throw unexpectedAttribute(reader, i);
                }
              }
              if (propName == null || propValue == null) {
                Set<Attribute> missing = new HashSet<Attribute>();
                if (propName == null) {
                  missing.add(Attribute.NAME);
                }
                if (propValue == null) {
                  missing.add(Attribute.VALUE);
                }
                throw missingRequired(reader, missing);
              }
              node.add(propName, propValue);

              if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                throw unexpectedElement(reader);
              }
            }
        }
      }
      return node;
    }
  /**
   * {@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);
          }
      }
    }
  }
Example #14
0
    private ModelNode parseTimeSpec(final XMLExtendedStreamReader reader)
        throws XMLStreamException {
      final int attrCount = reader.getAttributeCount();
      TimeUnit unit = null;
      Long duration = null;
      for (int i = 0; i < attrCount; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch (attribute) {
          case TIME:
            {
              duration = reader.getLongAttributeValue(i);
              break;
            }
          case UNIT:
            {
              unit = Enum.valueOf(TimeUnit.class, value.toUpperCase());
              break;
            }
          default:
            throw unexpectedAttribute(reader, i);
        }
      }

      if (duration == null || unit == null) {
        Set<Attribute> missing = new HashSet<Attribute>();
        if (duration == null) {
          missing.add(Attribute.TIME);
        }
        if (unit == null) {
          missing.add(Attribute.UNIT);
        }
      }

      if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        throw unexpectedElement(reader);
      }

      ModelNode node = new ModelNode();
      node.get(TIME).set(duration);
      node.get(UNIT).set(unit.toString());
      return node;
    }
 static ModelNode parseSimpleLoadProvider(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 FACTOR:
         load.get(FACTOR).set(value);
         break;
       default:
         unexpectedAttribute(reader, i);
     }
   }
   ParseUtils.requireNoContent(reader);
   return load;
 }
Example #16
0
 /**
  * Handle the xts-environment element
  *
  * @param reader
  * @return ModelNode for the core-environment
  * @throws XMLStreamException
  */
 static ModelNode parseXTSEnvironmentElement(XMLExtendedStreamReader reader)
     throws XMLStreamException {
   final ModelNode store = new ModelNode();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     ParseUtils.requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case URL:
         store.get(ModelDescriptionConstants.URL).set(value);
         break;
       default:
         throw ParseUtils.unexpectedAttribute(reader, i);
     }
   }
   // Handle elements
   ParseUtils.requireNoContent(reader);
   return store;
 }
Example #17
0
 static ModelNode parseSso(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode sso = 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 CACHE_CONTAINER:
       case CACHE_NAME:
       case DOMAIN:
       case REAUTHENTICATE:
         sso.get(attribute.getLocalName()).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   requireNoContent(reader);
   return sso;
 }
 void parsePropConf(XMLExtendedStreamReader reader, ModelNode conf) throws XMLStreamException {
   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 ADVERTISE_SOCKET:
       case PROXY_LIST:
       case PROXY_URL:
       case ADVERTISE:
       case ADVERTISE_SECURITY_KEY:
       case EXCLUDED_CONTEXTS:
       case AUTO_ENABLE_CONTEXTS:
       case STOP_CONTEXT_TIMEOUT:
       case SOCKET_TIMEOUT:
       case STICKY_SESSION:
       case STICKY_SESSION_REMOVE:
       case STICKY_SESSION_FORCE:
       case WORKER_TIMEOUT:
       case MAX_ATTEMPTS:
       case FLUSH_PACKETS:
       case FLUSH_WAIT:
       case PING:
       case SMAX:
       case TTL:
       case NODE_TIMEOUT:
       case BALANCER:
       case LOAD_BALANCING_GROUP:
       case CONNECTOR:
       case SESSION_DRAINING_STRATEGY:
         ModClusterConfigResourceDefinition.ATTRIBUTES_BY_NAME
             .get(attribute.getLocalName())
             .parseAndSetParameter(value, conf, reader);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
 }
  @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);
          }
      }
    }
  }
Example #20
0
 static ModelNode parseStaticResources(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode resources = 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 LISTINGS:
         resources.get(LISTINGS).set(value);
         break;
       case SENDFILE:
         resources.get(SENDFILE).set(value);
         break;
       case FILE_ENCONDING:
         resources.get(FILE_ENCONDING).set(value);
         break;
       case READ_ONLY:
         resources.get(READ_ONLY).set(value);
         break;
       case WEBDAV:
         resources.get(WEBDAV).set(value);
         break;
       case SECRET:
         resources.get(SECRET).set(value);
         break;
       case MAX_DEPTH:
         resources.get(MAX_DEPTH).set(value);
         break;
       case DISABLED:
         resources.get(DISABLED).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   requireNoContent(reader);
   return resources;
 }
  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 Map<String, String> parseXnioOption(final XMLExtendedStreamReader reader)
      throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
    final int count = reader.getAttributeCount();
    String optionName = null;
    String optionValue = null;
    for (int i = 0; i < count; i++) {
      requireNoNamespaceAttribute(reader, i);
      final String value = reader.getAttributeValue(i);
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      required.remove(attribute);
      switch (attribute) {
        case NAME:
          {
            if (value.trim().isEmpty()) {
              throw ParseUtils.invalidAttributeValue(reader, i);
            }
            optionName = value;
            break;
          }
        case VALUE:
          {
            optionValue = value;
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }
    if (!required.isEmpty()) {
      throw missingRequired(reader, required);
    }
    // This element is just composed of attributes which we already processed, so no more content
    // is expected
    requireNoContent(reader);

    return Collections.singletonMap(optionName, optionValue);
  }
 static ModelNode parseSSL(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode ssl = new ModelNode();
   ssl.setEmptyObject();
   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 KEY_ALIAS:
         ssl.get(KEY_ALIAS).set(value);
         break;
       case PASSWORD:
         ssl.get(PASSWORD).set(value);
         break;
       case CERTIFICATE_KEY_FILE:
         ssl.get(CERTIFICATE_KEY_FILE).set(value);
         break;
       case CIPHER_SUITE:
         ssl.get(CIPHER_SUITE).set(value);
         break;
       case PROTOCOL:
         ssl.get(PROTOCOL).set(value);
         break;
       case CA_CERTIFICATE_FILE:
         ssl.get(CA_CERTIFICATE_FILE).set(value);
         break;
       case CA_REVOCATION_URL:
         ssl.get(CA_REVOCATION_URL).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   ParseUtils.requireNoContent(reader);
   return ssl;
 }
Example #24
0
 static ModelNode parseJSPConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode jsp = 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 DEVELOPMENT:
       case DISABLED:
       case KEEP_GENERATED:
       case TRIM_SPACES:
       case TAG_POOLING:
       case MAPPED_FILE:
       case CHECK_INTERVAL:
       case MODIFIFICATION_TEST_INTERVAL:
       case RECOMPILE_ON_FAIL:
       case SMAP:
       case DUMP_SMAP:
       case GENERATE_STRINGS_AS_CHAR_ARRAYS:
       case ERROR_ON_USE_BEAN_INVALID_CLASS_ATTRIBUTE:
       case SCRATCH_DIR:
       case SOURCE_VM:
       case TARGET_VM:
       case JAVA_ENCODING:
       case X_POWERED_BY:
       case DISPLAY_SOURCE_FRAGMENT:
         jsp.get(attribute.getLocalName()).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   requireNoContent(reader);
   return jsp;
 }
Example #25
0
  /** {@inheritDoc} */
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list)
      throws XMLStreamException {
    final ModelNode address = new ModelNode();
    address.add(SUBSYSTEM, WebExtension.SUBSYSTEM_NAME);
    address.protect();

    final ModelNode subsystem = new ModelNode();
    subsystem.get(OP).set(ADD);
    subsystem.get(OP_ADDR).set(address);
    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 NATIVE:
        case DEFAULT_VIRTUAL_SERVER:
        case INSTANCE_ID:
          subsystem.get(attribute.getLocalName()).set(value);
          break;
        default:
          throw unexpectedAttribute(reader, i);
      }
    }
    list.add(subsystem);

    // elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      switch (Namespace.forUri(reader.getNamespaceURI())) {
        case WEB_1_0:
        case WEB_1_1:
          {
            final Element element = Element.forName(reader.getLocalName());
            switch (element) {
              case CONTAINER_CONFIG:
                {
                  final ModelNode config = parseContainerConfig(reader);
                  subsystem.get(CONTAINER_CONFIG).set(config);
                  break;
                }
              case CONNECTOR:
                {
                  parseConnector(reader, address, list);
                  break;
                }
              case VIRTUAL_SERVER:
                {
                  parseHost(reader, address, list);
                  break;
                }
              default:
                {
                  throw unexpectedElement(reader);
                }
            }
            break;
          }
        default:
          {
            throw unexpectedElement(reader);
          }
      }
    }
  }
 static void parsePropConf(XMLExtendedStreamReader reader, ModelNode conf)
     throws XMLStreamException {
   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 ADVERTISE_SOCKET:
         conf.get(ADVERTISE_SOCKET).set(value);
         break;
       case PROXY_LIST:
         conf.get(PROXY_LIST).set(value);
         break;
       case PROXY_URL:
         conf.get(PROXY_URL).set(value);
         break;
       case ADVERTISE:
         conf.get(ADVERTISE).set(value);
         break;
       case ADVERTISE_SECURITY_KEY:
         conf.get(ADVERTISE_SECURITY_KEY).set(value);
         break;
       case EXCLUDED_CONTEXTS:
         conf.get(EXCLUDED_CONTEXTS).set(value);
         break;
       case AUTO_ENABLE_CONTEXTS:
         conf.get(AUTO_ENABLE_CONTEXTS).set(value);
         break;
       case STOP_CONTEXT_TIMEOUT:
         conf.get(STOP_CONTEXT_TIMEOUT).set(value);
         break;
       case SOCKET_TIMEOUT:
         conf.get(SOCKET_TIMEOUT).set(value);
         break;
       case STICKY_SESSION:
         conf.get(STICKY_SESSION).set(value);
         break;
       case STICKY_SESSION_REMOVE:
         conf.get(STICKY_SESSION_REMOVE).set(value);
         break;
       case STICKY_SESSION_FORCE:
         conf.get(STICKY_SESSION_FORCE).set(value);
         break;
       case WORKER_TIMEOUT:
         conf.get(WORKER_TIMEOUT).set(value);
         break;
       case MAX_ATTEMPTS:
         conf.get(MAX_ATTEMPTS).set(value);
         break;
       case FLUSH_PACKETS:
         conf.get(FLUSH_PACKETS).set(value);
         break;
       case FLUSH_WAIT:
         conf.get(FLUSH_WAIT).set(value);
         break;
       case PING:
         conf.get(PING).set(value);
         break;
       case SMAX:
         conf.get(SMAX).set(value);
         break;
       case TTL:
         conf.get(TTL).set(value);
         break;
       case NODE_TIMEOUT:
         conf.get(NODE_TIMEOUT).set(value);
         break;
       case BALANCER:
         conf.get(BALANCER).set(value);
         break;
       case DOMAIN:
         conf.get(DOMAIN).set(value);
         break;
       default:
         unexpectedAttribute(reader, i);
     }
   }
 }
Example #27
0
 static ModelNode parseHostAccessLog(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode log = new ModelNode();
   log.setEmptyObject();
   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 PATTERN:
         log.get(PATTERN).set(value);
         break;
       case RESOLVE_HOSTS:
         log.get(RESOLVE_HOSTS).set(value);
         break;
       case EXTENDED:
         log.get(EXTENDED).set(value);
         break;
       case PREFIX:
         log.get(PREFIX).set(value);
         break;
       case ROTATE:
         log.get(ROTATE).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     switch (Namespace.forUri(reader.getNamespaceURI())) {
       case WEB_1_0:
       case WEB_1_1:
         {
           final Element element = Element.forName(reader.getLocalName());
           switch (element) {
             case DIRECTORY:
               final ModelNode directory = new ModelNode();
               final int count2 = reader.getAttributeCount();
               for (int i = 0; i < count2; i++) {
                 requireNoNamespaceAttribute(reader, i);
                 final String value = reader.getAttributeValue(i);
                 final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                 switch (attribute) {
                   case PATH:
                     directory.get(PATH).set(value);
                     break;
                   case RELATIVE_TO:
                     directory.get(RELATIVE_TO).set(value);
                     break;
                   default:
                     throw unexpectedAttribute(reader, i);
                 }
               }
               requireNoContent(reader);
               log.get(DIRECTORY).set(directory);
               break;
             default:
               throw unexpectedElement(reader);
           }
           break;
         }
       default:
         throw unexpectedElement(reader);
     }
   }
   return log;
 }
Example #28
0
 static ModelNode parseHostRewrite(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode rewrite = new ModelNode();
   rewrite.setEmptyObject();
   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 PATTERN:
         rewrite.get(PATTERN).set(value);
         break;
       case SUBSTITUTION:
         rewrite.get(SUBSTITUTION).set(value);
         break;
       case FLAGS:
         rewrite.get(FLAGS).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     switch (Namespace.forUri(reader.getNamespaceURI())) {
       case WEB_1_0:
       case WEB_1_1:
         {
           final Element element = Element.forName(reader.getLocalName());
           switch (element) {
             case CONDITION:
               final ModelNode condition = new ModelNode();
               condition.setEmptyObject();
               final int count2 = reader.getAttributeCount();
               for (int i = 0; i < count2; i++) {
                 requireNoNamespaceAttribute(reader, i);
                 final String value = reader.getAttributeValue(i);
                 final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                 switch (attribute) {
                   case TEST:
                     condition.get(TEST).set(value);
                     break;
                   case PATTERN:
                     condition.get(PATTERN).set(value);
                     break;
                   case FLAGS:
                     condition.get(FLAGS).set(value);
                     break;
                   default:
                     throw unexpectedAttribute(reader, i);
                 }
               }
               requireNoContent(reader);
               rewrite.get(CONDITION).add(condition);
               break;
             default:
               throw unexpectedElement(reader);
           }
           break;
         }
       default:
         throw unexpectedElement(reader);
     }
   }
   return rewrite;
 }
Example #29
0
 static void parseConnector(
     XMLExtendedStreamReader reader, ModelNode address, List<ModelNode> list)
     throws XMLStreamException {
   String name = null;
   String protocol = null;
   String bindingRef = null;
   String scheme = null;
   String executorRef = null;
   String enabled = null;
   String enableLookups = null;
   String proxyName = null;
   String proxyPort = null;
   String maxPostSize = null;
   String maxSavePostSize = null;
   String secure = null;
   String redirectPort = null;
   String maxConnections = null;
   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 NAME:
         name = value;
         break;
       case SOCKET_BINDING:
         bindingRef = value;
         break;
       case SCHEME:
         scheme = value;
         break;
       case PROTOCOL:
         protocol = value;
         break;
       case EXECUTOR:
         executorRef = value;
         break;
       case ENABLED:
         enabled = value;
         break;
       case ENABLE_LOOKUPS:
         enableLookups = value;
         break;
       case PROXY_NAME:
         proxyName = value;
         break;
       case PROXY_PORT:
         proxyPort = value;
         break;
       case MAX_POST_SIZE:
         maxPostSize = value;
         break;
       case MAX_SAVE_POST_SIZE:
         maxSavePostSize = value;
         break;
       case SECURE:
         secure = value;
         break;
       case REDIRECT_PORT:
         redirectPort = value;
         break;
       case MAX_CONNECTIONS:
         maxConnections = value;
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   if (name == null) {
     throw missingRequired(reader, Collections.singleton(Attribute.NAME));
   }
   if (bindingRef == null) {
     throw missingRequired(reader, Collections.singleton(Attribute.SOCKET_BINDING));
   }
   final ModelNode connector = new ModelNode();
   connector.get(OP).set(ADD);
   connector.get(OP_ADDR).set(address).add(CONNECTOR, name);
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     switch (Namespace.forUri(reader.getNamespaceURI())) {
       case WEB_1_0:
       case WEB_1_1:
         {
           final Element element = Element.forName(reader.getLocalName());
           switch (element) {
             case SSL:
               final ModelNode ssl = parseSsl(reader);
               connector.get(SSL).set(ssl);
               break;
             case VIRTUAL_SERVER:
               connector
                   .get(VIRTUAL_SERVER)
                   .add(readStringAttributeElement(reader, Attribute.NAME.getLocalName()));
               break;
             default:
               throw unexpectedElement(reader);
           }
           break;
         }
       default:
         throw unexpectedElement(reader);
     }
   }
   if (protocol != null) connector.get(PROTOCOL).set(protocol);
   connector.get(SOCKET_BINDING).set(bindingRef);
   if (scheme != null) connector.get(SCHEME).set(scheme);
   if (executorRef != null) connector.get(EXECUTOR).set(executorRef);
   if (enabled != null) connector.get(ENABLED).set(enabled);
   if (enableLookups != null) connector.get(ENABLE_LOOKUPS).set(enableLookups);
   if (proxyName != null) connector.get(PROXY_NAME).set(proxyName);
   if (proxyPort != null) connector.get(PROXY_PORT).set(proxyPort);
   if (maxPostSize != null) connector.get(MAX_POST_SIZE).set(maxPostSize);
   if (maxSavePostSize != null) connector.get(MAX_SAVE_POST_SIZE).set(maxSavePostSize);
   if (secure != null) connector.get(SECURE).set(secure);
   if (redirectPort != null) connector.get(REDIRECT_PORT).set(redirectPort);
   if (maxConnections != null) connector.get(MAX_CONNECTIONS).set(maxConnections);
   list.add(connector);
 }
Example #30
0
  static void parseHost(
      XMLExtendedStreamReader reader, final ModelNode address, List<ModelNode> list)
      throws XMLStreamException {
    String name = null;
    String defaultWebModule = null;
    boolean welcome = false;
    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 NAME:
          name = value;
          break;
        case DEFAULT_WEB_MODULE:
          if (welcome)
            throw new XMLStreamException(
                "A default web module can not be specified when the welcome root has been enabled",
                reader.getLocation());
          defaultWebModule = value;
          break;
        case ENABLE_WELCOME_ROOT:
          welcome = Boolean.parseBoolean(value);
          if (welcome && defaultWebModule != null)
            throw new XMLStreamException(
                "The welcome root can not be enabled on a host that has a default web module",
                reader.getLocation());
          break;
        default:
          throw unexpectedAttribute(reader, i);
      }
    }
    if (name == null) {
      throw missingRequired(reader, Collections.singleton(Attribute.NAME));
    }

    final ModelNode host = new ModelNode();
    host.get(OP).set(ADD);
    host.get(OP_ADDR).set(address).add(VIRTUAL_SERVER, name);
    if (defaultWebModule != null) {
      host.get(DEFAULT_WEB_MODULE).set(defaultWebModule);
    }
    host.get(ENABLE_WELCOME_ROOT).set(welcome);
    list.add(host);

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      switch (Namespace.forUri(reader.getNamespaceURI())) {
        case WEB_1_0:
          {
            final Element element = Element.forName(reader.getLocalName());
            switch (element) {
              case ALIAS:
                host.get(ALIAS)
                    .add(readStringAttributeElement(reader, Attribute.NAME.getLocalName()));
                break;
              case ACCESS_LOG:
                final ModelNode log = parseHostAccessLog(reader);
                host.get(ACCESS_LOG).set(log);
                break;
              case REWRITE:
                final ModelNode rewrite = parseHostRewrite(reader);
                host.get(REWRITE).add(rewrite);
                break;
              default:
                throw unexpectedElement(reader);
            }
            break;
          }
        case WEB_1_1:
          {
            final Element element = Element.forName(reader.getLocalName());
            switch (element) {
              case ALIAS:
                host.get(ALIAS)
                    .add(readStringAttributeElement(reader, Attribute.NAME.getLocalName()));
                break;
              case ACCESS_LOG:
                final ModelNode log = parseHostAccessLog(reader);
                host.get(ACCESS_LOG).set(log);
                break;
              case REWRITE:
                final ModelNode rewrite = parseHostRewrite(reader);
                host.get(REWRITE).add(rewrite);
                break;
              case SSO:
                final ModelNode sso = parseSso(reader);
                host.get(SSO).set(sso);
                break;
              default:
                throw unexpectedElement(reader);
            }
            break;
          }
        default:
          throw unexpectedElement(reader);
      }
    }
  }