ca.sqlpower.wabit
Class WabitUtils

java.lang.Object
  extended by ca.sqlpower.wabit.WabitUtils

public class WabitUtils
extends java.lang.Object


Constructor Summary
WabitUtils()
           
 
Method Summary
static void addRecursivelyWithTransaction(WabitObject parent, WabitObject child)
          This inserts a child into it's parent and does that for all the hierarchy recursively.
static CleanupExceptions cleanupWabitObject(WabitObject o)
          This method will recursively clean up this object and all of its descendants.
static void displayCleanupErrors(CleanupExceptions cleanupObject, ca.sqlpower.util.UserPrompterFactory upf)
          This method will display the cleanup errors to the user.
static
<T extends WabitObject>
T
findByUuid(WabitObject root, java.lang.String uuid, java.lang.Class<T> expectedType)
          Locates the WabitObject inside the root wabit object which has the given UUID, returning null if the item is not found.
static java.util.List<WabitObject> getAncestorList(WabitObject o)
          This method returns a list of all of the ancestors of the given WabitObject.
static WabitSession getSession(WabitObject o)
          Walks up the parent chain of WabitObjects and returns the WabitSession that these objects belong to.
static WabitWorkspace getWorkspace(WabitObject o)
          Walks up the parent chain of WabitObjects and returns the WabitWorkspace that these objects belong to or null if the workspace does not exist.
static void listenToHierarchy(WabitObject root, WabitListener wcl)
          Adds the given listeners to the hierarchy of Wabit objects rooted at root.
static void logCleanupErrors(CleanupExceptions cleanupObject)
          Logs the exceptions and errors.
static boolean nullSafeEquals(java.lang.Object o1, java.lang.Object o2)
          Checks if the two arguments o1 and o2 are equal to each other, either because both are null, or because o1.equals(o2).
static void printSubtree(java.io.PrintWriter out, WabitObject startWith)
          Prints the subtree rooted at the given WabitObject to the given output stream.
static java.lang.String randomWabitUUID()
          Generates a new UUID in the format suitable for use with any WabitObject's UUID property.
static java.lang.String serviceInfoSummary(WabitServerInfo si)
          Returns the human-readable summary of the given service info object.
static void unlistenToHierarchy(WabitObject root, WabitListener wcl)
          Removes the given listeners from the hierarchy of Wabit objects rooted at root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WabitUtils

public WabitUtils()
Method Detail

listenToHierarchy

public static void listenToHierarchy(WabitObject root,
                                     WabitListener wcl)
Adds the given listeners to the hierarchy of Wabit objects rooted at root.

Parameters:
root - The object at the top of the subtree to listen to. Must not be null.
wcl - The Wabit child listener to add to root and all its WabitObject descendants. If you do not want Wabit child events, you can provide null for this parameter.

unlistenToHierarchy

public static void unlistenToHierarchy(WabitObject root,
                                       WabitListener wcl)
Removes the given listeners from the hierarchy of Wabit objects rooted at root.

Parameters:
root - The object at the top of the subtree to unlisten to. Must not be null.
wcl - The Wabit child listener to remove from root and all its WabitObject descendants. If you do not want to unlisten to Wabit child events, you can provide null for this parameter.

serviceInfoSummary

public static java.lang.String serviceInfoSummary(WabitServerInfo si)
Returns the human-readable summary of the given service info object. Anywhere a server is referred to within the Wabit, this method should be used to convert the service info object into the string the user sees.

Parameters:
si - The service info to summarize.
Returns:
The Wabit's canonical human-readable representation of the given service info.

nullSafeEquals

public static boolean nullSafeEquals(java.lang.Object o1,
                                     java.lang.Object o2)
Checks if the two arguments o1 and o2 are equal to each other, either because both are null, or because o1.equals(o2).

Parameters:
o1 - One object or null reference to compare
o2 - The other object or null reference to compare

getAncestorList

public static java.util.List<WabitObject> getAncestorList(WabitObject o)
This method returns a list of all of the ancestors of the given WabitObject. The order of the ancestors is such that the highest ancestor is at the start of the list and the parent of the object itself is at the end of the list.


cleanupWabitObject

public static CleanupExceptions cleanupWabitObject(WabitObject o)
This method will recursively clean up this object and all of its descendants.

Parameters:
o - The object to clean up, including its dependencies.
Returns:
A collection of exceptions and errors that occurred during cleanup if any occurred.

displayCleanupErrors

public static void displayCleanupErrors(@Nonnull
                                        CleanupExceptions cleanupObject,
                                        ca.sqlpower.util.UserPrompterFactory upf)
This method will display the cleanup errors to the user. If the user prompter factory given is null the errors will be logged instead.


logCleanupErrors

public static void logCleanupErrors(@Nonnull
                                    CleanupExceptions cleanupObject)
Logs the exceptions and errors. This is useful if there is no available user prompter.


getWorkspace

public static WabitWorkspace getWorkspace(WabitObject o)
Walks up the parent chain of WabitObjects and returns the WabitWorkspace that these objects belong to or null if the workspace does not exist.

Parameters:
o - The object to follow the parent chain.
Returns:
A WabitWorkspace that contains the given WabitObject and all of its children or null if the given object is not in a workspace.

getSession

public static WabitSession getSession(WabitObject o)
Walks up the parent chain of WabitObjects and returns the WabitSession that these objects belong to. This can throw a SessionNotFoundException if the object is not attached to a session.

Parameters:
o - The object to follow the parent chain.
Returns:
A WabitSession that contains the given WabitObject and all of its children.

findByUuid

public static <T extends WabitObject> T findByUuid(WabitObject root,
                                                   java.lang.String uuid,
                                                   java.lang.Class<T> expectedType)
Locates the WabitObject inside the root wabit object which has the given UUID, returning null if the item is not found. Throws ClassCastException if in item is found, but it is not of the expected type.

Type Parameters:
T - The expected type of the item
Parameters:
uuid - The UUID of the item
expectedType - The type of the item with the given UUID. If you are uncertain what type of object it is, or you do not want a ClassCastException in case the item is of the wrong type, use WabitObject.class for this parameter.
Returns:
The item, or null if no item with the given UUID exists in the descendent tree rooted at the given root object.

addRecursivelyWithTransaction

public static void addRecursivelyWithTransaction(WabitObject parent,
                                                 WabitObject child)
This inserts a child into it's parent and does that for all the hierarchy recursively. Wraps everything in a transaction.

Parameters:
parent -
child -

randomWabitUUID

public static java.lang.String randomWabitUUID()
Generates a new UUID in the format suitable for use with any WabitObject's UUID property.


printSubtree

public static void printSubtree(java.io.PrintWriter out,
                                WabitObject startWith)
Prints the subtree rooted at the given WabitObject to the given output stream. This is only intended for debugging; any machine parsing of the output of this method is incorrect!

Parameters:
out - the target of the debug information (often System.out)
startWith - the root object for the dump


Copyright © 2009. All Rights Reserved.