Check for readonly flag in putProperty method so that write protected

properties can't be modified from script code.

Deleted stuff that was permanently commented out:
  * setNode() method
  * readonly check for created and lastmodified props
This commit is contained in:
hns 2002-02-25 14:48:11 +00:00
parent 4e192c39c0
commit 4a3879b0ee

View file

@ -89,21 +89,6 @@ public class ESNode extends ObjectPrototype {
return node;
}
/* public void setNode (INode node) {
if (node != null) {
this.node = node;
// set node handle to wrapped node
if (node instanceof helma.objectmodel.db.Node)
handle = ((helma.objectmodel.db.Node) node).getHandle ();
else
handle = null;
eval.objectcache.put (node, this);
// reset cache Node - will be reinitialized when needed
cache = null;
cacheWrapper = null;
}
} */
public void setPrototype (String protoName) {
checkNode ();
node.setPrototype (protoName);
@ -240,8 +225,7 @@ public class ESNode extends ObjectPrototype {
public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException {
checkNode ();
// eval.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass());
if (/* "lastmodified".equalsIgnoreCase (propertyName) || "created".equalsIgnoreCase (propertyName) || */
"cache".equalsIgnoreCase (propertyName))
if ("cache".equalsIgnoreCase (propertyName))
throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\".");
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
@ -249,6 +233,14 @@ public class ESNode extends ObjectPrototype {
return;
}
// check if the property is write protected, i.e. the type.property file describes it as [readonly]
DbMapping dbm = node.getDbMapping ();
if (dbm != null) {
Relation rel = dbm.getPropertyRelation (propertyName);
if (rel != null && rel.isReadonly ())
return;
}
if (propertyValue instanceof ESNull || propertyValue instanceof ESUndefined)
node.unset (propertyName);
else if (propertyValue instanceof ESString)