org.pm4j.core.pm.impl
Class PmUtil

java.lang.Object
  extended by org.pm4j.core.pm.impl.PmUtil

public final class PmUtil
extends java.lang.Object

Some convenience algorithms that may be used often but are not (yet?) members of the PM interfaces.

Author:
olaf boede

Constructor Summary
PmUtil()
           
 
Method Summary
static java.util.Set<PmCacheApi.CacheKind> cacheKindArrayToSet(PmCacheApi.CacheKind... cacheKinds)
          Converts an array of cache kinds defintions to a set.
static java.util.List<PmObject> findChangedPms(PmObject searchRootPm)
          Reports the set of changed PMs within a sub-tree of PMs.
static PmObject findChildPm(PmObject pm, java.lang.String localName)
          Searches for a direct child PM.
Finds PM's declared in public fields as well as PM's that where added dynamically.
static
<T extends PmObject>
T
findPmParentOfType(PmObject startPm, java.lang.Class<T> type)
          Searches an instance of the requested type within the PM context hierarchy of the given PM.
static java.lang.String getAbsoluteName(PmObject pm)
          A name that includes the names of all elements and sessions within the complete context hierarchy of the PM.
static java.util.List<PmObject> getPmChildren(PmObject pm)
           
static java.io.Serializable getPmContentAspect(PmObject pm, PmAspect aspect)
           
static java.util.List<PmObject> getPmHierarchy(PmObject pm, boolean withSessionHierarchy)
          Generates a list that represents the PM hierarchy of the given PM.
static java.lang.String getPmLogString(PmObject pm)
          Provides a string for logging and debugging.
static
<T extends PmObject>
T
getPmParentOfType(PmObject startPm, java.lang.Class<T> type)
          Gets the PM parent with the requested type from the PM hierarchy of the given PM.
static PmConversation getRootSession(PmObject pm)
          Provides the root of the session hierarchy for the given PM.
static java.util.List<? extends PmObject> getVisibleItems(java.util.Collection<? extends PmObject> allItems)
          Provides the subset of visible PMs.
static java.util.List<PmCommand> getVisiblePmCommands(PmObject pm)
          Provides the set of all visible commands.
static java.util.List<PmCommand> getVisiblePmCommands(PmObject pm, PmCommand.CommandSet commandSet)
           
static boolean hasValidAttributes(PmElement pm)
           
static boolean isChild(PmObject parentCandidate, PmObject childCandidate)
          Determines if the given instances are participants of a parent child relation.
static void setPmContentAspect(PmObject pm, PmAspect aspect, java.io.Serializable value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PmUtil

public PmUtil()
Method Detail

getPmHierarchy

public static java.util.List<PmObject> getPmHierarchy(PmObject pm,
                                                      boolean withSessionHierarchy)
Generates a list that represents the PM hierarchy of the given PM.

The first item is the given PM itself.
The last item is the highest one of the reported PM hierarchy..

Parameters:
pm - The PM to analyze.
withSessionHierarchy - If true PM's till the root session will be returned.
If false PM's till the session (exclusive) that manages the given PM will returned.
Returns:
The session hierarchy.

getRootSession

public static PmConversation getRootSession(PmObject pm)
Provides the root of the session hierarchy for the given PM.

Parameters:
pm - The PM to get the root session for.
Returns:
The root session instance.

getVisibleItems

public static java.util.List<? extends PmObject> getVisibleItems(java.util.Collection<? extends PmObject> allItems)
Provides the subset of visible PMs.

Parameters:
allItems - The collection to filter.
Returns:
The visible items of the given collection.

findPmParentOfType

public static <T extends PmObject> T findPmParentOfType(PmObject startPm,
                                                        java.lang.Class<T> type)
Searches an instance of the requested type within the PM context hierarchy of the given PM.

Parameters:
startPm - The PM to get the context object for.
type - The type of the requested context object.
Returns:
The found instance or null if there was not context object with the given type.

getPmParentOfType

public static <T extends PmObject> T getPmParentOfType(PmObject startPm,
                                                       java.lang.Class<T> type)
Gets the PM parent with the requested type from the PM hierarchy of the given PM.

Parameters:
startPm - The PM to get the context object for.
type - The type of the requested context object.
Returns:
The found parent instance.
Throws:
org.pm4j.core.exception.PmRuntimeException - if there is no parent PM with the given type.

cacheKindArrayToSet

public static final java.util.Set<PmCacheApi.CacheKind> cacheKindArrayToSet(PmCacheApi.CacheKind... cacheKinds)
Converts an array of cache kinds defintions to a set.

If no argument is provided, the PmObject.CacheKind#ALL_SET will be returned.

Parameters:
cacheKinds - The array to convert.
Returns:
The corresponding set.

hasValidAttributes

public static boolean hasValidAttributes(PmElement pm)
Parameters:
pm - The element to check.
Returns:
true if all attributes do not have an error state.

getPmChildren

public static java.util.List<PmObject> getPmChildren(PmObject pm)
Returns:
The set of all child PM's. Includes field bound PM's as well as dynamically created PM's.

findChildPm

public static PmObject findChildPm(PmObject pm,
                                   java.lang.String localName)
Searches for a direct child PM.
Finds PM's declared in public fields as well as PM's that where added dynamically.

Parameters:
localName - Name of the child within this instance.
Returns:
The found child PM or null.

isChild

public static boolean isChild(PmObject parentCandidate,
                              PmObject childCandidate)
Determines if the given instances are participants of a parent child relation.

Parameters:
parentCandidate - The parent candidate.
childCandidate - The child candidate.
Returns:
true if the given child has the given PM as parent.

findChangedPms

public static java.util.List<PmObject> findChangedPms(PmObject searchRootPm)
Reports the set of changed PMs within a sub-tree of PMs.

Provides usually a set of changed PmAttrs.

Parameters:
searchRootPm - The root element to start with.
Returns:
The set of changed PMs.

getVisiblePmCommands

public static java.util.List<PmCommand> getVisiblePmCommands(PmObject pm)
Provides the set of all visible commands.

Instances of PmCommandSeparator will automatically appear/disappear, depending on the visibility of the commands before/after/between these separators.

Returns:
The list of visible commands and separators.

getVisiblePmCommands

public static java.util.List<PmCommand> getVisiblePmCommands(PmObject pm,
                                                             PmCommand.CommandSet commandSet)
Parameters:
The - command set kind to get.
Returns:
The command set that should be shown within the given command set kind.

getAbsoluteName

public static java.lang.String getAbsoluteName(PmObject pm)
A name that includes the names of all elements and sessions within the complete context hierarchy of the PM.

Example: The name attribute of a user presentation model may have the long name 'userSession.userPm.name'.

Returns:
The canonical name.

getPmLogString

public static java.lang.String getPmLogString(PmObject pm)
Provides a string for logging and debugging.

Returns:
A 'toString' like output.

setPmContentAspect

public static void setPmContentAspect(PmObject pm,
                                      PmAspect aspect,
                                      java.io.Serializable value)
                               throws org.pm4j.core.exception.PmConverterException
Throws:
org.pm4j.core.exception.PmConverterException

getPmContentAspect

public static java.io.Serializable getPmContentAspect(PmObject pm,
                                                      PmAspect aspect)