KickJava   Java API By Example, From Geeks To Geeks.

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


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.api.SpeedoGenClassProxy;
21 import org.objectweb.speedo.mim.api.SpeedoAccessor;
22
23 import java.util.Map JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Hashtable JavaDoc;
29
30 /**
31  *
32  * @author S.Chassande-Barrioz
33  */

34 public abstract class HashtableImpl extends Hashtable JavaDoc
35         implements SpeedoGenClassProxy {
36
37     public HashtableImpl() {
38         super();
39         accessor = (MapAccessor) createAccessor();
40     }
41
42     public synchronized String JavaDoc toString() {
43         return "";
44     }
45
46     MapAccessor accessor;
47
48     public SpeedoAccessor getReferenceAccessor() {
49         return accessor;
50     }
51     public void setReferenceAccessor(SpeedoAccessor refAcc) {
52         accessor = (MapAccessor) refAcc;
53     }
54
55     public Object JavaDoc createGenClass() {
56         return new Hashtable JavaDoc();
57     }
58
59     public SpeedoAccessor createAccessor() {
60         return new MapAccessor(this);
61     }
62
63     // IMPLEMENTS THE HashSet CLASS //
64
//------------------------------//
65

66     public int size() {
67         if (!jdoIsActive()) {
68             return accessor.size();
69         } else {
70             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
71             return ma.size();
72         }
73     }
74
75     public boolean isEmpty() {
76         if (!jdoIsActive()) {
77             return accessor.isEmpty();
78         } else {
79             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
80             return ma.isEmpty();
81         }
82     }
83
84     public synchronized Enumeration JavaDoc keys() {
85         return Collections.enumeration(entrySet());
86     }
87
88     public synchronized Enumeration JavaDoc elements() {
89         return Collections.enumeration(values());
90     }
91
92     public synchronized boolean contains(Object JavaDoc o) {
93         return containsKey(o);
94     }
95
96     public boolean containsValue(Object JavaDoc o) {
97         if (!jdoIsActive()) {
98             return accessor.containsValue(o);
99         } else {
100             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
101             return ma.containsValue(o);
102         }
103     }
104
105     public synchronized boolean containsKey(Object JavaDoc o) {
106         if (!jdoIsActive()) {
107             return accessor.containsKey(o);
108         } else {
109             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
110             return ma.containsKey(o);
111         }
112     }
113
114     public synchronized Object JavaDoc get(Object JavaDoc o) {
115         if (!jdoIsActive()) {
116             return accessor.get(o);
117         } else {
118             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
119             return ma.get(o);
120         }
121     }
122
123     protected void rehash() {
124     }
125
126     public synchronized Object JavaDoc put(Object JavaDoc o, Object JavaDoc o1) {
127         if (!jdoIsActive()) {
128             return accessor.put(o, o1);
129         } else {
130             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
131             return ma.put(o, o1);
132         }
133     }
134
135     public synchronized Object JavaDoc remove(Object JavaDoc o) {
136         if (!jdoIsActive()) {
137             return accessor.remove(o);
138         } else {
139             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
140             return ma.remove(o);
141         }
142     }
143
144     public synchronized void putAll(Map JavaDoc map) {
145         if (!jdoIsActive()) {
146             accessor.putAll(map);
147         } else {
148             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
149             ma.putAll(map);
150         }
151     }
152
153     public synchronized void clear() {
154         if (!jdoIsActive()) {
155             accessor.clear();
156         } else {
157             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
158             ma.clear();
159         }
160     }
161
162     public Set JavaDoc keySet() {
163         if (!jdoIsActive()) {
164             return accessor.keySet();
165         } else {
166             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
167             return ma.keySet();
168         }
169     }
170
171     public Set JavaDoc entrySet() {
172         if (!jdoIsActive()) {
173             return accessor.entrySet();
174         } else {
175             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
176             return ma.entrySet();
177         }
178     }
179
180     public Collection JavaDoc values() {
181         if (!jdoIsActive()) {
182             return accessor.values();
183         } else {
184             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
185             return ma.values();
186         }
187     }
188 }
189
Popular Tags