net.groboclown.xml.resource.v1
Class XMLResourceHandler

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--net.groboclown.xml.resource.v1.XMLResourceHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class XMLResourceHandler
extends DefaultHandler

This class handles the loading of IXMLResource instances from an XML file. You can define a resource in the XML document by associating the "class" attribute with each tag. Its value specifies which class is used to instantiate the instance. Also, you may specify the "jarURL" attribute to tell the handler in which jar file the class definition can be found. If no jarURL attribute is given, then the class is loaded from the default class loader.

If no class is specified, then the tag is loaded as a DefaultXMLResource instance.

Version:
Alpha 0.9.0 - JDK 1.0+
Author:
Matt Albrecht

Inner Class Summary
(package private)  class XMLResourceHandler.ResourceHolder
           
 
Field Summary
private  IInputStreamGenerator m_isg
           
private  Locator m_locator
           
private  Stack m_nodeStack
           
private  IXMLResource m_rootResource
           
private  String m_systemId
           
static String XMLResource_URI
           
 
Constructor Summary
XMLResourceHandler()
          Default constructor
XMLResourceHandler(IInputStreamGenerator isg, String systemId)
          Specify the system id.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(String uri, String localName, String rawName)
           
 void endPrefixMapping(String prefix)
           
 IXMLResource getRootResource()
          Call this method after XML parsing has completed, and everything went ok.
 InputSource resolveEntity(String publicId, String systemId)
          Allow the application to resolve external entities.
 void setDocumentLocator(Locator locator)
           
 void startDocument()
           
 void startElement(String uri, String localName, String rawName, Attributes attributes)
           
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, skippedEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

XMLResource_URI

public static final String XMLResource_URI

m_locator

private Locator m_locator

m_nodeStack

private Stack m_nodeStack

m_rootResource

private IXMLResource m_rootResource

m_systemId

private String m_systemId

m_isg

private IInputStreamGenerator m_isg
Constructor Detail

XMLResourceHandler

public XMLResourceHandler()
Default constructor

XMLResourceHandler

public XMLResourceHandler(IInputStreamGenerator isg,
                          String systemId)
Specify the system id.
Method Detail

getRootResource

public IXMLResource getRootResource()
Call this method after XML parsing has completed, and everything went ok.

setDocumentLocator

public void setDocumentLocator(Locator locator)
Overrides:
setDocumentLocator in class DefaultHandler

startDocument

public void startDocument()
Overrides:
startDocument in class DefaultHandler

endDocument

public void endDocument()
                 throws SAXException
Overrides:
endDocument in class DefaultHandler

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Overrides:
startPrefixMapping in class DefaultHandler

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Overrides:
endPrefixMapping in class DefaultHandler

startElement

public void startElement(String uri,
                         String localName,
                         String rawName,
                         Attributes attributes)
                  throws SAXException
Overrides:
startElement in class DefaultHandler

endElement

public void endElement(String uri,
                       String localName,
                       String rawName)
                throws SAXException
Overrides:
endElement in class DefaultHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Overrides:
characters in class DefaultHandler

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException
Allow the application to resolve external entities.

The Parser will call this method before opening any external entity except the top-level document entity (including the external DTD subset, external entities referenced within the DTD, and external entities referenced within the document element): the application may request that the parser resolve the entity itself, that it use an alternative URI, or that it use an entirely different input source.

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box).

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Overrides:
resolveEntity in class DefaultHandler
Parameters:
publicId - The public identifier of the external entity being referenced, or null if none was supplied.
systemId - The system identifier of the external entity being referenced.
Returns:
An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.


Written under the LGPL