Package com.cmobilecom.af.model.property
Class HierarchyAccessor<T extends Hierarchy>
- java.lang.Object
-
- com.cmobilecom.af.model.property.HierarchyAccessor<T>
-
- All Implemented Interfaces:
java.io.Serializable
public class HierarchyAccessor<T extends Hierarchy> extends java.lang.Object implements java.io.Serializable
HierarchyAccessor for accessing hierarchy entities.- Since:
- 5.17
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
HierarchyAccessor.HierarchyNode
HierarchyNode represents a hierarchy entity for building hierarchy entity tree (parent/child relationship).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearCache()
Clear cache including hierarchy node tree and id rule.static void
clearCache(DataAccessUnit ownerDataAccessUnit)
Clear caches of all HierarchyAccessor instances whose hierarchy entities are owned by the ownerDataAccessUnit.static void
clearCache(java.lang.Class hierarchyClass, java.lang.String rootHierarchyId, DataAccessUnit dauAccessFrom)
Clear the cache of a HierarchyAccessor instance.static int[]
convertHierarchyIdRule(java.lang.String rootHierarchyId, int[] idRule, java.lang.String newRootHierarchyId)
Convert hierarchy id rule for the descendants of the specified newRootHierarchyId.static java.util.List<HierarchyAccessor>
getCachedInstances(java.lang.Class hierarchyClass, DataAccessUnit dauAccessFrom)
Get all the cached HierarchyAccessor(s) for the specified hierarchy type and the owner dataAccessUnitint
getChildHierarchyCount(java.lang.String hierarchyId)
Get child hierarchy count of the hierarchyint
getChildHierarchyCount(T hierarchy)
Get child hierarchy count of the hierarchyjava.util.List<HierarchyAccessor.HierarchyNode>
getChildHierarchyNodes(T hierarchy)
Get child hierarchy nodes of the hierarchyjava.util.List<SelectItem>
getChildHierarchySelectItems(HierarchyAccessor.HierarchyNode hierarchyNode, boolean localIdAsValue, boolean addEmptySelection)
Get child hierarchy select items.java.util.List<SelectItem>
getChildHierarchySelectItems(java.lang.String hierarchyId, boolean localIdAsValue, boolean addEmptySelection)
Get child hierarchy select items.int
getDepth(Hierarchy hierarchy)
Get the depth of the hierarchy.int
getDepth(java.lang.String hierarchyId)
Get the depth of the hierarchy.static int
getDepth(java.lang.String hierarchyId, int rootHierarchyIdLen, int[] idRule)
Get hierarchy depth according to the id rule.int
getHierarchyIdLength(int depth)
Get hierarchy id length at the specific depth according to the id rule.static int
getHierarchyIdLength(int depth, int[] idRule)
Get hierarchy id length of the specified depth according to the id rule.HierarchyAccessor.HierarchyNode
getHierarchyNode(java.lang.String hierarchyId)
Get the HierarchyNode in the hierarchy tree for the hierarchy with the id.HierarchyAccessor.HierarchyNode
getHierarchyNode(T hierarchy)
Get the HierarchyNode in the hierarchy tree for the hierarchy entity.int
getIdLengthAt(int index)
Get id length at the specified index.static int
getIdLengthAt(int[] idRule, int index)
Get id length at the specified index.int[]
getIdRule()
Get the hierarchy id rule.static <T extends Hierarchy>
HierarchyAccessorgetInstance(java.lang.Class<T> hierarchyClass, java.lang.String rootHierarchyId, DataAccessUnit dauAccessFrom)
Get a HierarchyAccessor instance.static <T extends Hierarchy>
HierarchyAccessorgetInstance(java.lang.Class<T> hierarchyClass, java.lang.String rootHierarchyId, DataAccessUnit dauAccessFrom, boolean createIfNotFound)
Get a HierarchyAccessor instance.java.lang.String
getNextAvailableChildHierarchyId(java.lang.String hierarchyId)
Get the next available child hierarchy id.java.lang.String
getNextAvailableSiblingHierarchyId(java.lang.String hierarchyId)
Get the next available sibling hierarchy id.java.lang.String
getParentHierarchyId(java.lang.String hierarchyId)
Get parent hierarchy id.static java.lang.String
getParentHierarchyId(java.lang.String hierarchyId, int[] idRule)
Get parent hierarchy id based on the id rule.java.util.List<HierarchyAccessor.HierarchyNode>
getPath(java.lang.String hierarchyId)
Get the hierarchy path from the root to the hierarchy.java.util.List<HierarchyAccessor.HierarchyNode>
getPath(T hierarchy)
Get the hierarchy path from the root to the hierarchy.java.lang.String
getRootHierarchyId()
Get root hierarchy id.int
getRootHierarchyIdLen()
Get root hierarchy id length.HierarchyAccessor.HierarchyNode
getRootNode()
Get the root hierarchy node.boolean
matchIdRule(java.lang.String idRule)
Does the IdRule of this HierarchyAccessor match the specified idRule?
-
-
-
Method Detail
-
getInstance
public static <T extends Hierarchy> HierarchyAccessor getInstance(java.lang.Class<T> hierarchyClass, java.lang.String rootHierarchyId, DataAccessUnit dauAccessFrom, boolean createIfNotFound) throws SystemException
Get a HierarchyAccessor instance.- Parameters:
hierarchyClass
- hierarchy entity classrootHierarchyId
- root hierarchy id for this accessor. null for accessing whole hierarchy.dauAccessFrom
- the DataAccessUnit from which to access the hierarchy entitiescreateIfNotFound
- whether to create one if not found- Throws:
SystemException
- throw if an error occurs
-
getInstance
public static <T extends Hierarchy> HierarchyAccessor getInstance(java.lang.Class<T> hierarchyClass, java.lang.String rootHierarchyId, DataAccessUnit dauAccessFrom) throws SystemException
Get a HierarchyAccessor instance. Create one if not found.- Parameters:
hierarchyClass
- hierarchy entity classrootHierarchyId
- root hierarchy id for this accessor. null for accessing whole hierarchy.dauAccessFrom
- the DataAccessUnit from which to access the hierarchy entities- Throws:
SystemException
- throw if an error occurs
-
getCachedInstances
public static java.util.List<HierarchyAccessor> getCachedInstances(java.lang.Class hierarchyClass, DataAccessUnit dauAccessFrom)
Get all the cached HierarchyAccessor(s) for the specified hierarchy type and the owner dataAccessUnit- Parameters:
hierarchyClass
- hierarchy classdauAccessFrom
- the dataAccessUnit to get the hierarchy type's ownerDataAccessUnit- Returns:
- a list of HierarchyAccessor(s)
-
clearCache
public static void clearCache(java.lang.Class hierarchyClass, java.lang.String rootHierarchyId, DataAccessUnit dauAccessFrom) throws SystemException
Clear the cache of a HierarchyAccessor instance.- Parameters:
hierarchyClass
- hierarchy entity classrootHierarchyId
- root hierarchy id for this accessor. null for accessing whole hierarchy.dauAccessFrom
- the DataAccessUnit from which to access the hierarchy entities- Throws:
SystemException
-
clearCache
public static void clearCache(DataAccessUnit ownerDataAccessUnit)
Clear caches of all HierarchyAccessor instances whose hierarchy entities are owned by the ownerDataAccessUnit.- Parameters:
ownerDataAccessUnit
- owner DataAccessUnit
-
convertHierarchyIdRule
public static int[] convertHierarchyIdRule(java.lang.String rootHierarchyId, int[] idRule, java.lang.String newRootHierarchyId) throws SystemException
Convert hierarchy id rule for the descendants of the specified newRootHierarchyId.- Parameters:
rootHierarchyId
- root hierarchy id (null for empty)idRule
- id rule for descendants of the rootHierarchyIdnewRootHierarchyId
- new root hierarchy id- Returns:
- new id rule for newRootHierarchyId
- Throws:
SystemException
- throw if newRootHierarchyId does not comply with the IdRule
-
getIdRule
public int[] getIdRule()
Get the hierarchy id rule.- If rootHierarchyId is not null, root is the entity with the rootHierarchyId.
- If rootHierarchyId is null, root is a virtual entity (null).
- Returns:
- id rule.
- See Also:
IdRule
-
matchIdRule
public boolean matchIdRule(java.lang.String idRule)
Does the IdRule of this HierarchyAccessor match the specified idRule?- Parameters:
idRule
- id rule as string- Returns:
- true if they match or this idRule is not initialized, false otherwise
-
getChildHierarchySelectItems
public java.util.List<SelectItem> getChildHierarchySelectItems(HierarchyAccessor.HierarchyNode hierarchyNode, boolean localIdAsValue, boolean addEmptySelection)
Get child hierarchy select items. If localIdAsValue is true, only partial hierarchy id is used. For example, parent hierarchyId is US, and a child hierarchyId is USNY, then NY will be the select item value for the child hierarchy.- Parameters:
hierarchyNode
- a hierarchy nodelocalIdAsValue
- whether to use local id as select item values.addEmptySelection
- whether to add empty selection (value is the hierarchyId)
-
getChildHierarchySelectItems
public java.util.List<SelectItem> getChildHierarchySelectItems(java.lang.String hierarchyId, boolean localIdAsValue, boolean addEmptySelection)
Get child hierarchy select items. If localIdAsValue is true, only partial hierarchy id is used. For example, parent hierarchyId is US, and a child hierarchyId is USNY, then NY will be the select item value for the child hierarchy.- Parameters:
hierarchyId
- parent hierarchy nodelocalIdAsValue
- whether to use local id as select item values.addEmptySelection
- whether to add empty selection (value is the hierarchyId)
-
getRootNode
public HierarchyAccessor.HierarchyNode getRootNode()
Get the root hierarchy node.- Returns:
- root
-
clearCache
public void clearCache()
Clear cache including hierarchy node tree and id rule. They will be rebuilt on demand.
-
getHierarchyNode
public HierarchyAccessor.HierarchyNode getHierarchyNode(T hierarchy)
Get the HierarchyNode in the hierarchy tree for the hierarchy entity.- Parameters:
hierarchy
- hierarchy entity- Returns:
- HierarchyNode object
-
getHierarchyNode
public HierarchyAccessor.HierarchyNode getHierarchyNode(java.lang.String hierarchyId)
Get the HierarchyNode in the hierarchy tree for the hierarchy with the id.- Parameters:
hierarchyId
- hierarchy id- Returns:
- HierarchyNode object
-
getRootHierarchyId
public java.lang.String getRootHierarchyId()
Get root hierarchy id. null for the root of whole hierarchy tree.- Returns:
- root hierarchy id.
-
getRootHierarchyIdLen
public int getRootHierarchyIdLen()
Get root hierarchy id length.- Returns:
- id length
-
getDepth
public static int getDepth(java.lang.String hierarchyId, int rootHierarchyIdLen, int[] idRule) throws BackingBeanException
Get hierarchy depth according to the id rule. The root depth is 1.- Parameters:
hierarchyId
- hierarchy idrootHierarchyIdLen
- the length of root hierarchy ididRule
- id rule for descendants of the rootHierarchyIdLen- Returns:
- the depth of the hierarchy id
- Throws:
BackingBeanException
- throw if the hierarchyId does not comply with the Id Rule.
-
getDepth
public int getDepth(Hierarchy hierarchy) throws BackingBeanException
Get the depth of the hierarchy. The depth of root is 1.- Parameters:
hierarchy
- a hierarchy entity- Returns:
- the depth of the hierarchy
- Throws:
BackingBeanException
-
getDepth
public int getDepth(java.lang.String hierarchyId) throws BackingBeanException
Get the depth of the hierarchy. The depth of root is 1.- Parameters:
hierarchyId
- hierarchy id- Returns:
- depth
- Throws:
BackingBeanException
- throw if the hierarchyId does not comply with the Id Rule.
-
getIdLengthAt
public static int getIdLengthAt(int[] idRule, int index)
Get id length at the specified index. The last digit of id rule will repeat as many times as needed.- Parameters:
idRule
- Id Ruleindex
- zero-based index- Returns:
- id length at the index
-
getIdLengthAt
public int getIdLengthAt(int index)
Get id length at the specified index. The last digit of id rule will repeat as many times as needed.- Parameters:
index
- zero-based index- Returns:
- id length at the index
-
getHierarchyIdLength
public static int getHierarchyIdLength(int depth, int[] idRule)
Get hierarchy id length of the specified depth according to the id rule. The root depth is 1.- Parameters:
depth
- hierarchy depthidRule
- id rule- Returns:
- hierarchy id length
-
getHierarchyIdLength
public int getHierarchyIdLength(int depth)
Get hierarchy id length at the specific depth according to the id rule. The root depth is 1.- Parameters:
depth
- hierarchy depth- Returns:
- hierarchy id length
-
getParentHierarchyId
public java.lang.String getParentHierarchyId(java.lang.String hierarchyId) throws SystemException
Get parent hierarchy id.- Parameters:
hierarchyId
- a hierarchy id- Returns:
- parent hierarchy id. return null for the virtual root.
- Throws:
SystemException
-
getParentHierarchyId
public static java.lang.String getParentHierarchyId(java.lang.String hierarchyId, int[] idRule) throws SystemException
Get parent hierarchy id based on the id rule.- Parameters:
hierarchyId
- hierarchy ididRule
- hierarchy id rule- Returns:
- parent hierarchy id. return null if the hierarchy does not have a parent.
- Throws:
BackingBeanException
- throw if the hierarchyId does not comply with the Id ruleSystemException
-
getChildHierarchyNodes
public java.util.List<HierarchyAccessor.HierarchyNode> getChildHierarchyNodes(T hierarchy)
Get child hierarchy nodes of the hierarchy- Parameters:
hierarchy
- a hierarchy entity, null for root- Returns:
- a list of child HierarchyNodes. return null if there is no children.
-
getChildHierarchyCount
public int getChildHierarchyCount(T hierarchy)
Get child hierarchy count of the hierarchy- Parameters:
hierarchy
- a hierarchy entity, null for root- Returns:
- a list of child HierarchyNodes. return null if there is no children.
-
getNextAvailableChildHierarchyId
public java.lang.String getNextAvailableChildHierarchyId(java.lang.String hierarchyId)
Get the next available child hierarchy id.- Parameters:
hierarchyId
- a parent hierarchy id in hierarchy tree- Returns:
- available child hierarchy id
-
getNextAvailableSiblingHierarchyId
public java.lang.String getNextAvailableSiblingHierarchyId(java.lang.String hierarchyId)
Get the next available sibling hierarchy id.- Parameters:
hierarchyId
- an existing hierarchy id in hierarchy tree, which can not be null.- Returns:
- hierarchy id
-
getChildHierarchyCount
public int getChildHierarchyCount(java.lang.String hierarchyId)
Get child hierarchy count of the hierarchy- Parameters:
hierarchyId
- hierarchy id, null for root- Returns:
- a list of child HierarchyNodes. return null if there is no children.
-
getPath
public java.util.List<HierarchyAccessor.HierarchyNode> getPath(T hierarchy)
Get the hierarchy path from the root to the hierarchy.- Parameters:
hierarchy
- a hierarchy entity- Returns:
- a list of HierarchyNodes from root to the hierarchy
- Throws:
java.lang.IllegalArgumentException
- throw if the hierarchy not found
-
getPath
public java.util.List<HierarchyAccessor.HierarchyNode> getPath(java.lang.String hierarchyId)
Get the hierarchy path from the root to the hierarchy.- Parameters:
hierarchyId
- a hierarchy id, null for the virtual root- Returns:
- a list of HierarchyNodes from root to the hierarchy
- Throws:
java.lang.IllegalArgumentException
- throw if the hierarchy not found
-
-