001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.migration.model22.impl.preferences;
023:
024: import org.apache.log4j.Logger;
025: import org.jboss.portal.migration.model22.other.Value;
026: import org.jboss.portal.migration.model22.other.ValueMap;
027:
028: import java.util.HashMap;
029: import java.util.Map;
030: import java.util.Set;
031:
032: /**
033: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
034: * @version $Revision: 8784 $
035: */
036: public class MappedPreferences implements ValueMap {
037:
038: /** Our logger. */
039: private static Logger log = Logger
040: .getLogger(MappedPreferences.class);
041:
042: private Long key;
043: private String id;
044: public Map map;
045:
046: /** Hibernate constructor. */
047: public MappedPreferences() {
048: this .key = null;
049: this .id = null;
050: this .map = null;
051: }
052:
053: public MappedPreferences(String id) {
054: this .key = null;
055: this .id = id;
056: this .map = new HashMap();
057: }
058:
059: /**
060: *
061: */
062: public Long getKey() {
063: return key;
064: }
065:
066: /** Called by hibernate. */
067: public void setKey(Long key) {
068: this .key = key;
069: }
070:
071: /**
072: *
073: */
074: public String getId() {
075: return id;
076: }
077:
078: /** Called by hibernate. */
079: public void setId(String id) {
080: this .id = id;
081: }
082:
083: /**
084: *
085: */
086: public Map getContent() {
087: return map;
088: }
089:
090: /**
091: *
092: */
093: public void setContent(Map content) {
094: this .map = content;
095: }
096:
097: // ValueMap implementation *************************************************************************************
098:
099: public Set getKeys() {
100: return map.keySet();
101: }
102:
103: public Value getValue(String key) {
104: if (key == null) {
105: throw new IllegalArgumentException("key must not be null");
106: }
107: MappedPreference preference = (MappedPreference) map.get(key);
108: if (preference != null) {
109: return preference.getValue();
110: } else {
111: return null;
112: }
113: }
114:
115: public void setValue(String key, Value value) {
116: if (key == null) {
117: throw new IllegalArgumentException("key must not be null");
118: }
119: if (value == null) {
120: map.remove(key);
121: } else {
122: MappedPreference pref = (MappedPreference) map.get(key);
123: if (pref != null) {
124: pref.setValue(value);
125: } else {
126: map.put(key, newPreference(key, value));
127: }
128: }
129: }
130:
131: public boolean isReadOnly(String key)
132: throws IllegalArgumentException {
133: throw new UnsupportedOperationException();
134: }
135:
136: public void setReadOnly(String key, boolean readOnly)
137: throws IllegalArgumentException,
138: UnsupportedOperationException {
139: throw new UnsupportedOperationException();
140: }
141:
142: // Overrrided *******************************************************************************************************
143:
144: /** Override to provide the implementation object. */
145: protected MappedPreference newPreference(String name, Value value) {
146: MappedPreference preference = new MappedPreference(name);
147: preference.setValue(value);
148: return preference;
149: }
150: }
|