Package uk.ac.starlink.datanode.nodes
Class DefaultDataNode
- java.lang.Object
-
- uk.ac.starlink.datanode.nodes.DefaultDataNode
-
- All Implemented Interfaces:
DataNode
- Direct Known Subclasses:
BranchDataNode
,CompressedDataNode
,DocumentDataNode
,EmptyDataNode
,ErrorDataNode
,FileDataNode
,FITSDataNode
,FtpDirectoryDataNode
,HDUDataNode
,HTMLDataNode
,PlainDataNode
,ResourceListDataNode
,ScalarDataNode
,StarTableDataNode
,TarBranchDataNode
,TarStreamDataNode
,VOComponentDataNode
,XMLDataNode
,ZipArchiveDataNode
,ZipBranchDataNode
public class DefaultDataNode extends java.lang.Object implements DataNode
A basic implementation of theDataNode
interface. It may be used directly for simple nodes, or it may be subclassed for convenience in writing more specificDataNode
implementors.- Version:
- $Id$
- Author:
- Mark Taylor (Starlink)
-
-
Constructor Summary
Constructors Constructor Description DefaultDataNode()
Constructs a blankDefaultDataNode
.DefaultDataNode(java.lang.String name)
Constructs aDefaultDataNode
with a given name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowsChildren()
The DefaultDataNode implementation of this method returns false.static void
beep()
It beeps.void
configureDetail(DetailViewer dv)
No custom configuration is performed.java.util.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.java.lang.Object
getDataObject(DataType type)
The DefaultDataNode implementation returns any data object which has been registered usingregisterDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object)
.java.lang.String
getDescription()
Gets a concise description of this object.javax.swing.Icon
getIcon()
Returns a default icon, unless setIconID has been called, in which case it returns the one indicated by that call.java.lang.String
getLabel()
Gets the label of this object.java.lang.String
getName()
Gets the name of this object.java.lang.String
getNodeTLA()
The DefaultDataNode implementation returns the string "...".java.lang.String
getNodeType()
Returns a short sentence indicating what kind of node this is.java.lang.Object
getParentObject()
Returns an object which is in some sense the parent of the one this node is based on.java.lang.String
getPathElement()
The DefaultDataNode implementation returns the label as a default path element.java.lang.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 usingregisterDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object)
.DataNode
makeChild(java.lang.Object childObj)
Uses the node's childMaker to turn objects into data nodes.DataNode
makeErrorChild(java.lang.Throwable th)
Constructs an error data node from a throwable.void
registerDataObject(DataType type, java.lang.Object data)
Provides a straightforward method of storing typed data objects for this node, as accessed by thehasDataObject(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(java.lang.String desc)
Sets the value which will be returned bygetDescription()
.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(java.lang.String label)
Sets a label for this object.protected void
setName(java.lang.String name)
Sets the name of this node.void
setParentObject(java.lang.Object parent)
Sets the object which is in some sense the parent of the one this node is based on.java.lang.String
toString()
-
-
-
Method Detail
-
allowsChildren
public boolean allowsChildren()
The DefaultDataNode implementation of this method returns false.- Specified by:
allowsChildren
in interfaceDataNode
- Returns:
true
if the node is of a type which can have child nodes,false
otherwise
-
getChildIterator
public java.util.Iterator getChildIterator()
The DefaultDataNode implementation of this method throws UnsupportedOperationException (allowsChildren()
is false).- Specified by:
getChildIterator
in interfaceDataNode
- Returns:
- an
Iterator
over the children. Each object iterated over should be aDataNode
. Behaviour is undefined if this method is called on an object for whichallowsChildren
returnsfalse
.
-
getParentObject
public java.lang.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 interfaceDataNode
- Returns:
- an object which is the parent of this one, or null
-
setParentObject
public void setParentObject(java.lang.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 interfaceDataNode
- Parameters:
parent
- an object which is the parent of this one
-
setLabel
public void setLabel(java.lang.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.
-
getLabel
public java.lang.String getLabel()
Description copied from interface:DataNode
Gets the label of this object. This ought to return the same valuegetName
unless the user of the implementing class has previously calledsetLabel
to change it.
-
setName
protected void setName(java.lang.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 java.lang.String getName()
Description copied from interface:DataNode
Gets the name of this object. This is an intrinsic property of the object.
-
setDescription
public void setDescription(java.lang.String desc)
Sets the value which will be returned bygetDescription()
.- Parameters:
desc
- the description string
-
getDescription
public java.lang.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 thegetName
method, since they may be presented together. It should be on one line, and preferably no longer than around 70 characters. Thenull
value may be returned if there is nothing to say.- Specified by:
getDescription
in interfaceDataNode
- Returns:
- a short string describing this object
-
getNodeTLA
public java.lang.String getNodeTLA()
The DefaultDataNode implementation returns the string "...".- Specified by:
getNodeTLA
in interfaceDataNode
- Returns:
- "..."
-
getNodeType
public java.lang.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 interfaceDataNode
- Returns:
- a short description of the type of this
DataNode
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.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 theIconFactory
class
-
getIcon
public javax.swing.Icon getIcon()
Returns a default icon, unless setIconID has been called, in which case it returns the one indicated by that call.
-
getPathSeparator
public java.lang.String getPathSeparator()
Returns a default separator string.- Specified by:
getPathSeparator
in interfaceDataNode
- Returns:
- "."
-
getPathElement
public java.lang.String getPathElement()
The DefaultDataNode implementation returns the label as a default path element.- Specified by:
getPathElement
in interfaceDataNode
- Returns:
- the node's label
-
registerDataObject
public void registerDataObject(DataType type, java.lang.Object data)
Provides a straightforward method of storing typed data objects for this node, as accessed by thehasDataObject(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 registerdata
- 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 usingregisterDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object)
.- Specified by:
hasDataObject
in interfaceDataNode
- Parameters:
type
- data object type of interest- Returns:
- true iff a subsequent call of getDataObject(type) is likely to be successful
-
getDataObject
public java.lang.Object getDataObject(DataType type) throws DataObjectException
The DefaultDataNode implementation returns any data object which has been registered usingregisterDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object)
.- Specified by:
getDataObject
in interfaceDataNode
- 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 interfaceDataNode
- 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 interfaceDataNode
- 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 interfaceDataNode
- Returns:
- the factory used for generating children
-
makeChild
public DataNode makeChild(java.lang.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(java.lang.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 interfaceDataNode
- 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 interfaceDataNode
- 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.
-
-