1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.impl;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.prefs.BackingStoreException;
22 import java.util.prefs.Preferences;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.jetspeed.util.ArgUtil;
27
28 /***
29 * <p>
30 * Base implementation for the hierarchy resolver.
31 * <p>
32 *
33 * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
34 */
35 public class BaseHierarchyResolver
36 {
37 /*** The logger. */
38 private static final Log log = LogFactory.getLog(BaseHierarchyResolver.class);
39
40 /***
41 * @see org.apache.jetspeed.security.HierarchyResolver#resolveChildren(java.util.prefs.Preferences)
42 */
43 public String[] resolveChildren(Preferences prefs)
44 {
45 ArgUtil.notNull(new Object[] { prefs }, new String[] { "preferences" }, "resolveChildren(java.util.prefs.Preferences)");
46
47 List children = new ArrayList();
48 processPreferences(prefs, children);
49 return (String[]) children.toArray(new String[0]);
50 }
51
52 /***
53 * <p>
54 * Recursively processes the preferences.
55 * </p>
56 *
57 * @param prefs The preferences.
58 * @param list The list to add the preferences to.
59 */
60 protected void processPreferences(Preferences prefs, List list)
61 {
62 if (!list.contains(prefs.absolutePath()))
63 {
64 list.add(prefs.absolutePath());
65 }
66 try
67 {
68 String[] names = prefs.childrenNames();
69 for (int i = 0; i < names.length; i++)
70 {
71 processPreferences(prefs.node(names[i]), list);
72 }
73 }
74 catch (BackingStoreException bse)
75 {
76 log.warn("can't find children of " + prefs.absolutePath(), bse);
77 }
78 }
79 }