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
FieldsModifier and TypeFieldDescriptionprotected intprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddComments(Object obj) Add current comments to the given entity.protected voidAdd 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 voidvoidcomment(char[] ch, int start, int length) protected ClassLoaderReturn 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 intReturn the parse depth.protected StringReturn the current location within the source file.protected StringReturn the text value within the current node.voidendCDATA()voidendDTD()protected abstract voidendElement(String name) Override this method marking the end of some element.voidendElement(String uri, String name, String qName) voidvoidvoidprotected voidfinish()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 ReaderOverride this method to return anyDOCTYPEdeclaration that should be dynamically included in xml documents that will be validated.protected SAXExceptiongetException(String msg) Returns a SAXException with the source file name and the given error message.protected SAXExceptionReturns a SAXException with the source file name and the given error message.protected SAXExceptiongetException(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.booleanbooleanWhether to parse element comments.booleanWhether to parse element text.Return the results from the last parse.protected ObjectImplement to return the XML schema source for the document.protected FileReturn the file of the source being parsed.booleanWhether to use the source name as the XML system id.protected StringReturn the name of the source file being parsed.Expected suffix for metadata resources, or null if unknown.protected voidignoreContent(boolean ignoreEnd) Ignore all content below the current element.booleanWhether parsed resource names are cached to avoid duplicate parsing.booleanbooleanWhether this is a validating parser.voidParse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.voidParse the metadata in the given reader.voidParse all possible metadata locations for the given class, going top-down or bottom-up.voidParse the given resource.voidParse the given resource.voidparse(MetaDataIterator itr) Parse the metadata supplied by the given iterator.protected booleanReturn true if the given source is parsed.protected voidparseNewResource(Reader xml, 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(ClassLoader loader) Classloader to use for class name resolution.voidsetDocumentLocator(Locator locator) voidThe lexical handler that should be registered with the SAX parser used by this class.voidsetLocation(Location location) The XML document location.voidThe 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.voidExpected suffix for metadata resources, or null if unknown.voidsetValidating(boolean validating) Whether this is a validating parser.voidvoidvoidstartElement(String uri, String name, String qName, Attributes attrs) protected abstract booleanstartElement(String name, Attributes attrs) Override this method marking the start of some element.voidstartEntity(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.extpackage 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.extpackage 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:
setClassLoaderin interfaceMetaDataParser
-
getResults
Description copied from interface:MetaDataParserReturn the results from the last parse.- Specified by:
getResultsin interfaceMetaDataParser
-
parse
Description copied from interface:MetaDataParserParse the given resource.- Specified by:
parsein interfaceMetaDataParser- Throws:
IOException
-
parse
Description copied from interface:MetaDataParserParse the given resource.- Specified by:
parsein interfaceMetaDataParser- Throws:
IOException
-
parse
Description 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:
IOException
-
parse
Description 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:
IOException
-
parse
Description 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:
IOException
-
parse
Description copied from interface:MetaDataParserParse the metadata supplied by the given iterator.- Specified by:
parsein 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:MetaDataParserClears the cache of parsed resource names.- Specified by:
clearin interfaceMetaDataParser
-
error
- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classDefaultHandler- Throws:
SAXException
-
fatalError
- Specified by:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin classDefaultHandler- Throws:
SAXException
-
setDocumentLocator
- Specified by:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler
-
startElement
public void startElement(String uri, String name, String qName, Attributes attrs) throws SAXException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) - Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler
-
comment
- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException
-
startCDATA
- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException
-
endCDATA
- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException
-
startDTD
- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException
-
startEntity
- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException
-
endEntity
- Specified by:
endEntityin 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:Stringpointing to schema URI.InputStreamcontaining schema contents.InputSourcecontaining schema contents.Filecontaining schema contents.- Array of any of the above elements.
- Throws:
IOException
-
getDocType
Override this method to return anyDOCTYPEdeclaration 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()
-