org.eigenbase.xom
public class DOMElementParser extends Object
Constructor and Description |
---|
DOMElementParser(DOMWrapper wrapper,
String prefix,
Class enclosure)
Constructs a new ElementParser based on an Element of the XML parse
tree wrapped in a DOMWrapper, and a prefix (to be applied to all element
tags except the root), and the name of the enclosing class.
|
Modifier and Type | Method and Description |
---|---|
NodeDef[] |
classArray(Class elemClass,
int min,
int max)
This function retrieves a collection of elements which are subclasses of
the given class, returning them as an array.
|
NodeDef[] |
getArray(Class elemClass,
int min,
int max)
This function retrieves a collection of elements which are subclasses of
the given class, returning them as an array.
|
Object |
getAttribute(String attrName,
String attrType,
String defaultValue,
String[] values,
boolean required)
Retrieve an Attribute from the parser.
|
NodeDef |
getElement(Class elementClass,
boolean required)
This function retrieves an Element from this parser, advancing the
parser if the element is found.
|
static Class |
getPluginClass(Class managerClass)
Get a Class object representing a plugin class, given a manager
class that implements the static method getXMLDefClass().
|
static Class |
getPluginClass(String packageName,
String className)
Get a Class object representing a plugin class, identified either
directly by a Java package and Java class name, or indirectly
by a Java package and Java class which defines a method called
getXMLDefClass() to return the appropriate class.
|
String |
getString(String elementName,
boolean required)
This function retrieves a String element from this parser,
advancing the parser if the element is found.
|
String[] |
getStringArray(String elemName,
int min,
int max)
This function returns a collection of String elements of the given
name, returning them as an array.
|
String |
getText()
This function is used to return a CDATA section as text.
|
int |
lastOptionIndex()
Returns the option index of the element returned through the last
requiredOption call.
|
DOMWrapper[] |
optionalArray(String elemName,
int min,
int max)
This function retrieves a collection of elements with the given name,
returning them as an array.
|
String |
optionalAttribute(String attrName)
This function retrieves an optional Attribute by name from the
current Element.
|
Boolean |
optionalBooleanAttribute(String attrName)
This function retrieves an optional Attribute by name from the
current Element, converting it to an Boolean.
|
Double |
optionalDoubleAttribute(String attrName)
This function retrieves an optional Attribute by name from the
current Element, converting it to a Double.
|
DOMWrapper |
optionalElement(String elementName)
This function retrieves an optional Element from this parser,
advancing the parser if the element is found.
|
Integer |
optionalIntegerAttribute(String attrName)
This function retrieves an optional Attribute by name from the
current Element, converting it to an Integer.
|
String |
optionalString(String elementName)
This function retrieves an optional String element from this parser,
advancing the parser if the element is found.
|
String |
requiredAttribute(String attrName)
This function retrieves a required Attribute by name from the
current Element.
|
Boolean |
requiredBooleanAttribute(String attrName)
This function retrieves an required Attribute by name from the
current Element, converting it to a Boolean.
|
NodeDef |
requiredClass(Class classTemplate)
This function retrieves a required Element of a specific class
from this parser, advancing the parser after the read.
|
static String |
requiredDefAttribute(DOMWrapper wrapper,
String attrName,
String defaultVal)
This static version of requiredAttribute uses any element definition
as a basis for the attribute.
|
DOMWrapper |
requiredElement(String elementName)
This function retrieves a required Element from this parser,
advancing the parser after the read.
|
Integer |
requiredIntegerAttribute(String attrName)
This function retrieves an required Attribute by name from the
current Element, converting it to an Integer.
|
DOMWrapper |
requiredOption(String[] elementNames)
This function retrieves a required element which may have one of a
number of names.
|
String |
requiredString(String elementName)
This function retrieves a required String element from this parser,
advancing the parser after the read.
|
public DOMElementParser(DOMWrapper wrapper, String prefix, Class enclosure) throws XOMException
wrapper
- a DOMWrapper representing the section of the XML parse tree
to traverse.XOMException
public String requiredString(String elementName) throws XOMException
elementName
- the name of the element to retrieve.XOMException
- if there is no element with the given name.public String optionalString(String elementName) throws XOMException
elementName
- the name of the element to retrieve.XOMException
public DOMWrapper requiredElement(String elementName) throws XOMException
elementName
- the name of the element to retrieve.XOMException
- if there is no element with the given name.public String getText()
public DOMWrapper optionalElement(String elementName) throws XOMException
elementName
- the name of the element to retrieve.XOMException
public DOMWrapper requiredOption(String[] elementNames) throws XOMException
elementNames
- an array of allowed names. Names are compared in
a case-insensitive fashion.XOMException
- if there are no more elements to read or if
the next element's name is not in the elementNames list.public NodeDef requiredClass(Class classTemplate) throws XOMException
XOMException
public int lastOptionIndex()
public String requiredAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
- if no attribute of this name is set.public static String requiredDefAttribute(DOMWrapper wrapper, String attrName, String defaultVal) throws XOMException
wrapper
- the Element in which to find the attribute.attrName
- the name of the attribute to retrieve.defaultVal
- the default value of the attribute to retrieve.XOMException
- if no attribute of this name is set.public String optionalAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
public Integer optionalIntegerAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
- if the value is set to an illegal
integer value.public Double optionalDoubleAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
- if the value is set to an illegal
double value.public Integer requiredIntegerAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
- if the value is not set, or is set to
an illegal integer value.public Boolean optionalBooleanAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
- if the value is set to an illegal
integer value.public Boolean requiredBooleanAttribute(String attrName) throws XOMException
attrName
- the name of the attribute.XOMException
public DOMWrapper[] optionalArray(String elemName, int min, int max) throws XOMException
elemName
- the element name.min
- the minimum number of elements required in the array. Set
this parameter to 0 to indicate no minimum.max
- the maximum number of elements allowed in the array. Set
this parameter to 0 to indicate no maximum.XOMException
- if there are fewer than min or more than max
elements with the name elemName.public NodeDef[] classArray(Class elemClass, int min, int max) throws XOMException
elemClass
- the element class.min
- the minimum number of elements required in the array. Set
this parameter to 0 to indicate no minimum.max
- the maximum number of elements allowed in the array. Set
this parameter to 0 to indicate no maximum.XOMException
- if there are fewer than min or more than max
elements with the name elemName.public NodeDef getElement(Class elementClass, boolean required) throws XOMException
elementClass
- the Class of the element to retrieve.required
- true to throw an exception if the element is not
found, false to simply return null.XOMException
- if required is true and the element could not
be found.public NodeDef[] getArray(Class elemClass, int min, int max) throws XOMException
elemClass
- the element class.min
- the minimum number of elements required in the array. Set
this parameter to 0 to indicate no minimum.max
- the maximum number of elements allowed in the array. Set
this parameter to 0 to indicate no maximum.XOMException
- if there are fewer than min or more than max
elements with the name elemName.public String getString(String elementName, boolean required) throws XOMException
elementName
- the name of the element to retrieve.required
- true to throw an exception if the element is not
found, false to simply return null.XOMException
public String[] getStringArray(String elemName, int min, int max) throws XOMException
elemName
- the element name.min
- the minimum number of elements required in the array. Set
this parameter to 0 to indicate no minimum.max
- the maximum number of elements allowed in the array. Set
this parameter to 0 to indicate no maximum.XOMException
- if there are fewer than min or more than max
elements with the name elemName.public static Class getPluginClass(String packageName, String className) throws XOMException
packageName
- the name of the Java package containing the
plugin class.className
- the name of the plugin definition class.XOMException
- if the plugin class cannot be located
or if the designated class is not suitable as a plugin class.public static Class getPluginClass(Class managerClass) throws XOMException
managerClass
- any Class that implements getXMLDefClass.XOMException
public Object getAttribute(String attrName, String attrType, String defaultValue, String[] values, boolean required) throws XOMException
attrName
- the name of the attribute to retreive.attrType
- a String naming a Java Class to serve as the type.
If attrType contains a "." character, the class is looked up directly
from the type name. Otherwise, the class is looked up in the
java.lang package. Finally, the class must have a constructor which
takes a String as an argument.defaultValue
- the default value for this attribute. If values
is set, the defaultValue must also be one of the set of values.
defaultValue may be null.values
- an array of possible values for the attribute. If
this parameter is not null, then the attribute's value must be one
of the listed set of values or an exception will be thrown.required
- if set, then this function will throw an exception
if the attribute has no value and defaultValue is null.XOMException