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
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
,LexicalHandler
- Direct Known Subclasses:
CFMetaDataParser
,PersistenceProductDerivation.ConfigurationParser
,XMLSchemaParser
,XMLVersionParser
public abstract class XMLMetaDataParser
extends DefaultHandler
implements 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
Modifier and TypeFieldDescriptionprotected int
protected int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addComments
(Object obj) Add current comments to the given entity.protected void
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 void
void
comment
(char[] ch, int start, int length) protected ClassLoader
Return the class loader to use when resolving resources and loading classes.protected String[]
Array of comments for the current node, or empty array if none.protected int
Return the parse depth.protected String
Return the current location within the source file.protected String
Return the text value within the current node.void
endCDATA()
void
endDTD()
protected abstract void
endElement
(String name) Override this method marking the end of some element.void
endElement
(String uri, String name, String qName) void
void
void
protected void
finish()
Override this method to finish up after a parse; this is only called if no errors are encountered during parsing.Classloader to use for class name resolution.protected Reader
Override this method to return anyDOCTYPE
declaration that should be dynamically included in xml documents that will be validated.protected SAXException
getException
(String msg) Returns a SAXException with the source file name and the given error message.protected SAXException
Returns a SAXException with the source file name and the given error message.protected SAXException
getException
(Localizer.Message msg, Throwable cause) Returns a SAXException with the source file name and the given error message.The lexical handler that should be registered with the SAX parser used by this class.The XML document location.getLog()
The log to write to.boolean
boolean
Whether to parse element comments.boolean
Whether to parse element text.Return the results from the last parse.protected Object
Implement to return the XML schema source for the document.protected File
Return the file of the source being parsed.boolean
Whether to use the source name as the XML system id.protected String
Return the name of the source file being parsed.Expected suffix for metadata resources, or null if unknown.protected void
ignoreContent
(boolean ignoreEnd) Ignore all content below the current element.boolean
Whether parsed resource names are cached to avoid duplicate parsing.boolean
boolean
Whether this is a validating parser.void
Parse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.void
Parse the metadata in the given reader.void
Parse all possible metadata locations for the given class, going top-down or bottom-up.void
Parse the given resource.void
Parse the given resource.void
parse
(MetaDataIterator itr) Parse the metadata supplied by the given iterator.protected boolean
Return true if the given source is parsed.protected void
parseNewResource
(Reader xml, String sourceName) Parse a previously-unseen source.protected void
reset()
Override this method to clear any state and ready the parser for a new document.void
setCaching
(boolean caching) Whether parsed resource names are cached to avoid duplicate parsing.void
setClassLoader
(ClassLoader loader) Classloader to use for class name resolution.void
setDocumentLocator
(Locator locator) void
The lexical handler that should be registered with the SAX parser used by this class.void
setLocation
(Location location) The XML document location.void
The log to write to.void
setOverrideContextClassloader
(boolean overrideCCL) void
setParseComments
(boolean comments) Whether to parse element comments.void
setParseText
(boolean text) Whether to parse element text.void
setParsing
(boolean parsing) void
setSourceIsSystemId
(boolean systemId) Whether to use the source name as the XML system id.void
Expected suffix for metadata resources, or null if unknown.void
setValidating
(boolean validating) Whether this is a validating parser.void
void
void
startElement
(String uri, String name, String qName, Attributes attrs) protected abstract boolean
startElement
(String name, Attributes attrs) Override this method marking the start of some element.void
startEntity
(String name) Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
Field Details
-
_extendedNamespace
protected int _extendedNamespace -
_openjpaNamespace
protected int _openjpaNamespace
-
-
Constructor Details
-
XMLMetaDataParser
public XMLMetaDataParser()
-
-
Method Details
-
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
The XML document location. -
getLexicalHandler
The lexical handler that should be registered with the SAX parser used by this class. Since theorg.xml.sax.ext
package is not a required part of SAX2, this handler might not be used by the parser. -
setLexicalHandler
The lexical handler that should be registered with the SAX parser used by this class. Since theorg.xml.sax.ext
package is not a required part of SAX2, this handler might not be used by the parser. -
setLocation
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
Expected suffix for metadata resources, or null if unknown. -
setSuffix
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
The log to write to. -
setLog
The log to write to. -
getClassLoader
Classloader to use for class name resolution. -
setClassLoader
Classloader to use for class name resolution.- Specified by:
setClassLoader
in interfaceMetaDataParser
-
getResults
Description copied from interface:MetaDataParser
Return the results from the last parse.- Specified by:
getResults
in interfaceMetaDataParser
-
parse
Description copied from interface:MetaDataParser
Parse the given resource.- Specified by:
parse
in interfaceMetaDataParser
- Throws:
IOException
-
parse
Description copied from interface:MetaDataParser
Parse the given resource.- Specified by:
parse
in interfaceMetaDataParser
- Throws:
IOException
-
parse
Description copied from interface:MetaDataParser
Parse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.- Specified by:
parse
in interfaceMetaDataParser
- Throws:
IOException
-
parse
Description copied from interface:MetaDataParser
Parse 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:
parse
in interfaceMetaDataParser
- Throws:
IOException
-
parse
Description copied from interface:MetaDataParser
Parse the metadata in the given reader.- Specified by:
parse
in interfaceMetaDataParser
- Parameters:
xml
- reader containing the metadata to parsesourceName
- the name of the source being parsed, for use in error messages- Throws:
IOException
-
parse
Description copied from interface:MetaDataParser
Parse the metadata supplied by the given iterator.- Specified by:
parse
in interfaceMetaDataParser
- Throws:
IOException
-
parseNewResource
Parse a previously-unseen source. All parsing methods delegate to this one.- Throws:
IOException
-
parsed
Return true if the given source is parsed. Otherwise, record that it will be parsed. -
clear
public void clear()Description copied from interface:MetaDataParser
Clears the cache of parsed resource names.- Specified by:
clear
in interfaceMetaDataParser
-
error
- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classDefaultHandler
- Throws:
SAXException
-
fatalError
- Specified by:
fatalError
in interfaceErrorHandler
- Overrides:
fatalError
in classDefaultHandler
- Throws:
SAXException
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
-
startElement
public void startElement(String uri, String name, String qName, Attributes attrs) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) - Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
-
comment
- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-
startCDATA
- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endCDATA
- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
startDTD
- Specified by:
startDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
endDTD
- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startEntity
- Specified by:
startEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
endEntity
- Specified by:
endEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
startElement
Override 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:
SAXException
-
endElement
Override this method marking the end of some element.- Throws:
SAXException
-
addResult
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
Implement to return the XML schema source for the document. Returns null by default. May return:String
pointing to schema URI.InputStream
containing schema contents.InputSource
containing schema contents.File
containing schema contents.- Array of any of the above elements.
- Throws:
IOException
-
getDocType
Override this method to return anyDOCTYPE
declaration that should be dynamically included in xml documents that will be validated. Returns null by default.- Throws:
IOException
-
getSourceName
Return the name of the source file being parsed. -
getSourceFile
Return the file of the source being parsed. -
addComments
Add current comments to the given entity. By default, assumes entity isCommentable
. -
currentComments
Array of comments for the current node, or empty array if none. -
currentText
Return the text value within the current node. -
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
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
Returns a SAXException with the source file name and the given error message. -
getException
Returns a SAXException with the source file name and the given error message. -
getException
Returns a SAXException with the source file name and the given error message. -
clearDeferredMetaData
protected void clearDeferredMetaData()
-