001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: UserPrefsAsMap.java,v 1.2 2006/09/29 12:32:11 drmlipp Exp $
021: *
022: * $Log: UserPrefsAsMap.java,v $
023: * Revision 1.2 2006/09/29 12:32:11 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.1 2003/06/30 20:05:12 drmlipp
027: * Initial import
028: *
029: * Revision 1.8 2003/06/27 08:51:46 lipp
030: * Fixed copyright/license information.
031: *
032: * Revision 1.7 2003/04/25 14:50:59 lipp
033: * Fixed javadoc errors and warnings.
034: *
035: * Revision 1.6 2003/03/31 16:50:28 huaiyang
036: * Logging using common-logging.
037: *
038: * Revision 1.5 2003/03/03 12:52:58 lipp
039: * Improved exception handling.
040: *
041: * Revision 1.4 2003/03/03 12:35:18 lipp
042: * Removed inappropriate use of printStacktrace.
043: *
044: * Revision 1.3 2002/10/17 13:10:41 schlue
045: * Using of UserPrefsAsMap added.
046: *
047: * Revision 1.2 2002/01/29 15:15:14 feldgen
048: * Implemented the methods
049: *
050: * Revision 1.1 2001/11/25 14:12:34 lipp
051: * Prepared.
052: *
053: */
054:
055: package de.danet.an.util.userprefs;
056:
057: import java.rmi.RemoteException;
058: import java.util.HashMap;
059: import java.util.Iterator;
060: import java.util.Map;
061: import java.util.Set;
062:
063: /**
064: * This class provides a {@link java.util.Map map} view of user
065: * preferences as provided by a {@link
066: * de.danet.an.util.userprefs.UserPrefsService user preferences
067: * service}. This adapter allows user preferences to be fed to the
068: * {@link de.danet.an.util.SegmentedMap <code>SegmentedMap</code>}
069: * class. NOTE: This view is a snapshot of the preference data at
070: * creation time. Subsequent modifications to the preferences are not
071: * mirrored by this view.
072: */
073: public class UserPrefsAsMap extends HashMap {
074:
075: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
076: .getLog(UserPrefsAsMap.class);
077:
078: /**
079: * the UserPrefsService
080: */
081: private UserPrefsService pService = null;
082:
083: /**
084: * Default constructor.
085: * @param prefsService UserPrefsService to be used
086: * @throws RemoteException if a system level error occurs while
087: * accessing the <code>prefsService</code>.
088: */
089: public UserPrefsAsMap(UserPrefsService prefsService)
090: throws RemoteException {
091: this .pService = prefsService;
092: Set pSet = pService.preferencesSet();
093: Iterator iterator = pSet.iterator();
094: while (iterator.hasNext()) {
095: Object key = iterator.next();
096: super .put(key, pService.getPreference((String) key));
097: }
098: }
099:
100: /**
101: * This Method is not supported by UserPrefsService.
102: */
103: public void clear() {
104: throw new UnsupportedOperationException();
105: }
106:
107: /**
108: * This Method puts the given key/value pair into the hashmap
109: * and the UserPreferences
110: * @param key The key to the given value
111: * @param value The value to be set
112: * @return the previous value of the key
113: */
114: public Object put(Object key, Object value) {
115: try {
116: pService.setPreference((String) key, value);
117: } catch (RemoteException ex) {
118: logger.error(ex.getMessage(), ex);
119: throw new IllegalStateException(ex.getMessage());
120: }
121: return super .put(key, value);
122: }
123:
124: /**
125: * This Method adds all key/value pairs from the given Map
126: * into the hashmap and the UserPreferences
127: * @param t The Map to be copied
128: */
129: public void putAll(Map t) {
130: super .putAll(t);
131:
132: Set kSet = t.keySet();
133: Object k = null;
134: Iterator i = kSet.iterator();
135: while (i.hasNext()) {
136: k = i.next();
137: put(k, t.get(k));
138: }
139: }
140:
141: /**
142: * This Method is not supported by UserPrefsService
143: * @param key key of the object to be removed
144: * @return Map-representation of the given UserPrefs
145: */
146: public Object remove(Object key) {
147: throw new UnsupportedOperationException();
148: }
149: }
|