Basic Annotation Conditions
In last section were presented four basic annotation conditions:
Annotation |
Meaning |
StartDocument |
annotated method must execute when starting XML document parsing |
EndDocument |
annotated method must execute when ending XML document parsing |
StartElement |
annotated method must execute when an element from XML is starting |
EndElement |
annotated method must execute when an element from XML is ending |
The above annotations work in a similar way that the methods startDocument, endDocument, startElement and endElement, from DefaultHandler, the main class from SAX, as you could see in Hello World With JColtrane.
One or more of above annotations must to be present in a method, if you want JColtrane executes it.
StartDocument is used, in general, to start up your classes, for example a buffer, before the parsing process.
EndDocument is used, in general, to free system resources, for example flushing a buffer, after the parsing process.
Both previous annotatios must be used only in methods without parameters, once it's not make sense receive information before parsing start or after its end.
The another 2 annotations, StartElement and EndElement, are destinated to methods that make some handling in XML data. Because of this, JColtrane present some options to allow user choose the circunstaces which the annotated method should execute. JColtrane make possible, either, receive some parameters containing information about the parsing.
In next two sections will be presented the options to filter elements and how to receive parameters.