01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: /** The logger. */
37: private static final Log log = LogFactory
38: .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: ArgUtil.notNull(new Object[] { prefs },
45: new String[] { "preferences" },
46: "resolveChildren(java.util.prefs.Preferences)");
47:
48: List children = new ArrayList();
49: processPreferences(prefs, children);
50: return (String[]) children.toArray(new String[0]);
51: }
52:
53: /**
54: * <p>
55: * Recursively processes the preferences.
56: * </p>
57: *
58: * @param prefs The preferences.
59: * @param list The list to add the preferences to.
60: */
61: protected void processPreferences(Preferences prefs, List list) {
62: if (!list.contains(prefs.absolutePath())) {
63: list.add(prefs.absolutePath());
64: }
65: try {
66: String[] names = prefs.childrenNames();
67: for (int i = 0; i < names.length; i++) {
68: processPreferences(prefs.node(names[i]), list);
69: }
70: } catch (BackingStoreException bse) {
71: log.warn("can't find children of " + prefs.absolutePath(),
72: bse);
73: }
74: }
75: }
|