SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

com.solarmetric.rd.meta
Class XMLMetaDataParser

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--com.solarmetric.rd.meta.XMLMetaDataParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, MetaDataParser
Direct Known Subclasses:
CFMetaDataParser, XMLSchemaParser

public abstract class XMLMetaDataParser
extends org.xml.sax.helpers.DefaultHandler
implements MetaDataParser

Custom SAX parser used by the system to quickly parse metadata files. Subclasses should handle the processing of the metadata content.


Constructor Summary
XMLMetaDataParser()
           
 
Method Summary
protected  void addResult(java.lang.Object result)
          Add a result to be returned from the current parse.
 void characters(char[] ch, int start, int length)
           
 void clear()
          Clears the cache of parsed resource names.
protected  java.lang.ClassLoader currentClassLoader()
          Return the class loader to use when resolving resources and loading classes.
protected abstract  void endElement(java.lang.String name)
          Override this method marking the end of some element.
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
           
 void error(org.xml.sax.SAXParseException se)
           
 void fatalError(org.xml.sax.SAXParseException se)
           
 java.net.URL findMetaData(java.lang.Class type)
          Find the metadata resource for the given class.
protected  void finish()
          Override this method to finish up after a parse; this is only called if no errors are encountered during parsing.
 java.lang.ClassLoader getClassLoader()
          Return the class loader set for loading related types.
protected  java.lang.String getCurrentLocation()
           
protected  java.io.Reader getDocType()
          Override this method to return any DOCTYPE declaration that should be dynamically included in xml documents that will be validated.
protected abstract  java.lang.String getExtension()
          Override this method to return the extension used for metadata resources.
 com.solarmetric.rd.meta.Location getLocation()
           
 org.apache.commons.logging.Log getLog()
          Return the log to write to.
 java.util.Collection getResults()
          Return the results from the last parse.
protected  java.io.File getSourceFile()
          Return the file of the source being parsed.
protected  java.lang.String getSourceName()
          Return the name of the source file being parsed.
protected  java.lang.String getText()
          Return the text value within the current node.
 boolean isValidating()
          Return true if this is a validating parser, false otherwise.
 void parse(java.lang.Class type)
          Parse the metadata for the given type.
 void parse(java.io.File file)
          Parse the metadata for the given file.
 void parse(java.io.Reader xml, java.lang.String sourceName)
          Parse the metadata in the given reader.
 void parse(java.net.URL url)
          Parse the metadata for the given URL.
protected  void reset()
          Override this method to clear any state and ready the parser for a new document.
 void setClassLoader(java.lang.ClassLoader loader)
          Set the class loader to use for loading related types.
 void setDocumentLocator(org.xml.sax.Locator loc)
           
 void setLocation(com.solarmetric.rd.meta.Location location)
           
 void setLog(org.apache.commons.logging.Log log)
          Set the log to write to.
 void setValidating(boolean validating)
          Set whether or not the parser should validate.
protected abstract  void startElement(java.lang.String name, org.xml.sax.Attributes attrs)
          Override this method marking the start of some element.
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)
           
protected  void throwException(java.lang.String msg)
          Throws a SAXException with the source file name and the given error message.
protected  void throwException(java.lang.String msg, java.lang.Exception cause)
          Throws a SAXException with the source file name and the given error message.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLMetaDataParser

public XMLMetaDataParser()
Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the class loader set for loading related types. Note that during parsing, subclasses should use the currentClassLoader() method, which will default to the current thread's context loader if no class loader has been set.


setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Set the class loader to use for loading related types.


currentClassLoader

protected java.lang.ClassLoader currentClassLoader()
Return the class loader to use when resolving resources and loading classes.


isValidating

public boolean isValidating()
Description copied from interface: MetaDataParser
Return true if this is a validating parser, false otherwise.

Specified by:
isValidating in interface MetaDataParser

setValidating

public void setValidating(boolean validating)
Description copied from interface: MetaDataParser
Set whether or not the parser should validate.

Specified by:
setValidating in interface MetaDataParser

getLog

public org.apache.commons.logging.Log getLog()
Description copied from interface: MetaDataParser
Return the log to write to.

Specified by:
getLog in interface MetaDataParser

setLog

public void setLog(org.apache.commons.logging.Log log)
Description copied from interface: MetaDataParser
Set the log to write to.

Specified by:
setLog in interface MetaDataParser

getResults

public java.util.Collection getResults()
Description copied from interface: MetaDataParser
Return the results from the last parse.

Specified by:
getResults in interface MetaDataParser

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator loc)
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class org.xml.sax.helpers.DefaultHandler

getLocation

public com.solarmetric.rd.meta.Location getLocation()

setLocation

public void setLocation(com.solarmetric.rd.meta.Location location)

findMetaData

public java.net.URL findMetaData(java.lang.Class type)
Find the metadata resource for the given class. This does not guarantee that the returned resource includes the class metadata, only that it should include the metadata if the class has any. The resource is located using the set class loader, or if none is set then the class loader of the given class. The resource is first looked for as [class-name].[extension], then, for each token of the class' package, the resource is looked for as [package-name].[extension], then ../[package-name].[extension], then package.[extension]. Thus package-level metadata can include the information for all sub-package as well. Finally, the parser looks for a top-level [product-name].[extension] resource.

Specified by:
findMetaData in interface MetaDataParser

parse

public void parse(java.lang.Class type)
           throws java.io.IOException
Description copied from interface: MetaDataParser
Parse the metadata for the given type.

Specified by:
parse in interface MetaDataParser
java.io.IOException
See Also:
MetaDataParser.findMetaData(java.lang.Class)

parse

public void parse(java.net.URL url)
           throws java.io.IOException
Description copied from interface: MetaDataParser
Parse the metadata for the given URL.

Specified by:
parse in interface MetaDataParser
java.io.IOException
See Also:
MetaDataParser.parse(Class)

parse

public void parse(java.io.File file)
           throws java.io.IOException
Description copied from interface: MetaDataParser
Parse the metadata for the given file.

Specified by:
parse in interface MetaDataParser
java.io.IOException
See Also:
MetaDataParser.parse(Class)

parse

public void parse(java.io.Reader xml,
                  java.lang.String sourceName)
           throws java.io.IOException
Description copied from interface: MetaDataParser
Parse the metadata in the given reader. Subclasses who wish to override the standard parsing behavior can use this method, as the other parse methods all call it for parsing.

Specified by:
parse in interface MetaDataParser
Parameters:
xml - reader containing the metadata to parse
sourceName - the name of the source being parsed, for use in error messages
java.io.IOException
See Also:
MetaDataParser.parse(Class)

clear

public void clear()
Description copied from interface: MetaDataParser
Clears the cache of parsed resource names. If this method is not called, attempting to parse a resource that has already been seen by the parser will always return no results.

Specified by:
clear in interface MetaDataParser

error

public void error(org.xml.sax.SAXParseException se)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException se)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       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
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

startElement

protected abstract void startElement(java.lang.String name,
                                     org.xml.sax.Attributes attrs)
                              throws org.xml.sax.SAXException
Override this method marking the start of some element.

org.xml.sax.SAXException

endElement

protected abstract void endElement(java.lang.String name)
                            throws org.xml.sax.SAXException
Override this method marking the end of some element.

org.xml.sax.SAXException

getExtension

protected abstract java.lang.String getExtension()
Override this method to return the extension used for metadata resources.


addResult

protected void addResult(java.lang.Object result)
Add a result to be returned from the current parse.


finish

protected void finish()
Override this method to finish up after a parse; this is only called if no errors are encountered during parsing. Subclasses should call super.finish () to resolve superclass state.


reset

protected void reset()
Override this method to clear any state and ready the parser for a new document. Subclasses should call super.reset () to clear superclass state.


getDocType

protected java.io.Reader getDocType()
                             throws java.io.IOException
Override this method to return any DOCTYPE declaration that should be dynamically included in xml documents that will be validated. Returns null by default.

java.io.IOException

getText

protected java.lang.String getText()
Return the text value within the current node.


getSourceName

protected java.lang.String getSourceName()
Return the name of the source file being parsed.


getSourceFile

protected java.io.File getSourceFile()
Return the file of the source being parsed.


getCurrentLocation

protected java.lang.String getCurrentLocation()

throwException

protected void throwException(java.lang.String msg)
                       throws org.xml.sax.SAXException
Throws a SAXException with the source file name and the given error message.

org.xml.sax.SAXException

throwException

protected void throwException(java.lang.String msg,
                              java.lang.Exception cause)
                       throws org.xml.sax.SAXException
Throws a SAXException with the source file name and the given error message.

org.xml.sax.SAXException

SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.