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.prefs.impl;
1819import java.util.prefs.Preferences;
20import java.util.prefs.PreferencesFactory;
2122import org.apache.jetspeed.prefs.PreferencesException;
23import org.apache.jetspeed.prefs.PreferencesProvider;
2425/***26 * <p>{@link java.util.prefs.PreferencesFactory} implementation to27 * return {@link PreferencesImpl}.</p>28 *29 * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>30 */31publicclassPreferencesFactoryImpl implements PreferencesFactory
32 {
3334protectedstatic PreferencesProvider prefsProvider;
3536publicPreferencesFactoryImpl()
37 {
38super();
39 System.setProperty("java.util.prefs.PreferencesFactory", getClass().getName());
40 }
4142/***43 * @see java.util.prefs.PreferencesFactory#systemRoot()44 */45public Preferences systemRoot()
46 {
47return PreferencesImpl.systemRoot;
48 }
4950/***51 * @see java.util.prefs.PreferencesFactory#userRoot()52 */53public Preferences userRoot()
54 {
55return PreferencesImpl.userRoot;
56 }
5758/***59 * <p>60 * Initializes the factory.61 * </p>62 * 63 * @throws Exception64 */65publicvoid init() throws Exception
66 {
67try68 {
69 PreferencesImpl.setPreferencesProvider(prefsProvider);
70 PreferencesImpl.systemRoot = newPreferencesImpl(null, "", PreferencesImpl.SYSTEM_NODE_TYPE);
71 PreferencesImpl.userRoot = new PreferencesImpl(null, "", PreferencesImpl.USER_NODE_TYPE);
72 }
73catch(Throwable e)
74 {
75 e.printStackTrace();
76thrownew PreferencesException("Failed to initialize prefs api. "+e.toString());
77 }
78 }
7980/***81 * @return The {@link PreferencesProvider}82 */83public PreferencesProvider getPrefsProvider()
84 {
85return prefsProvider;
86 }
8788/***89 * <p>90 * Set the preferences provider.91 * </p>92 * 93 * @param prefsProvider The {@link PreferencesProvider}94 */95publicvoid setPrefsProvider(PreferencesProvider prefsProvider)
96 {
97 PreferencesFactoryImpl.prefsProvider = prefsProvider;
98 }
99 }