org.apache.openjpa.persistence
Class XMLPersistenceMetaDataParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.openjpa.lib.meta.XMLMetaDataParser
          extended by org.apache.openjpa.lib.meta.CFMetaDataParser
              extended by 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 i metadata files.

Author:
Steve Kim

Field Summary
protected static String ELEM_ACCESS
           
protected static String ELEM_ATTRS
           
protected static String ELEM_CASCADE
           
protected static String ELEM_CASCADE_ALL
           
protected static String ELEM_CASCADE_MER
           
protected static String ELEM_CASCADE_PER
           
protected static String ELEM_CASCADE_REF
           
protected static String ELEM_CASCADE_REM
           
protected static String ELEM_LISTENER
           
protected static String ELEM_PKG
           
protected static String ELEM_PU_DEF
           
protected static String ELEM_PU_META
           
protected static String ELEM_XML_MAP_META_COMPLETE
           
 
Constructor Summary
XMLPersistenceMetaDataParser(OpenJPAConfiguration conf)
          Constructor; supply configuration.
 
Method Summary
protected  Class classForName(String name)
          Instantiate the given class, taking into account the default package.
protected  Object currentElement()
          Return the current element being parsed.
protected  Object currentParent()
          Return the tag of the current parent element.
protected  PersistenceStrategy currentStrategy()
          Return the current PersistenceStrategy if any.
protected  void endClass(String elem)
          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 endEmbeddedId()
           
protected  void endFieldMapping(FieldMetaData field)
          Implement to finalize field mapping.
protected  void endGeneratedValue()
           
protected  void endId()
           
protected  void endIdClass()
           
protected  void endLob()
           
protected  void endNamedNativeQuery()
           
protected  void endNamedQuery()
           
protected  void endQueryHint()
           
protected  void endQueryString()
           
protected  void endSequenceGenerator()
           
protected  void endSystemElement(String name)
          Override this method marking the end of an element outside of any package or class.
protected  void endSystemMappingElement(String name)
          Implement to parse a mapping element outside of any class.
protected  void endVersion()
           
 AnnotationPersistenceMetaDataParser getAnnotationParser()
          The annotation parser.
protected  String getClassAttributeName()
          The attribute of the class element that holds the name, or null to use the element text.
protected  int getClassElementDepth()
          The depth of the class element.
 OpenJPAConfiguration getConfiguration()
          Configuration supplied on construction.
 ClassLoader getEnvClassLoader()
          Return the environmental class loader to pass on to parsed metadata instances.
 boolean getMappingOverride()
          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 getPackageAttributeName()
          The attribute of the package element that holds the name, or null to use the element text.
 MetaDataRepository getRepository()
          Returns the repository for this parser.
protected  Object getSchemaSource()
          Implement to return the XML schema source for the document.
protected  boolean isClassElementName(String name)
          The name of the class element.
protected  boolean isMappingMode()
          Convenience method for interpreting getMode().
protected  boolean isMappingOverrideMode()
          Returns true if we're in mapping mode or in metadata mode with mapping override enabled.
protected  boolean isMetaDataMode()
          Convenience method for interpreting getMode().
protected  boolean isQueryMode()
          Convenience method for interpreting getMode().
protected  boolean isRuntime()
          Return whether we're running the parser at runtime.
protected  void parseBasic(FieldMetaData fmd, Attributes attrs)
          Parse basic.
protected  void parseEmbedded(FieldMetaData fmd, Attributes attrs)
          Parse embedded.
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  Object popElement()
          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 setAnnotationParser(AnnotationPersistenceMetaDataParser parser)
          The annotation parser.
protected  void setCascades(FieldMetaData fmd)
          Set the cached cascades into the field.
 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.
 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 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 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, 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, getParseComments, getParseText, getResults, getSourceFile, getSourceIsSystemId, getSourceName, getSuffix, ignoreContent, isCaching, isValidating, parse, parse, parse, parse, parse, parse, parsed, parseNewResource, setCaching, setClassLoader, setDocumentLocator, setLexicalHandler, setLocation, setLog, setParseComments, setParseText, 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, parse, parse, setClassLoader
 

Field Detail

ELEM_PKG

protected static final String ELEM_PKG
See Also:
Constant Field Values

ELEM_ACCESS

protected static final String ELEM_ACCESS
See Also:
Constant Field Values

ELEM_ATTRS

protected static final String ELEM_ATTRS
See Also:
Constant Field Values

ELEM_LISTENER

protected static final String ELEM_LISTENER
See Also:
Constant Field Values

ELEM_CASCADE

protected static final String ELEM_CASCADE
See Also:
Constant Field Values

ELEM_CASCADE_ALL

protected static final String ELEM_CASCADE_ALL
See Also:
Constant Field Values

ELEM_CASCADE_PER

protected static final String ELEM_CASCADE_PER
See Also:
Constant Field Values

ELEM_CASCADE_MER

protected static final String ELEM_CASCADE_MER
See Also:
Constant Field Values

ELEM_CASCADE_REM

protected static final String ELEM_CASCADE_REM
See Also:
Constant Field Values

ELEM_CASCADE_REF

protected static final String ELEM_CASCADE_REF
See Also:
Constant Field Values

ELEM_PU_META

protected static final String ELEM_PU_META
See Also:
Constant Field Values

ELEM_PU_DEF

protected static final String ELEM_PU_DEF
See Also:
Constant Field Values

ELEM_XML_MAP_META_COMPLETE

protected static final String ELEM_XML_MAP_META_COMPLETE
See Also:
Constant Field Values
Constructor Detail

XMLPersistenceMetaDataParser

public XMLPersistenceMetaDataParser(OpenJPAConfiguration conf)
Constructor; supply configuration.

Method Detail

getConfiguration

public OpenJPAConfiguration getConfiguration()
Configuration supplied on construction.


getAnnotationParser

public AnnotationPersistenceMetaDataParser getAnnotationParser()
The annotation parser. When class is discovered in an XML file, we first parse any annotations present, then override with the XML.


setAnnotationParser

public void setAnnotationParser(AnnotationPersistenceMetaDataParser parser)
The annotation parser. When class is discovered in an XML file, we first parse any annotations present, then override with the XML.


getRepository

public MetaDataRepository getRepository()
Returns the repository for this parser. If none has been set, creates a new repository and sets it.

Specified by:
getRepository in interface AbstractCFMetaDataFactory.Parser

setRepository

public void setRepository(MetaDataRepository repos)
Set the metadata repository for this parser.


getEnvClassLoader

public ClassLoader getEnvClassLoader()
Return the environmental class loader to pass on to parsed metadata instances.


setEnvClassLoader

public void setEnvClassLoader(ClassLoader loader)
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 interface AbstractCFMetaDataFactory.Parser

isMetaDataMode

protected boolean isMetaDataMode()
Convenience method for interpreting getMode().


isQueryMode

protected boolean isQueryMode()
Convenience method for interpreting getMode().


isMappingMode

protected boolean isMappingMode()
Convenience method for interpreting getMode().


isMappingOverrideMode

protected boolean isMappingOverrideMode()
Returns true if we're in mapping mode or in metadata mode with mapping override enabled.


pushElement

protected void pushElement(Object elem)
Push a parse element onto the stack.


popElement

protected Object popElement()
Pop a parse element from the stack.


currentElement

protected Object currentElement()
Return the current element being parsed. May be a class metadata, field metadata, query metadata, etc.


currentStrategy

protected PersistenceStrategy currentStrategy()
Return the current PersistenceStrategy if any.


currentParent

protected Object currentParent()
Return the tag of the current parent element.


isRuntime

protected boolean isRuntime()
Return whether we're running the parser at runtime.


getSchemaSource

protected Object getSchemaSource()
Description copied from class: XMLMetaDataParser
Implement to return the XML schema source for the document. Returns null by default. May return:

Overrides:
getSchemaSource in class XMLMetaDataParser

getPackageAttributeName

protected String 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 class CFMetaDataParser

getClassAttributeName

protected String 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 class CFMetaDataParser

getClassElementDepth

protected int getClassElementDepth()
Description copied from class: CFMetaDataParser
The depth of the class element. Defaults to 2.

Overrides:
getClassElementDepth in class CFMetaDataParser

isClassElementName

protected boolean isClassElementName(String name)
Description copied from class: CFMetaDataParser
The name of the class element. Defaults to "class".

Overrides:
isClassElementName in class CFMetaDataParser

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 call super.reset() to clear superclass state.

Overrides:
reset in class CFMetaDataParser

startSystemElement

protected boolean startSystemElement(String name,
                                     Attributes attrs)
                              throws SAXException
Description copied from class: CFMetaDataParser
Override this method marking the start of an element outside of any package or class.

Overrides:
startSystemElement in class CFMetaDataParser
Throws:
SAXException

endSystemElement

protected void endSystemElement(String name)
                         throws SAXException
Description copied from class: CFMetaDataParser
Override this method marking the end of an element outside of any package or class.

Overrides:
endSystemElement in class CFMetaDataParser
Throws:
SAXException

startSystemMappingElement

protected Object startSystemMappingElement(String name,
                                           Attributes attrs)
                                    throws SAXException
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

protected void endSystemMappingElement(String name)
                                throws SAXException
Implement to parse a mapping element outside of any class.

Throws:
SAXException

startClassElement

protected boolean startClassElement(String name,
                                    Attributes attrs)
                             throws SAXException
Description copied from class: CFMetaDataParser
Override this method marking the start of an element within a declared class.

Overrides:
startClassElement in class CFMetaDataParser
Throws:
SAXException

endClassElement

protected void endClassElement(String name)
                        throws SAXException
Description copied from class: CFMetaDataParser
Override this method marking the end of an element within a declared class.

Overrides:
endClassElement in class CFMetaDataParser
Throws:
SAXException

startClassMappingElement

protected Object startClassMappingElement(String name,
                                          Attributes attrs)
                                   throws SAXException
Implement to parse a mapping element within a class.

Returns:
the tag for the given element, or null to skip element
Throws:
SAXException

endClassMappingElement

protected void endClassMappingElement(String name)
                               throws SAXException
Implement to parse a mapping element within a class.

Throws:
SAXException

startClass

protected boolean startClass(String elem,
                             Attributes attrs)
                      throws SAXException
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 class CFMetaDataParser
Throws:
SAXException

endClass

protected void endClass(String elem)
                 throws SAXException
Description copied from class: CFMetaDataParser
End a class. Parses contained text by default.

Overrides:
endClass in class CFMetaDataParser
Throws:
SAXException

startClassMapping

protected void startClassMapping(ClassMetaData mapping,
                                 boolean mappedSuper,
                                 Attributes attrs)
                          throws SAXException
Implement to add mapping attributes to class.

Throws:
SAXException

endClassMapping

protected void endClassMapping(ClassMetaData mapping)
                        throws SAXException
Implement to finalize class mapping.

Throws:
SAXException

startSequenceGenerator

protected boolean startSequenceGenerator(Attributes attrs)
Parse sequence-generator.


endSequenceGenerator

protected void endSequenceGenerator()

startId

protected boolean startId(Attributes attrs)
                   throws SAXException
Parse id.

Throws:
SAXException

endId

protected void endId()
              throws SAXException
Throws:
SAXException

startEmbeddedId

protected boolean startEmbeddedId(Attributes attrs)
                           throws SAXException
Parse embedded-id.

Throws:
SAXException

endEmbeddedId

protected void endEmbeddedId()
                      throws SAXException
Throws:
SAXException

startIdClass

protected boolean startIdClass(Attributes attrs)
                        throws SAXException
Parse id-class.

Throws:
SAXException

endIdClass

protected void endIdClass()
                   throws SAXException
Throws:
SAXException

startLob

protected boolean startLob(Attributes attrs)
                    throws SAXException
Parse lob.

Throws:
SAXException

endLob

protected void endLob()
               throws SAXException
Throws:
SAXException

startGeneratedValue

protected boolean startGeneratedValue(Attributes attrs)
                               throws SAXException
Parse generated-value.

Throws:
SAXException

endGeneratedValue

protected void endGeneratedValue()
                          throws SAXException
Throws:
SAXException

startCascade

protected boolean startCascade(Object tag,
                               Attributes attrs)
                        throws SAXException
Lazily parse cascades.

Throws:
SAXException

setCascades

protected void setCascades(FieldMetaData fmd)
Set the cached cascades into the field.


startFieldMapping

protected void startFieldMapping(FieldMetaData field,
                                 Attributes attrs)
                          throws SAXException
Implement to add field mapping data. Does nothing by default.

Throws:
SAXException

endFieldMapping

protected void endFieldMapping(FieldMetaData field)
                        throws SAXException
Implement to finalize field mapping. Does nothing by default.

Throws:
SAXException

startVersion

protected boolean startVersion(Attributes attrs)
                        throws SAXException
Parse version.

Throws:
SAXException

endVersion

protected void endVersion()
                   throws SAXException
Throws:
SAXException

parseBasic

protected void parseBasic(FieldMetaData fmd,
                          Attributes attrs)
                   throws SAXException
Parse basic.

Throws:
SAXException

parseEmbedded

protected void parseEmbedded(FieldMetaData fmd,
                             Attributes attrs)
                      throws SAXException
Parse embedded.

Throws:
SAXException

parseOneToOne

protected void parseOneToOne(FieldMetaData fmd,
                             Attributes attrs)
                      throws SAXException
Parse one-to-one.

Throws:
SAXException

parseManyToOne

protected void parseManyToOne(FieldMetaData fmd,
                              Attributes attrs)
                       throws SAXException
Parse many-to-one.

Throws:
SAXException

parseManyToMany

protected void parseManyToMany(FieldMetaData fmd,
                               Attributes attrs)
                        throws SAXException
Parse many-to-many.

Throws:
SAXException

parseOneToMany

protected void parseOneToMany(FieldMetaData fmd,
                              Attributes attrs)
                       throws SAXException
Parse one-to-many.

Throws:
SAXException

startNamedQuery

protected boolean startNamedQuery(Attributes attrs)
                           throws SAXException
Parse named-query.

Throws:
SAXException

endNamedQuery

protected void endNamedQuery()
                      throws SAXException
Throws:
SAXException

startQueryString

protected boolean startQueryString(Attributes attrs)
                            throws SAXException
Throws:
SAXException

endQueryString

protected void endQueryString()
                       throws SAXException
Throws:
SAXException

startQueryHint

protected boolean startQueryHint(Attributes attrs)
                          throws SAXException
Parse query-hint.

Throws:
SAXException

endQueryHint

protected void endQueryHint()
                     throws SAXException
Throws:
SAXException

startNamedNativeQuery

protected boolean startNamedNativeQuery(Attributes attrs)
                                 throws SAXException
Parse native-named-query.

Throws:
SAXException

endNamedNativeQuery

protected void endNamedNativeQuery()
                            throws SAXException
Throws:
SAXException

classForName

protected Class classForName(String name)
                      throws SAXException
Instantiate the given class, taking into account the default package.

Throws:
SAXException


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.