ch.sahits.codegen.input
Class XMLJDomParser

java.lang.Object
  extended by ch.sahits.codegen.input.XMLJDomParser
Direct Known Subclasses:
WebserviceParser, WSDLParser, XHTMLModelParser, XMLParserWithoutDB, XMLTableParser

public class XMLJDomParser
extends java.lang.Object

This XML parser is based on JDom. This is a basic parser that only retrieves the parser class. This class is intended to be extended by the parser class.

Since:
0.9.3
Author:
Andi Hotz

Field Summary
protected  Document document
          This is the document representation of the XML file
protected  Element root
          This is the root tag of the XML document
 
Constructor Summary
XMLJDomParser()
          Default constructor
XMLJDomParser(java.lang.String inputFile)
          Initialize the parser with the input file
 
Method Summary
 java.util.List<Attribute> getAllAttributes(Element e)
          Retrieve all attributes of an Element
 java.util.List<Element> getAllElements(java.lang.String elementName)
          Retrieve all elements elementName in the XML document.
 java.lang.String getAttributeValue(Element e, java.lang.String attributName)
          Retrieve the attribute value for the attributeattributeName
 java.lang.String getFileExtension()
          This parser parses XML files
 Element getFirstElement(java.lang.String elementName)
          Retrieve the first element elementName in the XML document.
 java.lang.String getParserName()
          Retrieve the fully qualified class name of the parser that is specified in the XML tag <modelgenerator>.
protected  Content getPredecessor(Element elem)
          Retrieve the predecessor of an element
 int getRanking()
          The ranking for xml input parsers is ignored since each xml file must specify the parser
 boolean hasChild(Element elem)
          Check whether an element has at least one child
 boolean hasChild(Element elem, java.lang.String childName)
          Check whether an element has at least on child of a given name
 boolean hasText(Element elem)
          Check whether the element has textual value
 void init(java.lang.String inputFile)
          Initialize the parser
protected  java.util.List<Element> lookup(Element parent, java.lang.String elementName)
          Find all elements with the name elementName that are children to parent or the parent itself
 IGeneratedObject parse()
          This method is depricated use the appropriate generateModel method instead.
 void setNamespace(java.lang.String namespace)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

document

protected Document document
This is the document representation of the XML file


root

protected Element root
This is the root tag of the XML document

Constructor Detail

XMLJDomParser

public XMLJDomParser(java.lang.String inputFile)
              throws JDOMException,
                     java.io.IOException
Initialize the parser with the input file

Parameters:
inputFile - input XML file
Throws:
java.io.IOException
JDOMException

XMLJDomParser

public XMLJDomParser()
Default constructor

Method Detail

init

public void init(java.lang.String inputFile)
          throws java.lang.Exception
Initialize the parser

Parameters:
inputFile - Input parser
Throws:
java.lang.Exception - one of the following
JDOMException - Could not create a SAX parser
java.io.IOException - Could not read from input file
java.net.MalformedURLException - malformed input file

getParserName

public java.lang.String getParserName()
Retrieve the fully qualified class name of the parser that is specified in the XML tag <modelgenerator>.

Returns:
fully classified class name

getFirstElement

public final Element getFirstElement(java.lang.String elementName)
Retrieve the first element elementName in the XML document. This neglects the structure of the document. All tags are searched recursively from the root tag.

Parameters:
elementName - name of the XML tag
Returns:
Element that matches the elementName or null if no element was found

getAllElements

public final java.util.List<Element> getAllElements(java.lang.String elementName)
Retrieve all elements elementName in the XML document. This neglects the structure of the document. All tags are searched recursievly from the root tag.

Parameters:
elementName - name of the XML tag
Returns:
List of Element that matches the elementName or empty list if no element was found

getAttributeValue

public final java.lang.String getAttributeValue(Element e,
                                                java.lang.String attributName)
Retrieve the attribute value for the attributeattributeName

Parameters:
e - Element of the Attribute
attributName - name of the attribute
Returns:
Value of the attribute or null if the attribute was not found

getAllAttributes

public final java.util.List<Attribute> getAllAttributes(Element e)
Retrieve all attributes of an Element

Parameters:
e - Element of the Attributes
Returns:
List of Attributes or empty list if no attributes were found

lookup

protected final java.util.List<Element> lookup(Element parent,
                                               java.lang.String elementName)
Find all elements with the name elementName that are children to parent or the parent itself

Parameters:
parent - Element to start the lookup
elementName - name of the element
Returns:
List of Elements or empty List if no elements where found

hasText

public final boolean hasText(Element elem)
Check whether the element has textual value

Parameters:
elem - Element to be checked
Returns:
true if the element contains text (not recursive)
Since:
0.9.4

hasChild

public final boolean hasChild(Element elem)
Check whether an element has at least one child

Parameters:
elem - element to be checked
Returns:
true if at least on child is found
Since:
0.9.4

hasChild

public final boolean hasChild(Element elem,
                              java.lang.String childName)
Check whether an element has at least on child of a given name

Parameters:
elem - element to be checked
childName - type of the child
Returns:
true if on child was found
Since:
0.9.4

setNamespace

public final void setNamespace(java.lang.String namespace)
Parameters:
namespace - the namespace to set
Since:
0.9.4

getPredecessor

protected final Content getPredecessor(Element elem)
Retrieve the predecessor of an element

Parameters:
elem - whose predecessor is searched
Returns:
predecessor of elem or null if elem is the first child of the parent. The predecessor is of type Content

getFileExtension

public java.lang.String getFileExtension()
This parser parses XML files

Returns:
xml

parse

public IGeneratedObject parse()
This method is depricated use the appropriate generateModel method instead.

Returns:
null

getRanking

public int getRanking()
The ranking for xml input parsers is ignored since each xml file must specify the parser

Returns:
0