Class ContextParser

java.lang.Object
org.xml.sax.helpers.DefaultHandler
com.nt.udc.util.xml.ContextParser
All Implemented Interfaces:
NamedContextFactory, ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
HierarchySchemaParser, NARHandler, TemplateSchemaParser, TemplateSchemaWriter

public class ContextParser extends DefaultHandler implements NamedContextFactory
A basic SAX event handler for parsing XML documents using the com.nt.udc.util.xml framework.

The class is responsible for handling the SAX events from the parser and passing the necessary information to the appropriate ElementContext object. There are to services it provides in doing this:

  • A registration service for the ElementContextFactory objects
  • A SAX event handler to be used by the parser
The registration service is in the form of the addFactory method. The ContextParser is typically extended to provide a single location where all ElementContext objects can be registered.
 public class ExportHandler extends ContextParser {
    public ExportHandler() {
       addFactory("export", ExportContext.getFactory());
       addFactory("export", ExportContext.getFactory());
       addFactory("systemModel", SystemModelContext.getFactory());
       addFactory("nodeManager", NodeManagerContext.getFactory());
       ...
    }
 }
 
This sub-class can then be used with your favorite SAX2 parser. There are two ways in which this may be used.
  • To build object models from XML documents
  • To serialize object models as XML documents
When the ContextParser recieves a startElement event from the parser it creates the ElementContext using the ElementContextFactory that has been registered for that element name. If no factory has been registered then the UnknowContext is used. It is left to the parent application to decide how to handle the UnknownContext. Subsequent SAX events are used to populate the necessary information in the ElementContext object. When the endElement event is called, the ContextParser will add the current context to the parent. It is at this point that the ElementContext becomes responsible for associating any created Objects with the rest of the object model.