ca.sqlpower.wabit
Class AbstractWabitObject

java.lang.Object
  extended by ca.sqlpower.wabit.AbstractWabitObject
All Implemented Interfaces:
WabitObject
Direct Known Subclasses:
CellSetRenderer, Chart, ChartColumn, ChartRenderer, ColumnInfo, ContentBox, Grant, Group, GroupMember, Guide, ImageRenderer, Label, Layout, OlapQuery, Page, QueryCache, ReportTask, ResultSetRenderer, User, WabitContainer, WabitDataSource, WabitImage, WabitItem, WabitJoin, WabitOlapAxis, WabitOlapDimension, WabitOlapSelection, WabitWorkspace

public abstract class AbstractWabitObject
extends java.lang.Object
implements WabitObject


Constructor Summary
AbstractWabitObject()
           
AbstractWabitObject(java.lang.String uuid)
          The uuid string passed in must be the toString representation of the UUID for this object.
 
Method Summary
 void addChild(WabitObject child, int index)
          Adds the given child object to this object.
protected  void addChildImpl(WabitObject child, int index)
          This is the object specific implementation of #addChild(WabitObject).
 void addWabitListener(WabitListener l)
          Adds a listener that will be notified when children are added to or removed from this object, when properties change, and when a transaction starts and ends.
 void begin(java.lang.String message)
          Starts a transaction that will pool multiple events into a compound event.
 void beginTransaction(java.lang.String message)
           
 CleanupExceptions cleanup()
          Default cleanup method that does nothing.
 void commit()
          Signals the end of a transaction of a compound event.
 void commitTransaction()
           
 boolean equals(java.lang.Object obj)
           
protected  WabitChildEvent fireChildAdded(java.lang.Class<? extends WabitObject> type, WabitObject child, int index)
          Fires a child added event to all child listeners.
protected  WabitChildEvent fireChildRemoved(java.lang.Class<? extends WabitObject> type, WabitObject child, int index)
          Fires a child removed event to all child listeners.
protected  java.beans.PropertyChangeEvent firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
          Fires a property change on the foreground thread as defined by the current session being used.
protected  java.beans.PropertyChangeEvent firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
          Fires a property change on the foreground thread as defined by the current session being used.
protected  java.beans.PropertyChangeEvent firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Fires a property change on the foreground thread as defined by the current session being used.
protected  ca.sqlpower.util.TransactionEvent fireTransactionEnded()
          Fires a transaction ended event.
protected  ca.sqlpower.util.TransactionEvent fireTransactionRollback(java.lang.String message)
          Fires a transaction rollback event with a message indicating the reason/type of the rollback.
protected  ca.sqlpower.util.TransactionEvent fireTransactionStarted(java.lang.String message)
          Fires a transaction started event with a message indicating the reason/type of the transaction.
 void generateNewUUID()
          Sets the UUID of this object to a newly generated UUID.
<T extends WabitObject>
java.util.List<T>
getChildren(java.lang.Class<T> type)
          Returns a list of all children of the given type
 java.lang.String getName()
          Returns the short name for this object.
 WabitObject getParent()
          Returns the parent of this WabitObject.
protected  WabitSession getSession()
          Helper method to find the session of a WabitObject.
 java.lang.String getUUID()
           
protected  boolean isForegroundThread()
           
 boolean removeChild(WabitObject child)
          Removes the given child object from this object.
protected abstract  boolean removeChildImpl(WabitObject child)
          This is the object specific implementation of removeChild.
 void removeWabitListener(WabitListener l)
          Removes a listener that was previously attached to this wabit object.
 void rollback(java.lang.String message)
          Signals the roll back of a transaction.
 void rollbackTransaction()
           
protected  void runInBackground(java.lang.Runnable runner)
          Calls the runInBackground method on the session this object is attached to if it exists.
protected  void runInForeground(java.lang.Runnable runner)
          Calls the runInForeground method on the session this object is attached to if it exists.
 void setName(java.lang.String name)
          Sets the name for this object
 void setParent(WabitObject parent)
          Sets the parent of this object to the given object.
 void setUUID(java.lang.String uuid)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ca.sqlpower.wabit.WabitObject
allowsChildren, childPositionOffset, getChildren, getDependencies, removeDependency
 

Constructor Detail

AbstractWabitObject

public AbstractWabitObject()

AbstractWabitObject

public AbstractWabitObject(java.lang.String uuid)
The uuid string passed in must be the toString representation of the UUID for this object. If the uuid string given is null then a new UUID will be automatically generated.

Method Detail

setUUID

public void setUUID(java.lang.String uuid)
Specified by:
setUUID in interface WabitObject

generateNewUUID

public void generateNewUUID()
Description copied from interface: WabitObject
Sets the UUID of this object to a newly generated UUID. This is necessary if the object is being cloned or copied to a new workspace.

Specified by:
generateNewUUID in interface WabitObject

addWabitListener

public void addWabitListener(WabitListener l)
Description copied from interface: WabitObject
Adds a listener that will be notified when children are added to or removed from this object, when properties change, and when a transaction starts and ends. The events will always be fired in the foreground.

Specified by:
addWabitListener in interface WabitObject
Parameters:
l - The listener to add.
See Also:
WabitListener, WabitSession.runInForeground(Runnable)

removeWabitListener

public void removeWabitListener(WabitListener l)
Description copied from interface: WabitObject
Removes a listener that was previously attached to this wabit object.

Specified by:
removeWabitListener in interface WabitObject
Parameters:
l - The listener to remove.

fireChildAdded

protected WabitChildEvent fireChildAdded(java.lang.Class<? extends WabitObject> type,
                                         WabitObject child,
                                         int index)
Fires a child added event to all child listeners. The child should have been added by the calling code already. The event will be fired on the foreground thread defined by the session being used.

Parameters:
type - The canonical type of the child being added
child - The child object that was added
index - The index of the added child within its own child list (this will be converted to the overall child position before the event object is constructed).
Returns:
The child event that was fired or null if no event was fired, for testing purposes.

fireChildRemoved

protected WabitChildEvent fireChildRemoved(java.lang.Class<? extends WabitObject> type,
                                           WabitObject child,
                                           int index)
Fires a child removed event to all child listeners. The child should have been removed by the calling code. The event will be fired on the foreground thread defined by the session being used.

Parameters:
type - The canonical type of the child being removed
child - The child object that was removed
index - The index that the removed child was at within its own child list (this will be converted to the overall child position before the event object is constructed).
Returns:
The child event that was fired or null if no event was fired, for testing purposes.

firePropertyChange

protected java.beans.PropertyChangeEvent firePropertyChange(java.lang.String propertyName,
                                                            boolean oldValue,
                                                            boolean newValue)
Fires a property change on the foreground thread as defined by the current session being used.

Returns:
The property change event that was fired or null if no event was fired, for testing purposes.

firePropertyChange

protected java.beans.PropertyChangeEvent firePropertyChange(java.lang.String propertyName,
                                                            int oldValue,
                                                            int newValue)
Fires a property change on the foreground thread as defined by the current session being used.

Returns:
The property change event that was fired or null if no event was fired, for testing purposes.

firePropertyChange

protected java.beans.PropertyChangeEvent firePropertyChange(java.lang.String propertyName,
                                                            java.lang.Object oldValue,
                                                            java.lang.Object newValue)
Fires a property change on the foreground thread as defined by the current session being used.

Returns:
The property change event that was fired or null if no event was fired, for testing purposes.

beginTransaction

public void beginTransaction(java.lang.String message)

commitTransaction

public void commitTransaction()

rollbackTransaction

public void rollbackTransaction()

fireTransactionStarted

protected ca.sqlpower.util.TransactionEvent fireTransactionStarted(java.lang.String message)
Fires a transaction started event with a message indicating the reason/type of the transaction.

Returns:
The event that was fired or null if no event was fired, for testing purposes.

fireTransactionEnded

protected ca.sqlpower.util.TransactionEvent fireTransactionEnded()
Fires a transaction ended event.

Returns:
The event that was fired or null if no event was fired, for testing purposes.

fireTransactionRollback

protected ca.sqlpower.util.TransactionEvent fireTransactionRollback(java.lang.String message)
Fires a transaction rollback event with a message indicating the reason/type of the rollback.

Returns:
The event that was fired or null if no event was fired, for testing purposes.

getChildren

public <T extends WabitObject> java.util.List<T> getChildren(java.lang.Class<T> type)
Description copied from interface: WabitObject
Returns a list of all children of the given type

Specified by:
getChildren in interface WabitObject

getParent

public WabitObject getParent()
Description copied from interface: WabitObject
Returns the parent of this WabitObject. This will be null when the object is first created until it is added as a child to another object. If this object is never added as a child to another object this will remain null and the object may be treated as the root node of a WabitObject tree.

Specified by:
getParent in interface WabitObject
Returns:
The parent of this object.

setParent

public void setParent(WabitObject parent)
Description copied from interface: WabitObject
Sets the parent of this object to the given object. This should only be done when this object is being added as a child to another object.

Specified by:
setParent in interface WabitObject
Parameters:
parent - The new parent of this object.

getName

public java.lang.String getName()
Description copied from interface: WabitObject
Returns the short name for this object.

Specified by:
getName in interface WabitObject

setName

public void setName(java.lang.String name)
Description copied from interface: WabitObject
Sets the name for this object

Specified by:
setName in interface WabitObject

getUUID

public java.lang.String getUUID()
Specified by:
getUUID in interface WabitObject

removeChild

public final boolean removeChild(WabitObject child)
                          throws ObjectDependentException
Description copied from interface: WabitObject
Removes the given child object from this object. If the given child is not an actual child of this object an illegal argument exception will be thrown. If the child has dependencies and cannot be removed an object dependent exception will be thrown.

Specified by:
removeChild in interface WabitObject
Parameters:
child - The object to remove as a child of this object.
Returns:
True if the child was successfully removed. False if the child was not removed from this object.
Throws:
ObjectDependentException

removeChildImpl

protected abstract boolean removeChildImpl(WabitObject child)
This is the object specific implementation of removeChild. There are checks in the removeChild method to ensure the child being removed has no dependencies and is a child of this object.

See Also:
removeChild(WabitObject)

addChild

public final void addChild(WabitObject child,
                           int index)
                    throws java.lang.IllegalArgumentException
Description copied from interface: WabitObject
Adds the given child object to this object.

Specified by:
addChild in interface WabitObject
Parameters:
child - The object to add as a child of this object.
index - The index to add the child to. This cannot be greater than the number of children in the object of the given type. This is the position of the child in the list of children of a specific type. The position of the child is in respect to children of its type.
Throws:
java.lang.IllegalArgumentException - If the given child is not a valid child type of the object.

addChildImpl

protected void addChildImpl(WabitObject child,
                            int index)
This is the object specific implementation of #addChild(WabitObject). There are checks in the #addChild(WabitObject) method to ensure that the object given here is a valid child type of this object.

This method should be overwritten if children are allowed.

Parameters:
child - The child to add to this object.
index - The index to add the child at.

cleanup

public CleanupExceptions cleanup()
Default cleanup method that does nothing. Override and implement this method if cleanup is necessary.

Specified by:
cleanup in interface WabitObject
Returns:
A collection of exceptions and errors that occurred during cleanup if any occurred.

getSession

protected WabitSession getSession()
Helper method to find the session of a WabitObject. This will walk up the workspace tree to the WabitWorkspace and get its session. If the highest ancestor is not a WabitWorkspace or the workspace is not attached to a session this will throw a SessionNotFoundException.


runInBackground

protected void runInBackground(java.lang.Runnable runner)
Calls the runInBackground method on the session this object is attached to if it exists. If this object is not attached to a session, which can occur when loading, copying, or creating a new object, the runner will be run on the current thread due to not being able to run elsewhere. Any WabitObject that wants to run a runnable in the background should call to this method instead of to the session.

See Also:
WabitSession.runInBackground(Runnable)

runInForeground

protected void runInForeground(java.lang.Runnable runner)
Calls the runInForeground method on the session this object is attached to if it exists. If this object is not attached to a session, which can occur when loading, copying, or creating a new object, the runner will be run on the current thread due to not being able to run elsewhere. Any WabitObject that wants to run a runnable in the foreground should call to this method instead of to the session.

See Also:
WabitSession.runInBackground(Runnable)

isForegroundThread

protected boolean isForegroundThread()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

begin

public void begin(java.lang.String message)
Description copied from interface: WabitObject
Starts a transaction that will pool multiple events into a compound event.

Specified by:
begin in interface WabitObject
Parameters:
message - Description of the compound event.

commit

public void commit()
Description copied from interface: WabitObject
Signals the end of a transaction of a compound event.

Specified by:
commit in interface WabitObject

rollback

public void rollback(java.lang.String message)
Description copied from interface: WabitObject
Signals the roll back of a transaction. The events of the transaction should not be acted on and/or should be undone.

Specified by:
rollback in interface WabitObject
Parameters:
message - Reason for the roll back.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.