001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.genclass.map;
018:
019: import org.objectweb.speedo.genclass.GenClass;
020: import org.objectweb.speedo.mim.api.StateItf;
021:
022: import java.util.Collection;
023: import java.util.HashMap;
024: import java.util.Map;
025: import java.util.Set;
026:
027: public class MapImpl extends GenClass implements Map {
028:
029: private static final long serialVersionUID = 64364678132168L;
030:
031: /**
032: * Instantiates a new map.
033: */
034: public MapImpl() {
035: super ();
036: accessor = (MapAccessor) speedoCreateState();
037: }
038:
039: // ------------------------------------------------------------------------
040: // IMPLEMENTATION OF THE Collection INTERFACE
041: // ------------------------------------------------------------------------
042:
043: public int size() {
044: if (!speedoIsActive) {
045: return accessor.size();
046: } else {
047: MapAccessor ca = (MapAccessor) speedoGetHome()
048: .readIntention(this , null);
049: return ca.size();
050: }
051: }
052:
053: public boolean isEmpty() {
054: if (!speedoIsActive) {
055: return accessor.isEmpty();
056: } else {
057: MapAccessor ca = (MapAccessor) speedoGetHome()
058: .readIntention(this , null);
059: return ca.isEmpty();
060: }
061: }
062:
063: public boolean containsKey(Object key) {
064: if (!speedoIsActive) {
065: return accessor.containsKey(key);
066: } else {
067: MapAccessor ca = (MapAccessor) speedoGetHome()
068: .readIntention(this , null);
069: return ca.containsKey(key);
070: }
071: }
072:
073: public boolean containsValue(Object value) {
074: if (!speedoIsActive) {
075: return accessor.containsValue(value);
076: } else {
077: MapAccessor ca = (MapAccessor) speedoGetHome()
078: .readIntention(this , null);
079: return ca.containsValue(value);
080: }
081: }
082:
083: public Object get(Object key) {
084: if (!speedoIsActive) {
085: return accessor.get(key);
086: } else {
087: MapAccessor ca = (MapAccessor) speedoGetHome()
088: .readIntention(this , null);
089: return ca.get(key);
090: }
091: }
092:
093: public Object put(Object key, Object value) {
094: if (!speedoIsActive) {
095: return accessor.put(key, value);
096: } else {
097: MapAccessor ca = (MapAccessor) speedoGetHome()
098: .writeIntention(this , null);
099: return ca.put(key, value);
100: }
101: }
102:
103: public Object remove(Object key) {
104: if (!speedoIsActive) {
105: return accessor.remove(key);
106: } else {
107: MapAccessor ca = (MapAccessor) speedoGetHome()
108: .writeIntention(this , null);
109: return ca.remove(key);
110: }
111: }
112:
113: public void putAll(Map t) {
114: if (!speedoIsActive) {
115: accessor.putAll(t);
116: } else {
117: MapAccessor ca = (MapAccessor) speedoGetHome()
118: .writeIntention(this , null);
119: ca.putAll(t);
120: }
121: }
122:
123: public void clear() {
124: if (!speedoIsActive) {
125: accessor.clear();
126: } else {
127: MapAccessor ca = (MapAccessor) speedoGetHome()
128: .writeIntention(this , null);
129: ca.clear();
130: }
131: }
132:
133: public Set keySet() {
134: if (!speedoIsActive) {
135: return accessor.keySet();
136: } else {
137: MapAccessor ca = (MapAccessor) speedoGetHome()
138: .readIntention(this , null);
139: return ca.keySet();
140: }
141: }
142:
143: public Collection values() {
144: if (!speedoIsActive) {
145: return accessor.values();
146: } else {
147: MapAccessor ca = (MapAccessor) speedoGetHome()
148: .writeIntention(this , null);
149: return ca.values();
150: }
151: }
152:
153: public Set entrySet() {
154: if (!speedoIsActive) {
155: return accessor.entrySet();
156: } else {
157: MapAccessor ca = (MapAccessor) speedoGetHome()
158: .readIntention(this , null);
159: return ca.entrySet();
160: }
161: }
162:
163: // IMPLEMENTATION OF THE PersistentObjectItf INTERFACE //
164: //---------------------------------------------//
165:
166: public void setGCValue(Object o) {
167: if (speedoIsActive) {
168: MapAccessor ca = (MapAccessor) speedoGetHome()
169: .writeIntention(this , null);
170: ca.clear();
171: if (o != null) {
172: ca.putAll(((Map) o));
173: }
174: } else {
175: accessor.clear();
176: if (o != null) {
177: accessor.putAll(((Map) o));
178: }
179: }
180: }
181:
182: MapAccessor accessor;
183:
184: public StateItf speedoGetReferenceState() {
185: return accessor;
186: }
187:
188: public void speedoSetReferenceState(StateItf refAcc) {
189: accessor = (MapAccessor) refAcc;
190: }
191:
192: public StateItf speedoCreateState() {
193: return new MapAccessor(this );
194: }
195:
196: public Object createGenClass() {
197: return new HashMap();
198: }
199:
200: }
|