jgb.builder
Class DefaultBuilder

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--jgb.builder.DefaultBuilder
All Implemented Interfaces:
Builder, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, WindowContext

public class DefaultBuilder
extends org.xml.sax.helpers.DefaultHandler
implements Builder

The class that builds the windows and controls on behalf of the application. This class instantiates the necessary objects while reading the XML source file.

Since:
0.2a
Author:
Francois Beausoleil, fbos@users.sourceforge.net

Constructor Summary
DefaultBuilder()
          Instantiate a Builder and use the default TagHandlerFactory.
DefaultBuilder(jgb.builder.TagHandlerFactory tagsFactory)
          Instantiate a Builder with the specified TagHandlerFactory.
 
Method Summary
 void addResolver(org.xml.sax.EntityResolver resolver)
          Adds an EntityResolver through which this Builder should try to resolve entities before letting the default handling do it's job.
 Component build(org.xml.sax.InputSource in)
          Initiates building of the objects by reading the specified InputSource.
 Component build(InputStream in)
          Initiates building of the objects by reading the specified InputStream.
 void endElement(String namespaceURI, String localName, String qName)
          Terminates processing of the given element.
 void error(org.xml.sax.SAXParseException e)
          Displays an error message on the console, or no-op if in quiet mode.
 void fatalError(org.xml.sax.SAXParseException e)
          Displays a fatal error message on the console, or no-op if in quiet mode.
 Object getObject(String name)
           
 org.xml.sax.InputSource resolveEntity(String publicId, String systemId)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
          Saves the document locator that the parser might provide.
 void setLoggingStream(PrintWriter logStream)
          Specifies the stream to which warnings, errors, fatal errors and elements should be reported.
 void setQuiet(boolean quiet)
          Initiates or terminates quiet mode.
 void setVerbose(boolean b)
          Makes the Builder more verbose than normal.
 void startElement(String namespaceURI, String localName, String qName, org.xml.sax.Attributes atts)
          Initiates processing of the given element.
 void warning(org.xml.sax.SAXParseException e)
          Displays a warning message on the console, or no-op if in quiet mode.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startDocument, startPrefixMapping
 

Constructor Detail

DefaultBuilder

public DefaultBuilder()
Instantiate a Builder and use the default TagHandlerFactory. The default factory is PackageTagHandlerFactory.


DefaultBuilder

public DefaultBuilder(jgb.builder.TagHandlerFactory tagsFactory)
Instantiate a Builder with the specified TagHandlerFactory. The Builder uses this factory to get all of it's tag handlers. All tags must implement TagHandler.

Method Detail

setQuiet

public void setQuiet(boolean quiet)
Description copied from interface: Builder
Initiates or terminates quiet mode.

When in quiet mode, the Builder will not report any messages to the logging stream. By default, the Builder is NOT quiet.

This attribute is mutually exclusive with verbose.

Specified by:
setQuiet in interface Builder
Parameters:
quiet - true to make the Builder quiet, false otherwise.

build

public Component build(InputStream in)
                throws IOException,
                       org.xml.sax.SAXException
Description copied from interface: Builder
Initiates building of the objects by reading the specified InputStream. This stream will be parsed as an XML file. The parser used to parse the file will be validating.

Specified by:
build in interface Builder
Throws:
org.xml.sax.SAXException - If a parser could not be instantiated, or a build error occurs.
IOException - If an I/O error occurs while reading the stream.

build

public Component build(org.xml.sax.InputSource in)
                throws IOException,
                       org.xml.sax.SAXException
Description copied from interface: Builder
Initiates building of the objects by reading the specified InputSource. The parser used to parse the source will be validating.

Specified by:
build in interface Builder
Throws:
IOException - If an I/O error occurs while reading the stream.
org.xml.sax.SAXException - If a parser could not be instantiated, or a build error occurs.

setLoggingStream

public void setLoggingStream(PrintWriter logStream)
Description copied from interface: Builder
Specifies the stream to which warnings, errors, fatal errors and elements should be reported.

Specified by:
setLoggingStream in interface Builder
Parameters:
logStream - The stream to which information will be sent.

getObject

public Object getObject(String name)
Specified by:
getObject in interface WindowContext

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Initiates processing of the given element. This method will use the factory to get a TagHandler to process this tag.
Tag specific operations may occur during this method call.

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

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws org.xml.sax.SAXException
Terminates processing of the given element. This method will use the factory to get a TagHandler to process this tag.
Tag specific operations may occur during this method call.

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

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Displays a warning message on the console, or no-op if in quiet mode.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Displays a fatal error message on the console, or no-op if in quiet mode. In all cases, it throws a SAXException to signify that processing should stop.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Displays an error message on the console, or no-op if in quiet mode. In all cases, it throws a SAXException to signify that processing should stop.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Saves the document locator that the parser might provide. If it does so, we are in business, else, we're toast...

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class org.xml.sax.helpers.DefaultHandler

setVerbose

public void setVerbose(boolean b)
Description copied from interface: Builder
Makes the Builder more verbose than normal.

If the Builder is verbose, it should log all start and end elements to the logging stream.

This attribute is mutually exclusive with quiet.

Specified by:
setVerbose in interface Builder
Parameters:
b - true to make the Builder verbose, false otherwise.

addResolver

public void addResolver(org.xml.sax.EntityResolver resolver)
Description copied from interface: Builder
Adds an EntityResolver through which this Builder should try to resolve entities before letting the default handling do it's job.

Specified by:
addResolver in interface Builder
Parameters:
resolver - An EntityResolver that will be used while building the window.

resolveEntity

public org.xml.sax.InputSource resolveEntity(String publicId,
                                             String systemId)
                                      throws org.xml.sax.SAXException
Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException


Copyright 2002-2003, François Beausoleil, All Rights Reserved