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.mim.api.StateItf;
020: import org.objectweb.speedo.genclass.api.SpeedoGenClassPO;
021:
022: import java.util.Properties;
023: import java.util.Enumeration;
024: import java.util.Map;
025: import java.util.Set;
026: import java.util.Collection;
027: import java.util.Collections;
028: import java.io.InputStream;
029: import java.io.IOException;
030: import java.io.OutputStream;
031: import java.io.PrintStream;
032: import java.io.PrintWriter;
033:
034: /**
035: *
036: * @author S.Chassande-Barrioz
037: */
038: public abstract class PropertiesImpl extends Properties implements
039: SpeedoGenClassPO {
040:
041: public PropertiesImpl() {
042: super ();
043: accessor = (MapAccessor) speedoCreateState();
044: }
045:
046: public synchronized String toString() {
047: return "";
048: }
049:
050: MapAccessor accessor;
051:
052: public StateItf speedoGetReferenceState() {
053: return accessor;
054: }
055:
056: public void speedoSetReferenceState(StateItf refAcc) {
057: accessor = (MapAccessor) refAcc;
058: }
059:
060: public Object createGenClass() {
061: return new Properties();
062: }
063:
064: public StateItf speedoCreateState() {
065: return new MapAccessor(this );
066: }
067:
068: // IMPLEMENTS THE HashSet CLASS //
069: //------------------------------//
070:
071: public synchronized Object setProperty(String s, String s1) {
072: if (!speedoIsActive()) {
073: return accessor.put(s, s1);
074: } else {
075: MapAccessor ma = (MapAccessor) speedoGetHome()
076: .writeIntention(this , null);
077: return ma.put(s, s1);
078: }
079: }
080:
081: public synchronized void load(InputStream inputStream)
082: throws IOException {
083: Properties p = new Properties();
084: p.load(inputStream);
085: if (!speedoIsActive()) {
086: accessor.putAll(p);
087: } else {
088: MapAccessor ma = (MapAccessor) speedoGetHome()
089: .writeIntention(this , null);
090: ma.putAll(p);
091: }
092: }
093:
094: public synchronized void store(OutputStream outputStream, String s)
095: throws IOException {
096: Properties p = new Properties();
097: if (!speedoIsActive()) {
098: p.putAll(accessor);
099: } else {
100: MapAccessor ma = (MapAccessor) speedoGetHome()
101: .readIntention(this , null);
102: p.putAll(ma);
103: }
104: p.store(outputStream, s);
105: }
106:
107: public String getProperty(String s) {
108: if (!speedoIsActive()) {
109: return (String) accessor.get(s);
110: } else {
111: MapAccessor ma = (MapAccessor) speedoGetHome()
112: .readIntention(this , null);
113: return (String) ma.get(s);
114: }
115: }
116:
117: public String getProperty(String s, String s1) {
118: String res;
119: if (!speedoIsActive()) {
120: res = (String) accessor.get(s);
121: } else {
122: MapAccessor ma = (MapAccessor) speedoGetHome()
123: .readIntention(this , null);
124: res = (String) ma.get(s);
125: }
126: return res == null ? s1 : s;
127: }
128:
129: public Enumeration propertyNames() {
130: if (!speedoIsActive()) {
131: return Collections.enumeration(accessor.entrySet());
132: } else {
133: MapAccessor ma = (MapAccessor) speedoGetHome()
134: .readIntention(this , null);
135: return Collections.enumeration(ma.keySet());
136: }
137: }
138:
139: public void list(PrintStream printStream) {
140: if (!speedoIsActive()) {
141: super .list(printStream);
142: } else {
143: MapAccessor ma = (MapAccessor) speedoGetHome()
144: .readIntention(this , null);
145: Properties p = new Properties();
146: p.putAll(ma);
147: p.list(printStream);
148: }
149: }
150:
151: public void list(PrintWriter printWriter) {
152: Properties p = new Properties();
153: if (!speedoIsActive()) {
154: p.putAll(accessor);
155: } else {
156: MapAccessor ma = (MapAccessor) speedoGetHome()
157: .readIntention(this , null);
158: p.putAll(ma);
159: }
160: p.list(printWriter);
161: }
162:
163: public int size() {
164: if (!speedoIsActive()) {
165: return accessor.size();
166: } else {
167: MapAccessor ma = (MapAccessor) speedoGetHome()
168: .readIntention(this , null);
169: return ma.size();
170: }
171: }
172:
173: public boolean isEmpty() {
174: if (!speedoIsActive()) {
175: return accessor.isEmpty();
176: } else {
177: MapAccessor ma = (MapAccessor) speedoGetHome()
178: .readIntention(this , null);
179: return ma.isEmpty();
180: }
181: }
182:
183: public synchronized Enumeration keys() {
184: if (!speedoIsActive()) {
185: return Collections.enumeration(accessor.keySet());
186: } else {
187: MapAccessor ma = (MapAccessor) speedoGetHome()
188: .readIntention(this , null);
189: return Collections.enumeration(ma.keySet());
190: }
191: }
192:
193: public synchronized Enumeration elements() {
194: if (!speedoIsActive()) {
195: return Collections.enumeration(accessor.values());
196: } else {
197: MapAccessor ma = (MapAccessor) speedoGetHome()
198: .readIntention(this , null);
199: return Collections.enumeration(ma.values());
200: }
201: }
202:
203: public synchronized boolean contains(Object o) {
204: if (!speedoIsActive()) {
205: return accessor.containsKey(o);
206: } else {
207: MapAccessor ma = (MapAccessor) speedoGetHome()
208: .readIntention(this , null);
209: return ma.containsKey(o);
210: }
211: }
212:
213: public boolean containsValue(Object o) {
214: if (!speedoIsActive()) {
215: return accessor.containsValue(o);
216: } else {
217: MapAccessor ma = (MapAccessor) speedoGetHome()
218: .readIntention(this , null);
219: return ma.containsValue(o);
220: }
221: }
222:
223: public synchronized boolean containsKey(Object o) {
224: if (!speedoIsActive()) {
225: return accessor.containsKey(o);
226: } else {
227: MapAccessor ma = (MapAccessor) speedoGetHome()
228: .readIntention(this , null);
229: return ma.containsKey(o);
230: }
231: }
232:
233: public synchronized Object get(Object o) {
234: if (!speedoIsActive()) {
235: return accessor.get(o);
236: } else {
237: MapAccessor ma = (MapAccessor) speedoGetHome()
238: .readIntention(this , null);
239: return ma.get(o);
240: }
241: }
242:
243: protected void rehash() {
244: if (!speedoIsActive()) {
245: super .rehash();
246: } else {
247: speedoGetHome().readIntention(this , null);
248: }
249: }
250:
251: public synchronized Object put(Object o, Object o1) {
252: if (!speedoIsActive()) {
253: return accessor.put(o, o1);
254: } else {
255: MapAccessor ma = (MapAccessor) speedoGetHome()
256: .writeIntention(this , null);
257: return ma.put(o, o1);
258: }
259: }
260:
261: public synchronized Object remove(Object o) {
262: if (!speedoIsActive()) {
263: return accessor.remove(o);
264: } else {
265: MapAccessor ma = (MapAccessor) speedoGetHome()
266: .writeIntention(this , null);
267: return ma.remove(o);
268: }
269: }
270:
271: public synchronized void putAll(Map map) {
272: if (!speedoIsActive()) {
273: accessor.putAll(map);
274: } else {
275: MapAccessor ma = (MapAccessor) speedoGetHome()
276: .writeIntention(this , null);
277: ma.putAll(map);
278: }
279: }
280:
281: public synchronized void clear() {
282: if (!speedoIsActive()) {
283: accessor.clear();
284: } else {
285: MapAccessor ma = (MapAccessor) speedoGetHome()
286: .writeIntention(this , null);
287: ma.clear();
288: }
289: }
290:
291: public Set keySet() {
292: if (!speedoIsActive()) {
293: return accessor.keySet();
294: } else {
295: MapAccessor ma = (MapAccessor) speedoGetHome()
296: .readIntention(this , null);
297: return ma.keySet();
298: }
299: }
300:
301: public Set entrySet() {
302: if (!speedoIsActive()) {
303: return accessor.entrySet();
304: } else {
305: MapAccessor ma = (MapAccessor) speedoGetHome()
306: .readIntention(this , null);
307: return ma.entrySet();
308: }
309: }
310:
311: public Collection values() {
312: if (!speedoIsActive()) {
313: return accessor.values();
314: } else {
315: MapAccessor ma = (MapAccessor) speedoGetHome()
316: .readIntention(this, null);
317: return ma.values();
318: }
319: }
320: }
|