1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* 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 and15* limitations under the License.16*/17packageorg.apache.jetspeed.security.impl;
1819import java.util.ArrayList;
20import java.util.List;
21import java.util.prefs.BackingStoreException;
22import java.util.prefs.Preferences;
2324import org.apache.commons.logging.Log;
25import org.apache.commons.logging.LogFactory;
26import org.apache.jetspeed.util.ArgUtil;
2728/***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 */35publicclassBaseHierarchyResolver36 {
37/*** The logger. */38privatestaticfinal Log log = LogFactory.getLog(BaseHierarchyResolver.class);
3940/***41 * @see org.apache.jetspeed.security.HierarchyResolver#resolveChildren(java.util.prefs.Preferences)42 */43public String[] resolveChildren(Preferences prefs)
44 {
45 ArgUtil.notNull(new Object[] { prefs }, new String[] { "preferences" }, "resolveChildren(java.util.prefs.Preferences)");
4647 List children = new ArrayList();
48 processPreferences(prefs, children);
49return (String[]) children.toArray(new String[0]);
50 }
5152/***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 */60protectedvoid processPreferences(Preferences prefs, List list)
61 {
62if (!list.contains(prefs.absolutePath()))
63 {
64 list.add(prefs.absolutePath());
65 }
66try67 {
68 String[] names = prefs.childrenNames();
69for (int i = 0; i < names.length; i++)
70 {
71 processPreferences(prefs.node(names[i]), list);
72 }
73 }
74catch (BackingStoreException bse)
75 {
76 log.warn("can't find children of " + prefs.absolutePath(), bse);
77 }
78 }
79 }