jsky.science
Class AbstractScienceObject

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

public abstract class AbstractScienceObject
extends java.lang.Object
implements ScienceObjectModel, java.lang.Cloneable, java.io.Serializable, java.lang.Comparable

Basic implementation of the ScienceObjectModel interface.

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
static interface AbstractScienceObject.EventMonitor
           
 
Field Summary
 
Fields inherited from interface jsky.science.ScienceObjectModel
NAME_PROPERTY, PENDING_PROPERTY, VALID_PROPERTY
 
Constructor Summary
AbstractScienceObject()
           
AbstractScienceObject(java.lang.String inName)
           
 
Method Summary
static void addEventMonitor(AbstractScienceObject.EventMonitor listener)
          add an event monitor, each monitor will be notified of of all PropertyChangeEvents fired by this object.
 void addPropertyChangeListener(ReplaceablePropertyChangeListener listener)
          add a listener
protected  boolean areNamesEqual(ScienceObjectModel target)
          checks equality of the Name property.
 void clearAllListeners()
          Convenience method for cloning.
 java.lang.Object clone()
          default implementation: fires superclass (Object)'s clone and suppresses the CloneNotSupportedException, returning null if super.clone() fails
 int compareTo(java.lang.Object o)
          Default implementation: compares the Names of the objects if they are ScienceObjectModels.
protected  java.lang.String createDefaultName()
          Creates and returns a default name for an object.
 boolean equals(java.lang.Object obj)
          Default implementation: checks for same name only
 void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, boolean trace)
          Report a bound property update to any registered listeners.
 void fireReplaceObject(java.lang.Object oldObject, java.lang.Object newObject)
          Report a replaceObject event to any registered ReplaceablePropertyChangeListeners that are also ReplaceablePropertyChangeListeners No events are sent if the old and new objects are '=='.
 void fireReplaceObject(java.lang.Object oldObject, java.lang.Object newObject, boolean trace)
          Report a replaceObject event to any registered ReplaceablePropertyChangeListeners that are also ReplaceablePropertyChangeListeners No events are sent if the old and new objects are '=='.
 void fireReplaceObject(ReplaceablePropertyChangeListener newObject)
          Report a replaceObject event to any registered propertyChangelisteners that are also ReplaceablePropertyChangeListeners No events are sent if the old and new objects are '=='.
 void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Report a bound property update to any registered listeners.
 void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, boolean trace)
          Report a bound property update to any registered fListeners.
 java.lang.Exception getException()
          returns the local exception (if any).
 java.lang.String getLabel()
          Convenience method for storing a "user friendly" name for an object.
 java.lang.String getName()
          returns the Name property.
 java.lang.String getObjectIdString()
          Useful for debugging output, returns a String containing the class and hashcode of the specified object.
static java.lang.String getObjectIdString(java.lang.Object obj)
          Useful for debugging output, returns a String containing the class and hashcode of the specified object.
 ScienceObjectNodeModel getParent()
          Returns the parent object in a hierarchy of objects.
 boolean isHolding()
          default implementation: always returns false, should be overridden by subclasses that want to implement a delayed updating capability
 boolean isPending()
          default implement: always returns false.
 boolean isTracing()
          Returns the current tracing mode, @see setTracing()
 boolean isValid()
          default implementation: the object is valid if and only if there is no specified local exception
 void notifyEventMonitors(java.lang.Object target, java.util.EventObject event)
           
 void propertyChange(java.beans.PropertyChangeEvent ev)
          default implementation.
static void removeEventMonitor(AbstractScienceObject.EventMonitor listener)
          Remove a listener
 void removePropertyChangeListener(ReplaceablePropertyChangeListener listener)
          Remove a listener
 void replaceObject(ReplacementEvent ev)
          Default implementation.
static void replaceObjectNYI(java.lang.Object source, ReplacementEvent event)
          Convenience debugging method for classes that do not support replaceObject() but find it has been called anyway.
 void setException(java.lang.Exception e)
          sets an exception.
 void setHolding(boolean hold)
          default implementation: does nothing
 void setName(java.lang.String inName)
          Sets the Name property.
 void setParent(ScienceObjectNodeModel model)
          Sets the parent in the hierarchy.
static void setTraceAll(boolean t)
          Sets a global tracing flag to turn tracing on for all AbstractScienceObjects.
 void setTracing(boolean onOff)
          Sets debugging tracing on or off.
 java.lang.String toString()
          local implementation: returns the name of the object, unless thats null in which case it returns call the superclass (Object)'s toString()
protected  void writeDebug(java.lang.Object source, java.lang.Object message)
          default implementation.
protected  void writeError(java.lang.Object source, java.lang.Object message)
          default implementation.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractScienceObject

public AbstractScienceObject()

AbstractScienceObject

public AbstractScienceObject(java.lang.String inName)
Method Detail

toString

public java.lang.String toString()
local implementation: returns the name of the object, unless thats null in which case it returns call the superclass (Object)'s toString()

Overrides:
toString in class java.lang.Object

getParent

public ScienceObjectNodeModel getParent()
Returns the parent object in a hierarchy of objects. May return null.

Specified by:
getParent in interface ScienceObjectModel

setParent

public void setParent(ScienceObjectNodeModel model)
Sets the parent in the hierarchy. Note that this does not send out any change notification, to avoid endless looping

Specified by:
setParent in interface ScienceObjectModel

isPending

public boolean isPending()
default implement: always returns false. Subclasses that wish to implement a "pending" capability should override this method


getException

public java.lang.Exception getException()
returns the local exception (if any). Returns null indicates that there are no current problems with the state of this object

Specified by:
getException in interface ScienceObjectModel

setException

public void setException(java.lang.Exception e)
sets an exception. This is public, but would normally be used within the object when a problems arises.

Specified by:
setException in interface ScienceObjectModel

isValid

public boolean isValid()
default implementation: the object is valid if and only if there is no specified local exception

Specified by:
isValid in interface ScienceObjectModel

isHolding

public boolean isHolding()
default implementation: always returns false, should be overridden by subclasses that want to implement a delayed updating capability

Specified by:
isHolding in interface ScienceObjectModel

setHolding

public void setHolding(boolean hold)
default implementation: does nothing

Specified by:
setHolding in interface ScienceObjectModel

clone

public java.lang.Object clone()
default implementation: fires superclass (Object)'s clone and suppresses the CloneNotSupportedException, returning null if super.clone() fails

Specified by:
clone in interface ScienceObjectModel
Overrides:
clone in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Default implementation: compares the Names of the objects if they are ScienceObjectModels. If compared object is not a ScienceObjectModel, returns -1.

Specified by:
compareTo in interface java.lang.Comparable

equals

public boolean equals(java.lang.Object obj)
Default implementation: checks for same name only

Overrides:
equals in class java.lang.Object

getName

public java.lang.String getName()
returns the Name property. Returns empty string if the name is null. Will not return null!

Specified by:
getName in interface ScienceObjectModel

areNamesEqual

protected boolean areNamesEqual(ScienceObjectModel target)
checks equality of the Name property.


createDefaultName

protected java.lang.String createDefaultName()
Creates and returns a default name for an object. May not be pretty: the default name is the last part of the class name and a numerical suffix. Should be a unique name within each program run.


setName

public void setName(java.lang.String inName)
Sets the Name property.

Specified by:
setName in interface ScienceObjectModel

getLabel

public java.lang.String getLabel()
Convenience method for storing a "user friendly" name for an object. Should return a "pretty" label for a multi-line pane, something nicer (and non-recursive) than plain old toString(). However, in this default implementation, toString() is what you get.

Specified by:
getLabel in interface ScienceObjectModel

isTracing

public boolean isTracing()
Returns the current tracing mode, @see setTracing()

Specified by:
isTracing in interface ScienceObjectModel

setTraceAll

public static void setTraceAll(boolean t)
Sets a global tracing flag to turn tracing on for all AbstractScienceObjects.

See Also:
setTracing(boolean)

setTracing

public void setTracing(boolean onOff)
Sets debugging tracing on or off. This is a debugging feature for developers. When set to true, trace messages will be sent to the debug destination for _every_ call to firePropertyChange or fireReplaceObject.

This is particularly useful for tracking down problems in clone() or replaceObject().

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

clearAllListeners

public void clearAllListeners()
Convenience method for cloning. Useful where subclassed object does not want to have the listener vector "cloned" but rather emptied

Specified by:
clearAllListeners in interface ScienceObjectModel

addPropertyChangeListener

public void addPropertyChangeListener(ReplaceablePropertyChangeListener listener)
add a listener

Specified by:
addPropertyChangeListener in interface ScienceObjectModel
Parameters:
listener - The ReplaceablePropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(ReplaceablePropertyChangeListener listener)
Remove a listener

Specified by:
removePropertyChangeListener in interface ScienceObjectModel
Parameters:
listener - The ReplaceablePropertyChangeListener to be removed

addEventMonitor

public static void addEventMonitor(AbstractScienceObject.EventMonitor listener)
add an event monitor, each monitor will be notified of of all PropertyChangeEvents fired by this object. Expected to be of use for testing and debugging ONLY

Parameters:
listener - An event monitor to be added

removeEventMonitor

public static void removeEventMonitor(AbstractScienceObject.EventMonitor listener)
Remove a listener

Parameters:
listener - The ReplaceablePropertyChangeListener to be removed

notifyEventMonitors

public void notifyEventMonitors(java.lang.Object target,
                                java.util.EventObject event)

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent ev)
default implementation. Propogates propertyChanges to all listeners. This is a basic component of the hierarchy of changes events supported by AbstractScienceObject.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

replaceObjectNYI

public static void replaceObjectNYI(java.lang.Object source,
                                    ReplacementEvent event)
Convenience debugging method for classes that do not support replaceObject() but find it has been called anyway. Displays a message indicating that the replaceObject() method has not yet been "implemented". Should be called by Objects who want to postpont defining replaceObject but gives centralize message and tracking ability


replaceObject

public void replaceObject(ReplacementEvent ev)
                   throws ReplacementVetoException
Default implementation. Does nothing

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

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)
Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.

Specified by:
firePropertyChange in interface ScienceObjectModel
Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               java.lang.Object oldValue,
                               java.lang.Object newValue,
                               boolean trace)
Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.

Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.

fireVetoableChange

public void fireVetoableChange(java.lang.String propertyName,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)
                        throws ReplaceablePropertyVetoException
Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.

Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.
Throws:
ReplaceablePropertyVetoException

fireVetoableChange

public void fireVetoableChange(java.lang.String propertyName,
                               java.lang.Object oldValue,
                               java.lang.Object newValue,
                               boolean trace)
                        throws ReplaceablePropertyVetoException
Report a bound property update to any registered fListeners. If any listener throws a ReplaceablePropertyVetoException, then this method will "undo" the property change notifications and throw the exception back to the original caller

Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.
Throws:
ReplaceablePropertyVetoException - passed on if received from a listener

fireReplaceObject

public void fireReplaceObject(java.lang.Object oldObject,
                              java.lang.Object newObject)
                       throws ReplacementVetoException
Report a replaceObject event to any registered ReplaceablePropertyChangeListeners that are also ReplaceablePropertyChangeListeners No events are sent if the old and new objects are '=='. It does not matter if they are .equals() true

Parameters:
oldObject - The object to be replaced by a new object
newObject - The new object to replace the current object
Throws:
ReplacementVetoException

fireReplaceObject

public void fireReplaceObject(ReplaceablePropertyChangeListener newObject)
                       throws ReplacementVetoException
Report a replaceObject event to any registered propertyChangelisteners that are also ReplaceablePropertyChangeListeners No events are sent if the old and new objects are '=='. It does not matter if they are .equals() true

Parameters:
newObject - The new object to replace the current object
Throws:
ReplacementVetoException

fireReplaceObject

public void fireReplaceObject(java.lang.Object oldObject,
                              java.lang.Object newObject,
                              boolean trace)
                       throws ReplacementVetoException
Report a replaceObject event to any registered ReplaceablePropertyChangeListeners that are also ReplaceablePropertyChangeListeners No events are sent if the old and new objects are '=='. It does not matter if they are .equals() true

Parameters:
newObject - The new object to replace the current object
Throws:
ReplacementVetoException

writeDebug

protected void writeDebug(java.lang.Object source,
                          java.lang.Object message)
default implementation. Sends a formatted DEBUG message to System.err


writeError

protected void writeError(java.lang.Object source,
                          java.lang.Object message)
default implementation. Sends a formatted ERROR message to System.err


getObjectIdString

public java.lang.String getObjectIdString()
Useful for debugging output, returns a String containing the class and hashcode of the specified object.


getObjectIdString

public static java.lang.String getObjectIdString(java.lang.Object obj)
Useful for debugging output, returns a String containing the class and hashcode of the specified object.