Package org.apache.openjpa.lib.meta
Class XMLMetaDataParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.openjpa.lib.meta.XMLMetaDataParser
-
- All Implemented Interfaces:
MetaDataParser,org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler,org.xml.sax.ext.LexicalHandler
- Direct Known Subclasses:
CFMetaDataParser,PersistenceProductDerivation.ConfigurationParser,XMLSchemaParser,XMLVersionParser
public abstract class XMLMetaDataParser extends org.xml.sax.helpers.DefaultHandler implements org.xml.sax.ext.LexicalHandler, MetaDataParser
Custom SAX parser used by the system to quickly parse metadata files. Subclasses should handle the processing of the content.- Author:
- Abe White
-
-
Field Summary
Fields Modifier and Type Field Description protected int_extendedNamespaceprotected int_openjpaNamespace
-
Constructor Summary
Constructors Constructor Description XMLMetaDataParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddComments(java.lang.Object obj)Add current comments to the given entity.protected voidaddResult(java.lang.Object result)Add a result to be returned from the current parse.voidcharacters(char[] ch, int start, int length)voidclear()Clears the cache of parsed resource names.protected voidclearDeferredMetaData()voidcomment(char[] ch, int start, int length)protected java.lang.ClassLoadercurrentClassLoader()Return the class loader to use when resolving resources and loading classes.protected java.lang.String[]currentComments()Array of comments for the current node, or empty array if none.protected intcurrentDepth()Return the parse depth.protected java.lang.StringcurrentLocation()Return the current location within the source file.protected java.lang.StringcurrentText()Return the text value within the current node.voidendCDATA()voidendDTD()protected abstract voidendElement(java.lang.String name)Override this method marking the end of some element.voidendElement(java.lang.String uri, java.lang.String name, java.lang.String qName)voidendEntity(java.lang.String name)voiderror(org.xml.sax.SAXParseException se)voidfatalError(org.xml.sax.SAXParseException se)protected voidfinish()Override this method to finish up after a parse; this is only called if no errors are encountered during parsing.java.lang.ClassLoadergetClassLoader()Classloader to use for class name resolution.protected java.io.ReadergetDocType()Override this method to return anyDOCTYPEdeclaration that should be dynamically included in xml documents that will be validated.protected org.xml.sax.SAXExceptiongetException(java.lang.String msg)Returns a SAXException with the source file name and the given error message.protected org.xml.sax.SAXExceptiongetException(Localizer.Message msg)Returns a SAXException with the source file name and the given error message.protected org.xml.sax.SAXExceptiongetException(Localizer.Message msg, java.lang.Throwable cause)Returns a SAXException with the source file name and the given error message.org.xml.sax.ext.LexicalHandlergetLexicalHandler()The lexical handler that should be registered with the SAX parser used by this class.LocationgetLocation()The XML document location.LoggetLog()The log to write to.booleangetOverrideContextClassloader()booleangetParseComments()Whether to parse element comments.booleangetParseText()Whether to parse element text.java.util.ListgetResults()Return the results from the last parse.protected java.lang.ObjectgetSchemaSource()Implement to return the XML schema source for the document.protected java.io.FilegetSourceFile()Return the file of the source being parsed.booleangetSourceIsSystemId()Whether to use the source name as the XML system id.protected java.lang.StringgetSourceName()Return the name of the source file being parsed.java.lang.StringgetSuffix()Expected suffix for metadata resources, or null if unknown.protected voidignoreContent(boolean ignoreEnd)Ignore all content below the current element.booleanisCaching()Whether parsed resource names are cached to avoid duplicate parsing.booleanisParsing()booleanisValidating()Whether this is a validating parser.voidparse(java.io.File file)Parse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.voidparse(java.io.Reader xml, java.lang.String sourceName)Parse the metadata in the given reader.voidparse(java.lang.Class cls, boolean topDown)Parse all possible metadata locations for the given class, going top-down or bottom-up.voidparse(java.lang.String rsrc)Parse the given resource.voidparse(java.net.URL url)Parse the given resource.voidparse(MetaDataIterator itr)Parse the metadata supplied by the given iterator.protected booleanparsed(java.lang.String src)Return true if the given source is parsed.protected voidparseNewResource(java.io.Reader xml, java.lang.String sourceName)Parse a previously-unseen source.protected voidreset()Override this method to clear any state and ready the parser for a new document.voidsetCaching(boolean caching)Whether parsed resource names are cached to avoid duplicate parsing.voidsetClassLoader(java.lang.ClassLoader loader)Classloader to use for class name resolution.voidsetDocumentLocator(org.xml.sax.Locator locator)voidsetLexicalHandler(org.xml.sax.ext.LexicalHandler lh)The lexical handler that should be registered with the SAX parser used by this class.voidsetLocation(Location location)The XML document location.voidsetLog(Log log)The log to write to.voidsetOverrideContextClassloader(boolean overrideCCL)voidsetParseComments(boolean comments)Whether to parse element comments.voidsetParseText(boolean text)Whether to parse element text.voidsetParsing(boolean parsing)voidsetSourceIsSystemId(boolean systemId)Whether to use the source name as the XML system id.voidsetSuffix(java.lang.String suffix)Expected suffix for metadata resources, or null if unknown.voidsetValidating(boolean validating)Whether this is a validating parser.voidstartCDATA()voidstartDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)voidstartElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)protected abstract booleanstartElement(java.lang.String name, org.xml.sax.Attributes attrs)Override this method marking the start of some element.voidstartEntity(java.lang.String name)
-
-
-
Method Detail
-
getOverrideContextClassloader
public boolean getOverrideContextClassloader()
-
setOverrideContextClassloader
public void setOverrideContextClassloader(boolean overrideCCL)
-
isParsing
public boolean isParsing()
-
setParsing
public void setParsing(boolean parsing)
-
getParseText
public boolean getParseText()
Whether to parse element text.
-
setParseText
public void setParseText(boolean text)
Whether to parse element text.
-
getParseComments
public boolean getParseComments()
Whether to parse element comments.
-
setParseComments
public void setParseComments(boolean comments)
Whether to parse element comments.
-
getLocation
public Location getLocation()
The XML document location.
-
getLexicalHandler
public org.xml.sax.ext.LexicalHandler getLexicalHandler()
The lexical handler that should be registered with the SAX parser used by this class. Since theorg.xml.sax.extpackage is not a required part of SAX2, this handler might not be used by the parser.
-
setLexicalHandler
public void setLexicalHandler(org.xml.sax.ext.LexicalHandler lh)
The lexical handler that should be registered with the SAX parser used by this class. Since theorg.xml.sax.extpackage is not a required part of SAX2, this handler might not be used by the parser.
-
setLocation
public void setLocation(Location location)
The XML document location.
-
getSourceIsSystemId
public boolean getSourceIsSystemId()
Whether to use the source name as the XML system id.
-
setSourceIsSystemId
public void setSourceIsSystemId(boolean systemId)
Whether to use the source name as the XML system id.
-
isValidating
public boolean isValidating()
Whether this is a validating parser.
-
setValidating
public void setValidating(boolean validating)
Whether this is a validating parser.
-
getSuffix
public java.lang.String getSuffix()
Expected suffix for metadata resources, or null if unknown.
-
setSuffix
public void setSuffix(java.lang.String suffix)
Expected suffix for metadata resources, or null if unknown.
-
isCaching
public boolean isCaching()
Whether parsed resource names are cached to avoid duplicate parsing.
-
setCaching
public void setCaching(boolean caching)
Whether parsed resource names are cached to avoid duplicate parsing.
-
getLog
public Log getLog()
The log to write to.
-
setLog
public void setLog(Log log)
The log to write to.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Classloader to use for class name resolution.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader loader)
Classloader to use for class name resolution.- Specified by:
setClassLoaderin interfaceMetaDataParser
-
getResults
public java.util.List getResults()
Description copied from interface:MetaDataParserReturn the results from the last parse.- Specified by:
getResultsin interfaceMetaDataParser
-
parse
public void parse(java.lang.String rsrc) throws java.io.IOExceptionDescription copied from interface:MetaDataParserParse the given resource.- Specified by:
parsein interfaceMetaDataParser- Throws:
java.io.IOException
-
parse
public void parse(java.net.URL url) throws java.io.IOExceptionDescription copied from interface:MetaDataParserParse the given resource.- Specified by:
parsein interfaceMetaDataParser- Throws:
java.io.IOException
-
parse
public void parse(java.io.File file) throws java.io.IOExceptionDescription copied from interface:MetaDataParserParse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.- Specified by:
parsein interfaceMetaDataParser- Throws:
java.io.IOException
-
parse
public void parse(java.lang.Class cls, boolean topDown) throws java.io.IOExceptionDescription copied from interface:MetaDataParserParse all possible metadata locations for the given class, going top-down or bottom-up. If the class is null, only top-level locations will be parsed.- Specified by:
parsein interfaceMetaDataParser- Throws:
java.io.IOException
-
parse
public void parse(java.io.Reader xml, java.lang.String sourceName) throws java.io.IOExceptionDescription copied from interface:MetaDataParserParse the metadata in the given reader.- Specified by:
parsein interfaceMetaDataParser- Parameters:
xml- reader containing the metadata to parsesourceName- the name of the source being parsed, for use in error messages- Throws:
java.io.IOException
-
parse
public void parse(MetaDataIterator itr) throws java.io.IOException
Description copied from interface:MetaDataParserParse the metadata supplied by the given iterator.- Specified by:
parsein interfaceMetaDataParser- Throws:
java.io.IOException
-
parseNewResource
protected void parseNewResource(java.io.Reader xml, java.lang.String sourceName) throws java.io.IOExceptionParse a previously-unseen source. All parsing methods delegate to this one.- Throws:
java.io.IOException
-
parsed
protected boolean parsed(java.lang.String src)
Return true if the given source is parsed. Otherwise, record that it will be parsed.
-
clear
public void clear()
Description copied from interface:MetaDataParserClears the cache of parsed resource names.- Specified by:
clearin interfaceMetaDataParser
-
error
public void error(org.xml.sax.SAXParseException se) throws org.xml.sax.SAXException- Specified by:
errorin interfaceorg.xml.sax.ErrorHandler- Overrides:
errorin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
fatalError
public void fatalError(org.xml.sax.SAXParseException se) throws org.xml.sax.SAXException- Specified by:
fatalErrorin interfaceorg.xml.sax.ErrorHandler- Overrides:
fatalErrorin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin classorg.xml.sax.helpers.DefaultHandler
-
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:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
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:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length)- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler
-
comment
public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
commentin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXException- Specified by:
startCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXException- Specified by:
endCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startDTD
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException- Specified by:
startDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endDTD
public void endDTD() throws org.xml.sax.SAXException- Specified by:
endDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startEntity
public void startEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
startEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endEntity
public void endEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
endEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startElement
protected abstract boolean startElement(java.lang.String name, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXExceptionOverride this method marking the start of some element. If this method returns false, the content of the element and the end element event will be ignored.- Throws:
org.xml.sax.SAXException
-
endElement
protected abstract void endElement(java.lang.String name) throws org.xml.sax.SAXExceptionOverride this method marking the end of some element.- Throws:
org.xml.sax.SAXException
-
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 callsuper.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 callsuper.reset()to clear superclass state.
-
getSchemaSource
protected java.lang.Object getSchemaSource() throws java.io.IOExceptionImplement to return the XML schema source for the document. Returns null by default. May return:Stringpointing to schema URI.InputStreamcontaining schema contents.InputSourcecontaining schema contents.Filecontaining schema contents.- Array of any of the above elements.
- Throws:
java.io.IOException
-
getDocType
protected java.io.Reader getDocType() throws java.io.IOExceptionOverride this method to return anyDOCTYPEdeclaration that should be dynamically included in xml documents that will be validated. Returns null by default.- Throws:
java.io.IOException
-
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.
-
addComments
protected void addComments(java.lang.Object obj)
Add current comments to the given entity. By default, assumes entity isCommentable.
-
currentComments
protected java.lang.String[] currentComments()
Array of comments for the current node, or empty array if none.
-
currentText
protected java.lang.String currentText()
Return the text value within the current node.
-
currentLocation
protected java.lang.String currentLocation()
Return the current location within the source file.
-
currentDepth
protected int currentDepth()
Return the parse depth. Within the root element, the depth is 0, within the first nested element, it is 1, and so forth.
-
currentClassLoader
protected java.lang.ClassLoader currentClassLoader()
Return the class loader to use when resolving resources and loading classes.
-
ignoreContent
protected void ignoreContent(boolean ignoreEnd)
Ignore all content below the current element.- Parameters:
ignoreEnd- whether to ignore the end element event
-
getException
protected org.xml.sax.SAXException getException(java.lang.String msg)
Returns a SAXException with the source file name and the given error message.
-
getException
protected org.xml.sax.SAXException getException(Localizer.Message msg)
Returns a SAXException with the source file name and the given error message.
-
getException
protected org.xml.sax.SAXException getException(Localizer.Message msg, java.lang.Throwable cause)
Returns a SAXException with the source file name and the given error message.
-
clearDeferredMetaData
protected void clearDeferredMetaData()
-
-