Package org.apache.openjpa.jdbc.schema
Class XMLSchemaParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.openjpa.lib.meta.XMLMetaDataParser
-
- org.apache.openjpa.jdbc.schema.XMLSchemaParser
-
- All Implemented Interfaces:
SchemaParser,MetaDataParser,ContentHandler,DTDHandler,EntityResolver,ErrorHandler,LexicalHandler
public class XMLSchemaParser extends XMLMetaDataParser implements SchemaParser
Custom SAX parser used to parseSchemaobjects. The parser will place all parsed schemas into the currentSchemaGroup, set via thesetSchemaGroup(org.apache.openjpa.jdbc.schema.SchemaGroup)method. This allows parsing of multiple files into a single schema group. The parser deserializes from the following XML format:
<!ELEMENT schemas (schema)+>Schema parsers are not threadsafe.
<!ELEMENT schema (table|sequence)+>
<!ATTLIST schema name CDATA #IMPLIED>
<!ELEMENT table (column|index|pk|fk|unique)+>
<!ATTLIST table name CDATA #REQUIRED>
<!ELEMENT column EMPTY>
<!ATTLIST column name CDATA #REQUIRED>
<!ATTLIST column type (array|bigint|binary|bit|blob|char|clob |date|decimal|distinct|double|float|integer|java_object |longvarbinary|longvarchar|null|numeric|other|real|ref|smallint|struct |time|timstamp|tinyint|varbinary|varchar) #REQUIRED>
<!ATTLIST column type-name CDATA #IMPLIED>
<!ATTLIST column size CDATA #IMPLIED>
<!ATTLIST column decimal-digits CDATA #IMPLIED>
<!ATTLIST column not-null (true|false) "false">
<!ATTLIST column default CDATA #IMPLIED>
<!ATTLIST column auto-assign (true|false) "false">
<!ELEMENT index (on)*>
<!ATTLIST index name CDATA #REQUIRED>
<!ATTLIST index column CDATA #IMPLIED>
<!ATTLIST index unique (true|false) "false">
<!ELEMENT on EMPTY>
<!ATTLIST on column CDATA #REQUIRED>
<!ELEMENT pk (on)*>
<!ATTLIST pk name CDATA #IMPLIED>
<!ATTLIST pk column CDATA #IMPLIED>
<!ELEMENT fk (join)*>
<!ATTLIST fk name CDATA #IMPLIED>
<!ATTLIST fk deferred (true|false) "false">
<!ATTLIST fk column CDATA #IMPLIED>
<!ATTLIST fk to-table CDATA #REQUIRED>
<!ATTLIST fk delete-action (cascade|default|restrict|none|null) "none">
<!ATTLIST fk update-action (cascade|default|restrict|none|null) "none">
<!ELEMENT unique (on)*>
<!ATTLIST unique name CDATA #IMPLIED>
<!ATTLIST unique column CDATA #IMPLIED>
<!ATTLIST unique deferred (true|false) "false">
<!ELEMENT join EMPTY>
<!ATTLIST join column CDATA #IMPLIED>
<!ATTLIST join value CDATA #IMPLIED>
<!ATTLIST join to-column CDATA #REQUIRED>
<!ELEMENT sequence EMPTY>
<!ATTLIST sequence name CDATA #REQUIRED>
<!ATTLIST sequence initial-value CDATA #IMPLIED>
<!ATTLIST sequence increment CDATA #IMPLIED>
<!ATTLIST sequence allocate CDATA #IMPLIED>
- Author:
- Abe White
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXMLSchemaParser.UniqueInfoUsed to hold unique constraint info before it is resolved.
-
Field Summary
-
Fields inherited from class org.apache.openjpa.lib.meta.XMLMetaDataParser
_extendedNamespace, _openjpaNamespace
-
-
Constructor Summary
Constructors Constructor Description XMLSchemaParser(JDBCConfiguration conf)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidendElement(String name)Override this method marking the end of some element.protected voidfinish()Parse the schema relating to the given class.booleangetDelayConstraintResolve()Delay resolution of foreign key constraints untilSchemaParser.resolveConstraints()is called.protected ReadergetDocType()Override this method to return anyDOCTYPEdeclaration that should be dynamically included in xml documents that will be validated.SchemaGroupgetSchemaGroup()Return the current schema group.protected voidreset()Override this method to clear any state and ready the parser for a new document.voidresolveConstraints()If this parser is in delayed resolve mode, resolve all constraints.voidsetDelayConstraintResolve(boolean delay)Delay resolution of foreign key constraints untilSchemaParser.resolveConstraints()is called.voidsetSchemaGroup(SchemaGroup group)Set the current schema group; this clears all state from the last group.protected booleanstartElement(String name, Attributes attrs)Override this method marking the start of some element.-
Methods inherited from class org.apache.openjpa.lib.meta.XMLMetaDataParser
addComments, addResult, characters, clear, clearDeferredMetaData, comment, currentClassLoader, currentComments, currentDepth, currentLocation, currentText, endCDATA, endDTD, endElement, endEntity, error, fatalError, getClassLoader, getException, getException, getException, getLexicalHandler, getLocation, getLog, getOverrideContextClassloader, getParseComments, getParseText, getResults, getSchemaSource, getSourceFile, getSourceIsSystemId, getSourceName, getSuffix, ignoreContent, isCaching, isParsing, isValidating, parse, parse, 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, parse, parse, setClassLoader
-
-
-
-
Constructor Detail
-
XMLSchemaParser
public XMLSchemaParser(JDBCConfiguration conf)
Constructor. Supply configuration.
-
-
Method Detail
-
getDelayConstraintResolve
public boolean getDelayConstraintResolve()
Description copied from interface:SchemaParserDelay resolution of foreign key constraints untilSchemaParser.resolveConstraints()is called. This allows you to parse multiple resources where a foreign key in one resource might refer to a table in another.- Specified by:
getDelayConstraintResolvein interfaceSchemaParser
-
setDelayConstraintResolve
public void setDelayConstraintResolve(boolean delay)
Description copied from interface:SchemaParserDelay resolution of foreign key constraints untilSchemaParser.resolveConstraints()is called. This allows you to parse multiple resources where a foreign key in one resource might refer to a table in another.- Specified by:
setDelayConstraintResolvein interfaceSchemaParser
-
resolveConstraints
public void resolveConstraints()
Description copied from interface:SchemaParserIf this parser is in delayed resolve mode, resolve all constraints.- Specified by:
resolveConstraintsin interfaceSchemaParser
-
getSchemaGroup
public SchemaGroup getSchemaGroup()
Description copied from interface:SchemaParserReturn the current schema group.- Specified by:
getSchemaGroupin interfaceSchemaParser
-
setSchemaGroup
public void setSchemaGroup(SchemaGroup group)
Description copied from interface:SchemaParserSet the current schema group; this clears all state from the last group.- Specified by:
setSchemaGroupin interfaceSchemaParser
-
finish
protected void finish()
Parse the schema relating to the given class. The schemas will be added to the current schema group.- Overrides:
finishin classXMLMetaDataParser
-
reset
protected void reset()
Description copied from class:XMLMetaDataParserOverride this method to clear any state and ready the parser for a new document. Subclasses should callsuper.reset()to clear superclass state.- Overrides:
resetin classXMLMetaDataParser
-
getDocType
protected Reader getDocType() throws IOException
Description copied from class:XMLMetaDataParserOverride this method to return anyDOCTYPEdeclaration that should be dynamically included in xml documents that will be validated. Returns null by default.- Overrides:
getDocTypein classXMLMetaDataParser- Throws:
IOException
-
startElement
protected boolean startElement(String name, Attributes attrs) throws SAXException
Description copied from class:XMLMetaDataParserOverride 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.- Specified by:
startElementin classXMLMetaDataParser- Throws:
SAXException
-
endElement
protected void endElement(String name)
Description copied from class:XMLMetaDataParserOverride this method marking the end of some element.- Specified by:
endElementin classXMLMetaDataParser
-
-