Пример #1
0
 static {
   final Map<String, Attribute> map = new HashMap<String, Attribute>();
   for (Attribute element : values()) {
     final String name = element.getLocalName();
     if (name != null) map.put(name, element);
   }
   MAP = map;
 }
 @Override
 public void marshallAsElement(ModelNode resourceModel, XMLStreamWriter writer)
     throws XMLStreamException {
   if (isMarshallable(resourceModel)) {
     writer.writeEmptyElement(getXmlName());
     writer.writeAttribute(attribute.getLocalName(), resourceModel.get(getName()).asString());
   }
 }
  /** 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);
  }
  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);
  }
  private void parseOutboundConnection(
      final XMLExtendedStreamReader reader,
      final ModelNode address,
      final List<ModelNode> operations)
      throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.URI);
    final int count = reader.getAttributeCount();
    String name = null;
    String uri = 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:
          {
            name = value;
            break;
          }
        case URI:
          {
            uri = value;
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }
    if (!required.isEmpty()) {
      throw missingRequired(reader, required);
    }

    // parse the nested elements
    Map<String, String> connectionCreationOptions = Collections.emptyMap();
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      if (visited.contains(element)) {
        throw ParseUtils.unexpectedElement(reader);
      }
      visited.add(element);
      switch (element) {
        case CONNECTION_CREATION_OPTIONS:
          {
            connectionCreationOptions = this.parseXnioOptions(reader);
            break;
          }
        default:
          {
            throw unexpectedElement(reader);
          }
      }
    }

    // create add operation
    final ModelNode addOperation =
        GenericOutboundConnectionAdd.getAddOperation(name, uri, connectionCreationOptions);
    // add it to the list of operations
    operations.add(addOperation);
  }
  void parseConnector(
      final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list)
      throws XMLStreamException {

    String name = null;
    String socketBinding = null;
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.SOCKET_BINDING);
    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));
      required.remove(attribute);
      switch (attribute) {
        case NAME:
          {
            name = value;
            break;
          }
        case SOCKET_BINDING:
          {
            socketBinding = value;
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }
    if (!required.isEmpty()) {
      throw missingRequired(reader, required);
    }
    assert name != null;
    assert socketBinding != null;

    final ModelNode connector = new ModelNode();
    connector.get(OP).set(ADD);
    connector.get(OP_ADDR).set(address).add(CONNECTOR, name);
    // requestProperties.get(NAME).set(name); // Name is part of the address
    connector.get(SOCKET_BINDING).set(socketBinding);
    list.add(connector);

    // Handle nested elements.
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      if (visited.contains(element)) {
        throw unexpectedElement(reader);
      }
      visited.add(element);
      switch (element) {
        case SASL:
          {
            parseSaslElement(reader, connector.get(OP_ADDR), list);
            break;
          }
        case PROPERTIES:
          {
            parseProperties(reader, connector.get(OP_ADDR), list);
            break;
          }
        case AUTHENTICATION_PROVIDER:
          {
            connector.get(AUTHENTICATION_PROVIDER).set(readStringAttributeElement(reader, "name"));
            break;
          }
        default:
          {
            throw unexpectedElement(reader);
          }
      }
    }
  }