wt.projmgmt.msproject.mppobject
Class MPPObjectBuilder

java.lang.Object
  extended bywt.projmgmt.msproject.DefaultSAXContentHandler
      extended bywt.projmgmt.msproject.ChildContentHandler
          extended bywt.projmgmt.msproject.mppobject.MPPObjectBuilder
All Implemented Interfaces:
ContentHandler, ContentHandler
Direct Known Subclasses:
MPPAssignmentBuilder, MPPPlanBuilder, MPPResourceBuilder, MPPTaskBuilder

public abstract class MPPObjectBuilder
extends ChildContentHandler

A ContentHandler that builds a MPPObject from the data contained in a section of the document it is parsing.


Field Summary
private  StringBuffer buffer
           
private  MPPExtendedAttributeBuilder eaBuilder
           
private  IgnoreContentHandler ignoreHandler
           
private  MPPObject mppObject
           
private  String scope
           
 
Fields inherited from class wt.projmgmt.msproject.ChildContentHandler
 
Constructor Summary
MPPObjectBuilder(ContentHandler parent)
          Create a handler that builds a MPPObject from a particular portion of the document being scanned.
MPPObjectBuilder(ContentHandler parent, String localName)
          Create a handler that builds a MPPObject from a particular portion of the document being scanned.
 
Method Summary
private  void addEA(long value_id, String val)
          Add the extended attribute to the object using the correct key.
private  void addKeyValuePair(String localName)
          If there is character content in the content buffer, add it it to the object.
 void characters(char[] ch, int start, int length)
           
protected abstract  MPPObject createObject()
          Create the MPPObject that should be populated by this builder.
 void endElement(String namespaceURL, String localName, String qName)
           
private  void endScope()
          The end of this builder's scope has been reached.
 MPPObject getObject()
          Get the MPPObject that this builder is building or has built.
protected  boolean isObjectValid(MPPObject mppObj)
          Return true if the constructed object is valid.
protected  boolean isScopeEnd(String namespaceURL, String localName, String qName)
          Returns true when the specified element indicates the end of this handler's scope
protected abstract  boolean isUnsupported(String namespaceURL, String localName, String qName)
          Returns true if the specified element contains data that should be ignored by this builder.
private  void printKeyValuePairs()
          Print out the key=>value pairs that this handler has parsed so far.
 void reset()
          Reset the builder so that it can be used again.
 void setScope(String localName)
          Set the scope of this builder.
 void startElement(String namespaceURL, String localName, String qName, Attributes atts)
           
 
Methods inherited from class wt.projmgmt.msproject.ChildContentHandler
getDocumentLocator, getImportInfo, getParent, getReader, setDocumentLocator, setParent
 
Methods inherited from class wt.projmgmt.msproject.DefaultSAXContentHandler
endDocument, endPrefixMapping, ignorableWhitespace, outputEndElement, outputStartElement, processingInstruction, skippedEntity, startDocument, startPrefixMapping
 
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
endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startDocument, startPrefixMapping
 

Field Detail

mppObject

private MPPObject mppObject

buffer

private StringBuffer buffer

eaBuilder

private final MPPExtendedAttributeBuilder eaBuilder

ignoreHandler

private final IgnoreContentHandler ignoreHandler

scope

private String scope
Constructor Detail

MPPObjectBuilder

public MPPObjectBuilder(ContentHandler parent)
Create a handler that builds a MPPObject from a particular portion of the document being scanned.

If this constructor is used then setScope(java.lang.String) must be called to set the scope before the builder is used.

Parameters:
parent - the parent handler

MPPObjectBuilder

public MPPObjectBuilder(ContentHandler parent,
                        String localName)
Create a handler that builds a MPPObject from a particular portion of the document being scanned.

When the end tag for the specified scope element is encontered, control is passed back to the parent handler.

Parameters:
parent - the parent handler
localName - the localName of the scoping element
Method Detail

reset

public void reset()
Reset the builder so that it can be used again. This causes a fresh object to be created, the content buffer to be cleared and the extended attribute builder to be reset.


getObject

public final MPPObject getObject()
Get the MPPObject that this builder is building or has built.

See Also:
isObjectValid(wt.projmgmt.msproject.mppobject.MPPObject)

createObject

protected abstract MPPObject createObject()
Create the MPPObject that should be populated by this builder.


isObjectValid

protected boolean isObjectValid(MPPObject mppObj)
Return true if the constructed object is valid. By default, this method returns true.

This method is used by getObject(). If this method return false then getObject returns null, otherwise it returns the built object.


isUnsupported

protected abstract boolean isUnsupported(String namespaceURL,
                                         String localName,
                                         String qName)
Returns true if the specified element contains data that should be ignored by this builder. If this returns true for a particular element, then control will be turned over to a IgnoreContentHandler until the element is complete.


startElement

public void startElement(String namespaceURL,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultSAXContentHandler
Throws:
SAXException

characters

public final void characters(char[] ch,
                             int start,
                             int length)
                      throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultSAXContentHandler
Throws:
SAXException

endElement

public void endElement(String namespaceURL,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultSAXContentHandler
Throws:
SAXException

isScopeEnd

protected boolean isScopeEnd(String namespaceURL,
                             String localName,
                             String qName)
Returns true when the specified element indicates the end of this handler's scope


endScope

private final void endScope()
                     throws SAXException
The end of this builder's scope has been reached. Finish processing and pass control back to the parent handler.

Throws:
SAXException

setScope

public void setScope(String localName)
Set the scope of this builder. Resets the builder.


addKeyValuePair

private final void addKeyValuePair(String localName)
If there is character content in the content buffer, add it it to the object. Use the specified local name of the current element as the key for the value. Clear the content buffer before returning.

If there is no content this method does not add any value to the object. It still clears the content buffer in these cases.


addEA

private final void addEA(long value_id,
                         String val)
Add the extended attribute to the object using the correct key.


printKeyValuePairs

private final void printKeyValuePairs()
Print out the key=>value pairs that this handler has parsed so far.