projectviewer.persist
Class NodeHandler

java.lang.Object
  extended byprojectviewer.persist.NodeHandler
Direct Known Subclasses:
DirectoryNodeHandler, FileNodeHandler, OpenFileNodeHandler, ProjectNodeHandler, PropertyNodeHandler, VFSFileNodeHandler

public abstract class NodeHandler
extends java.lang.Object

A node handler is a class that takes care of loading an saving nodes to/from the configuration file.

Loading

When the parser finds a node that macthes the node name published by the handler, it calls the callback method with the attributes read from the file. The handler then should instantiate a node, fill any data and return the object.

Saving

The handler also publishes the class of the node (a java.lang.Class object) to register itself as the handler to save nodes of that type to the config file. When traversing the node tree, each time a node of that class is found, the appropriate handler callback method will be called.

Version:
$Id: NodeHandler.java 7059 2006-09-17 20:58:10Z ezust $
Author:
Marcelo Vanzin

Constructor Summary
NodeHandler()
           
 
Method Summary
abstract  VPTNode createNode(org.xml.sax.Attributes attrs, VPTProject project)
          Instantiates a VPTNode based on the information given in the attribute list.
abstract  java.lang.Class getNodeClass()
          Returns the class of the nodes that should be delegated to this handler when saving node data to the config file.
abstract  java.lang.String getNodeName()
          Returns the name of the tag representing nodes handled by this handler when loading the project's XML file.
abstract  boolean hasChildren()
          Returns whether the node(s) handled by this handler are expected to have children or not.
abstract  boolean isChild()
          Returns whether the node is a child of some other node or not.
abstract  void saveNode(VPTNode node, java.io.Writer out)
          Saves a node to the given Writer.
protected  void startElement(java.lang.String name, java.io.Writer out)
          Writes the start of an element to the given writer, using the given string as the node name.
protected  void startElement(java.io.Writer out)
          Writes the start of an element to the given writer.
protected  java.lang.String translatePath(java.lang.String src)
          Translates any "\" found in the string to "/".
protected  void writeAttr(java.lang.String name, java.lang.String value, java.io.Writer out)
          Writes an attribute to the writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeHandler

public NodeHandler()
Method Detail

getNodeName

public abstract java.lang.String getNodeName()
Returns the name of the tag representing nodes handled by this handler when loading the project's XML file.


getNodeClass

public abstract java.lang.Class getNodeClass()
Returns the class of the nodes that should be delegated to this handler when saving node data to the config file.


isChild

public abstract boolean isChild()
Returns whether the node is a child of some other node or not. For example, property nodes are not children of any other nodes, they simply add a property to a project.

This controls whether the node will be added to the parent node read from the XML file after instantiation.


hasChildren

public abstract boolean hasChildren()
Returns whether the node(s) handled by this handler are expected to have children or not.


createNode

public abstract VPTNode createNode(org.xml.sax.Attributes attrs,
                                   VPTProject project)
Instantiates a VPTNode based on the information given in the attribute list.

Parameters:
attrs - The attributes read from the config file.
project - The project that holds this node.
Since:
PV 2.1.3.4 (older version have a different method signature)

saveNode

public abstract void saveNode(VPTNode node,
                              java.io.Writer out)
                       throws java.io.IOException
Saves a node to the given Writer. The node is guaranteed to be an instance of the class returned by the getNodeClass() method.

This method should create the tag, but it shouldn't close it, even if it's an empty tag. Closing tags is done by the PersistenceManager based on the value returned by hasChildren(). The config file format does not support text elements inside other elements, so don't use them when saving nodes or you won't be able to read them later.

Throws:
java.io.IOException

startElement

protected void startElement(java.io.Writer out)
                     throws java.io.IOException
Writes the start of an element to the given writer.

Throws:
java.io.IOException

startElement

protected void startElement(java.lang.String name,
                            java.io.Writer out)
                     throws java.io.IOException
Writes the start of an element to the given writer, using the given string as the node name. This writer the opening < symbol and the node name, but does not writed the closing >, since attributed may still need to be written.

Throws:
java.io.IOException

writeAttr

protected void writeAttr(java.lang.String name,
                         java.lang.String value,
                         java.io.Writer out)
                  throws java.io.IOException
Writes an attribute to the writer.

Throws:
java.io.IOException

translatePath

protected final java.lang.String translatePath(java.lang.String src)
Translates any "\" found in the string to "/". Paths saved to the XML file are generally expected to be in Unix format, so this method is useful when saving the project in a Windows system.