/** * Get all descendant roles, the order is randomly * * @param roleName */ public List<String> getDescendants(String roleName) { checkRole(roleName); Set<String> descendants = new HashSet<String>(); fillDescendents(getChildren(roleName), descendants); List<String> result = new ArrayList<String>(); result.addAll(descendants); return result; }
/** * recursive method to fill the descendant list * * @param children * @param descendants */ protected void fillDescendents(List<String> children, Set<String> descendants) { if (children == null || children.size() == 0) return; // end recursion for (String childName : children) { if (descendants.contains(childName)) // cycle cycleDetected(childName, null); descendants.add(childName); } for (String childName : children) { List<String> grandchildren = getChildren(childName); fillDescendents(grandchildren, descendants); } }