Package org.apache.commons.jxpath.xml
Class DocumentContainer
- java.lang.Object
-
- org.apache.commons.jxpath.xml.XMLParser2
-
- org.apache.commons.jxpath.xml.DocumentContainer
-
public class DocumentContainer extends XMLParser2 implements Container
An XML document container reads and parses XML only when it is accessed. JXPath traverses Containers transparently - you use the same paths to access objects in containers as you do to access those objects directly. You can create XMLDocumentContainers for various XML documents that may or may not be accessed by XPaths. If they are, they will be automatically read, parsed and traversed. If they are not - they won't be read at all.- Version:
- $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Objectdocumentprivate java.lang.Stringmodelstatic java.lang.StringMODEL_DOMDOM constantstatic java.lang.StringMODEL_JDOMJDOM constantprivate static java.util.HashMapparserClassesprivate static java.util.HashMapparsersprivate static longserialVersionUIDprivate java.net.URLxmlURL
-
Constructor Summary
Constructors Constructor Description DocumentContainer(java.net.URL xmlURL)Use this constructor if the desired model is DOM.DocumentContainer(java.net.URL xmlURL, java.lang.String model)Construct a new DocumentContainer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static XMLParsergetParser(java.lang.String model)Maps a model type to a parser.java.lang.ObjectgetValue()Reads XML, caches it internally and returns the Document.java.lang.ObjectparseXML(java.io.InputStream stream)Parses XML using the parser for the specified model.static voidregisterXMLParser(java.lang.String model, java.lang.String parserClassName)Add a class of a custom XML parser.static voidregisterXMLParser(java.lang.String model, XMLParser parser)Add an XML parser.voidsetValue(java.lang.Object value)Throws an UnsupportedOperationException.-
Methods inherited from class org.apache.commons.jxpath.xml.XMLParser2
isCoalescing, isExpandEntityReferences, isIgnoringComments, isIgnoringElementContentWhitespace, isNamespaceAware, isValidating, setCoalescing, setExpandEntityReferences, setIgnoringComments, setIgnoringElementContentWhitespace, setNamespaceAware, setValidating
-
-
-
-
Field Detail
-
MODEL_DOM
public static final java.lang.String MODEL_DOM
DOM constant- See Also:
- Constant Field Values
-
MODEL_JDOM
public static final java.lang.String MODEL_JDOM
JDOM constant- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
parserClasses
private static java.util.HashMap parserClasses
-
parsers
private static java.util.HashMap parsers
-
document
private java.lang.Object document
-
xmlURL
private java.net.URL xmlURL
-
model
private java.lang.String model
-
-
Constructor Detail
-
DocumentContainer
public DocumentContainer(java.net.URL xmlURL)
Use this constructor if the desired model is DOM.- Parameters:
xmlURL- is a URL for an XML file. Use getClass().getResource(resourceName) to load XML from a resource file.
-
DocumentContainer
public DocumentContainer(java.net.URL xmlURL, java.lang.String model)Construct a new DocumentContainer.- Parameters:
xmlURL- is a URL for an XML file. Use getClass().getResource (resourceName) to load XML from a resource file.model- is one of the MODEL_* constants defined in this class. It determines which parser should be used to load the XML.
-
-
Method Detail
-
registerXMLParser
public static void registerXMLParser(java.lang.String model, XMLParser parser)Add an XML parser. Parsers for the models "DOM" and "JDOM" are pre-registered.- Parameters:
model- model nameparser- parser
-
registerXMLParser
public static void registerXMLParser(java.lang.String model, java.lang.String parserClassName)Add a class of a custom XML parser. Parsers for the models "DOM" and "JDOM" are pre-registered.- Parameters:
model- model nameparserClassName- parser classname
-
getValue
public java.lang.Object getValue()
Reads XML, caches it internally and returns the Document.
-
parseXML
public java.lang.Object parseXML(java.io.InputStream stream)
Parses XML using the parser for the specified model.- Specified by:
parseXMLin interfaceXMLParser- Specified by:
parseXMLin classXMLParser2- Parameters:
stream- InputStream- Returns:
- Object
-
setValue
public void setValue(java.lang.Object value)
Throws an UnsupportedOperationException.
-
getParser
private static XMLParser getParser(java.lang.String model)
Maps a model type to a parser.- Parameters:
model- input model type- Returns:
- XMLParser
-
-