org.argouml.persistence
Class SAXParserBase

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byorg.argouml.persistence.SAXParserBase
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
ArgoParser, TodoParser

public abstract class SAXParserBase
extends DefaultHandler


Field Summary
protected static boolean DBG
          Switching this to true gives some extra logging messages.
private static XMLElement[] elements
          This acts as a stack of elements.
private static XMLElement[] freeElements
          This acts as a stack of elements.
private static Logger LOG
          Logger.
private static int nElements
          The number of items actually in use on the elements stack.
private static int nFreeElements
           
private static long parseTime
           
private static String RETURNSTRING
           
private static boolean stats
           
 
Constructor Summary
SAXParserBase()
          The constructor.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
private  XMLElement createXmlElement(String name, Attributes atts)
          Factory method to return an XMLElement.
 void endElement(String uri, String localname, String name)
           
 String getJarResource(String cls)
           
 long getParseTime()
           
 boolean getStats()
           
protected abstract  void handleEndElement(XMLElement e)
          Implement in the concrete class to handle reaching the end tag of an element of interest.
protected abstract  void handleStartElement(XMLElement e)
          Implement in the concrete class to handle reaching the start tag of an element of interest.
 void ignoreElement(XMLElement e)
           
protected  boolean isElementOfInterest(String name)
          Determine if an element of the given name is of interest to the parser.
 void notImplemented(XMLElement e)
           
 void parse(InputStream is)
           
 InputSource resolveEntity(String publicId, String systemId)
           
 void setStats(boolean s)
           
 void startElement(String uri, String localname, String name, Attributes atts)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG
Logger.


RETURNSTRING

private static final String RETURNSTRING
See Also:
Constant Field Values

DBG

protected static final boolean DBG
Switching this to true gives some extra logging messages.

See Also:
Constant Field Values

elements

private static XMLElement[] elements
This acts as a stack of elements. startElement places an item on the stack end endElement removes it.


nElements

private static int nElements
The number of items actually in use on the elements stack.


freeElements

private static XMLElement[] freeElements
This acts as a stack of elements. startElement places an item on the stack end endElement removes it.


nFreeElements

private static int nFreeElements

stats

private static boolean stats

parseTime

private static long parseTime
Constructor Detail

SAXParserBase

public SAXParserBase()
The constructor.

Method Detail

setStats

public void setStats(boolean s)
Parameters:
s - true if statistics have to be shown

getStats

public boolean getStats()
Returns:
true if statistics have to be shown

getParseTime

public long getParseTime()
Returns:
the parsing time

parse

public void parse(InputStream is)
           throws SAXException
Parameters:
is - the inputstream of the project to read
Throws:
SAXException - when parsing xml

handleStartElement

protected abstract void handleStartElement(XMLElement e)
                                    throws SAXException
Implement in the concrete class to handle reaching the start tag of an element of interest.

Parameters:
e - the element.
Throws:
SAXException - on any error parsing the element.

handleEndElement

protected abstract void handleEndElement(XMLElement e)
                                  throws SAXException
Implement in the concrete class to handle reaching the end tag of an element of interest.

Parameters:
e - the element.
Throws:
SAXException - on any error parsing the element.

startElement

public void startElement(String uri,
                         String localname,
                         String name,
                         Attributes atts)
                  throws SAXException
Throws:
SAXException
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

createXmlElement

private XMLElement createXmlElement(String name,
                                    Attributes atts)
Factory method to return an XMLElement. This will reuse previously created elements when possible.

Parameters:
name - The element name.
atts - The element attributes.
Returns:
the element.

endElement

public void endElement(String uri,
                       String localname,
                       String name)
                throws SAXException
Throws:
SAXException
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

isElementOfInterest

protected boolean isElementOfInterest(String name)
Determine if an element of the given name is of interest to the parser. The base implementation assumes always true.

Parameters:
name - the element name.
Returns:
true if the element name is of interest.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Throws:
SAXException
See Also:
ContentHandler.characters(char[], int, int)

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException
Throws:
SAXException
See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)

getJarResource

public String getJarResource(String cls)
Parameters:
cls - the class
Returns:
the jar

ignoreElement

public void ignoreElement(XMLElement e)
Parameters:
e - the element

notImplemented

public void notImplemented(XMLElement e)
Parameters:
e - the element


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook