gate.creole
Class CreoleXmlHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by gate.creole.CreoleXmlHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class CreoleXmlHandler
extends DefaultHandler

This is a SAX handler for processing creole.xml files. It would have been better to write it using DOM or JDOM but.... Resource data objects are created and added to the CREOLE register. URLs for resource JAR files are added to the GATE class loader.


Field Summary
private  SimpleErrorHandler _seh
          This object indicates what to do when the parser encounts an error
private  StringBuffer contentBuffer
          This is used to capture all data within two tags before calling the actual characters method
private  Stack contentStack
          A stack to stuff PCDATA onto for reading back at element ends.
private  URL creoleFileUrl
          The URL to the creole.xml file being parsed.
private  Attributes currentAttributes
          The current element's attribute list
private  FeatureMap currentAutoinstanceParams
          This field represents the params map required for autoinstantiation Its a map from param name to param value.
private  List currentAutoinstances
          This field holds autoinstanceParams describing the resource that needs to be instantiated
private  Parameter currentParam
          The current parameter
private  SortedMap<Integer,List<Parameter>> currentParamDisjunction
          The current parameter disjunction.
private  ParameterList currentParamList
          The current parameter list
private static boolean DEBUG
          Debug flag
private  boolean readCharacterStatus
          This is a variable that shows if characters have been read
private  CreoleRegister register
          The register object that we add ResourceData objects to during parsing.
private  ResourceData resourceData
          The current resource data object
private  URL sourceUrl
          The source URL of the directory file being parsed.
 
Constructor Summary
CreoleXmlHandler(CreoleRegister register, URL directoryUrl, URL creoleFileUrl)
          Construction
 
Method Summary
private  String attributes2String(Attributes atts)
          A verboase method for Attributes
 void characters(char[] text, int start, int length)
          Called when the SAX parser encounts text (PCDATA) in the XML doc
 void charactersAction(char[] text, int start, int length)
          This method is called when all characters between specific tags have been read completely
private  void checkStack(String methodName, String elementName)
          Utility function to throw exceptions on stack errors.
protected  List<Parameter> currentFlattenedDisjunction()
          Flatten the currentParamDisjunction map into a single list ordered by priority.
 void endDocument()
          Called when the SAX parser encounts the end of the XML document
 void endElement(String uri, String qName, String elementName)
          Called when the SAX parser encounts the end of an XML element.
 void error(SAXParseException ex)
          Called for parse errors.
 void fatalError(SAXParseException ex)
          Called for fatal errors.
 void ignorableWhitespace(char[] ch, int start, int length)
          Called when the SAX parser encounts white space
 void startDocument()
          Called when the SAX parser encounts the beginning of the XML document
 void startElement(String uri, String qName, String elementName, Attributes atts)
          Called when the SAX parser encounts the beginning of an XML element
 void warning(SAXParseException ex)
          Called for warnings.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, 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

contentStack

private Stack contentStack
A stack to stuff PCDATA onto for reading back at element ends. (Probably redundant to have a stack as we only push one item onto it. Probably. Ok, so I should check, but a) it works, b) I'm bald already and c) life is short.)


resourceData

private ResourceData resourceData
The current resource data object


currentParamList

private ParameterList currentParamList
The current parameter list


currentParamDisjunction

private SortedMap<Integer,List<Parameter>> currentParamDisjunction
The current parameter disjunction. This is a map where each key is a "priority" and the value is a list of parameters tagged with that priority. This map is flattened into a single list when all the parameters in a single disjunction have been processed, such that parameters with a smaller priority value are listed ahead of those with a larger value, and those with no explicit priority are listed last of all. Parameters at the same priority are listed in document order. This is not so useful when writing creole.xml files by hand but is necessary to ensure a predictable order when using CreoleParameter annotations. The GATE developer GUI offers the first listed (i.e. highest priority) parameter for each disjunction as the default option in the resource parameters dialog box.


currentParam

private Parameter currentParam
The current parameter


currentAttributes

private Attributes currentAttributes
The current element's attribute list


DEBUG

private static final boolean DEBUG
Debug flag

See Also:
Constant Field Values

sourceUrl

private URL sourceUrl
The source URL of the directory file being parsed.


creoleFileUrl

private URL creoleFileUrl
The URL to the creole.xml file being parsed.


_seh

private SimpleErrorHandler _seh
This object indicates what to do when the parser encounts an error


currentAutoinstanceParams

private FeatureMap currentAutoinstanceParams
This field represents the params map required for autoinstantiation Its a map from param name to param value.


currentAutoinstances

private List currentAutoinstances
This field holds autoinstanceParams describing the resource that needs to be instantiated


contentBuffer

private StringBuffer contentBuffer
This is used to capture all data within two tags before calling the actual characters method


readCharacterStatus

private boolean readCharacterStatus
This is a variable that shows if characters have been read


register

private CreoleRegister register
The register object that we add ResourceData objects to during parsing.

Constructor Detail

CreoleXmlHandler

public CreoleXmlHandler(CreoleRegister register,
                        URL directoryUrl,
                        URL creoleFileUrl)
Construction

Method Detail

startDocument

public void startDocument()
                   throws GateSaxException
Called when the SAX parser encounts the beginning of the XML document

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
GateSaxException

endDocument

public void endDocument()
                 throws GateSaxException
Called when the SAX parser encounts the end of the XML document

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
Throws:
GateSaxException

attributes2String

private String attributes2String(Attributes atts)
A verboase method for Attributes


startElement

public void startElement(String uri,
                         String qName,
                         String elementName,
                         Attributes atts)
                  throws SAXException
Called when the SAX parser encounts the beginning of an XML element

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException

checkStack

private void checkStack(String methodName,
                        String elementName)
                 throws GateSaxException
Utility function to throw exceptions on stack errors.

Throws:
GateSaxException

endElement

public void endElement(String uri,
                       String qName,
                       String elementName)
                throws GateSaxException,
                       SAXException
Called when the SAX parser encounts the end of an XML element. This is where ResourceData objects get values set, and where they are added to the CreoleRegister when we parsed their complete metadata entries.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
GateSaxException
SAXException

characters

public void characters(char[] text,
                       int start,
                       int length)
                throws SAXException
Called when the SAX parser encounts text (PCDATA) in the XML doc

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException

charactersAction

public void charactersAction(char[] text,
                             int start,
                             int length)
                      throws SAXException
This method is called when all characters between specific tags have been read completely

Throws:
SAXException

currentFlattenedDisjunction

protected List<Parameter> currentFlattenedDisjunction()
Flatten the currentParamDisjunction map into a single list ordered by priority.


ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Called when the SAX parser encounts white space

Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class DefaultHandler
Throws:
SAXException

error

public void error(SAXParseException ex)
           throws SAXException
Called for parse errors.

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Throws:
SAXException

fatalError

public void fatalError(SAXParseException ex)
                throws SAXException
Called for fatal errors.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
Throws:
SAXException

warning

public void warning(SAXParseException ex)
             throws SAXException
Called for warnings.

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Throws:
SAXException