001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.jumpimpl.module.preferences;
026:
027: import com.sun.jump.module.preferences.JUMPPreferencesModuleFactory;
028: import com.sun.jump.module.preferences.JUMPPreferencesModule;
029: import java.util.Map;
030: import java.util.Vector;
031:
032: public class PreferencesModuleFactoryImpl extends
033: JUMPPreferencesModuleFactory {
034: // singleton instances
035: private static JUMPPreferencesModule systemPreferencesModule = null;
036: private Map configData;
037:
038: /**
039: * Returns a <code>JUMPPreferencesModule</code> for the type specified.
040: *
041: * @param type the type or namespace of the preferences.
042: * The supported values are
043: * <ul>
044: * <li>{@link #TYPE_SYSTEM_PREFERENCES}</li>
045: * <li>{@link #TYPE_APPLICATION_PREFERENCES}</li>
046: * </ul>
047: * @throws java.lang.IllegalArgumentException if the type is not
048: * not supported by the factory.
049: */
050: public JUMPPreferencesModule getModule(String type) {
051: if (type
052: .equals(JUMPPreferencesModuleFactory.TYPE_SYSTEM_PREFERENCES))
053: return getSystemPreferencesModule();
054: else
055: throw new IllegalArgumentException(
056: "Preferences Type "
057: + type
058: + " not supported; only System preferences type is supported");
059:
060: }
061:
062: private synchronized JUMPPreferencesModule getSystemPreferencesModule() {
063: if (systemPreferencesModule == null) {
064: systemPreferencesModule = new SystemPreferencesModuleImpl();
065: systemPreferencesModule.load(configData);
066: }
067: return systemPreferencesModule;
068: }
069:
070: /**
071: * @return a list of all registered preferences in the system for all
072: * namespaces.
073: */
074: public JUMPPreferencesModule[] getAllPreferences() {
075: Vector moduleVector = new Vector();
076: JUMPPreferencesModule systemPrefs = getSystemPreferencesModule();
077: if (systemPrefs != null)
078: moduleVector.add(systemPrefs);
079: return (JUMPPreferencesModule[]) moduleVector
080: .toArray(new JUMPPreferencesModule[] {});
081: }
082:
083: /**
084: * load this module with the given properties
085: * @param map properties of this module
086: */
087: public void load(Map config) {
088: this .configData = config;
089: }
090:
091: /**
092: * unload the module
093: */
094: public void unload() {
095: if (systemPreferencesModule != null)
096: systemPreferencesModule.unload();
097: systemPreferencesModule = null;
098: }
099:
100: }
|