Beispiel #1
0
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations)
      throws XMLStreamException {

    ParseUtils.requireNoAttributes(reader);
    final Map<String, List<ModelNode>> profileOps = new LinkedHashMap<String, List<ModelNode>>();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      if (Namespace.forUri(reader.getNamespaceURI()) != Namespace.UNKNOWN) {
        throw unexpectedElement(reader);
      }
      if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) {
        throw unexpectedElement(reader);
      }
      String namespace = reader.getNamespaceURI();
      if (profileOps.containsKey(namespace)) {
        throw ControllerMessages.MESSAGES.duplicateDeclaration("subsystem", reader.getLocation());
      }
      // parse subsystem
      final List<ModelNode> subsystems = new ArrayList<ModelNode>();
      reader.handleAny(subsystems);

      profileOps.put(namespace, subsystems);
    }

    // Let extensions modify the profile
    Set<ProfileParsingCompletionHandler> completionHandlers =
        extensionRegistry.getProfileParsingCompletionHandlers();
    for (ProfileParsingCompletionHandler completionHandler : completionHandlers) {
      completionHandler.handleProfileParsingCompletion(profileOps, operations);
    }

    for (List<ModelNode> subsystems : profileOps.values()) {
      operations.addAll(subsystems);
    }
  }
Beispiel #2
0
  void parseProfiles(
      final XMLExtendedStreamReader reader,
      final ModelNode address,
      final Namespace expectedNs,
      final List<ModelNode> list)
      throws XMLStreamException {
    requireNoAttributes(reader);

    final Set<String> names = new HashSet<String>();

    while (reader.nextTag() != END_ELEMENT) {
      requireNamespace(reader, expectedNs);
      Element element = Element.forName(reader.getLocalName());
      if (Element.PROFILE != element) {
        throw unexpectedElement(reader);
      }

      // Attributes
      requireSingleAttribute(reader, Attribute.NAME.getLocalName());
      final String name = reader.getAttributeValue(0);
      if (!names.add(name)) {
        throw MESSAGES.duplicateDeclaration("profile", name, reader.getLocation());
      }

      // final Set<String> includes = new HashSet<String>();  // See commented out section below.
      // final ModelNode profileIncludes = new ModelNode();

      // Content
      // Sequence
      final Map<String, List<ModelNode>> profileOps = new LinkedHashMap<String, List<ModelNode>>();
      while (reader.nextTag() != END_ELEMENT) {
        Namespace ns = Namespace.forUri(reader.getNamespaceURI());
        switch (ns) {
          case UNKNOWN:
            {
              if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) {
                throw unexpectedElement(reader);
              }
              String namespace = reader.getNamespaceURI();
              if (profileOps.containsKey(namespace)) {
                throw MESSAGES.duplicateDeclaration("subsystem", name, reader.getLocation());
              }
              // parse content
              final List<ModelNode> subsystems = new ArrayList<ModelNode>();
              reader.handleAny(subsystems);

              profileOps.put(namespace, subsystems);

              break;
            }
          case DOMAIN_1_0:
          case DOMAIN_1_1:
          case DOMAIN_1_2:
          case DOMAIN_1_3:
            {
              requireNamespace(reader, expectedNs);
              // include should come first
              if (profileOps.size() > 0) {
                throw unexpectedElement(reader);
              }
              if (Element.forName(reader.getLocalName()) != Element.INCLUDE) {
                throw unexpectedElement(reader);
              }
              // Remove support for profile includes until 7.2.0
              if (ns == Namespace.DOMAIN_1_0) {
                HOST_CONTROLLER_LOGGER.warnIgnoringProfileInclude(reader.getLocation());
              }
              throw unexpectedElement(reader);
              /* This will be reintroduced for 7.2.0, leave commented out
              final String includedName = readStringAttributeElement(reader, Attribute.PROFILE.getLocalName());
              if (! names.contains(includedName)) {
                  throw MESSAGES.profileNotFound(reader.getLocation());
              }
              if (! includes.add(includedName)) {
                  throw MESSAGES.duplicateProfile(reader.getLocation());
              }
              profileIncludes.add(includedName);
              break;
              */
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
      }

      // Let extensions modify the profile
      Set<ProfileParsingCompletionHandler> completionHandlers =
          extensionRegistry.getProfileParsingCompletionHandlers();
      for (ProfileParsingCompletionHandler completionHandler : completionHandlers) {
        completionHandler.handleProfileParsingCompletion(profileOps, list);
      }

      final ModelNode profile = new ModelNode();
      profile.get(OP).set(ADD);
      profile.get(OP_ADDR).set(address).add(ModelDescriptionConstants.PROFILE, name);
      /* This will be reintroduced for 7.2.0, leave commented out
      profile.get(INCLUDES).set(profileIncludes);
      */
      list.add(profile);

      // Process subsystems
      for (List<ModelNode> subsystems : profileOps.values()) {
        for (final ModelNode update : subsystems) {
          // Process relative subsystem path address
          final ModelNode subsystemAddress =
              address.clone().set(address).add(ModelDescriptionConstants.PROFILE, name);
          for (final Property path : update.get(OP_ADDR).asPropertyList()) {
            subsystemAddress.add(path.getName(), path.getValue().asString());
          }
          update.get(OP_ADDR).set(subsystemAddress);
          list.add(update);
        }
      }

      if (profileOps.size() == 0) {
        throw MESSAGES.profileHasNoSubsystems(reader.getLocation());
      }
    }
  }