KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > genclass > map > MapImpl


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.genclass.map;
19
20 import org.objectweb.speedo.genclass.GenClass;
21 import org.objectweb.speedo.mim.api.SpeedoAccessor;
22
23 import java.util.Map JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 public class MapImpl extends GenClass implements Map JavaDoc {
29
30     /**
31      * Instantiates a new map.
32      */

33     public MapImpl() {
34         super();
35         accessor = (MapAccessor) createAccessor();
36     }
37
38     // ------------------------------------------------------------------------
39
// IMPLEMENTATION OF THE Collection INTERFACE
40
// ------------------------------------------------------------------------
41

42     public int size() {
43         if (!jdoIsActive) {
44             return accessor.size();
45         } else {
46             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
47             return ca.size();
48         }
49     }
50
51     public boolean isEmpty() {
52         if (!jdoIsActive) {
53             return accessor.isEmpty();
54         } else {
55             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
56             return ca.isEmpty();
57         }
58     }
59
60     public boolean containsKey(Object JavaDoc key) {
61         if (!jdoIsActive) {
62             return accessor.containsKey(key);
63         } else {
64             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
65             return ca.containsKey(key);
66         }
67     }
68
69     public boolean containsValue(Object JavaDoc value) {
70         if (!jdoIsActive) {
71             return accessor.containsValue(value);
72         } else {
73             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
74             return ca.containsValue(value);
75         }
76     }
77
78     public Object JavaDoc get(Object JavaDoc key) {
79         if (!jdoIsActive) {
80             return accessor.get(key);
81         } else {
82             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
83             return ca.get(key);
84         }
85     }
86
87     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
88         if (!jdoIsActive) {
89             return accessor.put(key, value);
90         } else {
91             MapAccessor ca = (MapAccessor) getSpeedoHome().writeIntention(this, null);
92             return ca.put(key, value);
93         }
94     }
95
96     public Object JavaDoc remove(Object JavaDoc key) {
97         if (!jdoIsActive) {
98             return accessor.remove(key);
99         } else {
100             MapAccessor ca = (MapAccessor) getSpeedoHome().writeIntention(this, null);
101             return ca.remove(key);
102         }
103     }
104
105     public void putAll(Map JavaDoc t) {
106         if (!jdoIsActive) {
107             accessor.putAll(t);
108         } else {
109             MapAccessor ca = (MapAccessor) getSpeedoHome().writeIntention(this, null);
110             ca.putAll(t);
111         }
112     }
113
114     public void clear() {
115         if (!jdoIsActive) {
116             accessor.clear();
117         } else {
118             MapAccessor ca = (MapAccessor) getSpeedoHome().writeIntention(this, null);
119             ca.clear();
120         }
121     }
122
123     public Set JavaDoc keySet() {
124         if (!jdoIsActive) {
125             return accessor.keySet();
126         } else {
127             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
128             return ca.keySet();
129         }
130     }
131
132     public Collection JavaDoc values() {
133         if (!jdoIsActive) {
134             return accessor.values();
135         } else {
136             MapAccessor ca = (MapAccessor) getSpeedoHome().writeIntention(this, null);
137             return ca.values();
138         }
139     }
140
141     public Set JavaDoc entrySet() {
142         if (!jdoIsActive) {
143             return accessor.entrySet();
144         } else {
145             MapAccessor ca = (MapAccessor) getSpeedoHome().readIntention(this, null);
146             return ca.entrySet();
147         }
148     }
149
150     // IMPLEMENTATION OF THE SpeedoProxy INTERFACE //
151
//---------------------------------------------//
152

153     public void setGCValue(Object JavaDoc o) {
154         if (jdoIsActive) {
155             MapAccessor ca = (MapAccessor) getSpeedoHome().writeIntention(this, null);
156             ca.clear();
157             if (o != null) {
158                 ca.putAll(((Map JavaDoc) o));
159             }
160         } else {
161             accessor.clear();
162             if (o != null) {
163                 accessor.putAll(((Map JavaDoc) o));
164             }
165         }
166     }
167
168     MapAccessor accessor;
169
170     public SpeedoAccessor getReferenceAccessor() {
171         return accessor;
172     }
173     public void setReferenceAccessor(SpeedoAccessor refAcc) {
174         accessor = (MapAccessor) refAcc;
175     }
176     public SpeedoAccessor createAccessor() {
177         return new MapAccessor(this);
178     }
179
180     public Object JavaDoc createGenClass() {
181         return new HashMap JavaDoc();
182     }
183
184 }
185
Popular Tags