Package org.apache.openjpa.persistence
Class XMLPersistenceMetaDataParser
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.apache.openjpa.lib.meta.XMLMetaDataParser
org.apache.openjpa.lib.meta.CFMetaDataParser
org.apache.openjpa.persistence.XMLPersistenceMetaDataParser
- All Implemented Interfaces:
MetaDataParser,AbstractCFMetaDataFactory.Parser,ContentHandler,DTDHandler,EntityResolver,ErrorHandler,LexicalHandler
- Direct Known Subclasses:
XMLPersistenceMappingParser
public class XMLPersistenceMetaDataParser
extends CFMetaDataParser
implements AbstractCFMetaDataFactory.Parser
Custom SAX parser used by the system to quickly parse persistence
metadata files. This parser may invoke
another parser to scan
source code annotation.
- Author:
- Steve Kim, Pinaki Poddar
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Class<?>protected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringFields inherited from class org.apache.openjpa.lib.meta.XMLMetaDataParser
_extendedNamespace, _openjpaNamespace -
Constructor Summary
ConstructorsConstructorDescriptionConstructor; supply configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidProcess all deferred embeddables using an unknown access type.protected voidaddDeferredEmbeddableMetaData(Class<?> embedType, int access) Process all deferred embeddables and embeddable mapping overrides for a given class.voidaddToParseList(Class<?> parentCls) voidaddToParseList(ArrayList<Class<?>> parseList) protected voidprotected Class<?>classForName(String name) Instantiate the given class, taking into account the default package.protected voidprotected ObjectReturn the current element being parsed.protected ObjectReturn the tag of the current parent element.protected PersistenceStrategyReturn the currentPersistenceStrategyif any.protected voiddeferEmbeddable(Class<?> embedType, MetaDataContext fmd) protected voidEnd a class.protected voidendClassElement(String name) Override this method marking the end of an element within a declared class.protected voidendClassMapping(ClassMetaData mapping) Implement to finalize class mapping.protected voidendClassMappingElement(String name) Implement to parse a mapping element within a class.protected voidprotected voidendExtendedClass(String elem) protected voidendFieldMapping(FieldMetaData field) Implement to finalize field mapping.protected voidprotected voidendId()protected voidprotected voidendLob()protected voidprotected voidprotected voidprotected voidprotected voidprotected voidendSystemElement(String name) Override this method marking the end of an element outside of any package or class.protected voidImplement to parse a mapping element outside of any class.protected voidThe annotation parser.protected StringThe attribute of the class element that holds the name, or null to use the element text.protected intThe depth of the class element.Configuration supplied on construction.Return the environmental class loader to pass on to parsed metadata instances.booleanWhether to allow later parses of mapping information to override earlier information for the same class.intgetMode()The parse mode according to the expected document type.protected StringThe attribute of the package element that holds the name, or null to use the element text.Class<?>Returns the repository for this parser.protected ObjectImplement to return the XML schema source for the document.protected booleanisClassElementName(String name) The name of the class element.protected booleanisDeferredEmbeddable(Class<?> embedType, MetaDataContext fmd) protected booleanDetermines whether the ClassMetaData has been resolved more than once.protected booleanDetermines whether the QueryMetaData has been resolved more than once.protected booleanConvenience method for interpretinggetMode().protected booleanReturns true if we're in mapping mode or in metadata mode with mapping override enabled.protected booleanConvenience method for interpretinggetMode().protected booleanConvenience method for interpretinggetMode().protected booleanReturn whether we're running the parser at runtime.protected StringnormalizeCatalogName(String catName) protected StringnormalizeSchemaName(String schName) protected StringnormalizeSequenceName(String seqName) voidParse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.voidParse the given resource.protected voidparseBasic(FieldMetaData fmd, Attributes attrs) Parse basic.protected voidparseEagerFetchModeAttr(FieldMetaData fmd, Attributes attrs) protected voidparseElementClassCriteriaAttr(FieldMetaData fmd, Attributes attrs) protected voidparseElementCollection(FieldMetaData fmd, Attributes attrs) protected voidparseEmbedded(FieldMetaData fmd, Attributes attrs) Parse embedded.booleanparseListContains(Class<?> cls) protected voidparseManyToMany(FieldMetaData fmd, Attributes attrs) Parse many-to-many.protected voidparseManyToOne(FieldMetaData fmd, Attributes attrs) Parse many-to-one.protected voidparseOneToMany(FieldMetaData fmd, Attributes attrs) Parse one-to-many.protected voidparseOneToOne(FieldMetaData fmd, Attributes attrs) Parse one-to-one.protected voidparseStrategy(FieldMetaData fmd, Attributes attrs) protected ObjectPeek a parse element from the stack.protected ObjectPop a parse element from the stack.protected voidpushElement(Object elem) Push a parse element onto the stack.protected voidreset()Override this method to clear any state and ready the parser for a new document.voidThe annotation parser.protected voidsetCascades(FieldMetaData fmd) Set the cached cascades into the field.protected voidsetDeferredEmbeddableAccessType(Class<?> embedType, int access) voidsetEnvClassLoader(ClassLoader loader) Set the environmental class loader to pass on to parsed metadata instances.voidsetMappingOverride(boolean override) Whether to allow later parses of mapping information to override earlier information for the same class.voidsetMode(int mode) The parse mode according to the expected document type.voidsetMode(int mode, boolean on) The parse mode according to the expected document type.protected voidsetOrphanRemoval(ValueMetaData vmd, boolean orphanRemoval) voidsetRepository(MetaDataRepository repos) Set the metadata repository for this parser.protected booleanstartCascade(Object tag, Attributes attrs) Lazily parse cascades.protected booleanstartClass(String elem, Attributes attrs) Start a class.protected booleanstartClassElement(String name, Attributes attrs) Override this method marking the start of an element within a declared class.protected voidstartClassMapping(ClassMetaData mapping, boolean mappedSuper, Attributes attrs) Implement to add mapping attributes to class.protected ObjectstartClassMappingElement(String name, Attributes attrs) Implement to parse a mapping element within a class.protected booleanprotected booleanstartEmbeddedId(Attributes attrs) Parse embedded-id.protected voidstartFieldMapping(FieldMetaData field, Attributes attrs) Implement to add field mapping data.protected booleanstartGeneratedValue(Attributes attrs) Parse generated-value.protected booleanstartId(Attributes attrs) Parse id.protected booleanstartIdClass(Attributes attrs) Parse id-class.protected booleanstartLob(Attributes attrs) Parse lob.protected booleanstartNamedNativeQuery(Attributes attrs) Parse native-named-query.protected booleanstartNamedQuery(Attributes attrs) Parse named-query.protected booleanstartOrderColumn(Attributes attrs) protected booleanstartQueryHint(Attributes attrs) Parse query-hint.protected booleanstartQueryString(Attributes attrs) protected booleanstartSequenceGenerator(Attributes attrs) Parse sequence-generator.protected booleanstartSystemElement(String name, Attributes attrs) Override this method marking the start of an element outside of any package or class.protected ObjectstartSystemMappingElement(String name, Attributes attrs) Implement to parse a mapping element outside of any class.protected booleanstartVersion(Attributes attrs) Parse version.Methods inherited from class org.apache.openjpa.lib.meta.CFMetaDataParser
classForName, classForName, currentClassName, currentPackage, endElement, endPackage, endPackageElement, getPackageElementDepth, isPackageElementName, startElement, startExtendedClass, startPackage, startPackageElementMethods inherited from class org.apache.openjpa.lib.meta.XMLMetaDataParser
addComments, addResult, characters, clear, comment, currentClassLoader, currentComments, currentDepth, currentLocation, currentText, endCDATA, endDTD, endElement, endEntity, error, fatalError, finish, getClassLoader, getDocType, getException, getException, getException, getLexicalHandler, getLocation, getLog, getOverrideContextClassloader, getParseComments, getParseText, getResults, getSourceFile, getSourceIsSystemId, getSourceName, getSuffix, ignoreContent, isCaching, isParsing, isValidating, parse, parse, parse, parse, parsed, parseNewResource, setCaching, setClassLoader, setDocumentLocator, setLexicalHandler, setLocation, setLog, setOverrideContextClassloader, setParseComments, setParseText, setParsing, setSourceIsSystemId, setSuffix, setValidating, startCDATA, startDTD, startElement, startEntityMethods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.openjpa.lib.meta.MetaDataParser
clear, getResults, parse, parse, parse, parse, setClassLoader
-
Field Details
-
ELEM_PKG
- See Also:
-
ELEM_ACCESS
- See Also:
-
ELEM_ATTRS
- See Also:
-
ELEM_LISTENER
- See Also:
-
ELEM_CASCADE
- See Also:
-
ELEM_CASCADE_ALL
- See Also:
-
ELEM_CASCADE_PER
- See Also:
-
ELEM_CASCADE_MER
- See Also:
-
ELEM_CASCADE_REM
- See Also:
-
ELEM_CASCADE_REF
- See Also:
-
ELEM_CASCADE_DET
- See Also:
-
ELEM_PU_META
- See Also:
-
ELEM_PU_DEF
- See Also:
-
ELEM_XML_MAP_META_COMPLETE
- See Also:
-
ELEM_DELIM_IDS
- See Also:
-
_cls
-
-
Constructor Details
-
XMLPersistenceMetaDataParser
Constructor; supply configuration.
-
-
Method Details
-
getConfiguration
Configuration supplied on construction. -
getAnnotationParser
The annotation parser. When class is discovered in an XML file, we first parse any annotations present, then override with the XML. -
setAnnotationParser
The annotation parser. When class is discovered in an XML file, we first parse any annotations present, then override with the XML. -
getRepository
Returns the repository for this parser. If none has been set, creates a new repository and sets it.- Specified by:
getRepositoryin interfaceAbstractCFMetaDataFactory.Parser
-
setRepository
Set the metadata repository for this parser. -
getEnvClassLoader
Return the environmental class loader to pass on to parsed metadata instances. -
setEnvClassLoader
Set the environmental class loader to pass on to parsed metadata instances. -
getMappingOverride
public boolean getMappingOverride()Whether to allow later parses of mapping information to override earlier information for the same class. Defaults to false. Useful when a tool is mapping a class, so that .jdo file partial mapping information can be used even when mappings are stored in .orm files or other locations. -
setMappingOverride
public void setMappingOverride(boolean override) Whether to allow later parses of mapping information to override earlier information for the same class. Defaults to false. Useful when a tool is mapping a class, so that .jdo file partial mapping information can be used even when mappings are stored in .orm files or other locations. -
getMode
public int getMode()The parse mode according to the expected document type. The mode constants act as bit flags, and therefore can be combined. -
setMode
public void setMode(int mode, boolean on) The parse mode according to the expected document type. -
setMode
public void setMode(int mode) The parse mode according to the expected document type.- Specified by:
setModein interfaceAbstractCFMetaDataFactory.Parser
-
parse
Description copied from interface:MetaDataParserParse the given resource.- Specified by:
parsein interfaceMetaDataParser- Overrides:
parsein classXMLMetaDataParser- 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- Overrides:
parsein classXMLMetaDataParser- Throws:
IOException
-
isMetaDataMode
protected boolean isMetaDataMode()Convenience method for interpretinggetMode(). -
isQueryMode
protected boolean isQueryMode()Convenience method for interpretinggetMode(). -
isMappingMode
protected boolean isMappingMode()Convenience method for interpretinggetMode(). -
isMappingOverrideMode
protected boolean isMappingOverrideMode()Returns true if we're in mapping mode or in metadata mode with mapping override enabled. -
pushElement
Push a parse element onto the stack. -
popElement
Pop a parse element from the stack. -
peekElement
Peek a parse element from the stack. -
currentElement
Return the current element being parsed. May be a class metadata, field metadata, query metadata, etc. -
currentStrategy
Return the currentPersistenceStrategyif any. -
currentParent
Return the tag of the current parent element. -
isRuntime
protected boolean isRuntime()Return whether we're running the parser at runtime. -
getSchemaSource
Description copied from class:XMLMetaDataParserImplement 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.
- Overrides:
getSchemaSourcein classXMLMetaDataParser
-
getPackageAttributeName
Description copied from class:CFMetaDataParserThe attribute of the package element that holds the name, or null to use the element text. Defaults to "name".- Overrides:
getPackageAttributeNamein classCFMetaDataParser
-
getClassAttributeName
Description copied from class:CFMetaDataParserThe attribute of the class element that holds the name, or null to use the element text. Defaults to "name".- Overrides:
getClassAttributeNamein classCFMetaDataParser
-
getClassElementDepth
protected int getClassElementDepth()Description copied from class:CFMetaDataParserThe depth of the class element. Defaults to 2.- Overrides:
getClassElementDepthin classCFMetaDataParser
-
isClassElementName
Description copied from class:CFMetaDataParserThe name of the class element. Defaults to "class".- Overrides:
isClassElementNamein classCFMetaDataParser
-
reset
protected void reset()Description copied from class:CFMetaDataParserOverride this method to clear any state and ready the parser for a new document. Subclasses should callsuper.reset()to clear superclass state.- Overrides:
resetin classCFMetaDataParser
-
startSystemElement
Description copied from class:CFMetaDataParserOverride this method marking the start of an element outside of any package or class.- Overrides:
startSystemElementin classCFMetaDataParser- Throws:
SAXException
-
endSystemElement
Description copied from class:CFMetaDataParserOverride this method marking the end of an element outside of any package or class.- Overrides:
endSystemElementin classCFMetaDataParser- Throws:
SAXException
-
startSystemMappingElement
Implement to parse a mapping element outside of any class.- Returns:
- the tag for the given element, or null to skip the element
- Throws:
SAXException
-
endSystemMappingElement
Implement to parse a mapping element outside of any class.- Throws:
SAXException
-
startClassElement
Description copied from class:CFMetaDataParserOverride this method marking the start of an element within a declared class.- Overrides:
startClassElementin classCFMetaDataParser- Throws:
SAXException
-
endClassElement
Description copied from class:CFMetaDataParserOverride this method marking the end of an element within a declared class.- Overrides:
endClassElementin classCFMetaDataParser- Throws:
SAXException
-
startClassMappingElement
Implement to parse a mapping element within a class.- Returns:
- the tag for the given element, or null to skip element
- Throws:
SAXException
-
endClassMappingElement
Implement to parse a mapping element within a class.- Throws:
SAXException
-
startClass
Description copied from class:CFMetaDataParserStart a class. Parses out class name by default. Return false to skip class element and its contents.- Overrides:
startClassin classCFMetaDataParser- Throws:
SAXException
-
endClass
Description copied from class:CFMetaDataParserEnd a class. Parses contained text by default.- Overrides:
endClassin classCFMetaDataParser- Throws:
SAXException
-
startClassMapping
protected void startClassMapping(ClassMetaData mapping, boolean mappedSuper, Attributes attrs) throws SAXException Implement to add mapping attributes to class.- Throws:
SAXException
-
endClassMapping
Implement to finalize class mapping.- Throws:
SAXException
-
startSequenceGenerator
Parse sequence-generator. -
endSequenceGenerator
protected void endSequenceGenerator() -
startId
Parse id.- Throws:
SAXException
-
endId
- Throws:
SAXException
-
startEmbeddedId
Parse embedded-id.- Throws:
SAXException
-
endEmbeddedId
- Throws:
SAXException
-
startIdClass
Parse id-class.- Throws:
SAXException
-
endIdClass
- Throws:
SAXException
-
startLob
Parse lob.- Throws:
SAXException
-
endLob
- Throws:
SAXException
-
startGeneratedValue
Parse generated-value.- Throws:
SAXException
-
endGeneratedValue
- Throws:
SAXException
-
startCascade
Lazily parse cascades.- Throws:
SAXException
-
setCascades
Set the cached cascades into the field. -
startFieldMapping
Implement to add field mapping data. Does nothing by default.- Throws:
SAXException
-
endFieldMapping
Implement to finalize field mapping. Does nothing by default.- Throws:
SAXException
-
startVersion
Parse version.- Throws:
SAXException
-
endVersion
- Throws:
SAXException
-
parseBasic
Parse basic.- Throws:
SAXException
-
parseEmbedded
Parse embedded.- Throws:
SAXException
-
parseOneToOne
Parse one-to-one.- Throws:
SAXException
-
parseManyToOne
Parse many-to-one.- Throws:
SAXException
-
parseManyToMany
Parse many-to-many.- Throws:
SAXException
-
parseOneToMany
Parse one-to-many.- Throws:
SAXException
-
setOrphanRemoval
-
parseElementCollection
- Throws:
SAXException
-
startNamedQuery
Parse named-query.- Throws:
SAXException
-
endNamedQuery
- Throws:
SAXException
-
startQueryString
- Throws:
SAXException
-
endQueryString
- Throws:
SAXException
-
startQueryHint
Parse query-hint.- Throws:
SAXException
-
endQueryHint
- Throws:
SAXException
-
startNamedNativeQuery
Parse native-named-query.- Throws:
SAXException
-
endNamedNativeQuery
- Throws:
SAXException
-
startOrderColumn
- Throws:
SAXException
-
classForName
Instantiate the given class, taking into account the default package.- Throws:
SAXException
-
addDeferredEmbeddableMetaData
protected void addDeferredEmbeddableMetaData()Process all deferred embeddables using an unknown access type. -
addDeferredEmbeddableMetaData
Process all deferred embeddables and embeddable mapping overrides for a given class. This should only happen after the access type of the embeddable is known.- Parameters:
embedType- embeddable classaccess- class level access for embeddable- Throws:
SAXException
-
setDeferredEmbeddableAccessType
-
clearDeferredMetaData
protected void clearDeferredMetaData()- Overrides:
clearDeferredMetaDatain classXMLMetaDataParser
-
isDeferredEmbeddable
-
deferEmbeddable
-
applyDeferredEmbeddableOverrides
- Throws:
SAXException
-
addToParseList
-
addToParseList
-
parseListContains
-
getParseList
-
getParseClass
-
startDelimitedIdentifiers
protected boolean startDelimitedIdentifiers() -
normalizeSequenceName
-
normalizeSchemaName
-
normalizeCatalogName
-
isDuplicateClass
Determines whether the ClassMetaData has been resolved more than once. Compares the current sourceName and linenumber to the ones used to originally resolve the metadata.- Parameters:
meta- The ClassMetaData to inspect.- Returns:
- true if the source was has already been resolved from a different location. Otherwise return false
-
isDuplicateQuery
Determines whether the QueryMetaData has been resolved more than once.- Parameters:
meta- QueryMetaData that has already been resolved.- Returns:
- true if the QueryMetaData was defined in a different place - e.g. another line in orm.xml.
-
parseStrategy
-
parseElementClassCriteriaAttr
protected void parseElementClassCriteriaAttr(FieldMetaData fmd, Attributes attrs) throws SAXException - Throws:
SAXException
-
parseEagerFetchModeAttr
- Throws:
SAXException
-
endExtendedClass
- Overrides:
endExtendedClassin classCFMetaDataParser- Throws:
SAXException
-