cuba.wired.ddread
Class XmlReader

java.lang.Object
  extended by cuba.wired.ddread.XmlReader
Direct Known Subclasses:
PlainPersistenceReader, WiredAppReader, WiredJarReader

public class XmlReader
extends java.lang.Object

Convenience class for XML document analysis. This class in turn uses an object implementing the XmlParserI interface for actually reading an XML file from an input stream. Although being well-hidden in this package, this class is the basis for all XML input processing within CUBA.

Author:
Jan Lessner

Field Summary
static java.lang.String REVISION_ID
           
 
Constructor Summary
XmlReader()
           
XmlReader(java.util.Properties props)
           
 
Method Summary
static java.lang.String getAttribute(org.w3c.dom.Node node, java.lang.String key)
           
 java.lang.String getChild(org.w3c.dom.Node node, java.lang.String key)
           
static org.w3c.dom.Node getChildNode(org.w3c.dom.Node node, java.lang.String key)
           
static java.lang.String getElementName(org.w3c.dom.Element element)
           
static java.io.InputStream getJarEntry(java.lang.String jarFileName, java.lang.String dirname, java.lang.String filename)
           
static java.lang.String getMandatoryAttribute(org.w3c.dom.Node node, java.lang.String key)
           
 java.lang.String getMandatoryChild(org.w3c.dom.Node node, java.lang.String key)
           
static org.w3c.dom.Node getMandatoryChildNode(org.w3c.dom.Node node, java.lang.String key)
           
static java.lang.String getMandatoryFirstChildValue(org.w3c.dom.Node node)
           
static java.io.InputStream getResource(java.lang.String filename)
           
static org.w3c.dom.Element getRootElement(java.io.InputStream is)
           
static org.w3c.dom.Element getRootElement(java.io.InputStream is, java.lang.String fileName)
          Read an XML file from an input stream and return the root element of the DOM tree.
static java.io.InputStream getSystemResource(java.lang.String dirname, java.lang.String filename)
          Load the specified resource from the current class loader.
static java.net.URL getURL(java.lang.String filename)
           
static void setXmlParser(XmlParserI value)
          Set the parser to use for reading an XML file from an input stream.
static void setXmlParserType(java.lang.String typeName)
          Set the parser type to instanciate for reading an XML file from an input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION_ID

public static final java.lang.String REVISION_ID
See Also:
Constant Field Values
Constructor Detail

XmlReader

public XmlReader()

XmlReader

public XmlReader(java.util.Properties props)
Method Detail

setXmlParser

public static void setXmlParser(XmlParserI value)
Set the parser to use for reading an XML file from an input stream. If this function is not called, there is an instance created from the XML parser type name set by setXmlParserType(java.lang.String).

Parameters:
value - a parser object implementing the XmlParserI interface.

setXmlParserType

public static void setXmlParserType(java.lang.String typeName)
Set the parser type to instanciate for reading an XML file from an input stream. If this function is not called, the class XmlParserXerces is used as a default.

Parameters:
typeName - The fully qualified class name to instanciate. The class must implement the XmlParserI interface and provide a default constructor.

getRootElement

public static org.w3c.dom.Element getRootElement(java.io.InputStream is)
                                          throws InitException
Throws:
InitException

getRootElement

public static org.w3c.dom.Element getRootElement(java.io.InputStream is,
                                                 java.lang.String fileName)
                                          throws InitException
Read an XML file from an input stream and return the root element of the DOM tree.

Parameters:
is - The input stream to read from
fileName - the name of the file represented be the input stream. Only required for error message assembly
Throws:
InitException - if the instantiation of an XML parser failed or if the input could not be parsed propperly.

getMandatoryAttribute

public static java.lang.String getMandatoryAttribute(org.w3c.dom.Node node,
                                                     java.lang.String key)
                                              throws InitException
Throws:
InitException

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Node node,
                                            java.lang.String key)

getMandatoryChild

public java.lang.String getMandatoryChild(org.w3c.dom.Node node,
                                          java.lang.String key)
                                   throws InitException
Throws:
InitException

getMandatoryFirstChildValue

public static java.lang.String getMandatoryFirstChildValue(org.w3c.dom.Node node)
                                                    throws InitException
Throws:
InitException

getChild

public java.lang.String getChild(org.w3c.dom.Node node,
                                 java.lang.String key)

getMandatoryChildNode

public static org.w3c.dom.Node getMandatoryChildNode(org.w3c.dom.Node node,
                                                     java.lang.String key)
                                              throws InitException
Throws:
InitException

getChildNode

public static org.w3c.dom.Node getChildNode(org.w3c.dom.Node node,
                                            java.lang.String key)

getElementName

public static java.lang.String getElementName(org.w3c.dom.Element element)

getJarEntry

public static java.io.InputStream getJarEntry(java.lang.String jarFileName,
                                              java.lang.String dirname,
                                              java.lang.String filename)
                                       throws InitException
Throws:
InitException

getURL

public static java.net.URL getURL(java.lang.String filename)

getResource

public static java.io.InputStream getResource(java.lang.String filename)
                                       throws java.io.IOException
Throws:
java.io.IOException

getSystemResource

public static java.io.InputStream getSystemResource(java.lang.String dirname,
                                                    java.lang.String filename)
                                             throws InitException
Load the specified resource from the current class loader. If there is no individual class loader found for this class, use the system class loader instead.

Parameters:
dirname - The resource' location in a directory structure. The method tries both the directory name as is and in capital letters. This turned out to be safer for directories like meta-inf.
filename - The actual resource to load.
Throws:
InitException