uk.ac.starlink.datanode.nodes
Class DefaultDataNode

java.lang.Object
  extended by uk.ac.starlink.datanode.nodes.DefaultDataNode
All Implemented Interfaces:
DataNode
Direct Known Subclasses:
BranchDataNode, CompressedDataNode, DocumentDataNode, EmptyDataNode, ErrorDataNode, FileDataNode, FITSDataNode, FrameDataNode, FtpDirectoryDataNode, HDSDataNode, HDUDataNode, HDXDataNode, HistoryDataNode, HTMLDataNode, NDArrayDataNode, NdxDataNode, PlainDataNode, ResourceListDataNode, ScalarDataNode, StarTableDataNode, TarBranchDataNode, TarStreamDataNode, VOComponentDataNode, WCSDataNode, XMLDataNode, ZipArchiveDataNode, ZipBranchDataNode

public class DefaultDataNode
extends Object
implements DataNode

A basic implementation of the DataNode interface. It may be used directly for simple nodes, or it may be subclassed for convenience in writing more specific DataNode implementors.

Version:
$Id$
Author:
Mark Taylor (Starlink)

Constructor Summary
DefaultDataNode()
          Constructs a blank DefaultDataNode.
DefaultDataNode(String name)
          Constructs a DefaultDataNode with a given name.
 
Method Summary
 boolean allowsChildren()
          The DefaultDataNode implementation of this method returns false.
static void beep()
          It beeps.
 void configureDetail(DetailViewer dv)
          No custom configuration is performed.
 Iterator getChildIterator()
          The DefaultDataNode implementation of this method throws UnsupportedOperationException (allowsChildren() is false).
 DataNodeFactory getChildMaker()
          Gets the factory which should in general be used to generate descendant nodes.
 CreationState getCreator()
          Retrieves information about how this node was created.
 Object getDataObject(DataType type)
          The DefaultDataNode implementation returns any data object which has been registered using registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object).
 String getDescription()
          Gets a concise description of this object.
 Icon getIcon()
          Returns a default icon, unless setIconID has been called, in which case it returns the one indicated by that call.
 String getLabel()
          Gets the label of this object.
 String getName()
          Gets the name of this object.
 String getNodeTLA()
          The DefaultDataNode implementation returns the string "...".
 String getNodeType()
          Returns a short sentence indicating what kind of node this is.
 Object getParentObject()
          Returns an object which is in some sense the parent of the one this node is based on.
 String getPathElement()
          The DefaultDataNode implementation returns the label as a default path element.
 String getPathSeparator()
          Returns a default separator string.
 boolean hasDataObject(DataType type)
          The DefaultDataNode implementation returns true for only those data objects which have been registered using registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object).
 DataNode makeChild(Object childObj)
          Uses the node's childMaker to turn objects into data nodes.
 DataNode makeErrorChild(Throwable th)
          Constructs an error data node from a throwable.
 void registerDataObject(DataType type, Object data)
          Provides a straightforward method of storing typed data objects for this node, as accessed by the hasDataObject(uk.ac.starlink.datanode.nodes.DataType)/getDataObject(uk.ac.starlink.datanode.nodes.DataType) methods.
 void setChildMaker(DataNodeFactory factory)
          Sets the factory which should in general be used to generate child nodes.
 void setCreator(CreationState state)
          Stores information about how this node was created.
 void setDescription(String desc)
          Sets the value which will be returned by getDescription().
protected  void setIconID(short id)
          This may be called by subclasses to set the icon returned by this node to one of the ones defined in the IconFactory class.
 void setLabel(String label)
          Sets a label for this object.
protected  void setName(String name)
          Sets the name of this node.
 void setParentObject(Object parent)
          Sets the object which is in some sense the parent of the one this node is based on.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultDataNode

public DefaultDataNode()
Constructs a blank DefaultDataNode.


DefaultDataNode

public DefaultDataNode(String name)
Constructs a DefaultDataNode with a given name.

Parameters:
name - the name to use for this object.
Method Detail

allowsChildren

public boolean allowsChildren()
The DefaultDataNode implementation of this method returns false.

Specified by:
allowsChildren in interface DataNode
Returns:
true if the node is of a type which can have child nodes, false otherwise

getChildIterator

public Iterator getChildIterator()
The DefaultDataNode implementation of this method throws UnsupportedOperationException (allowsChildren() is false).

Specified by:
getChildIterator in interface DataNode
Returns:
an Iterator over the children. Each object iterated over should be a DataNode. Behaviour is undefined if this method is called on an object for which allowsChildren returns false.

getParentObject

public Object getParentObject()
Description copied from interface: DataNode
Returns an object which is in some sense the parent of the one this node is based on. The parent is not a DataNode, it is something which may get fed to a DataNodeFactory to create DataNode. If no such object exists, which may well be the case, null should be returned.

Specified by:
getParentObject in interface DataNode
Returns:
an object which is the parent of this one, or null

setParentObject

public void setParentObject(Object parent)
Description copied from interface: DataNode
Sets the object which is in some sense the parent of the one this node is based on. The parent is not a DataNode, it is something which may get fed to a DataNodeFactory to create DataNode.

Specified by:
setParentObject in interface DataNode
Parameters:
parent - an object which is the parent of this one

setLabel

public void setLabel(String label)
Description copied from interface: DataNode
Sets a label for this object. This is like a name but is not intrinsic to the object, so users of implementing classes may call this method to impose a label of their own.

Specified by:
setLabel in interface DataNode
Parameters:
label - the label to be given to this object

getLabel

public String getLabel()
Description copied from interface: DataNode
Gets the label of this object. This ought to return the same value getName unless the user of the implementing class has previously called setLabel to change it.

Specified by:
getLabel in interface DataNode
Returns:
the label of the object

setName

protected void setName(String name)
Sets the name of this node. Since the name of a node should not change over its lifetime (though a label can), this is only intended for use during construction by subclasses.

Parameters:
name - the node's name

getName

public String getName()
Description copied from interface: DataNode
Gets the name of this object. This is an intrinsic property of the object.

Specified by:
getName in interface DataNode
Returns:
the name of the object

setDescription

public void setDescription(String desc)
Sets the value which will be returned by getDescription().

Parameters:
desc - the description string

getDescription

public String getDescription()
Description copied from interface: DataNode
Gets a concise description of this object. The form of the description will depend on the type of node, but it might detail the shape or type of data represented, or otherwise give some information additional to the name. It should not include the return value of the getName method, since they may be presented together. It should be on one line, and preferably no longer than around 70 characters. The null value may be returned if there is nothing to say.

Specified by:
getDescription in interface DataNode
Returns:
a short string describing this object

getNodeTLA

public String getNodeTLA()
The DefaultDataNode implementation returns the string "...".

Specified by:
getNodeTLA in interface DataNode
Returns:
"..."

getNodeType

public String getNodeType()
Description copied from interface: DataNode
Returns a short sentence indicating what kind of node this is. The return value should be just a few words. As a rough guideline it should indicate what the implementing class is.

Specified by:
getNodeType in interface DataNode
Returns:
a short description of the type of this DataNode

toString

public String toString()
Overrides:
toString in class Object

setIconID

protected void setIconID(short id)
This may be called by subclasses to set the icon returned by this node to one of the ones defined in the IconFactory class.

Parameters:
id - one of the icon identifiers defined as static final members of the IconFactory class

getIcon

public Icon getIcon()
Returns a default icon, unless setIconID has been called, in which case it returns the one indicated by that call.

Specified by:
getIcon in interface DataNode
Returns:
an icon representing this node

getPathSeparator

public String getPathSeparator()
Returns a default separator string.

Specified by:
getPathSeparator in interface DataNode
Returns:
"."

getPathElement

public String getPathElement()
The DefaultDataNode implementation returns the label as a default path element.

Specified by:
getPathElement in interface DataNode
Returns:
the node's label

registerDataObject

public void registerDataObject(DataType type,
                               Object data)
Provides a straightforward method of storing typed data objects for this node, as accessed by the hasDataObject(uk.ac.starlink.datanode.nodes.DataType)/getDataObject(uk.ac.starlink.datanode.nodes.DataType) methods. You can invoke this method to register a data object for a particular data type. Note that this is only suitable if the data object is free or cheap to come by - in the case that its construction is expensive then the data object ought to be constructed on demand by getDataObject rather than being registered as a matter of course (since it may never be needed).

Parameters:
type - data type of object to register
data - data object of type type for this node - must be non-null and of class type.getDataClass()

hasDataObject

public boolean hasDataObject(DataType type)
The DefaultDataNode implementation returns true for only those data objects which have been registered using registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object).

Specified by:
hasDataObject in interface DataNode
Parameters:
type - data object type of interest
Returns:
true iff a subsequent call of getDataObject(type) is likely to be successful

getDataObject

public Object getDataObject(DataType type)
                     throws DataObjectException
The DefaultDataNode implementation returns any data object which has been registered using registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object).

Specified by:
getDataObject in interface DataNode
Parameters:
type - data object type of interest
Returns:
data object of type type
Throws:
DataObjectException

configureDetail

public void configureDetail(DetailViewer dv)
No custom configuration is performed.

Specified by:
configureDetail in interface DataNode
Parameters:
dv - the detail viewer which this node is given an opportunity to configure

setChildMaker

public void setChildMaker(DataNodeFactory factory)
Description copied from interface: DataNode
Sets the factory which should in general be used to generate child nodes. This is not necessarily the factory which is used for generating children of this node, since this node may have special procedures for generating children. However it is the factory which should in general be used for creating descendants of this node.

This method should only be used by applications which wish to restrict the type of node which can appear in a whole subtree of the node hierarchy. The childMaker is normally inherited from parent to child, so for instance customising the childMaker of the tree root by removing certain builders will prevent such nodes from appearing anywhere in the tree.

Specified by:
setChildMaker in interface DataNode
Parameters:
factory - the factory to use for generating children

getChildMaker

public DataNodeFactory getChildMaker()
Description copied from interface: DataNode
Gets the factory which should in general be used to generate descendant nodes.

Specified by:
getChildMaker in interface DataNode
Returns:
the factory used for generating children

makeChild

public DataNode makeChild(Object childObj)
Uses the node's childMaker to turn objects into data nodes. This convenience method just calls getChildMaker().makeChildNode(this,childObj). In general, nodes should use this method to construct their children.

Parameters:
childObj - the object which forms the basis for a child data node
See Also:
DataNodeFactory.makeDataNode(uk.ac.starlink.datanode.nodes.DataNode, java.lang.Object)

makeErrorChild

public DataNode makeErrorChild(Throwable th)
Constructs an error data node from a throwable. This method can be used to create a error which is the child of this node. This convenience method just calls getChildMaker().makeErrorDataNode(this,th)

Parameters:
th - the throwable on which the data node will be based
See Also:
DataNodeFactory.makeErrorDataNode(uk.ac.starlink.datanode.nodes.DataNode, java.lang.Throwable)

setCreator

public void setCreator(CreationState state)
Description copied from interface: DataNode
Stores information about how this node was created.

Specified by:
setCreator in interface DataNode
Parameters:
state - an object encapsulating the means by which this node was created

getCreator

public CreationState getCreator()
Description copied from interface: DataNode
Retrieves information about how this node was created.

Specified by:
getCreator in interface DataNode
Returns:
an object encapsulating the means by which this node was created. May be null if no information is available

beep

public static void beep()
It beeps.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.