jsky.science
Class AbstractScienceObjectNode

java.lang.Object
  extended by jsky.science.AbstractScienceObject
      extended by jsky.science.AbstractScienceObjectNode
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, java.util.EventListener, ScienceObjectModel, ScienceObjectNodeModel, ReplaceablePropertyChangeListener
Direct Known Subclasses:
AbstractWavelength1D

public abstract class AbstractScienceObjectNode
extends AbstractScienceObject
implements ScienceObjectNodeModel

Basic implementation of the ScienceObjectNodeModel.

This code was originally developed by NASA, Goddard Space Flight Center, Code 588 for the Scientist's Expert Assistant (SEA) project for Next Generation Space Telescope (NGST).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jsky.science.AbstractScienceObject
AbstractScienceObject.EventMonitor
 
Field Summary
protected static java.lang.String cloneIndent
           
 
Fields inherited from interface jsky.science.ScienceObjectNodeModel
DATA_SOURCE_PROPERTY, MORE_DATA_PROPERTY
 
Fields inherited from interface jsky.science.ScienceObjectModel
NAME_PROPERTY, PENDING_PROPERTY, VALID_PROPERTY
 
Constructor Summary
AbstractScienceObjectNode()
          Creates new AbstractScienceObjectNode with blank name and holding turned off.
AbstractScienceObjectNode(boolean holding)
          Creates new AbstractScienceObjectNode with blank name and specified holding state.
AbstractScienceObjectNode(java.lang.String inName)
          Creates new AbstractScienceObjectNode with a name and holding turned off.
AbstractScienceObjectNode(java.lang.String inName, boolean holding)
          creates a new AbstractScienceObjectNode with specified name and specified initial holding status.
 
Method Summary
 void addChild(ScienceObjectModel newKid)
          Adds a ScienceObject as a "child" of the current object.
 java.lang.Object clone()
          Clones this object, and does a DEEP clone on the fChildren.
 boolean equals(java.lang.Object obj)
          Adds equals() checks on the object's DataSources and Children
 java.util.List getChildren()
          returns List of children of the science object should be used only when necessary
 ScienceObjectNodeModel getDataSource()
          Returns an object that describes the source of the ScienceObjectModel's data.
 int indexOfChild(java.lang.Object child)
          Looks up the index of a child in the children's list, matching on exact equality (==) NOT on equals().
protected  void initializeTransients()
          Sets default values for all transient fields.
 boolean isHolding()
          Returns true if updates to the object would be "held".
 boolean isMoreDataAvailable()
          Returns true if more data is available for this science object.
 boolean isPending()
          Returns true when the object is in the process of performing an update.
 boolean isUpToDate()
          Returns true if the object is up-to-date, false otherwise.
 boolean isValid()
          Returns true if the object is "valid".
 ScienceObjectModel namedClone()
          Copies a ScienceObjectModel and assigns it a new "Copy of" name.
protected  void processUpdates()
          Called when updates to a ScienceObject is processed.
 void removeAllChildren()
          Removes all children from the ScienceObjectModel.
 ScienceObjectModel removeChild(ScienceObjectModel oldKid)
          Removes all occurrences of a ScienceObjectModel as a "child" of the current object.
static java.lang.String repeat(java.lang.String inS, int n)
          Support method for saveAsText.
 ScienceObjectModel replaceChild(ScienceObjectModel oldKid, ScienceObjectModel newKid)
          Replaces all occurrence of the "old" child with the new child in the propertychange listings.
 void replaceObject(ReplacementEvent ev)
          Process a request from one of a ScienceObjectModel's children to "replace" itself with another object.
 void requestMoreData()
          Requests that the science object retrieve any extra data that it has available from its data source.
 void retrieveMoreData(ScienceObjectNodeModel forObject)
          Attempts to retrieve more information for the specified ScienceObjectModel and populate the ScienceObjectModel with that extra data.
 void saveAsText(java.io.PrintWriter pw)
          Single argument varient.
 void saveAsText(java.io.PrintWriter pw, int indent)
          Prints a reasonably user-friendly description of the object to the specified PrintWriter.
 void setDataSource(ScienceObjectNodeModel s)
          Sets the source of the ScienceObjectModel's data.
 void setHolding(boolean inH)
          Sets the "holding" property.
 void setMoreDataAvailable(boolean more)
          Sets whether or not more data is available for this science object from its DataSource.
protected  void setPending(boolean b)
          Sets the pending state.
 void setTracing(boolean onOff)
          Turns on/off the tracing of propertychange handling in an object;
 void setUpdatesPending(boolean inH)
          Sets the flag that indicates whether or not updates to the object are needed.
protected  void update()
          Fires off request to update source and background counts.
 
Methods inherited from class jsky.science.AbstractScienceObject
addEventMonitor, addPropertyChangeListener, areNamesEqual, clearAllListeners, compareTo, createDefaultName, firePropertyChange, firePropertyChange, fireReplaceObject, fireReplaceObject, fireReplaceObject, fireVetoableChange, fireVetoableChange, getException, getLabel, getName, getObjectIdString, getObjectIdString, getParent, isTracing, notifyEventMonitors, propertyChange, removeEventMonitor, removePropertyChangeListener, replaceObjectNYI, setException, setName, setParent, setTraceAll, toString, writeDebug, writeError
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jsky.science.ScienceObjectModel
addPropertyChangeListener, clearAllListeners, firePropertyChange, getException, getLabel, getName, getParent, isTracing, removePropertyChangeListener, setException, setName, setParent
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 

Field Detail

cloneIndent

protected static java.lang.String cloneIndent
Constructor Detail

AbstractScienceObjectNode

public AbstractScienceObjectNode()
Creates new AbstractScienceObjectNode with blank name and holding turned off.


AbstractScienceObjectNode

public AbstractScienceObjectNode(java.lang.String inName,
                                 boolean holding)
creates a new AbstractScienceObjectNode with specified name and specified initial holding status.

Subclasses will often initialize with holding=true in order to finish populating the object before trying to update it.


AbstractScienceObjectNode

public AbstractScienceObjectNode(boolean holding)
Creates new AbstractScienceObjectNode with blank name and specified holding state.


AbstractScienceObjectNode

public AbstractScienceObjectNode(java.lang.String inName)
Creates new AbstractScienceObjectNode with a name and holding turned off.

Method Detail

clone

public java.lang.Object clone()
Clones this object, and does a DEEP clone on the fChildren.

NOTE: for subclasses! If a subclass has a separate variable or list that points at fChildren, remember that after this clone() method is completed all fChildren will have also been cloned.

So subclasses may need to "repoint" variables or elemenets of lists that reference child objects, but should NOT re-clone those children.

See ExposureGroup.clone() and Exposure.clone() as examples of classes that need to re-proint existing pointers to correctly point at the correct elements.

Specified by:
clone in interface ScienceObjectModel
Overrides:
clone in class AbstractScienceObject

indexOfChild

public int indexOfChild(java.lang.Object child)
Looks up the index of a child in the children's list, matching on exact equality (==) NOT on equals(). If match is not found, returns -1, otherwise returns the index of the child in the list of children. This differs from a simple fChildren.indexOf( object) which test for .equals()

Parameters:
child - Child object to be located in the the children list
Returns:
index of child or -1 of child is not in the list

namedClone

public ScienceObjectModel namedClone()
Copies a ScienceObjectModel and assigns it a new "Copy of" name. The actual copying is deffered to the object's clone() method.

Returns:
clone of the ScienceObjectModel, but with a unique name

equals

public boolean equals(java.lang.Object obj)
Adds equals() checks on the object's DataSources and Children

Overrides:
equals in class AbstractScienceObject

replaceObject

public void replaceObject(ReplacementEvent ev)
                   throws ReplacementVetoException
Process a request from one of a ScienceObjectModel's children to "replace" itself with another object.

Specified by:
replaceObject in interface ReplaceablePropertyChangeListener
Overrides:
replaceObject in class AbstractScienceObject
Parameters:
ev - the event that contains details about replacement
Throws:
ReplacementVetoException

saveAsText

public void saveAsText(java.io.PrintWriter pw,
                       int indent)
Prints a reasonably user-friendly description of the object to the specified PrintWriter. This is performed recursiviely through each of the child objects.

Parameters:
pw - The PrintWriter to which to send the output
indent - A preliminary string (likely all blanks) to pre-pend to each line of output. Allows recursive calls to an object's children to indent their output.

repeat

public static java.lang.String repeat(java.lang.String inS,
                                      int n)
Support method for saveAsText. Concatenates the specified input string
n
times.


saveAsText

public void saveAsText(java.io.PrintWriter pw)
Single argument varient. Use initial indentation of 0


isMoreDataAvailable

public boolean isMoreDataAvailable()
Returns true if more data is available for this science object.

Specified by:
isMoreDataAvailable in interface ScienceObjectNodeModel

setMoreDataAvailable

public void setMoreDataAvailable(boolean more)
Sets whether or not more data is available for this science object from its DataSource.

Specified by:
setMoreDataAvailable in interface ScienceObjectNodeModel

retrieveMoreData

public void retrieveMoreData(ScienceObjectNodeModel forObject)
Attempts to retrieve more information for the specified ScienceObjectModel and populate the ScienceObjectModel with that extra data. This only makes sense for ScienceObjects where isMoreDataAvailable() is true. This method does nothing in AbstractScienceObjectModelNode, but can be defined in subclasses.

Specified by:
retrieveMoreData in interface ScienceObjectNodeModel
Parameters:
forObject - retrieve more data for this science object

requestMoreData

public void requestMoreData()
Requests that the science object retrieve any extra data that it has available from its data source.

Specified by:
requestMoreData in interface ScienceObjectNodeModel

getDataSource

public ScienceObjectNodeModel getDataSource()
Returns an object that describes the source of the ScienceObjectModel's data.

Specified by:
getDataSource in interface ScienceObjectNodeModel

setDataSource

public void setDataSource(ScienceObjectNodeModel s)
Sets the source of the ScienceObjectModel's data.

Specified by:
setDataSource in interface ScienceObjectNodeModel

isHolding

public boolean isHolding()
Returns true if updates to the object would be "held".

Specified by:
isHolding in interface ScienceObjectModel
Overrides:
isHolding in class AbstractScienceObject
See Also:
processUpdates()

setHolding

public void setHolding(boolean inH)
Sets the "holding" property.

Specified by:
setHolding in interface ScienceObjectModel
Overrides:
setHolding in class AbstractScienceObject
Parameters:
inH -
See Also:
processUpdates()

setUpdatesPending

public void setUpdatesPending(boolean inH)
Sets the flag that indicates whether or not updates to the object are needed.

Parameters:
inH -
See Also:
processUpdates()

update

protected void update()
Fires off request to update source and background counts. If the object's hold status is true, this will set a flag indicating that updates are needed. If the hold status is false, then the update process begins Note: subclasses should NOT override update(). Instead they should implement/override processUpdates();

See Also:
processUpdates()

processUpdates

protected void processUpdates()
Called when updates to a ScienceObject is processed. Works with isHolding(), setHolding(), setUpdatesPending(), and update() to provide to delay a possibly lengthy update process for an object.

In the default implementation, this method is empty, and should be overridden by classes that want to be able to hold updates.

To use this feature in a subclass of ScienceObject: - Use setHolding() to turn delaying of updates on/off.
- Override processUpdates() to contain the actual code that performs the updating of an object. Remember that processUpdates() or the subclass is responsible for setting Pending back to false. - Call update() to request that updates be made to an object. Subclasses should NOT override this method, it will call processUpdates() if holding is off. If holding is on, update() will set a flag so that processUpdates() will be called as soon as a setHolding(false) is received. - use setUpdatesPending() to manually override the setting of the pending flag. This is rarely used in subclasses as update() and setHolding() normally manage the pending flag.

Subclasses should not call processUpdates() directly.


isUpToDate

public boolean isUpToDate()
Returns true if the object is up-to-date, false otherwise. At this level it returns true when isHolding() is false, or when isHolding() is true, but there are no updates pending.


isValid

public boolean isValid()
Returns true if the object is "valid". At this level, always returns true, although subclasses may override this

Specified by:
isValid in interface ScienceObjectModel
Overrides:
isValid in class AbstractScienceObject

isPending

public boolean isPending()
Returns true when the object is in the process of performing an update.

Specified by:
isPending in interface ScienceObjectNodeModel
Overrides:
isPending in class AbstractScienceObject

setPending

protected void setPending(boolean b)
Sets the pending state. Should rarely be needed outside of the update() method.


setTracing

public void setTracing(boolean onOff)
Turns on/off the tracing of propertychange handling in an object;

Specified by:
setTracing in interface ScienceObjectModel
Overrides:
setTracing in class AbstractScienceObject
See Also:
ScienceObjectModel.isTracing()

initializeTransients

protected void initializeTransients()
Sets default values for all transient fields.


addChild

public void addChild(ScienceObjectModel newKid)
Adds a ScienceObject as a "child" of the current object. Automatically will handle propertyChange listending, cloning and loading/writing of all official children.

Specified by:
addChild in interface ScienceObjectNodeModel
Parameters:
newKid - ScienceObjectModel to be added

removeChild

public ScienceObjectModel removeChild(ScienceObjectModel oldKid)
Removes all occurrences of a ScienceObjectModel as a "child" of the current object. Automatically will handle removing listeners

Specified by:
removeChild in interface ScienceObjectNodeModel
Parameters:
oldKid - ScienceObjectModel to be added
Returns:
the ScienceObjectModel just removed, or null if oldKid not a valid child

removeAllChildren

public void removeAllChildren()
Removes all children from the ScienceObjectModel.

Specified by:
removeAllChildren in interface ScienceObjectNodeModel

replaceChild

public ScienceObjectModel replaceChild(ScienceObjectModel oldKid,
                                       ScienceObjectModel newKid)
Replaces all occurrence of the "old" child with the new child in the propertychange listings.

Specified by:
replaceChild in interface ScienceObjectNodeModel
Parameters:
oldKid - ScienceObjectModel to be replaced
newKid - new ScienceObjectModel to be "added"
Returns:
the ScienceObjectModel just removed, or null if oldKid not a valid child

getChildren

public java.util.List getChildren()
returns List of children of the science object should be used only when necessary

Specified by:
getChildren in interface ScienceObjectNodeModel