org.montsuqi.monsia
Class AbstractDocumentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.montsuqi.monsia.AbstractDocumentHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
Glade1Handler, MonsiaHandler

abstract class AbstractDocumentHandler
extends org.xml.sax.helpers.DefaultHandler

Abstract base class for Glade1Handler and MonsiaHandler.

Thid document parser runs as a state transition machine. Subclass must instantiate ParserState instances for each element to make this work.


Field Summary
protected  java.util.List accels
           
protected  java.lang.StringBuffer content
           
(package private)  ParserState FINISH
          A ParserState instance that represents that parsing is end.
protected static Logger logger
           
protected  ParserState prevState
           
protected  java.util.Map properties
           
protected  java.lang.String propertyName
           
protected  PropertyType propertyType
           
protected  java.util.List signals
           
protected  ParserState startState
           
protected  ParserState state
           
protected  java.util.List topLevels
           
protected  ParserState UNKNOWN
          A ParserState instance that represents the "UNKNOWN" state.
protected  int unknownDepth
           
protected  WidgetInfo widget
           
protected  int widgetDepth
           
protected  java.util.Map widgets
           
 
Constructor Summary
AbstractDocumentHandler()
          Constructs and initializes the instance.
 
Method Summary
 void characters(char[] chars, int start, int length)
          A SAX hander called on character chunks.
protected  void clearContent()
          Empties the content buffer.
protected  void dialogHack(WidgetInfo info)
          Replace className in a WidgetInfo to "Dialog" if it is a dialog.
 void endDocument()
          SAX handler called at te end of a document.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          SAX handler called at the end of an element.
 void error(org.xml.sax.SAXParseException e)
           
 void fatalError(org.xml.sax.SAXParseException e)
           
protected  void flushAccels()
          Assigns pending accel info to current WidgetInfo.
protected  void flushProperties()
          Assigns pending properties to the appropriate variable depending on current value of propertyType.
protected  void flushSignals()
          Assigns pending signal info to current WidgetInfo.
protected  Interface getInterface(Protocol protocol)
          Builds the interface as the result of parsing.
protected  boolean isFinished()
          Tests if the parsing has ended.
protected  int keyCode(java.lang.String keyName)
          Converts symbolic key names to AWT key code.
protected  java.lang.String makePropertyName(java.lang.String name)
          Returns a string all dashes in given name replaced to underscores.
protected  int parseButtonMask(java.lang.String mask)
          Converts button mask to integer.
protected  int parseModifiers(java.lang.String modifierValue)
          Converts a set of symbolic modifier names to an integer.
protected abstract  boolean shouldAppendCharactersToContent()
          Tests if current characters should be appended to the content.
 void startDocument()
          SAX handler called at the start of a document.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs)
          SAX handler called at the start of an element.
 void warning(org.xml.sax.SAXParseException e)
           
protected  void warnMissingAttribute(java.lang.String element)
          Warning helper method that warns that some attributes are missing.
protected  void warnNotSupported(java.lang.String value)
          Warning helper method that warns about an attribute alue which is not supported in Java.
protected  void warnNotZero(java.lang.String name, int actual)
          Warning helper method that warns about an attribute which should be zero but not.
protected  void warnUnexpectedElement(java.lang.String outer, java.lang.String inner)
          Warning helper method that warns unexpected element nesting is found.
protected  void warnUnknownAttribute(java.lang.String element, java.lang.String attr)
          Warning helper method that warns about an unknown attribute.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Logger logger

content

protected final java.lang.StringBuffer content

widgets

protected final java.util.Map widgets

topLevels

protected final java.util.List topLevels

properties

protected final java.util.Map properties

signals

protected final java.util.List signals

accels

protected final java.util.List accels

state

protected ParserState state

prevState

protected ParserState prevState

startState

protected ParserState startState

unknownDepth

protected int unknownDepth

widgetDepth

protected int widgetDepth

widget

protected WidgetInfo widget

propertyName

protected java.lang.String propertyName

propertyType

protected PropertyType propertyType

UNKNOWN

protected final ParserState UNKNOWN

A ParserState instance that represents the "UNKNOWN" state.

Parser starts parsing at this state.

Parser transits to this state when it detects an unknown element.


FINISH

final ParserState FINISH

A ParserState instance that represents that parsing is end.

Constructor Detail

AbstractDocumentHandler

public AbstractDocumentHandler()

Constructs and initializes the instance.

Method Detail

shouldAppendCharactersToContent

protected abstract boolean shouldAppendCharactersToContent()

Tests if current characters should be appended to the content.

Returns:
true if current characters are part of the con.tent. false otherwise.

isFinished

protected boolean isFinished()

Tests if the parsing has ended.

Returns:
true if parsing has ended(end tag for the root element is found). false otherwise.

clearContent

protected void clearContent()

Empties the content buffer.


warnNotZero

protected void warnNotZero(java.lang.String name,
                           int actual)

Warning helper method that warns about an attribute which should be zero but not.

Parameters:
name - an attribute that is expected to be zero.
actual - the attribute's actual value.

warnUnknownAttribute

protected void warnUnknownAttribute(java.lang.String element,
                                    java.lang.String attr)

Warning helper method that warns about an unknown attribute.

Parameters:
element - the element interested.
attr - an attribute detected but unknown.

warnMissingAttribute

protected void warnMissingAttribute(java.lang.String element)

Warning helper method that warns that some attributes are missing.

Parameters:
element - the element interested.

warnUnexpectedElement

protected void warnUnexpectedElement(java.lang.String outer,
                                     java.lang.String inner)

Warning helper method that warns unexpected element nesting is found.

Parameters:
outer - the outer method who does not expect the inner method.
inner - the inner method who is not expected to be a child of outer.

warnNotSupported

protected void warnNotSupported(java.lang.String value)

Warning helper method that warns about an attribute alue which is not supported in Java.

Parameters:
value - the unsupported value name.

getInterface

protected Interface getInterface(Protocol protocol)

Builds the interface as the result of parsing.

Parameters:
protocol - the protocol used for event binding(connecting).
Returns:
the Interface instance.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException

SAX handler called at the start of a document.

Initializes parser state and variables.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException

SAX handler called at te end of a document.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException

SAX handler called at the start of an element.This method delegates its work to current state's startElement.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException

SAX handler called at the end of an element.

This method delegates its work to current state's endElement.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

flushProperties

protected void flushProperties()

Assigns pending properties to the appropriate variable depending on current value of propertyType.


dialogHack

protected void dialogHack(WidgetInfo info)

Replace className in a WidgetInfo to "Dialog" if it is a dialog.

Since Gtk+ treats a Dialog as a kind of Window while Swing treats these two in different way, this hack is required.

Parameters:
info - the WidgetInfo interested.

flushSignals

protected void flushSignals()

Assigns pending signal info to current WidgetInfo.


flushAccels

protected void flushAccels()

Assigns pending accel info to current WidgetInfo.


keyCode

protected int keyCode(java.lang.String keyName)

Converts symbolic key names to AWT key code.

Parameters:
keyName - Key name
Returns:
key code

parseModifiers

protected int parseModifiers(java.lang.String modifierValue)

Converts a set of symbolic modifier names to an integer.

Parameters:
modifierValue - symbolic modifier names. Multiple modifiers can be OR-ed with | operator.
Returns:
algebraically or-ed modifier masks.

parseButtonMask

protected int parseButtonMask(java.lang.String mask)

Converts button mask to integer.

Parameters:
mask - a button mask
Returns:
integer value of the button mask.

makePropertyName

protected java.lang.String makePropertyName(java.lang.String name)

Returns a string all dashes in given name replaced to underscores.

Parameters:
name - dash-separated-parameter-name.
Returns:
underscore_separated_parameter_name.

characters

public void characters(char[] chars,
                       int start,
                       int length)
                throws org.xml.sax.SAXException

A SAX hander called on character chunks.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException