org.datanucleus.metadata.xml
Class AbstractMetaDataHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.datanucleus.metadata.xml.AbstractMetaDataHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
JDOMetaDataHandler, PersistenceFileMetaDataHandler

public class AbstractMetaDataHandler
extends org.xml.sax.helpers.DefaultHandler

Abstract handler for MetaData parsing. Should be extended to handle processing of specific types of metadata.


Field Summary
protected  java.lang.StringBuffer charactersBuffer
          parser buffer
protected  org.xml.sax.EntityResolver entityResolver
          Entity Resolver to use (if required)
protected  java.lang.String filename
          Filename for the parsed file.
protected static Localiser LOCALISER
          Localiser for messages.
protected  MetaData metadata
          The MetaData for this file (the end result of the parse process.
protected  MetaDataManager mgr
          Manager for the MetaData.
protected  java.util.Stack stack
          Stack of meta-data elements.
 
Constructor Summary
AbstractMetaDataHandler(MetaDataManager mgr, java.lang.String filename, org.xml.sax.EntityResolver resolver)
          Constructor.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Notification handler for the "body" data inside an element.
 void error(org.xml.sax.SAXParseException e)
          Parser error method.
protected  java.lang.String getAttr(org.xml.sax.Attributes attrs, java.lang.String key)
          Accessor for an attribute out of the attributes for an element.
protected  java.lang.String getAttr(org.xml.sax.Attributes attrs, java.lang.String key, java.lang.String defaultValue)
          Accessor for an attribute out of the attributes for an element.
 MetaData getMetaData()
          Accessor for the MetaData for this file.
protected  MetaData getStack()
          Accessor for the current MetaData component.
 java.lang.String getString()
          Accessor for the "body" text metadata.
protected  MetaData popStack()
          Method to remove the current MetaData component from the Stack.
protected  void pushStack(MetaData md)
          Method to add a MetaData component to the Stack.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Method to resolve XML entities.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endElement, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static Localiser LOCALISER
Localiser for messages.


mgr

protected final MetaDataManager mgr
Manager for the MetaData.


filename

protected final java.lang.String filename
Filename for the parsed file.


metadata

protected MetaData metadata
The MetaData for this file (the end result of the parse process.


entityResolver

protected final org.xml.sax.EntityResolver entityResolver
Entity Resolver to use (if required)


charactersBuffer

protected java.lang.StringBuffer charactersBuffer
parser buffer


stack

protected java.util.Stack stack
Stack of meta-data elements. The top of the stack is always the element being process at the moment. The elements are not the XML Element type but are things like ClassMetaData, PackageMetaData etc.

Constructor Detail

AbstractMetaDataHandler

public AbstractMetaDataHandler(MetaDataManager mgr,
                               java.lang.String filename,
                               org.xml.sax.EntityResolver resolver)
Constructor.

Parameters:
mgr - Manager for the MetaData
filename - The filename
resolver - Entity Resolver to use (null if not available)
Method Detail

getMetaData

public MetaData getMetaData()
Accessor for the MetaData for this file.

Returns:
The MetaData.

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Parser error method. If any syntactical errors are encountered on validation they will appear here and be logged as warnings. Just points the user to the line/column of their Meta-Data file for now.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - Parse Exception
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.error(org.xml.sax.SAXParseException)

getAttr

protected java.lang.String getAttr(org.xml.sax.Attributes attrs,
                                   java.lang.String key,
                                   java.lang.String defaultValue)
Accessor for an attribute out of the attributes for an element. Allows the specification of a default if no value is provided.

Parameters:
attrs - The attributes
key - Key for the attribute to return
defaultValue - A default to impose if no value.
Returns:
Value for the attribute with the specified key.

getAttr

protected java.lang.String getAttr(org.xml.sax.Attributes attrs,
                                   java.lang.String key)
Accessor for an attribute out of the attributes for an element.

Parameters:
attrs - The attributes
key - Key for the attribute to return
Returns:
Value for the attribute with the specified key.

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException
Method to resolve XML entities. Uses the entity resolver (if provided) to check for local variants.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
Parameters:
publicId - The public id.
systemId - The system id.
Returns:
Input Source for the URI.
Throws:
org.xml.sax.SAXException
See Also:
EntityResolver.resolveEntity(java.lang.String,java.lang.String)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Notification handler for the "body" data inside an element.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The characters
start - The start position in the character array.
length - The length of the string.
Throws:
org.xml.sax.SAXException - in parsing errors

getString

public java.lang.String getString()
Accessor for the "body" text metadata. Resets the body text after access.

Returns:
the string form of this metadata

getStack

protected MetaData getStack()
Accessor for the current MetaData component.

Returns:
The current MetaData component.

popStack

protected MetaData popStack()
Method to remove the current MetaData component from the Stack.

Returns:
Latest MetaData component.

pushStack

protected void pushStack(MetaData md)
Method to add a MetaData component to the Stack.

Parameters:
md - The component to add.


Copyright © 2009. All Rights Reserved.