private void parseProperty( XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException { ModelNode operation = operations.get(address); ParseUtils.requireSingleAttribute(reader, XMLAttribute.NAME.getLocalName()); readAttribute(reader, 0, operation, ProtocolResourceDefinition.Attribute.PROPERTIES); }
/** * Read an element which contains only a single string attribute. * * @param reader the reader * @param attributeName the attribute name, usually "value" or "name" * @return the string value * @throws javax.xml.stream.XMLStreamException if an error occurs or if the element does not * contain the specified attribute, contains other attributes, or contains child elements. */ public static String readStringAttributeElement( final XMLExtendedStreamReader reader, final String attributeName) throws XMLStreamException { requireSingleAttribute(reader, attributeName); final String value = reader.getAttributeValue(0); requireNoContent(reader); return value; }
/** * Read an element which contains only a single boolean attribute. * * @param reader the reader * @param attributeName the attribute name, usually "value" * @return the boolean value * @throws javax.xml.stream.XMLStreamException if an error occurs or if the element does not * contain the specified attribute, contains other attributes, or contains child elements. */ public static boolean readBooleanAttributeElement( final XMLExtendedStreamReader reader, final String attributeName) throws XMLStreamException { requireSingleAttribute(reader, attributeName); final boolean value = Boolean.parseBoolean(reader.getAttributeValue(0)); requireNoContent(reader); return value; }
/** * Read an element which contains only a single list attribute of a given type. * * @param reader the reader * @param attributeName the attribute name, usually "value" * @param type the value type class * @param <T> the value type * @return the value list * @throws javax.xml.stream.XMLStreamException if an error occurs or if the element does not * contain the specified attribute, contains other attributes, or contains child elements. */ @SuppressWarnings({"unchecked"}) public static <T> List<T> readListAttributeElement( final XMLExtendedStreamReader reader, final String attributeName, final Class<T> type) throws XMLStreamException { requireSingleAttribute(reader, attributeName); // todo: fix this when this method signature is corrected final List<T> value = (List<T>) reader.getListAttributeValue(0, type); requireNoContent(reader); return value; }
private void parseBeanValidation(final XMLExtendedStreamReader reader, final ModelNode node) throws XMLStreamException { requireSingleAttribute(reader, Attribute.ENABLED.getLocalName()); final boolean value = reader.getAttributeValue(0) != null ? Boolean.parseBoolean(reader.getAttributeValue(0)) : true; requireNoContent(reader); node.get(BEAN_VALIDATION_ENABLED).set(value); // Don't add a requireNoContent here as readBooleanAttributeElement // already performs that check. }
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()); } } }