KickJava   Java API By Example, From Geeks To Geeks.

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


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.mim.api.SpeedoAccessor;
21 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy;
22
23 import java.util.Properties JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.io.PrintStream JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35 /**
36  *
37  * @author S.Chassande-Barrioz
38  */

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

72     public synchronized Object JavaDoc setProperty(String JavaDoc s, String JavaDoc s1) {
73         if (!jdoIsActive()) {
74             return accessor.put(s, s1);
75         } else {
76             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
77             return ma.put(s, s1);
78         }
79     }
80
81     public synchronized void load(InputStream JavaDoc inputStream) throws IOException JavaDoc {
82         Properties JavaDoc p = new Properties JavaDoc();
83         p.load(inputStream);
84         if (!jdoIsActive()) {
85             accessor.putAll(p);
86         } else {
87             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
88             ma.putAll(p);
89         }
90     }
91
92     public synchronized void store(OutputStream JavaDoc outputStream, String JavaDoc s) throws IOException JavaDoc {
93         Properties JavaDoc p = new Properties JavaDoc();
94         if (!jdoIsActive()) {
95             p.putAll(accessor);
96         } else {
97             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
98             p.putAll(ma);
99         }
100         p.store(outputStream, s);
101     }
102
103     public String JavaDoc getProperty(String JavaDoc s) {
104         if (!jdoIsActive()) {
105             return (String JavaDoc) accessor.get(s);
106         } else {
107             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
108             return (String JavaDoc) ma.get(s);
109         }
110     }
111
112     public String JavaDoc getProperty(String JavaDoc s, String JavaDoc s1) {
113         String JavaDoc res;
114         if (!jdoIsActive()) {
115             res = (String JavaDoc) accessor.get(s);
116         } else {
117             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
118             res = (String JavaDoc) ma.get(s) ;
119         }
120         return res == null ? s1 : s;
121     }
122
123     public Enumeration JavaDoc propertyNames() {
124         if (!jdoIsActive()) {
125             return Collections.enumeration(accessor.entrySet());
126         } else {
127             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
128             return Collections.enumeration(ma.keySet());
129         }
130     }
131
132     public void list(PrintStream JavaDoc printStream) {
133         if (!jdoIsActive()) {
134             super.list(printStream);
135         } else {
136             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
137             Properties JavaDoc p = new Properties JavaDoc();
138             p.putAll(ma);
139             p.list(printStream);
140         }
141     }
142
143     public void list(PrintWriter JavaDoc printWriter) {
144         Properties JavaDoc p = new Properties JavaDoc();
145         if (!jdoIsActive()) {
146             p.putAll(accessor);
147         } else {
148             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
149             p.putAll(ma);
150         }
151         p.list(printWriter);
152     }
153
154     public int size() {
155         if (!jdoIsActive()) {
156             return accessor.size();
157         } else {
158             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
159             return ma.size();
160         }
161     }
162
163     public boolean isEmpty() {
164         if (!jdoIsActive()) {
165             return accessor.isEmpty();
166         } else {
167             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
168             return ma.isEmpty();
169         }
170     }
171
172     public synchronized Enumeration JavaDoc keys() {
173         if (!jdoIsActive()) {
174             return Collections.enumeration(accessor.keySet());
175         } else {
176             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
177             return Collections.enumeration(ma.keySet());
178         }
179     }
180
181     public synchronized Enumeration JavaDoc elements() {
182         if (!jdoIsActive()) {
183             return Collections.enumeration(accessor.values());
184         } else {
185             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
186             return Collections.enumeration(ma.values());
187         }
188     }
189
190     public synchronized boolean contains(Object JavaDoc o) {
191         if (!jdoIsActive()) {
192             return accessor.containsKey(o);
193         } else {
194             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
195             return ma.containsKey(o);
196         }
197     }
198
199     public boolean containsValue(Object JavaDoc o) {
200         if (!jdoIsActive()) {
201             return accessor.containsValue(o);
202         } else {
203             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
204             return ma.containsValue(o);
205         }
206     }
207
208     public synchronized boolean containsKey(Object JavaDoc o) {
209         if (!jdoIsActive()) {
210             return accessor.containsKey(o);
211         } else {
212             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
213             return ma.containsKey(o);
214         }
215     }
216
217     public synchronized Object JavaDoc get(Object JavaDoc o) {
218         if (!jdoIsActive()) {
219             return accessor.get(o);
220         } else {
221             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
222             return ma.get(o);
223         }
224     }
225
226     protected void rehash() {
227         if (!jdoIsActive()) {
228             super.rehash();
229         } else {
230             getSpeedoHome().readIntention(this, null);
231         }
232     }
233
234     public synchronized Object JavaDoc put(Object JavaDoc o, Object JavaDoc o1) {
235         if (!jdoIsActive()) {
236             return accessor.put(o, o1);
237         } else {
238             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
239             return ma.put(o, o1);
240         }
241     }
242
243     public synchronized Object JavaDoc remove(Object JavaDoc o) {
244         if (!jdoIsActive()) {
245             return accessor.remove(o);
246         } else {
247             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
248             return ma.remove(o);
249         }
250     }
251
252     public synchronized void putAll(Map JavaDoc map) {
253         if (!jdoIsActive()) {
254             accessor.putAll(map);
255         } else {
256             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
257             ma.putAll(map);
258         }
259     }
260
261     public synchronized void clear() {
262         if (!jdoIsActive()) {
263             accessor.clear();
264         } else {
265             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
266             ma.clear();
267         }
268     }
269
270     public Set JavaDoc keySet() {
271         if (!jdoIsActive()) {
272             return accessor.keySet();
273         } else {
274             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
275             return ma.keySet();
276         }
277     }
278
279     public Set JavaDoc entrySet() {
280         if (!jdoIsActive()) {
281             return accessor.entrySet();
282         } else {
283             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
284             return ma.entrySet();
285         }
286     }
287
288     public Collection JavaDoc values() {
289         if (!jdoIsActive()) {
290             return accessor.values();
291         } else {
292             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
293             return ma.values();
294         }
295     }
296 }
297
Popular Tags