/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.genclass.map;
import org.objectweb.speedo.mim.api.StateItf;
import org.objectweb.speedo.genclass.api.SpeedoGenClassPO;
import java.util.Properties;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;
import java.util.Collection;
import java.util.Collections;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
*
* @author S.Chassande-Barrioz
*/
public abstract class PropertiesImpl
extends Properties
implements SpeedoGenClassPO {
public PropertiesImpl() {
super();
accessor = (MapAccessor) speedoCreateState();
}
public synchronized String toString() {
return "";
}
MapAccessor accessor;
public StateItf speedoGetReferenceState() {
return accessor;
}
public void speedoSetReferenceState(StateItf refAcc) {
accessor = (MapAccessor) refAcc;
}
public Object createGenClass() {
return new Properties();
}
public StateItf speedoCreateState() {
return new MapAccessor(this);
}
// IMPLEMENTS THE HashSet CLASS //
//------------------------------//
public synchronized Object setProperty(String s, String s1) {
if (!speedoIsActive()) {
return accessor.put(s, s1);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().writeIntention(this, null);
return ma.put(s, s1);
}
}
public synchronized void load(InputStream inputStream) throws IOException {
Properties p = new Properties();
p.load(inputStream);
if (!speedoIsActive()) {
accessor.putAll(p);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().writeIntention(this, null);
ma.putAll(p);
}
}
public synchronized void store(OutputStream outputStream, String s) throws IOException {
Properties p = new Properties();
if (!speedoIsActive()) {
p.putAll(accessor);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
p.putAll(ma);
}
p.store(outputStream, s);
}
public String getProperty(String s) {
if (!speedoIsActive()) {
return (String) accessor.get(s);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return (String) ma.get(s);
}
}
public String getProperty(String s, String s1) {
String res;
if (!speedoIsActive()) {
res = (String) accessor.get(s);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
res = (String) ma.get(s) ;
}
return res == null ? s1 : s;
}
public Enumeration propertyNames() {
if (!speedoIsActive()) {
return Collections.enumeration(accessor.entrySet());
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return Collections.enumeration(ma.keySet());
}
}
public void list(PrintStream printStream) {
if (!speedoIsActive()) {
super.list(printStream);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
Properties p = new Properties();
p.putAll(ma);
p.list(printStream);
}
}
public void list(PrintWriter printWriter) {
Properties p = new Properties();
if (!speedoIsActive()) {
p.putAll(accessor);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
p.putAll(ma);
}
p.list(printWriter);
}
public int size() {
if (!speedoIsActive()) {
return accessor.size();
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.size();
}
}
public boolean isEmpty() {
if (!speedoIsActive()) {
return accessor.isEmpty();
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.isEmpty();
}
}
public synchronized Enumeration keys() {
if (!speedoIsActive()) {
return Collections.enumeration(accessor.keySet());
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return Collections.enumeration(ma.keySet());
}
}
public synchronized Enumeration elements() {
if (!speedoIsActive()) {
return Collections.enumeration(accessor.values());
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return Collections.enumeration(ma.values());
}
}
public synchronized boolean contains(Object o) {
if (!speedoIsActive()) {
return accessor.containsKey(o);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.containsKey(o);
}
}
public boolean containsValue(Object o) {
if (!speedoIsActive()) {
return accessor.containsValue(o);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.containsValue(o);
}
}
public synchronized boolean containsKey(Object o) {
if (!speedoIsActive()) {
return accessor.containsKey(o);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.containsKey(o);
}
}
public synchronized Object get(Object o) {
if (!speedoIsActive()) {
return accessor.get(o);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.get(o);
}
}
protected void rehash() {
if (!speedoIsActive()) {
super.rehash();
} else {
speedoGetHome().readIntention(this, null);
}
}
public synchronized Object put(Object o, Object o1) {
if (!speedoIsActive()) {
return accessor.put(o, o1);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().writeIntention(this, null);
return ma.put(o, o1);
}
}
public synchronized Object remove(Object o) {
if (!speedoIsActive()) {
return accessor.remove(o);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().writeIntention(this, null);
return ma.remove(o);
}
}
public synchronized void putAll(Map map) {
if (!speedoIsActive()) {
accessor.putAll(map);
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().writeIntention(this, null);
ma.putAll(map);
}
}
public synchronized void clear() {
if (!speedoIsActive()) {
accessor.clear();
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().writeIntention(this, null);
ma.clear();
}
}
public Set keySet() {
if (!speedoIsActive()) {
return accessor.keySet();
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.keySet();
}
}
public Set entrySet() {
if (!speedoIsActive()) {
return accessor.entrySet();
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.entrySet();
}
}
public Collection values() {
if (!speedoIsActive()) {
return accessor.values();
} else {
MapAccessor ma = (MapAccessor) speedoGetHome().readIntention(this, null);
return ma.values();
}
}
}