Package org.jboss.as.controller.parsing
Class ParseUtils
- java.lang.Object
-
- org.jboss.as.controller.parsing.ParseUtils
-
public final class ParseUtils extends Object
- Author:
- David M. Lloyd
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XMLStreamException
duplicateAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, String name)
Get an exception reporting that an attribute of a given name has already been declared in this scope.static XMLStreamException
duplicateNamedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String name)
Get an exception reporting that an element of a given type and name has already been declared in this scope.static XMLStreamException
invalidAttributeValue(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
Get an exception reporting an invalid XML attribute value.static boolean
isExpression(String value)
static boolean
isNoNamespaceAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
static XMLStreamException
missingOneOf(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<?> required)
Get an exception reporting a missing, required XML child element.static XMLStreamException
missingRequired(org.jboss.staxmapper.XMLExtendedStreamReader reader, String... required)
Get an exception reporting a missing, required XML attribute.static XMLStreamException
missingRequired(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<?> required)
Get an exception reporting a missing, required XML attribute.static XMLStreamException
missingRequiredElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<?> required)
Get an exception reporting a missing, required XML child element.static Element
nextElement(org.jboss.staxmapper.XMLExtendedStreamReader reader)
static Element
nextElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, Namespace expectedNamespace)
A variation of nextElement that verifies the nextElement is not in a different namespace.static org.jboss.dmr.ModelNode
parseAttributeValue(String value, boolean isExpressionAllowed, org.jboss.dmr.ModelType attributeType)
static org.jboss.dmr.ModelNode
parsePossibleExpression(String value)
static <T> T[]
readArrayAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName, Class<T> type)
Read an element which contains only a single list attribute of a given type, returning it as an array.static boolean
readBooleanAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName)
Read an element which contains only a single boolean attribute.static <T> List<T>
readListAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName, Class<T> type)
Read an element which contains only a single list attribute of a given type.static org.jboss.dmr.Property
readProperty(org.jboss.staxmapper.XMLExtendedStreamReader reader)
static org.jboss.dmr.Property
readProperty(org.jboss.staxmapper.XMLExtendedStreamReader reader, boolean supportsExpressions)
static String
readStringAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName)
Read an element which contains only a single string attribute.static String[]
requireAttributes(org.jboss.staxmapper.XMLExtendedStreamReader reader, String... attributeNames)
Require all the named attributes, returning their values in order.static void
requireNamespace(org.jboss.staxmapper.XMLExtendedStreamReader reader, Namespace requiredNs)
Require that the namespace of the current element matches the required namespace.static void
requireNoAttributes(org.jboss.staxmapper.XMLExtendedStreamReader reader)
Checks that the current element has no attributes, throwing anXMLStreamException
if one is found.static void
requireNoContent(org.jboss.staxmapper.XMLExtendedStreamReader reader)
Consumes the remainder of the current element, throwing anXMLStreamException
if it contains any child elements.static void
requireNoNamespaceAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
static void
requireSingleAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName)
Require that the current element have only a single attribute with the given name.static XMLStreamException
unexpectedAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
Get an exception reporting an unexpected XML attribute.static XMLStreamException
unexpectedAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index, Set<String> possibleAttributes)
Get an exception reporting an unexpected XML attribute.static XMLStreamException
unexpectedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader)
Get an exception reporting an unexpected XML element.static XMLStreamException
unexpectedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<String> possible)
Get an exception reporting an unexpected XML element.static XMLStreamException
unexpectedEndElement(org.jboss.staxmapper.XMLExtendedStreamReader reader)
Get an exception reporting an unexpected end tag for an XML element.static XMLStreamException
unsupportedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String supportedElement)
Get an exception reporting a missing, required XML attribute.
-
-
-
Method Detail
-
nextElement
public static Element nextElement(org.jboss.staxmapper.XMLExtendedStreamReader reader) throws XMLStreamException
- Throws:
XMLStreamException
-
nextElement
public static Element nextElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, Namespace expectedNamespace) throws XMLStreamException
A variation of nextElement that verifies the nextElement is not in a different namespace.- Parameters:
reader
- the XmlExtendedReader to read from.expectedNamespace
- the namespace expected.- Returns:
- the element or null if the end is reached
- Throws:
XMLStreamException
- if the namespace is wrong or there is a problem accessing the reader
-
unexpectedElement
public static XMLStreamException unexpectedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader)
Get an exception reporting an unexpected XML element.- Parameters:
reader
- the stream reader- Returns:
- the exception
-
unexpectedElement
public static XMLStreamException unexpectedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<String> possible)
Get an exception reporting an unexpected XML element.- Parameters:
reader
- the stream reader- Returns:
- the exception
-
unexpectedEndElement
public static XMLStreamException unexpectedEndElement(org.jboss.staxmapper.XMLExtendedStreamReader reader)
Get an exception reporting an unexpected end tag for an XML element.- Parameters:
reader
- the stream reader- Returns:
- the exception
-
unexpectedAttribute
public static XMLStreamException unexpectedAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
Get an exception reporting an unexpected XML attribute.- Parameters:
reader
- the stream readerindex
- the attribute index- Returns:
- the exception
-
unexpectedAttribute
public static XMLStreamException unexpectedAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index, Set<String> possibleAttributes)
Get an exception reporting an unexpected XML attribute.- Parameters:
reader
- the stream readerindex
- the attribute indexpossibleAttributes
- attributes that are expected on this element- Returns:
- the exception
-
invalidAttributeValue
public static XMLStreamException invalidAttributeValue(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
Get an exception reporting an invalid XML attribute value.- Parameters:
reader
- the stream readerindex
- the attribute index- Returns:
- the exception
-
missingRequired
public static XMLStreamException missingRequired(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<?> required)
Get an exception reporting a missing, required XML attribute.- Parameters:
reader
- the stream readerrequired
- a set of enums whose toString method returns the attribute name- Returns:
- the exception
-
missingRequired
public static XMLStreamException missingRequired(org.jboss.staxmapper.XMLExtendedStreamReader reader, String... required)
Get an exception reporting a missing, required XML attribute.- Parameters:
reader
- the stream readerrequired
- a set of enums whose toString method returns the attribute name- Returns:
- the exception
-
missingRequiredElement
public static XMLStreamException missingRequiredElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<?> required)
Get an exception reporting a missing, required XML child element.- Parameters:
reader
- the stream readerrequired
- a set of enums whose toString method returns the attribute name- Returns:
- the exception
-
missingOneOf
public static XMLStreamException missingOneOf(org.jboss.staxmapper.XMLExtendedStreamReader reader, Set<?> required)
Get an exception reporting a missing, required XML child element.- Parameters:
reader
- the stream readerrequired
- a set of enums whose toString method returns the attribute name- Returns:
- the exception
-
requireNoAttributes
public static void requireNoAttributes(org.jboss.staxmapper.XMLExtendedStreamReader reader) throws XMLStreamException
Checks that the current element has no attributes, throwing anXMLStreamException
if one is found.- Parameters:
reader
- the reader- Throws:
XMLStreamException
- if an error occurs
-
requireNoContent
public static void requireNoContent(org.jboss.staxmapper.XMLExtendedStreamReader reader) throws XMLStreamException
Consumes the remainder of the current element, throwing anXMLStreamException
if it contains any child elements.- Parameters:
reader
- the reader- Throws:
XMLStreamException
- if an error occurs
-
requireNamespace
public static void requireNamespace(org.jboss.staxmapper.XMLExtendedStreamReader reader, Namespace requiredNs) throws XMLStreamException
Require that the namespace of the current element matches the required namespace.- Parameters:
reader
- the readerrequiredNs
- the namespace required- Throws:
XMLStreamException
- if the current namespace does not match the required namespace
-
duplicateAttribute
public static XMLStreamException duplicateAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, String name)
Get an exception reporting that an attribute of a given name has already been declared in this scope.- Parameters:
reader
- the stream readername
- the name that was redeclared- Returns:
- the exception
-
duplicateNamedElement
public static XMLStreamException duplicateNamedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String name)
Get an exception reporting that an element of a given type and name has already been declared in this scope.- Parameters:
reader
- the stream readername
- the name that was redeclared- Returns:
- the exception
-
readBooleanAttributeElement
public static boolean readBooleanAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName) throws XMLStreamException
Read an element which contains only a single boolean attribute.- Parameters:
reader
- the readerattributeName
- the attribute name, usually "value"- Returns:
- the boolean value
- Throws:
XMLStreamException
- if an error occurs or if the element does not contain the specified attribute, contains other attributes, or contains child elements.
-
readStringAttributeElement
public static String readStringAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName) throws XMLStreamException
Read an element which contains only a single string attribute.- Parameters:
reader
- the readerattributeName
- the attribute name, usually "value" or "name"- Returns:
- the string value
- Throws:
XMLStreamException
- if an error occurs or if the element does not contain the specified attribute, contains other attributes, or contains child elements.
-
readListAttributeElement
public static <T> List<T> readListAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName, Class<T> type) throws XMLStreamException
Read an element which contains only a single list attribute of a given type.- Type Parameters:
T
- the value type- Parameters:
reader
- the readerattributeName
- the attribute name, usually "value"type
- the value type class- Returns:
- the value list
- Throws:
XMLStreamException
- if an error occurs or if the element does not contain the specified attribute, contains other attributes, or contains child elements.
-
readProperty
public static org.jboss.dmr.Property readProperty(org.jboss.staxmapper.XMLExtendedStreamReader reader) throws XMLStreamException
- Throws:
XMLStreamException
-
readProperty
public static org.jboss.dmr.Property readProperty(org.jboss.staxmapper.XMLExtendedStreamReader reader, boolean supportsExpressions) throws XMLStreamException
- Throws:
XMLStreamException
-
readArrayAttributeElement
public static <T> T[] readArrayAttributeElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName, Class<T> type) throws XMLStreamException
Read an element which contains only a single list attribute of a given type, returning it as an array.- Type Parameters:
T
- the value type- Parameters:
reader
- the readerattributeName
- the attribute name, usually "value"type
- the value type class- Returns:
- the value list as an array
- Throws:
XMLStreamException
- if an error occurs or if the element does not contain the specified attribute, contains other attributes, or contains child elements.
-
requireSingleAttribute
public static void requireSingleAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, String attributeName) throws XMLStreamException
Require that the current element have only a single attribute with the given name.- Parameters:
reader
- the readerattributeName
- the attribute name- Throws:
XMLStreamException
- if an error occurs
-
requireAttributes
public static String[] requireAttributes(org.jboss.staxmapper.XMLExtendedStreamReader reader, String... attributeNames) throws XMLStreamException
Require all the named attributes, returning their values in order.- Parameters:
reader
- the readerattributeNames
- the attribute names- Returns:
- the attribute values in order
- Throws:
XMLStreamException
- if an error occurs
-
isNoNamespaceAttribute
public static boolean isNoNamespaceAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index)
-
requireNoNamespaceAttribute
public static void requireNoNamespaceAttribute(org.jboss.staxmapper.XMLExtendedStreamReader reader, int index) throws XMLStreamException
- Throws:
XMLStreamException
-
parseAttributeValue
public static org.jboss.dmr.ModelNode parseAttributeValue(String value, boolean isExpressionAllowed, org.jboss.dmr.ModelType attributeType)
-
isExpression
public static boolean isExpression(String value)
-
parsePossibleExpression
public static org.jboss.dmr.ModelNode parsePossibleExpression(String value)
-
unsupportedElement
public static XMLStreamException unsupportedElement(org.jboss.staxmapper.XMLExtendedStreamReader reader, String supportedElement)
Get an exception reporting a missing, required XML attribute.- Parameters:
reader
- the stream readersupportedElement
- the element that is to be used in place of the unsupported one.- Returns:
- the exception
-
-