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
Modifier and TypeClassDescriptionprotected static enum
-
Field Summary
Modifier and TypeFieldDescriptionprotected Class<?>
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
Fields inherited from class org.apache.openjpa.lib.meta.XMLMetaDataParser
_extendedNamespace, _openjpaNamespace
-
Constructor Summary
ConstructorDescriptionConstructor; supply configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Process all deferred embeddables using an unknown access type.protected void
addDeferredEmbeddableMetaData
(Class<?> embedType, int access) Process all deferred embeddables and embeddable mapping overrides for a given class.void
addToParseList
(Class<?> parentCls) void
addToParseList
(ArrayList<Class<?>> parseList) protected void
protected Class<?>
classForName
(String name) Instantiate the given class, taking into account the default package.protected void
protected Object
Return the current element being parsed.protected Object
Return the tag of the current parent element.protected PersistenceStrategy
Return the currentPersistenceStrategy
if any.protected void
deferEmbeddable
(Class<?> embedType, MetaDataContext fmd) protected void
End a class.protected void
endClassElement
(String name) Override this method marking the end of an element within a declared class.protected void
endClassMapping
(ClassMetaData mapping) Implement to finalize class mapping.protected void
endClassMappingElement
(String name) Implement to parse a mapping element within a class.protected void
protected void
endExtendedClass
(String elem) protected void
endFieldMapping
(FieldMetaData field) Implement to finalize field mapping.protected void
protected void
endId()
protected void
protected void
endLob()
protected void
protected void
protected void
protected void
protected void
protected void
endSystemElement
(String name) Override this method marking the end of an element outside of any package or class.protected void
Implement to parse a mapping element outside of any class.protected void
The annotation parser.protected String
The attribute of the class element that holds the name, or null to use the element text.protected int
The depth of the class element.Configuration supplied on construction.Return the environmental class loader to pass on to parsed metadata instances.boolean
Whether to allow later parses of mapping information to override earlier information for the same class.int
getMode()
The parse mode according to the expected document type.protected String
The attribute of the package element that holds the name, or null to use the element text.Class<?>
Returns the repository for this parser.protected Object
Implement to return the XML schema source for the document.protected boolean
isClassElementName
(String name) The name of the class element.protected boolean
isDeferredEmbeddable
(Class<?> embedType, MetaDataContext fmd) protected boolean
Determines whether the ClassMetaData has been resolved more than once.protected boolean
Determines whether the QueryMetaData has been resolved more than once.protected boolean
Convenience method for interpretinggetMode()
.protected boolean
Returns true if we're in mapping mode or in metadata mode with mapping override enabled.protected boolean
Convenience method for interpretinggetMode()
.protected boolean
Convenience method for interpretinggetMode()
.protected boolean
Return whether we're running the parser at runtime.protected String
normalizeCatalogName
(String catName) protected String
normalizeSchemaName
(String schName) protected String
normalizeSequenceName
(String seqName) void
Parse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.void
Parse the given resource.protected void
parseBasic
(FieldMetaData fmd, Attributes attrs) Parse basic.protected void
parseEagerFetchModeAttr
(FieldMetaData fmd, Attributes attrs) protected void
parseElementClassCriteriaAttr
(FieldMetaData fmd, Attributes attrs) protected void
parseElementCollection
(FieldMetaData fmd, Attributes attrs) protected void
parseEmbedded
(FieldMetaData fmd, Attributes attrs) Parse embedded.boolean
parseListContains
(Class<?> cls) protected void
parseManyToMany
(FieldMetaData fmd, Attributes attrs) Parse many-to-many.protected void
parseManyToOne
(FieldMetaData fmd, Attributes attrs) Parse many-to-one.protected void
parseOneToMany
(FieldMetaData fmd, Attributes attrs) Parse one-to-many.protected void
parseOneToOne
(FieldMetaData fmd, Attributes attrs) Parse one-to-one.protected void
parseStrategy
(FieldMetaData fmd, Attributes attrs) protected Object
Peek a parse element from the stack.protected Object
Pop a parse element from the stack.protected void
pushElement
(Object elem) Push a parse element onto the stack.protected void
reset()
Override this method to clear any state and ready the parser for a new document.void
The annotation parser.protected void
setCascades
(FieldMetaData fmd) Set the cached cascades into the field.protected void
setDeferredEmbeddableAccessType
(Class<?> embedType, int access) void
setEnvClassLoader
(ClassLoader loader) Set the environmental class loader to pass on to parsed metadata instances.void
setMappingOverride
(boolean override) Whether to allow later parses of mapping information to override earlier information for the same class.void
setMode
(int mode) The parse mode according to the expected document type.void
setMode
(int mode, boolean on) The parse mode according to the expected document type.protected void
setOrphanRemoval
(ValueMetaData vmd, boolean orphanRemoval) void
setRepository
(MetaDataRepository repos) Set the metadata repository for this parser.protected boolean
startCascade
(Object tag, Attributes attrs) Lazily parse cascades.protected boolean
startClass
(String elem, Attributes attrs) Start a class.protected boolean
startClassElement
(String name, Attributes attrs) Override this method marking the start of an element within a declared class.protected void
startClassMapping
(ClassMetaData mapping, boolean mappedSuper, Attributes attrs) Implement to add mapping attributes to class.protected Object
startClassMappingElement
(String name, Attributes attrs) Implement to parse a mapping element within a class.protected boolean
protected boolean
startEmbeddedId
(Attributes attrs) Parse embedded-id.protected void
startFieldMapping
(FieldMetaData field, Attributes attrs) Implement to add field mapping data.protected boolean
startGeneratedValue
(Attributes attrs) Parse generated-value.protected boolean
startId
(Attributes attrs) Parse id.protected boolean
startIdClass
(Attributes attrs) Parse id-class.protected boolean
startLob
(Attributes attrs) Parse lob.protected boolean
startNamedNativeQuery
(Attributes attrs) Parse native-named-query.protected boolean
startNamedQuery
(Attributes attrs) Parse named-query.protected boolean
startOrderColumn
(Attributes attrs) protected boolean
startQueryHint
(Attributes attrs) Parse query-hint.protected boolean
startQueryString
(Attributes attrs) protected boolean
startSequenceGenerator
(Attributes attrs) Parse sequence-generator.protected boolean
startSystemElement
(String name, Attributes attrs) Override this method marking the start of an element outside of any package or class.protected Object
startSystemMappingElement
(String name, Attributes attrs) Implement to parse a mapping element outside of any class.protected boolean
startVersion
(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, startPackageElement
Methods 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, startEntity
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
Methods 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:
getRepository
in 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:
setMode
in interfaceAbstractCFMetaDataFactory.Parser
-
parse
Description copied from interface:MetaDataParser
Parse the given resource.- Specified by:
parse
in interfaceMetaDataParser
- Overrides:
parse
in classXMLMetaDataParser
- 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
- Overrides:
parse
in 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 currentPersistenceStrategy
if 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:XMLMetaDataParser
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.
- Overrides:
getSchemaSource
in classXMLMetaDataParser
-
getPackageAttributeName
Description copied from class:CFMetaDataParser
The attribute of the package element that holds the name, or null to use the element text. Defaults to "name".- Overrides:
getPackageAttributeName
in classCFMetaDataParser
-
getClassAttributeName
Description copied from class:CFMetaDataParser
The attribute of the class element that holds the name, or null to use the element text. Defaults to "name".- Overrides:
getClassAttributeName
in classCFMetaDataParser
-
getClassElementDepth
protected int getClassElementDepth()Description copied from class:CFMetaDataParser
The depth of the class element. Defaults to 2.- Overrides:
getClassElementDepth
in classCFMetaDataParser
-
isClassElementName
Description copied from class:CFMetaDataParser
The name of the class element. Defaults to "class".- Overrides:
isClassElementName
in classCFMetaDataParser
-
reset
protected void reset()Description copied from class:CFMetaDataParser
Override this method to clear any state and ready the parser for a new document. Subclasses should callsuper.reset()
to clear superclass state.- Overrides:
reset
in classCFMetaDataParser
-
startSystemElement
Description copied from class:CFMetaDataParser
Override this method marking the start of an element outside of any package or class.- Overrides:
startSystemElement
in classCFMetaDataParser
- Throws:
SAXException
-
endSystemElement
Description copied from class:CFMetaDataParser
Override this method marking the end of an element outside of any package or class.- Overrides:
endSystemElement
in 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:CFMetaDataParser
Override this method marking the start of an element within a declared class.- Overrides:
startClassElement
in classCFMetaDataParser
- Throws:
SAXException
-
endClassElement
Description copied from class:CFMetaDataParser
Override this method marking the end of an element within a declared class.- Overrides:
endClassElement
in 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:CFMetaDataParser
Start a class. Parses out class name by default. Return false to skip class element and its contents.- Overrides:
startClass
in classCFMetaDataParser
- Throws:
SAXException
-
endClass
Description copied from class:CFMetaDataParser
End a class. Parses contained text by default.- Overrides:
endClass
in 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:
clearDeferredMetaData
in 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:
endExtendedClass
in classCFMetaDataParser
- Throws:
SAXException
-