com.miginfocom.calendar.category
Class CategoryDepository

java.lang.Object
  extended by com.miginfocom.calendar.category.CategoryDepository

public class CategoryDepository
extends java.lang.Object

A class that keeps track of all categories in the application. Used for fast getting categories, and if objects has been overridden. Adding categories is done on the Category object itself.

This class is not thread safe.


Constructor Summary
CategoryDepository()
           
 
Method Summary
static void addBrokedCategories(java.util.Collection c, java.lang.Object source, int eventType)
          Adds a number of activities to the list.
static void addBrokedCategory(Category c, java.lang.Object source, int eventType)
          Adds an category to the list.
static void addCategoryStructureListener(CategoryStructureListener l)
          Adds a listener to changes in the category tree structure.
static void addCategoryStructureListener(CategoryStructureListener l, boolean asWeakRef)
          Adds a listener to changes in the category tree structure.
static void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds a listener that listens to all handeled categories of type Category and subclasses.
static void addPropertyChangeListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener that listens to all handeled categories of type Category and subclasses.
static void attachParent(java.lang.Object catId, java.lang.Object parentID, java.lang.Object source)
          Adds a parent to a category.
static boolean containsCategories(java.lang.Object[] ids)
          Return the if all nodes with exists in the node map
static boolean containsCategory(java.lang.Object id)
          Return the if an node with the id exists in the node map
static boolean detachParent(java.lang.Object catId, java.lang.Object parentID, java.lang.Object source)
          Removes a parent from a category.
static java.util.List getBrokedCategories()
          Returns a new list with all Category objects that are currently beeing broked (i.e.
static int getBrokedCategoryCount()
          Returns the number of broked categories in the depository.
static Category getCategory(java.lang.Object id)
          Return the node.
static CategoryResolver getCategoryResolver()
          Returns the current resolver.
static CategoryResolver getCurrentCategoryResolver()
          Returns the current resolver.
static java.lang.Class getEnforceIDClass()
          Returns the id class type that always should be used as id for the categories.
static java.lang.Object getFirstOverriddenObject(java.lang.Object[] catIDs, java.lang.String targetName, PropertyKey property, java.lang.Object def)
          Calls getOverriddenObject(Object, String, PropertyKey, Object) for every category in catIDs.
static java.util.logging.Logger getLogger()
          Returns the current logger or null if none is set.
static java.lang.Object getOverriddenObject(java.lang.Object catID, java.lang.String targetName, PropertyKey property, java.lang.Object def)
          Returns another object if there is an override registered for propName property for category catID.
static Category getRoot()
          Returns the single root node.
static void removeBrokedCategories(java.util.Collection c, java.lang.Object source, int eventType)
          Remove Categorys from the depository anre unregisters them from all their parents.
static boolean removeBrokedCategory(Category c, java.lang.Object source, int eventType)
          Remove an category from the list.
static Category removeBrokedCategoryById(java.lang.Object catID, java.lang.Object source, int eventType)
          Remove a category from the list.
static Category removeBrokedCategoryByIdDeep(java.lang.Object id, java.lang.Object source, int eventType)
          Remove a category from the list including all child categories.
static void removeCategoriesBelow(java.lang.Object id)
          Deprecated. use removeBrokedCategoryByIdDeep(Object, Object, int).
static Category removeCategory(java.lang.Object id)
          Deprecated. Use removeBrokedCategoryById(Object, Object, int) instead. Name has changed to be more similar to ActivityDepository.
static void removeCategoryStructureListener(CategoryStructureListener l)
          Adds a listener to changes in the category tree structure.
static void removeOverride(java.lang.Object catID, java.lang.String targetName, PropertyKey property)
          Removes an override for a property in a category.
static void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes the listener.
static void setCategoryResolver(CategoryResolver resolver)
          Sets the resolver.
static void setEnforceIDClass(java.lang.Class enforceIDClass)
          Sets the id class type that always should be used as id for the categories.
static void setLogger(java.util.logging.Logger l)
          Set the current logger.
static void setOverride(java.lang.Object catID, java.lang.String targetName, PropertyKey property, java.lang.Object o)
          Sets an override for a property in a category.
static int size()
          Returns the total number of categories in the depository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CategoryDepository

public CategoryDepository()
Method Detail

size

public static int size()
Returns the total number of categories in the depository.

Returns:
The total number of categories in the depository.

getEnforceIDClass

public static java.lang.Class getEnforceIDClass()
Returns the id class type that always should be used as id for the categories. This can be used as an extra check to protect against for instance the bug where Long id:s are used when created in code but it is an Integer when it is returned from a database.

Returns:
The class type. null if no check.

setEnforceIDClass

public static void setEnforceIDClass(java.lang.Class enforceIDClass)
Sets the id class type that always should be used as id for the categories. This can be used as an extra check to protect against for instance the bug where Long id:s are used when created in code but it is an Integer when it is returned from a database.

Parameters:
enforceIDClass - The class type. null will turn of the ID class type check.

getLogger

public static java.util.logging.Logger getLogger()
Returns the current logger or null if none is set.

Returns:
The current logger or null if none is set.

setLogger

public static void setLogger(java.util.logging.Logger l)
Set the current logger. Set to null to diable logging (default)

Parameters:
l - The new logger or null to disable logging (default)

getRoot

public static Category getRoot()
Returns the single root node. The category tree will always be mounted on this root and it is in the application name space.

Returns:
The single root node. Never null. id for root is always null.

getCategory

public static Category getCategory(java.lang.Object id)
Return the node. The nodes are backed by a HashMap so the lookup should be really fast.

Parameters:
id - The id to look for. null returns the root node.
Returns:
The found node or null if not found.

containsCategory

public static boolean containsCategory(java.lang.Object id)
Return the if an node with the id exists in the node map

Returns:
If an node with the id exists in the node map

containsCategories

public static boolean containsCategories(java.lang.Object[] ids)
Return the if all nodes with exists in the node map

Returns:
If all nodes with the id exists in the node map. The array should contain category id:s.

addBrokedCategories

public static void addBrokedCategories(java.util.Collection c,
                                       java.lang.Object source,
                                       int eventType)
Adds a number of activities to the list. Calls addBrokedCategory(Category, Object, int) for every category since they have to be checked so that there are no category with the same ID. If there is the resolver have to deal with that problem.

Parameters:
c - The collection of Category objects to add to the depository and parents.
source - The source object that is adding the category.
eventType - The type of add/remove. Indicated for data providers and synchronizers. E.g. CategoryStructureEvent.ADDED_CREATED
Since:
5.6

addBrokedCategory

public static void addBrokedCategory(Category c,
                                     java.lang.Object source,
                                     int eventType)
Adds an category to the list. The category should already be considered "created" and should only be handled by the broker.

The parentIDs (Category.PROP_PARENT_IDS must already be set and the categories they denote must be in the depository already or a IllegalStateException will be thrown.

Note that if an category with the same ID already exist the registered category resolver will be invoked. The old one can be removed and the new added or nothing will happen depending on the resolver.

Parameters:
c - The category to add to the depository and parents.
source - The source object that is adding the category.
eventType - The type of add/remove. Indicated for data providers and synchronizers. E.g. CategoryStructureEvent.ADDED_CREATED
Since:
5.6

attachParent

public static void attachParent(java.lang.Object catId,
                                java.lang.Object parentID,
                                java.lang.Object source)
Adds a parent to a category. This makes the category with id catId have another parent. If this parent already exist it will not be added.

Note that both catId and parentID must exist in the Depository before a call to this method.

Parameters:
catId - The if of the category to set a new parent for. Not null.
parentID - The parent to add. May be null which means the root will be added as parent.
source - The source. Will be used as source in the event that is fired.

detachParent

public static boolean detachParent(java.lang.Object catId,
                                   java.lang.Object parentID,
                                   java.lang.Object source)
Removes a parent from a category. This makes the category with id catId have one less parent if it has parentID as parent. If this parent does not exist nothing will happen.

Note that both catId and parentID must exist in the Depository before a call to this method.

Parameters:
catId - The if of the category to set a new parent for. Not null.
parentID - The parent to add. May be null which means the root will be added as parent.
source - The source. Will be used as source in the event that is fired.
Returns:
If the parent was found and thus removed.

removeCategory

public static Category removeCategory(java.lang.Object id)
Deprecated. Use removeBrokedCategoryById(Object, Object, int) instead. Name has changed to be more similar to ActivityDepository.

Removes a node from all parents.

Parameters:
id - The id to remove. Not null.
Returns:
The removed node or null if not found.

removeBrokedCategory

public static boolean removeBrokedCategory(Category c,
                                           java.lang.Object source,
                                           int eventType)
Remove an category from the list. The category is not deleted, it is only removed from handling by the broker. The category will be found on identity, not with .equals().

Parameters:
source - The source that is removing the category
c - The category to remove. Not null and not the root node.
eventType - The type of add/remove. Indicated for data providers and synchronizers. E.g. CategoryStructureEvent.REMOVED_DELETED
Returns:
true if foind in the depositior and removed. false otherwise.
Since:
5.6

removeBrokedCategoryById

public static Category removeBrokedCategoryById(java.lang.Object catID,
                                                java.lang.Object source,
                                                int eventType)
Remove a category from the list. The category is not deleted, it is only removed from handling by the broker. The method will change all parents of the category so they do not point to this category any more. The parents of the category will be asked to remove id from their child list.

Parameters:
catID - The category to remove.
source - The source that is removing the category
eventType - The type of add/remove. Indicated for data providers and synchronizers. E.g. CategoryStructureEvent.REMOVED_DELETED
Returns:
The removed category or null if not found.
Since:
5.6

removeCategoriesBelow

public static void removeCategoriesBelow(java.lang.Object id)
Deprecated. use removeBrokedCategoryByIdDeep(Object, Object, int).


removeBrokedCategoryByIdDeep

public static Category removeBrokedCategoryByIdDeep(java.lang.Object id,
                                                    java.lang.Object source,
                                                    int eventType)
Remove a category from the list including all child categories. The method will change all parents of the category so they do not point to this category any more. The parents of the category will be asked to remove id from their child list.

The removes will start from the leaves.

Parameters:
id - The category to remove.
source - The source that is removing the category
eventType - The type of add/remove. Indicated for data providers and synchronizers. E.g. CategoryStructureEvent.REMOVED_DELETED
Returns:
The removed category or null if not found.
Since:
5.6

removeBrokedCategories

public static void removeBrokedCategories(java.util.Collection c,
                                          java.lang.Object source,
                                          int eventType)
Remove Categorys from the depository anre unregisters them from all their parents.

Parameters:
source - The source that is removing the category
c - The Category objects to remove.
eventType - The type of add/remove. Indicated for data providers and synchronizers. E.g. CategoryStructureEvent.REMOVED_DELETED
Since:
5.6

getBrokedCategories

public static java.util.List getBrokedCategories()
Returns a new list with all Category objects that are currently beeing broked (i.e. handled) by this depository.

Changes in the depository will not be reflected in the list after its creation.

Returns:
A new list. Never null but can be empty.
Since:
5.6
See Also:
Arrays.asList(T...)

getBrokedCategoryCount

public static int getBrokedCategoryCount()
Returns the number of broked categories in the depository.

Returns:
The number of broked categories in the depository.

getCategoryResolver

public static CategoryResolver getCategoryResolver()
Returns the current resolver. If null this object (which is a CategoryResolver) will just choose the newest one (modification date wise).

Returns:
The current resolver. Can be null.

setCategoryResolver

public static void setCategoryResolver(CategoryResolver resolver)
Sets the resolver. If null this object (which is a CategoryResolver) will just choose the newest one (modification date wise).

Parameters:
resolver - The new resolver. Can be null.

getCurrentCategoryResolver

public static CategoryResolver getCurrentCategoryResolver()
Returns the current resolver. Will never return null as getCategoryResolver() might. This methods returns this if not other resolver is returned.

Returns:
The reolver. Not null.

addPropertyChangeListener

public static void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a listener that listens to all handeled categories of type Category and subclasses. Note that classes that only implement Category have to call Category.fireStaticPropertyChangeEvent(java.beans.PropertyChangeEvent) to fire the static notification.

See PROP_xxx in the Category class.

Parameters:
l - The listener

addPropertyChangeListener

public static void addPropertyChangeListener(java.beans.PropertyChangeListener l,
                                             boolean asWeakRef)
Adds a listener that listens to all handeled categories of type Category and subclasses. Note that classes that only implement Category have to call Category.fireStaticPropertyChangeEvent(java.beans.PropertyChangeEvent) to fire the static notification.

See PROP_xxx in the Category class.

Parameters:
l - The listener
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removePropertyChangeListener

public static void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes the listener.

Parameters:
l - The listener to remove.

addCategoryStructureListener

public static void addCategoryStructureListener(CategoryStructureListener l)
Adds a listener to changes in the category tree structure. For instance when categories are added or removed.

Parameters:
l - The listener to remove.

addCategoryStructureListener

public static void addCategoryStructureListener(CategoryStructureListener l,
                                                boolean asWeakRef)
Adds a listener to changes in the category tree structure. For instance when categories are added or removed.

Parameters:
l - The listener to remove.
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removeCategoryStructureListener

public static void removeCategoryStructureListener(CategoryStructureListener l)
Adds a listener to changes in the category tree structure. For instance when categories are added or removed.

Parameters:
l - The listener to remove.

getFirstOverriddenObject

public static final java.lang.Object getFirstOverriddenObject(java.lang.Object[] catIDs,
                                                              java.lang.String targetName,
                                                              PropertyKey property,
                                                              java.lang.Object def)
Calls getOverriddenObject(Object, String, PropertyKey, Object) for every category in catIDs.


getOverriddenObject

public static final java.lang.Object getOverriddenObject(java.lang.Object catID,
                                                         java.lang.String targetName,
                                                         PropertyKey property,
                                                         java.lang.Object def)
Returns another object if there is an override registered for propName property for category catID.

Parameters:
catID - The is for tha category. IF null the def will always be returned since the root id can not be set override on.
targetName - Then name of the target. Not null.
property - The property key to return the object for. E.g. AShape.A_PAINT. Not null.
def - The object to return if no override is active/on
Returns:
The overidden object or def if there in no override. Can be null since this might be the new value.

setOverride

public static final void setOverride(java.lang.Object catID,
                                     java.lang.String targetName,
                                     PropertyKey property,
                                     java.lang.Object o)
Sets an override for a property in a category. If there was an override for this exact combination earlier it will be replaced.

Parameters:
catID - The is for tha category. Not null.
targetName - Then name of the target. Not null.
property - The property key to return the object for. E.g. AShape.A_PAINT. Not null.
o - The new object that will be returned by getOverriddenObject(Object, String, PropertyKey, Object). May be null.

removeOverride

public static final void removeOverride(java.lang.Object catID,
                                        java.lang.String targetName,
                                        PropertyKey property)
Removes an override for a property in a category.

Parameters:
catID - The is for tha category. Not null.
targetName - Then name of the target. Not null.
property - The property key. E.g. AShape.A_PAINT. Not null.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.