allow ids to be called from transient nodes.

introduced simpler internal properties: _id and _parent.
removed support for the old created and lastmodified properties.
This commit is contained in:
hns 2001-08-25 17:47:29 +00:00
parent fac98332c9
commit b21d575fdf

View file

@ -236,7 +236,7 @@ public class ESNode extends ObjectPrototype {
public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException { public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException {
checkNode (); checkNode ();
// eval.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass()); // eval.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass());
if ("lastmodified".equalsIgnoreCase (propertyName) || "created".equalsIgnoreCase (propertyName) || if (/* "lastmodified".equalsIgnoreCase (propertyName) || "created".equalsIgnoreCase (propertyName) || */
"cache".equalsIgnoreCase (propertyName)) "cache".equalsIgnoreCase (propertyName))
throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\"."); throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\".");
@ -269,25 +269,25 @@ public class ESNode extends ObjectPrototype {
} }
public boolean deleteProperty(String propertyName, int hash) throws EcmaScriptException { public boolean deleteProperty(String propertyName, int hash) throws EcmaScriptException {
checkNode (); checkNode ();
// eval.app.logEvent ("delete property called: "+propertyName); // eval.app.logEvent ("delete property called: "+propertyName);
if (node.get (propertyName, false) != null) { if (node.get (propertyName, false) != null) {
node.unset (propertyName); node.unset (propertyName);
return true; return true;
} }
return super.deleteProperty (propertyName, hash); return super.deleteProperty (propertyName, hash);
} }
public ESValue getProperty (int i) throws EcmaScriptException { public ESValue getProperty (int i) throws EcmaScriptException {
checkNode (); checkNode ();
INode n = node.getSubnodeAt (i); INode n = node.getSubnodeAt (i);
if (n == null) if (n == null)
return ESNull.theNull; return ESNull.theNull;
return eval.getNodeWrapper (n); return eval.getNodeWrapper (n);
} }
public void putProperty(int index, ESValue propertyValue) throws EcmaScriptException { public void putProperty(int index, ESValue propertyValue) throws EcmaScriptException {
checkNode (); checkNode ();
if (propertyValue instanceof ESNode) { if (propertyValue instanceof ESNode) {
ESNode n = (ESNode) propertyValue; ESNode n = (ESNode) propertyValue;
node.addNode (n.getNode (), index); node.addNode (n.getNode (), index);
@ -305,16 +305,21 @@ public class ESNode extends ObjectPrototype {
if ("cache".equalsIgnoreCase (propertyName) && cache != null) if ("cache".equalsIgnoreCase (propertyName) && cache != null)
return cacheWrapper; return cacheWrapper;
if ("created".equalsIgnoreCase (propertyName))
return new DatePrototype (evaluator, node.created ());
if ("lastmodified".equalsIgnoreCase (propertyName))
return new DatePrototype (evaluator, node.lastModified ());
if ("subnodeRelation".equalsIgnoreCase (propertyName)) { if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
String rel = node.getSubnodeRelation (); String rel = node.getSubnodeRelation ();
return rel == null ? (ESValue) ESNull.theNull : new ESString (rel); return rel == null ? (ESValue) ESNull.theNull : new ESString (rel);
} }
if ("_id".equals (propertyName))
return new ESString (node.getID ());
if ("_parent".equals (propertyName)) {
INode n = node.getParent ();
if (n != null)
return eval.getNodeWrapper (n);
else
return ESNull.theNull;
}
// this is not very nice, but as a hack we return the id of a node as node.__id__ // this is not very nice, but as a hack we return the id of a node as node.__id__
if (propertyName.startsWith ("__") && propertyName.endsWith ("__")) if (propertyName.startsWith ("__") && propertyName.endsWith ("__"))
return getInternalProperty (propertyName); return getInternalProperty (propertyName);
@ -347,6 +352,12 @@ public class ESNode extends ObjectPrototype {
if (p.getType () == IProperty.JAVAOBJECT) if (p.getType () == IProperty.JAVAOBJECT)
return ESLoader.normalizeObject (p.getJavaObjectValue (), evaluator); return ESLoader.normalizeObject (p.getJavaObjectValue (), evaluator);
} }
// these are predefined
// if ("created".equalsIgnoreCase (propertyName))
// return new DatePrototype (evaluator, node.created ());
// if ("lastmodified".equalsIgnoreCase (propertyName))
// return new DatePrototype (evaluator, node.lastModified ());
// as last resort, try to get property as anonymous subnode // as last resort, try to get property as anonymous subnode
INode anon = node.getSubnode (propertyName); INode anon = node.getSubnode (propertyName);
@ -357,10 +368,8 @@ public class ESNode extends ObjectPrototype {
} }
private ESValue getInternalProperty (String propertyName) throws EcmaScriptException { private ESValue getInternalProperty (String propertyName) throws EcmaScriptException {
if ("__id__".equalsIgnoreCase (propertyName)) try { if ("__id__".equalsIgnoreCase (propertyName)) {
return new ESString (node.getID ()); return new ESString (node.getID ());
} catch (Exception noid) {
return new ESString ("transient");
} }
if ("__prototype__".equalsIgnoreCase (propertyName)) { if ("__prototype__".equalsIgnoreCase (propertyName)) {
String p = node.getPrototype (); String p = node.getPrototype ();