ch.sahits.phpclassgenerator
Class XMLTemplateParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by ch.sahits.phpclassgenerator.XMLTemplateParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XMLTemplateParser
extends org.xml.sax.helpers.DefaultHandler

Parsing of the XML template using a SAX parser

Version:
1.0 $Revision: 1.2 $ changed by $Author: hotzst $ at $Date: 2007/08/18 16:39:05 $
Author:
Andi Hotz, (c) 2007

Field Summary
private  ClassDeclaration _class
           
private  java.lang.String arg
           
private static java.lang.String ARG
           
private static java.lang.String ARGS
           
private static java.lang.String BODY
           
private static java.lang.String DESCRIPTION
           
private static java.lang.String DOCUMENT_START
           
private  java.lang.String documentation
           
private  java.lang.String include
           
private static java.lang.String INCLUDE
           
private static java.lang.String INIT_PK
           
private  java.lang.String member
           
private static java.lang.String MEMBER
           
private static java.lang.String MEMBERS
           
private  MethodDeclaration method
           
private static java.lang.String METHOD
           
private  java.lang.String methodBody
           
private static java.lang.String METHODS
           
private static java.lang.String NAME
           
private  java.util.Stack<java.lang.String> parent
           
private  javax.xml.parsers.SAXParser parser
           
private static java.lang.String STATIC
           
private static java.lang.String VALUE
           
private static java.lang.String VISIBILITY
           
 
Constructor Summary
XMLTemplateParser(java.lang.String templatePath)
          Initialize the Parser and do the work
 
Method Summary
 void characters(char[] ch, int start, int length)
          Handle the text according to the parent tag
private  void completeArgFromAttributes(org.xml.sax.Attributes attr)
          Complete the method arguments from the attributes
private  void completeMethodFromAttributes(org.xml.sax.Attributes attr)
          Complete the method signature with method name visibility and modifier
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 ClassDeclaration getClassDeclaration()
           
private  java.lang.String getMemberFromAttribute(org.xml.sax.Attributes attributes)
          Get the php member declaration from the name and value attribute.
 void ignorableWhitespace(char[] ch, int start, int length)
          Pass throught to characters(char[], int, int) to ensure no whitespaces are ignored
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Event for starting tag
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCUMENT_START

private static final java.lang.String DOCUMENT_START
See Also:
Constant Field Values

INCLUDE

private static final java.lang.String INCLUDE
See Also:
Constant Field Values

MEMBER

private static final java.lang.String MEMBER
See Also:
Constant Field Values

MEMBERS

private static final java.lang.String MEMBERS
See Also:
Constant Field Values

METHOD

private static final java.lang.String METHOD
See Also:
Constant Field Values

METHODS

private static final java.lang.String METHODS
See Also:
Constant Field Values

ARG

private static final java.lang.String ARG
See Also:
Constant Field Values

ARGS

private static final java.lang.String ARGS
See Also:
Constant Field Values

DESCRIPTION

private static final java.lang.String DESCRIPTION
See Also:
Constant Field Values

BODY

private static final java.lang.String BODY
See Also:
Constant Field Values

NAME

private static final java.lang.String NAME
See Also:
Constant Field Values

VALUE

private static final java.lang.String VALUE
See Also:
Constant Field Values

INIT_PK

private static final java.lang.String INIT_PK
See Also:
Constant Field Values

STATIC

private static final java.lang.String STATIC
See Also:
Constant Field Values

VISIBILITY

private static final java.lang.String VISIBILITY
See Also:
Constant Field Values

parent

private java.util.Stack<java.lang.String> parent

parser

private javax.xml.parsers.SAXParser parser

include

private java.lang.String include

member

private java.lang.String member

method

private MethodDeclaration method

documentation

private java.lang.String documentation

methodBody

private java.lang.String methodBody

_class

private ClassDeclaration _class

arg

private java.lang.String arg
Constructor Detail

XMLTemplateParser

public XMLTemplateParser(java.lang.String templatePath)
                  throws org.xml.sax.SAXException,
                         java.io.IOException,
                         javax.xml.parsers.ParserConfigurationException
Initialize the Parser and do the work

Parameters:
templatePath - path to the XML template to be parsed
Throws:
org.xml.sax.SAXException - Something in the parsing is gone wrong
java.io.IOException - The template could not be read
javax.xml.parsers.ParserConfigurationException - Bad configuration of the parser.
Method Detail

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException
See Also:
DefaultHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Event for starting tag

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException
See Also:
DefaultHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

completeArgFromAttributes

private void completeArgFromAttributes(org.xml.sax.Attributes attr)
Complete the method arguments from the attributes

Parameters:
attr -

completeMethodFromAttributes

private void completeMethodFromAttributes(org.xml.sax.Attributes attr)
Complete the method signature with method name visibility and modifier

Parameters:
attr -

getMemberFromAttribute

private java.lang.String getMemberFromAttribute(org.xml.sax.Attributes attributes)
Get the php member declaration from the name and value attribute. The value attribute may be null which means the variable is not initialized.

Parameters:
attributes -
Returns:
php member variable declaration

getClassDeclaration

public ClassDeclaration getClassDeclaration()
Returns:
the _class

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Handle the text according to the parent tag

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException
See Also:
DefaultHandler.characters(char[], int, int)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Pass throught to characters(char[], int, int) to ensure no whitespaces are ignored

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException
See Also:
DefaultHandler.ignorableWhitespace(char[], int, int)