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:
parent
fac98332c9
commit
b21d575fdf
1 changed files with 29 additions and 20 deletions
|
@ -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+"\".");
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -348,6 +353,12 @@ public class ESNode extends ObjectPrototype {
|
||||||
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);
|
||||||
if (anon != null)
|
if (anon != null)
|
||||||
|
@ -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 ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue