org.apache.torque.engine.database.transform
Class XmlToAppData

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.torque.engine.database.transform.XmlToAppData
All Implemented Interfaces:
DatabaseParser, ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class XmlToAppData
extends DefaultHandler
implements DatabaseParser

A Class that is used to parse an input xml schema file and creates a Database java structure.

Version:
$Id: XmlToAppData.java,v 1.1 2007-10-21 07:57:26 abyrne Exp $
Author:
Leon Messerschmidt, Jason van Zyl, Martin Poeschl, Daniel Rall, Thomas Fischer,
Nested Class Summary
private static class XmlToAppData.ParseStackElement
          When parsing multiple files that use nested tags we need to use a stack to remember some values.
 
Field Summary
private  Vector alreadyReadFiles
          remember all files we have already parsed to detect looping.
private  Column currColumn
           
private  String currentPackage
           
private  String currentXmlFile
           
private  ForeignKey currFK
           
private  Index currIndex
           
private  Table currTable
           
private  Unique currUnique
           
private  Database database
           
private  String defaultPackage
           
private  boolean firstPass
           
private  boolean isExternalSchema
           
private static org.apache.commons.logging.Log log
          Logging class from commons.logging
private  Stack parsingStack
          this is the stack to store parsing data
private static SAXParserFactory saxFactory
           
 
Constructor Summary
XmlToAppData(String databaseType)
          Creates a new instance for the specified database type.
XmlToAppData(String databaseType, String defaultPackage)
          Creates a new instance for the specified database type.
 
Method Summary
 void endElement(String uri, String localName, String rawName)
          Handles closing elements of the xml file.
 void error(SAXParseException e)
          Handles exception which occur when the xml file is parsed
 Database parseResource(String xmlFile)
          Parses a XML input file and returns a newly created and populated Database structure.
 InputSource resolveEntity(String publicId, String systemId)
          EntityResolver implementation.
 void setOption(Attributes attributes)
           
 void startElement(String uri, String localName, String rawName, Attributes attributes)
          Handles opening elements of the xml file.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, 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

log

private static org.apache.commons.logging.Log log
Logging class from commons.logging


database

private Database database

currTable

private Table currTable

currColumn

private Column currColumn

currFK

private ForeignKey currFK

currIndex

private Index currIndex

currUnique

private Unique currUnique

firstPass

private boolean firstPass

isExternalSchema

private boolean isExternalSchema

currentPackage

private String currentPackage

currentXmlFile

private String currentXmlFile

defaultPackage

private String defaultPackage

saxFactory

private static SAXParserFactory saxFactory

alreadyReadFiles

private Vector alreadyReadFiles
remember all files we have already parsed to detect looping.


parsingStack

private Stack parsingStack
this is the stack to store parsing data

Constructor Detail

XmlToAppData

public XmlToAppData(String databaseType)
Creates a new instance for the specified database type.

Parameters:
databaseType - The type of database for the application.

XmlToAppData

public XmlToAppData(String databaseType,
                    String defaultPackage)
Creates a new instance for the specified database type.

Parameters:
databaseType - The type of database for the application.
defaultPackage - the default java package used for the om
Method Detail

parseResource

public Database parseResource(String xmlFile)
                       throws EngineException
Parses a XML input file and returns a newly created and populated Database structure.

Specified by:
parseResource in interface DatabaseParser
Parameters:
xmlFile - The input file to parse.
Returns:
Database populated by xmlFile.
Throws:
EngineException

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException
EntityResolver implementation. Called by the XML parser

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class DefaultHandler
Parameters:
publicId - The public identifier of the external entity
systemId - The system identifier of the external entity
Returns:
an InputSource for the database.dtd file
Throws:
SAXException
See Also:
DTDResolver.resolveEntity(String, String)

startElement

public void startElement(String uri,
                         String localName,
                         String rawName,
                         Attributes attributes)
                  throws SAXException
Handles opening elements of the xml file.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Parameters:
uri -
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
rawName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The specified or defaulted attributes
Throws:
SAXException

endElement

public void endElement(String uri,
                       String localName,
                       String rawName)
                throws SAXException
Handles closing elements of the xml file.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Parameters:
uri -
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
rawName - The qualified name (with prefix), or the empty string if qualified names are not available.
Throws:
SAXException

setOption

public void setOption(Attributes attributes)

error

public void error(SAXParseException e)
           throws SAXException
Handles exception which occur when the xml file is parsed

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Parameters:
e - the exception which occured while parsing
Throws:
SAXException - always


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.