Introduce helma.util.WrappedMap, fixing bug 258.
http://helma.org/bugs/show_bug.cgi?id=258
This commit is contained in:
parent
a85de95c0b
commit
fad3f06b5c
3 changed files with 149 additions and 2 deletions
|
@ -19,6 +19,7 @@ package helma.framework.core;
|
|||
import helma.objectmodel.INode;
|
||||
import helma.util.CronJob;
|
||||
import helma.util.SystemMap;
|
||||
import helma.util.WrappedMap;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -35,6 +36,8 @@ import java.util.Map;
|
|||
public class ApplicationBean implements Serializable {
|
||||
Application app;
|
||||
|
||||
WrappedMap properties = null;
|
||||
|
||||
/**
|
||||
* Creates a new ApplicationBean object.
|
||||
*
|
||||
|
@ -387,7 +390,11 @@ public class ApplicationBean implements Serializable {
|
|||
* @return ...
|
||||
*/
|
||||
public Map getproperties() {
|
||||
return new SystemMap(app.getProperties());
|
||||
if (properties == null) {
|
||||
properties = new WrappedMap(app.getProperties());
|
||||
properties.setReadonly(true);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import helma.objectmodel.db.Relation;
|
|||
import helma.scripting.*;
|
||||
import helma.util.CacheMap;
|
||||
import helma.util.SystemMap;
|
||||
import helma.util.WrappedMap;
|
||||
import helma.util.SystemProperties;
|
||||
import helma.util.Updatable;
|
||||
import org.mozilla.javascript.*;
|
||||
|
@ -746,7 +747,7 @@ public final class RhinoCore {
|
|||
return getElementWrapper(obj);
|
||||
}
|
||||
|
||||
if (obj instanceof SystemMap) {
|
||||
if (obj instanceof SystemMap || obj instanceof WrappedMap) {
|
||||
return new MapWrapper((Map) obj, RhinoCore.this);
|
||||
}
|
||||
|
||||
|
|
139
src/helma/util/WrappedMap.java
Normal file
139
src/helma/util/WrappedMap.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Helma License Notice
|
||||
*
|
||||
* The contents of this file are subject to the Helma License
|
||||
* Version 2.0 (the "License"). You may not use this file except in
|
||||
* compliance with the License. A copy of the License is available at
|
||||
* http://adele.helma.org/download/helma/license.txt
|
||||
*
|
||||
* Copyright 1998-2003 Helma Software. All Rights Reserved.
|
||||
*
|
||||
* $RCSfile$
|
||||
* $Author$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
package helma.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A Map that wraps another map and can be set to read-only.
|
||||
*/
|
||||
public class WrappedMap implements Map {
|
||||
|
||||
// the wrapped map
|
||||
private Map wrapped = null;
|
||||
|
||||
// is this map readonly?
|
||||
boolean readonly = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public WrappedMap(Map map) {
|
||||
if (map == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Argument must not be null in WrappedMap constructor");
|
||||
}
|
||||
wrapped = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the readonly flag on or off
|
||||
*/
|
||||
public void setReadonly(boolean ro) {
|
||||
readonly = ro;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this map readonly?
|
||||
*/
|
||||
public boolean isReadonly() {
|
||||
return readonly;
|
||||
}
|
||||
|
||||
// Methods from interface java.util.Map -
|
||||
// these are just proxies to the wrapped map, except for
|
||||
// readonly checks on modifiers.
|
||||
|
||||
public int size() {
|
||||
return wrapped.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return wrapped.isEmpty();
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
return wrapped.containsKey(key);
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
return wrapped.containsValue(value);
|
||||
}
|
||||
|
||||
public Object get(Object key) {
|
||||
return wrapped.get(key);
|
||||
}
|
||||
|
||||
// Modification Operations - check for readonly
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
if (readonly) {
|
||||
throw new RuntimeException("Attempt to modify readonly map");
|
||||
}
|
||||
return wrapped.put(key, value);
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
if (readonly) {
|
||||
throw new RuntimeException("Attempt to modify readonly map");
|
||||
}
|
||||
return wrapped.remove(key);
|
||||
}
|
||||
|
||||
public void putAll(Map t) {
|
||||
if (readonly) {
|
||||
throw new RuntimeException("Attempt to modify readonly map");
|
||||
}
|
||||
wrapped.putAll(t);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (readonly) {
|
||||
throw new RuntimeException("Attempt to modify readonly map");
|
||||
}
|
||||
wrapped.clear();
|
||||
}
|
||||
|
||||
|
||||
// Views
|
||||
|
||||
public Set keySet() {
|
||||
return wrapped.keySet();
|
||||
}
|
||||
|
||||
public Collection values() {
|
||||
return wrapped.values();
|
||||
}
|
||||
|
||||
public Set entrySet() {
|
||||
return wrapped.entrySet();
|
||||
}
|
||||
|
||||
|
||||
// Comparison and hashing
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return wrapped.equals(o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return wrapped.hashCode();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue