Moved files to separate helma/scripting and helma/scripting/fesi packages
This commit is contained in:
parent
58b9422d2e
commit
d6e09cae8c
10 changed files with 0 additions and 3190 deletions
|
@ -1,290 +0,0 @@
|
|||
// Action.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Iterator;
|
||||
import java.io.*;
|
||||
import helma.framework.*;
|
||||
import helma.util.Updatable;
|
||||
import FESI.Data.*;
|
||||
import FESI.Parser.*;
|
||||
import FESI.AST.ASTFormalParameterList;
|
||||
import FESI.AST.ASTStatementList;
|
||||
import FESI.AST.EcmaScriptTreeConstants;
|
||||
import FESI.Interpreter.*;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An Action is a JavaScript function that is exposed as a URI. It is
|
||||
* usually represented by a file with extension .hac (hop action file)
|
||||
* that contains the pure JavaScript body of the function.
|
||||
*/
|
||||
|
||||
|
||||
public class Action implements Updatable {
|
||||
|
||||
String name;
|
||||
String functionName;
|
||||
Prototype prototype;
|
||||
Application app;
|
||||
File file;
|
||||
long lastmod;
|
||||
|
||||
// this is the parsed function which can be easily applied to RequestEvaluator objects
|
||||
TypeUpdater pfunc;
|
||||
|
||||
|
||||
public Action (File file, String name, Prototype proto) {
|
||||
this.prototype = proto;
|
||||
this.app = proto.app;
|
||||
this.name = name;
|
||||
this.file = file;
|
||||
if (file != null)
|
||||
update ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the type manager whether we need an update. this is the case when
|
||||
* the file has been modified or deleted.
|
||||
*/
|
||||
public boolean needsUpdate () {
|
||||
return lastmod != file.lastModified () || !file.exists ();
|
||||
}
|
||||
|
||||
|
||||
public void update () {
|
||||
|
||||
if (!file.exists ()) {
|
||||
// remove functions declared by this from all object prototypes
|
||||
remove ();
|
||||
} else {
|
||||
try {
|
||||
FileReader reader = new FileReader (file);
|
||||
char cbuf[] = new char[(int) file.length ()];
|
||||
reader.read (cbuf);
|
||||
reader.close ();
|
||||
String content = new String (cbuf);
|
||||
update (content);
|
||||
} catch (Exception filex) {
|
||||
app.logEvent ("*** Error reading action file "+file+": "+filex);
|
||||
}
|
||||
|
||||
lastmod = file.lastModified ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void update (String content) throws Exception {
|
||||
// app.logEvent ("Reading text template " + name);
|
||||
|
||||
functionName = name+"_action";
|
||||
|
||||
try {
|
||||
pfunc = parseFunction (functionName, "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", content);
|
||||
} catch (Throwable x) {
|
||||
String message = x.getMessage ();
|
||||
pfunc = new ErrorFeedback (functionName, message);
|
||||
}
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
updateRequestEvaluator (reval);
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
void remove () {
|
||||
prototype.actions.remove (name);
|
||||
prototype.updatables.remove (file.getName());
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
ObjectPrototype op = reval.getPrototype (prototype.getName());
|
||||
functionName = name+"_action";
|
||||
ESValue esv = (ESValue) op.getProperty (functionName, functionName.hashCode());
|
||||
if (esv instanceof ConstructedFunctionObject || esv instanceof ThrowException) {
|
||||
op.deleteProperty (functionName, functionName.hashCode());
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName () {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFunctionName () {
|
||||
return functionName;
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return prototype.getName()+"/"+file.getName();
|
||||
}
|
||||
|
||||
public synchronized void updateRequestEvaluator (RequestEvaluator reval) throws EcmaScriptException {
|
||||
if (pfunc != null)
|
||||
pfunc.updateRequestEvaluator (reval);
|
||||
}
|
||||
|
||||
protected TypeUpdater parseFunction (String funcname, String params, String body) throws EcmaScriptException {
|
||||
|
||||
// ESObject fp = app.eval.evaluator.getFunctionPrototype();
|
||||
// ConstructedFunctionObject function = null;
|
||||
ASTFormalParameterList fpl = null;
|
||||
ASTStatementList sl = null;
|
||||
FunctionEvaluationSource fes = null;
|
||||
|
||||
if (body == null || "".equals (body.trim()))
|
||||
body = ";\r\n";
|
||||
else
|
||||
body = body + "\r\n";
|
||||
if (params == null) params = "";
|
||||
else params = params.trim ();
|
||||
|
||||
String fulltext = "function "+funcname+" (" + params + ") {\n" + body + "\n}";
|
||||
|
||||
EcmaScript parser;
|
||||
StringReader is;
|
||||
|
||||
// Special case for empty parameters
|
||||
if (params.length()==0) {
|
||||
fpl = new ASTFormalParameterList(EcmaScriptTreeConstants.JJTFORMALPARAMETERLIST);
|
||||
} else {
|
||||
is = new java.io.StringReader(params);
|
||||
parser = new EcmaScript(is);
|
||||
try {
|
||||
fpl = (ASTFormalParameterList) parser.FormalParameterList();
|
||||
is.close();
|
||||
} catch (ParseException x) {
|
||||
throw new EcmaScriptParseException (x, new StringEvaluationSource(fulltext, null));
|
||||
}
|
||||
}
|
||||
// this is very very very strange: without the toString, lots of obscure exceptions
|
||||
// deep inside the parser...
|
||||
is = new java.io.StringReader(body.toString ());
|
||||
try {
|
||||
parser = new EcmaScript (is);
|
||||
sl = (ASTStatementList) parser.StatementList();
|
||||
is.close();
|
||||
} catch (ParseException x) {
|
||||
app.logEvent ("Error parsing file "+app.getName()+":"+prototype.getName()+"/"+file.getName()+": "+x);
|
||||
throw new EcmaScriptParseException (x, new StringEvaluationSource(fulltext, null));
|
||||
} catch (Exception x) {
|
||||
app.logEvent ("Error parsing file "+app.getName()+":"+prototype.getName()+"/"+file.getName()+": "+x);
|
||||
throw new RuntimeException (x.getMessage ());
|
||||
}
|
||||
|
||||
fes = new FunctionEvaluationSource (new StringEvaluationSource(fulltext, null), funcname);
|
||||
return new ParsedFunction (fpl, sl, fes, fulltext, funcname);
|
||||
}
|
||||
|
||||
class ParsedFunction implements TypeUpdater {
|
||||
|
||||
ASTFormalParameterList fpl = null;
|
||||
ASTStatementList sl = null;
|
||||
FunctionEvaluationSource fes = null;
|
||||
String fullFunctionText = null;
|
||||
String functionName;
|
||||
|
||||
public ParsedFunction (ASTFormalParameterList fpl, ASTStatementList sl, FunctionEvaluationSource fes,
|
||||
String fullFunctionText, String functionName) {
|
||||
this.fpl = fpl;
|
||||
this.sl = sl;
|
||||
this.fes = fes;
|
||||
this.fullFunctionText = fullFunctionText;
|
||||
this.functionName = functionName;
|
||||
}
|
||||
|
||||
public void updateRequestEvaluator (RequestEvaluator reval) throws EcmaScriptException {
|
||||
|
||||
ObjectPrototype op = reval.getPrototype (prototype.getName());
|
||||
|
||||
EcmaScriptVariableVisitor vdvisitor = reval.evaluator.getVarDeclarationVisitor();
|
||||
Vector vnames = vdvisitor.processVariableDeclarations(sl, fes);
|
||||
|
||||
FunctionPrototype fp = ConstructedFunctionObject.makeNewConstructedFunction (
|
||||
reval.evaluator, functionName, fes,
|
||||
fullFunctionText, fpl.getArguments(), vnames, sl);
|
||||
op.putHiddenProperty (functionName, fp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ErrorFeedback implements TypeUpdater {
|
||||
|
||||
String functionName, errorMessage;
|
||||
|
||||
public ErrorFeedback (String fname, String msg) {
|
||||
functionName = fname;
|
||||
errorMessage = msg;
|
||||
}
|
||||
|
||||
public void updateRequestEvaluator (RequestEvaluator reval) throws EcmaScriptException {
|
||||
|
||||
ObjectPrototype op = reval.getPrototype (prototype.getName ());
|
||||
|
||||
FunctionPrototype fp = (FunctionPrototype) reval.evaluator.getFunctionPrototype ();
|
||||
FunctionPrototype func = new ThrowException (functionName, reval.evaluator, fp, errorMessage);
|
||||
op.putHiddenProperty (functionName, func);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class ThrowException extends BuiltinFunctionObject {
|
||||
String message;
|
||||
ThrowException (String name, Evaluator evaluator, FunctionPrototype fp, String message) {
|
||||
super (fp, evaluator, name, 1);
|
||||
this.message = message == null ? "No error message available" : message;
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
throw new EcmaScriptException (message);
|
||||
}
|
||||
public ESObject doConstruct (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
throw new EcmaScriptException (message);
|
||||
}
|
||||
}
|
||||
|
||||
interface TypeUpdater {
|
||||
public void updateRequestEvaluator (RequestEvaluator reval) throws EcmaScriptException;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,181 +0,0 @@
|
|||
// ESAppNode.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import helma.objectmodel.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Data.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* ESApp represents the app node of an application, providing an app-wide transient shared
|
||||
* space as well as access to some app related runtime information.
|
||||
*/
|
||||
|
||||
public class ESAppNode extends ESNode {
|
||||
|
||||
private Application app;
|
||||
private DatePrototype createtime;
|
||||
|
||||
public ESAppNode (INode node, RequestEvaluator eval) throws EcmaScriptException {
|
||||
super (eval.esNodePrototype, eval.evaluator, node, eval);
|
||||
app = eval.app;
|
||||
createtime = new DatePrototype (eval.evaluator, node.created());
|
||||
FunctionPrototype fp = (FunctionPrototype) eval.evaluator.getFunctionPrototype();
|
||||
putHiddenProperty("getThreads", new AppCountThreads ("getThreads", evaluator, fp));
|
||||
putHiddenProperty("getMaxThreads", new AppCountEvaluators ("getMaxThreads", evaluator, fp));
|
||||
putHiddenProperty("getFreeThreads", new AppCountFreeEvaluators ("getFreeThreads", evaluator, fp));
|
||||
putHiddenProperty("getActiveThreads", new AppCountBusyEvaluators ("getActiveThreads", evaluator, fp));
|
||||
putHiddenProperty("getMaxActiveThreads", new AppCountMaxBusyEvaluators ("getMaxActiveThreads", evaluator, fp));
|
||||
putHiddenProperty("setMaxThreads", new AppSetNumberOfEvaluators ("setMaxThreads", evaluator, fp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides getProperty to return some app-specific properties
|
||||
*/
|
||||
public ESValue getProperty (String propname, int hash) throws EcmaScriptException {
|
||||
if ("requestCount".equals (propname)) {
|
||||
return new ESNumber (app.requestCount);
|
||||
}
|
||||
if ("xmlrpcCount".equals (propname)) {
|
||||
return new ESNumber (app.xmlrpcCount);
|
||||
}
|
||||
if ("errorCount".equals (propname)) {
|
||||
return new ESNumber (app.errorCount);
|
||||
}
|
||||
if ("upSince".equals (propname)) {
|
||||
return createtime;
|
||||
}
|
||||
if ("skinfiles".equals (propname)) {
|
||||
ESObject skinz = new ObjectPrototype (null, evaluator);
|
||||
for (Iterator it = app.typemgr.prototypes.values().iterator(); it.hasNext(); ) {
|
||||
Prototype p = (Prototype) it.next ();
|
||||
ESObject proto = new ObjectPrototype (null, evaluator);
|
||||
for (Iterator it2 = p.skins.values().iterator(); it2.hasNext(); ) {
|
||||
SkinFile sf = (SkinFile) it2.next ();
|
||||
String name = sf.getName ();
|
||||
Skin skin = sf.getSkin ();
|
||||
proto.putProperty (name, new ESString (skin.getSource ()), name.hashCode ());
|
||||
}
|
||||
skinz.putProperty (p.getName (), proto, p.getName ().hashCode ());
|
||||
}
|
||||
return skinz;
|
||||
}
|
||||
if ("__app__".equals (propname)) {
|
||||
return new ESWrapper (app, evaluator);
|
||||
}
|
||||
return super.getProperty (propname, hash);
|
||||
}
|
||||
|
||||
|
||||
class AppCountEvaluators extends BuiltinFunctionObject {
|
||||
AppCountEvaluators (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
return new ESNumber (app.allThreads.size()-1);
|
||||
}
|
||||
}
|
||||
|
||||
class AppCountFreeEvaluators extends BuiltinFunctionObject {
|
||||
AppCountFreeEvaluators (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
return new ESNumber (app.freeThreads.size());
|
||||
}
|
||||
}
|
||||
|
||||
class AppCountBusyEvaluators extends BuiltinFunctionObject {
|
||||
AppCountBusyEvaluators (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
return new ESNumber (app.allThreads.size() - app.freeThreads.size() -1);
|
||||
}
|
||||
}
|
||||
|
||||
class AppCountMaxBusyEvaluators extends BuiltinFunctionObject {
|
||||
AppCountMaxBusyEvaluators (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
return new ESNumber (app.typemgr.countRegisteredRequestEvaluators () -1);
|
||||
}
|
||||
}
|
||||
|
||||
class AppCountThreads extends BuiltinFunctionObject {
|
||||
AppCountThreads (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
return new ESNumber (app.threadgroup.activeCount() -1);
|
||||
}
|
||||
}
|
||||
|
||||
class AppSetNumberOfEvaluators extends BuiltinFunctionObject {
|
||||
AppSetNumberOfEvaluators (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
RequestEvaluator ev = new RequestEvaluator (app);
|
||||
if (arguments.length != 1)
|
||||
return ESBoolean.makeBoolean (false);
|
||||
return ESBoolean.makeBoolean (app.setNumberOfEvaluators (1 + arguments[0].toInt32()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String toString () {
|
||||
return ("AppNode "+node.getElementName ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
// ESGenericObject.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import helma.framework.IPathElement;
|
||||
import FESI.Interpreter.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Data.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public class ESGenericObject extends ObjectPrototype {
|
||||
|
||||
ESWrapper wrapper;
|
||||
IPathElement pathObj;
|
||||
|
||||
public ESGenericObject (ESObject prototype, Evaluator evaluator, IPathElement obj) {
|
||||
super (prototype, evaluator);
|
||||
pathObj = obj;
|
||||
wrapper = new ESWrapper (obj, evaluator);
|
||||
}
|
||||
|
||||
|
||||
public String getESClassName () {
|
||||
return "GenericObject";
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return pathObj.toString ();
|
||||
}
|
||||
|
||||
public String toDetailString () {
|
||||
return wrapper.toDetailString ();
|
||||
}
|
||||
|
||||
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException {
|
||||
wrapper.putProperty (propertyName, propertyValue, hash);
|
||||
}
|
||||
|
||||
public boolean hasProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
return super.hasProperty (propertyName, hash) || wrapper.hasProperty (propertyName, hash);
|
||||
}
|
||||
|
||||
public boolean deleteProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
return wrapper.deleteProperty (propertyName, hash);
|
||||
}
|
||||
|
||||
public ESValue getProperty (int i) throws EcmaScriptException {
|
||||
return wrapper.getProperty (i);
|
||||
}
|
||||
|
||||
public void putProperty(int index, ESValue propertyValue) throws EcmaScriptException {
|
||||
wrapper.putProperty (index, propertyValue);
|
||||
}
|
||||
|
||||
|
||||
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
ESValue val = super.getProperty (propertyName, hash);
|
||||
if (val == null || val == ESUndefined.theUndefined)
|
||||
val = wrapper.getProperty (propertyName, hash);
|
||||
return val;
|
||||
}
|
||||
|
||||
public ESValue doIndirectCall(Evaluator evaluator, ESObject thisObject, String functionName, ESValue[] arguments)
|
||||
throws EcmaScriptException, NoSuchMethodException {
|
||||
if (super.hasProperty (functionName, functionName.hashCode()))
|
||||
return super.doIndirectCall (evaluator, thisObject, functionName, arguments);
|
||||
return wrapper.doIndirectCall (evaluator, thisObject, functionName, arguments);
|
||||
}
|
||||
|
||||
public Enumeration getAllProperties () {
|
||||
return wrapper.getProperties ();
|
||||
}
|
||||
|
||||
public Enumeration getProperties () {
|
||||
return wrapper.getProperties ();
|
||||
}
|
||||
|
||||
public Object toJavaObject () {
|
||||
return pathObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* An ESNode equals another object if it is an ESNode that wraps the same INode
|
||||
* or the wrapped INode itself. FIXME: doesen't check dbmapping/type!
|
||||
*/
|
||||
public boolean equals (Object what) {
|
||||
if (what == null)
|
||||
return false;
|
||||
if (what == this)
|
||||
return true;
|
||||
if (what instanceof ESGenericObject) {
|
||||
ESGenericObject other = (ESGenericObject) what;
|
||||
return (pathObj.equals (other.pathObj));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,516 +0,0 @@
|
|||
// ESNode.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import helma.objectmodel.*;
|
||||
import helma.objectmodel.db.*;
|
||||
import helma.util.*;
|
||||
import FESI.Interpreter.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Data.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* An EcmaScript wrapper around a 'Node' object. This is the basic
|
||||
* HOP object type that can be stored in the internal or external databases.
|
||||
* All HOP types inherit from the Node object.
|
||||
*/
|
||||
|
||||
public class ESNode extends ObjectPrototype {
|
||||
|
||||
INode node;
|
||||
|
||||
// the cache node - persistent nodes have a transient property as a commodity to
|
||||
// store temporary stuff.
|
||||
INode cache;
|
||||
// the ecmascript wrapper for the cache.
|
||||
ESObject cacheWrapper;
|
||||
|
||||
// The handle of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
|
||||
NodeHandle handle;
|
||||
DbMapping dbmap;
|
||||
Throwable lastError = null;
|
||||
RequestEvaluator eval;
|
||||
|
||||
/**
|
||||
* Constructor used to create transient cache nodes
|
||||
*/
|
||||
protected ESNode (INode node, RequestEvaluator eval) {
|
||||
super (eval.esNodePrototype, eval.evaluator);
|
||||
this.eval = eval;
|
||||
this.node = node;
|
||||
cache = null;
|
||||
cacheWrapper = null;
|
||||
|
||||
// this is a transient node, set node handle to null
|
||||
handle = null;
|
||||
}
|
||||
|
||||
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
|
||||
super (prototype, evaluator);
|
||||
// eval.app.logEvent ("in ESNode constructor: "+o.getClass ());
|
||||
this.eval = eval;
|
||||
if (obj == null)
|
||||
node = new TransientNode (null);
|
||||
else if (obj instanceof ESWrapper)
|
||||
node = (INode) ((ESWrapper) obj).getJavaObject ();
|
||||
else if (obj instanceof INode)
|
||||
node = (INode) obj;
|
||||
else
|
||||
node = new TransientNode (obj.toString ());
|
||||
// set node handle to wrapped node
|
||||
if (node instanceof Node)
|
||||
handle = ((Node) node).getHandle ();
|
||||
else
|
||||
handle = null;
|
||||
|
||||
// cache Node is initialized on demend when it is needed
|
||||
cache = null;
|
||||
cacheWrapper = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the node has been invalidated. If so, it has to be re-fetched
|
||||
* from the db via the app's node manager.
|
||||
*/
|
||||
protected void checkNode () {
|
||||
if (node.getState () == INode.INVALID) try {
|
||||
node = handle.getNode (eval.app.nmgr.safe);
|
||||
} catch (Exception nx) {}
|
||||
}
|
||||
|
||||
public INode getNode () {
|
||||
checkNode ();
|
||||
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);
|
||||
}
|
||||
|
||||
public String getPrototypeName () {
|
||||
return node.getPrototype ();
|
||||
}
|
||||
|
||||
public String getESClassName () {
|
||||
return "HopObject";
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
if (node == null)
|
||||
return "<null>";
|
||||
return node.toString ();
|
||||
}
|
||||
|
||||
public String toDetailString () {
|
||||
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
||||
((node == null) ? "null" : node.toString()) + "]";
|
||||
}
|
||||
|
||||
protected void setError (Throwable e) {
|
||||
lastError = e;
|
||||
}
|
||||
|
||||
|
||||
public boolean add (ESValue what[]) {
|
||||
checkNode ();
|
||||
for (int i=0; i<what.length; i++)
|
||||
if (what[i] instanceof ESNode) {
|
||||
ESNode esn = (ESNode) what[i];
|
||||
INode added = node.addNode (esn.getNode ());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ESValue list () {
|
||||
checkNode ();
|
||||
int l = node.numberOfNodes ();
|
||||
Enumeration e = node.getSubnodes ();
|
||||
ESObject ap = evaluator.getArrayPrototype();
|
||||
ArrayPrototype theArray = new ArrayPrototype(ap, evaluator);
|
||||
if (e != null) {
|
||||
theArray.setSize(l);
|
||||
for (int i = 0; i<l; i++) {
|
||||
theArray.setElementAt (eval.getNodeWrapper ((INode) e.nextElement ()), i);
|
||||
}
|
||||
} else {
|
||||
theArray.setSize (0);
|
||||
}
|
||||
return theArray;
|
||||
}
|
||||
|
||||
public boolean addAt (ESValue what[]) throws EcmaScriptException {
|
||||
checkNode ();
|
||||
if (what.length < 2)
|
||||
throw new EcmaScriptException ("Wrong number of arguments");
|
||||
if (! (what[1] instanceof ESNode))
|
||||
throw new EcmaScriptException ("Can ony add Node objects as subnodes");
|
||||
ESNode esn = (ESNode) what[1];
|
||||
INode added = node.addNode (esn.getNode (), (int) what[0].toInt32 ());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove one or more subnodes.
|
||||
*/
|
||||
public boolean remove (ESValue args[]) {
|
||||
checkNode ();
|
||||
for (int i=0; i<args.length; i++) {
|
||||
if (args[i] instanceof ESNode) {
|
||||
ESNode esn = (ESNode) args[i];
|
||||
node.removeNode (esn.getNode ());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if node is contained in subnodes
|
||||
*/
|
||||
public int contains (ESValue args[]) {
|
||||
checkNode ();
|
||||
if (args.length == 1 && args[0] instanceof ESNode) {
|
||||
ESNode esn = (ESNode) args[0];
|
||||
return node.contains (esn.getNode ());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This used to be different from add(), it isn't anymore. It's left here for
|
||||
* compatibility.
|
||||
*/
|
||||
public boolean link (ESValue args[]) {
|
||||
checkNode ();
|
||||
for (int i=0; i<args.length; i++) {
|
||||
if (args[i] instanceof ESNode) {
|
||||
ESNode esn = (ESNode) args[i];
|
||||
node.addNode (esn.getNode ());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean setParent (ESValue[] pval) {
|
||||
// do a couple of checks: both nodes need to be persistent in order for setParent to make sense.
|
||||
if (!(node instanceof helma.objectmodel.db.Node))
|
||||
return false;
|
||||
if (pval == null || pval.length < 1 || pval.length > 2)
|
||||
return false;
|
||||
if (!(pval[0] instanceof ESNode))
|
||||
return false;
|
||||
ESNode esn = (ESNode) pval[0];
|
||||
INode pn = esn.getNode ();
|
||||
if (!(pn instanceof helma.objectmodel.db.Node))
|
||||
return false;
|
||||
// check if there is an additional string element - if so, it's the property name by which the node is
|
||||
// accessed, otherwise it will be accessed as anonymous subnode via its id
|
||||
String propname = null;
|
||||
if (pval.length == 2 && pval[1] != null && !(pval[1] instanceof ESNull))
|
||||
propname = pval[1].toString ();
|
||||
helma.objectmodel.db.Node n = (helma.objectmodel.db.Node) node;
|
||||
n.setParent ((helma.objectmodel.db.Node) pn, propname);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\".");
|
||||
|
||||
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
|
||||
node.setSubnodeRelation (propertyValue instanceof ESNull ? null : propertyValue.toString ());
|
||||
return;
|
||||
}
|
||||
|
||||
if (propertyValue instanceof ESNull)
|
||||
node.unset (propertyName);
|
||||
else if (propertyValue instanceof ESString)
|
||||
node.setString (propertyName, propertyValue.toString ());
|
||||
else if (propertyValue instanceof ESBoolean)
|
||||
node.setBoolean (propertyName, propertyValue.booleanValue ());
|
||||
else if (propertyValue instanceof ESNumber)
|
||||
node.setFloat (propertyName, propertyValue.doubleValue ());
|
||||
else if (propertyValue instanceof DatePrototype)
|
||||
node.setDate (propertyName, (Date) propertyValue.toJavaObject ());
|
||||
else if (propertyValue instanceof ESNode) {
|
||||
// long now = System.currentTimeMillis ();
|
||||
ESNode esn = (ESNode) propertyValue;
|
||||
node.setNode (propertyName, esn.getNode ());
|
||||
// eval.app.logEvent ("*** spent "+(System.currentTimeMillis () - now)+" ms to set property "+propertyName);
|
||||
} else {
|
||||
// eval.app.logEvent ("got "+propertyValue.getClass ());
|
||||
// A persistent node can't store anything other than the types above, so throw an exception
|
||||
// throw new EcmaScriptException ("Can't set a JavaScript Object or Array as property of "+node);
|
||||
node.setJavaObject (propertyName, propertyValue.toJavaObject ());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
checkNode ();
|
||||
// eval.app.logEvent ("delete property called: "+propertyName);
|
||||
if (node.get (propertyName, false) != null) {
|
||||
node.unset (propertyName);
|
||||
return true;
|
||||
}
|
||||
return super.deleteProperty (propertyName, hash);
|
||||
}
|
||||
|
||||
public ESValue getProperty (int i) throws EcmaScriptException {
|
||||
checkNode ();
|
||||
INode n = node.getSubnodeAt (i);
|
||||
if (n == null)
|
||||
return ESNull.theNull;
|
||||
return eval.getNodeWrapper (n);
|
||||
}
|
||||
|
||||
public void putProperty(int index, ESValue propertyValue) throws EcmaScriptException {
|
||||
checkNode ();
|
||||
if (propertyValue instanceof ESNode) {
|
||||
ESNode n = (ESNode) propertyValue;
|
||||
node.addNode (n.getNode (), index);
|
||||
} else
|
||||
throw new EcmaScriptException ("Can only add Nodes to Node arrays");
|
||||
}
|
||||
|
||||
|
||||
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
checkNode ();
|
||||
// eval.app.logEvent ("get property called: "+propertyName);
|
||||
ESValue retval = super.getProperty (propertyName, hash);
|
||||
if (! (retval instanceof ESUndefined))
|
||||
return retval;
|
||||
|
||||
// persistent or persistent capable nodes have a cache property that's a transient node.
|
||||
// it it hasn't requested before, initialize it now
|
||||
if ("cache".equalsIgnoreCase (propertyName) && node instanceof Node) {
|
||||
if (cacheWrapper == null) {
|
||||
cache = node.getCacheNode ();
|
||||
cacheWrapper = new ESNode (cache, eval);
|
||||
}
|
||||
return cacheWrapper;
|
||||
}
|
||||
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
|
||||
String rel = node.getSubnodeRelation ();
|
||||
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__
|
||||
if (propertyName.startsWith ("__") && propertyName.endsWith ("__"))
|
||||
return getInternalProperty (propertyName);
|
||||
|
||||
// this _may_ do a relational query if properties are mapped to a relational type.
|
||||
IProperty p = node.get (propertyName, false);
|
||||
if (p != null) {
|
||||
if (p.getType () == IProperty.STRING) {
|
||||
String str = p.getStringValue ();
|
||||
if (str == null)
|
||||
return ESNull.theNull;
|
||||
else
|
||||
return new ESString (str);
|
||||
}
|
||||
if (p.getType () == IProperty.BOOLEAN)
|
||||
return ESBoolean.makeBoolean (p.getBooleanValue ());
|
||||
if (p.getType () == IProperty.DATE)
|
||||
return new DatePrototype (evaluator, p.getDateValue ());
|
||||
if (p.getType () == IProperty.INTEGER)
|
||||
return new ESNumber ((double) p.getIntegerValue ());
|
||||
if (p.getType () == IProperty.FLOAT)
|
||||
return new ESNumber (p.getFloatValue ());
|
||||
if (p.getType () == IProperty.NODE) {
|
||||
INode nd = p.getNodeValue ();
|
||||
if (nd == null)
|
||||
return ESNull.theNull;
|
||||
else
|
||||
return eval.getNodeWrapper (nd);
|
||||
}
|
||||
if (p.getType () == IProperty.JAVAOBJECT)
|
||||
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
|
||||
INode anon = node.getSubnode (propertyName);
|
||||
if (anon != null)
|
||||
return eval.getNodeWrapper (anon);
|
||||
|
||||
return ESNull.theNull;
|
||||
}
|
||||
|
||||
private ESValue getInternalProperty (String propertyName) throws EcmaScriptException {
|
||||
if ("__id__".equalsIgnoreCase (propertyName)) {
|
||||
return new ESString (node.getID ());
|
||||
}
|
||||
if ("__prototype__".equalsIgnoreCase (propertyName)) {
|
||||
String p = node.getPrototype ();
|
||||
if (p == null)
|
||||
return ESNull.theNull;
|
||||
else
|
||||
return new ESString (node.getPrototype ());
|
||||
}
|
||||
// some more internal properties
|
||||
if ("__parent__".equals (propertyName)) {
|
||||
INode n = node.getParent ();
|
||||
if (n == null)
|
||||
return ESNull.theNull;
|
||||
else
|
||||
return eval.getNodeWrapper (n);
|
||||
}
|
||||
if ("__name__".equals (propertyName))
|
||||
return new ESString (node.getName ());
|
||||
if ("__fullname__".equals (propertyName))
|
||||
return new ESString (node.getFullName ());
|
||||
if ("__hash__".equals (propertyName))
|
||||
return new ESString (""+node.hashCode ());
|
||||
if ("__node__".equals (propertyName))
|
||||
return new ESWrapper (node, evaluator);
|
||||
if ("__created__".equalsIgnoreCase (propertyName))
|
||||
return new DatePrototype (evaluator, node.created ());
|
||||
if ("__lastmodified__".equalsIgnoreCase (propertyName))
|
||||
return new DatePrototype (evaluator, node.lastModified ());
|
||||
|
||||
return ESNull.theNull;
|
||||
}
|
||||
|
||||
public Enumeration getAllProperties () {
|
||||
return getProperties ();
|
||||
}
|
||||
|
||||
public Enumeration getProperties () {
|
||||
checkNode ();
|
||||
return node.properties ();
|
||||
}
|
||||
|
||||
|
||||
public String error() {
|
||||
if (lastError == null) {
|
||||
return "";
|
||||
} else {
|
||||
String exceptionName = lastError.getClass().getName();
|
||||
int l = exceptionName.lastIndexOf(".");
|
||||
if (l>0) exceptionName = exceptionName.substring(l+1);
|
||||
return exceptionName +": " + lastError.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearError() {
|
||||
lastError = null;
|
||||
}
|
||||
|
||||
public Object toJavaObject () {
|
||||
return getNode ();
|
||||
}
|
||||
|
||||
/**
|
||||
* An ESNode equals another object if it is an ESNode that wraps the same INode
|
||||
* or the wrapped INode itself. FIXME: doesen't check dbmapping/type!
|
||||
*/
|
||||
public boolean equals (Object what) {
|
||||
if (what == null)
|
||||
return false;
|
||||
if (what == this)
|
||||
return true;
|
||||
if (what instanceof ESNode) {
|
||||
ESNode other = (ESNode) what;
|
||||
if (handle != null)
|
||||
return handle.equals (other.handle);
|
||||
else
|
||||
return (node == other.node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // class ESNode
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
// ESRequestData.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import FESI.Data.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import helma.objectmodel.INode;
|
||||
|
||||
|
||||
/**
|
||||
* An EcmaScript object that makes stuff in a hashtable accessible as its properties
|
||||
*/
|
||||
|
||||
public class ESRequestData extends ESWrapper {
|
||||
|
||||
private Hashtable data;
|
||||
private RequestEvaluator reval;
|
||||
|
||||
public ESRequestData (RequestEvaluator reval) {
|
||||
super (new Object(), reval.evaluator);
|
||||
this.reval = reval;
|
||||
}
|
||||
|
||||
public void setData (Hashtable data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to make the object read-only
|
||||
*/
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException {
|
||||
throw new EcmaScriptException ("Can't set property, object is read-only");
|
||||
}
|
||||
|
||||
public boolean deleteProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
throw new EcmaScriptException ("Can't delete property, object is read-only");
|
||||
}
|
||||
|
||||
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
if (data == null)
|
||||
return ESNull.theNull;
|
||||
|
||||
Object val = data.get (propertyName);
|
||||
|
||||
if (val == null)
|
||||
return ESNull.theNull;
|
||||
|
||||
if (val instanceof String)
|
||||
return new ESString ((String) val);
|
||||
else if (val instanceof INode)
|
||||
return reval.getNodeWrapper ((INode) val);
|
||||
|
||||
return ESLoader.normalizeValue(val, evaluator);
|
||||
}
|
||||
|
||||
|
||||
public Enumeration getAllProperties () {
|
||||
return getProperties ();
|
||||
}
|
||||
|
||||
public Enumeration getProperties () {
|
||||
if (data == null)
|
||||
return new Hashtable().keys();
|
||||
return data.keys();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
// ESUser.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import helma.objectmodel.*;
|
||||
import FESI.Interpreter.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Data.*;
|
||||
|
||||
/**
|
||||
* The ESUser is a special kind of Node object that represents a user of
|
||||
* a HOP application. The actual user session data are kept in class User.
|
||||
* If the user is logged in as a registered member, the wrapped node represents
|
||||
* the user object in the database, while for anonymous surfers the node object
|
||||
* is just a transient node. <p>
|
||||
* This means that the wrapped node will be swapped when the user logs in or out.
|
||||
* To save session state across logins and logouts, the
|
||||
* cache property of the user object stays the same for the whole time the user
|
||||
* spends on this site.
|
||||
*/
|
||||
|
||||
public class ESUser extends ESNode {
|
||||
|
||||
/** if the user is online, this is his/her online session object */
|
||||
public User user;
|
||||
|
||||
public ESUser (INode node, RequestEvaluator eval, User user) {
|
||||
super (eval.esUserPrototype, eval.evaluator, node, eval);
|
||||
this.user = user;
|
||||
if (user != null) {
|
||||
cache = user.cache;
|
||||
cacheWrapper = new ESNode (cache, eval);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides getProperty to return the uid (which is not a regular property)
|
||||
*/
|
||||
public ESValue getProperty (String propname, int hash) throws EcmaScriptException {
|
||||
if ("uid".equals (propname)) {
|
||||
if (user == null || user.uid == null)
|
||||
return ESNull.theNull;
|
||||
else
|
||||
return new ESString (user.uid);
|
||||
}
|
||||
if ("sessionID".equals (propname)) {
|
||||
if (user == null || user.getSessionID () == null)
|
||||
return ESNull.theNull;
|
||||
else
|
||||
return new ESString (user.getSessionID ());
|
||||
}
|
||||
if ("cache".equals (propname))
|
||||
return cacheWrapper;
|
||||
return super.getProperty (propname, hash);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The node for a user object changes at login and logout, so we don't use our
|
||||
* own node, but just reach through to the session user object instead.
|
||||
*/
|
||||
public void setNode (INode node) {
|
||||
user.setNode (node);
|
||||
if (node != null) {
|
||||
this.node = node;
|
||||
} else {
|
||||
// user.getNode will never return null. If the node is set to null (=user logged out)
|
||||
// it will user the original transient cache node again.
|
||||
this.node = user.getNode ();
|
||||
}
|
||||
// set node handle to wrapped node
|
||||
if (node instanceof helma.objectmodel.db.Node)
|
||||
handle = ((helma.objectmodel.db.Node) node).getHandle ();
|
||||
else
|
||||
handle = null;
|
||||
// we don't take over the transient cache from the node,
|
||||
// because we always stick to the one from the user object.
|
||||
}
|
||||
|
||||
public void updateNodeFromUser () {
|
||||
node = user.getNode ();
|
||||
// set node handle to wrapped node
|
||||
if (node instanceof helma.objectmodel.db.Node)
|
||||
handle = ((helma.objectmodel.db.Node) node).getHandle ();
|
||||
else
|
||||
handle = null;
|
||||
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return ("UserObject "+node.getName ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,271 +0,0 @@
|
|||
// FunctionFile.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Enumeration;
|
||||
import java.io.*;
|
||||
import helma.framework.*;
|
||||
import helma.util.Updatable;
|
||||
import FESI.Data.*;
|
||||
import FESI.Exceptions.EcmaScriptException;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
|
||||
/**
|
||||
* This represents a File containing JavaScript functions for a given Object.
|
||||
*/
|
||||
|
||||
|
||||
public class FunctionFile implements Updatable {
|
||||
|
||||
String name;
|
||||
Prototype prototype;
|
||||
Application app;
|
||||
File file;
|
||||
String content;
|
||||
long lastmod;
|
||||
|
||||
// a set of funcion names defined by this file. We keep this to be able to
|
||||
// remove them once the file should get removed
|
||||
HashSet declaredProps;
|
||||
long declaredPropsTimestamp;
|
||||
|
||||
public FunctionFile (File file, String name, Prototype proto) {
|
||||
this.prototype = proto;
|
||||
this.app = proto.app;
|
||||
this.name = name;
|
||||
this.file = file;
|
||||
update ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a function file without a file, passing the code directly. This is used for
|
||||
* files contained in zipped applications. The whole update mechanism is bypassed
|
||||
* by immediately parsing the code.
|
||||
*/
|
||||
public FunctionFile (String body, String name, Prototype proto) {
|
||||
this.prototype = proto;
|
||||
this.app = proto.app;
|
||||
this.name = name;
|
||||
this.file = null;
|
||||
this.content = body;
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
|
||||
StringEvaluationSource es = new StringEvaluationSource (body, null);
|
||||
StringReader reader = new StringReader (body);
|
||||
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
updateRequestEvaluator (reval, reader, es);
|
||||
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the type manager whether we need an update. this is the case when
|
||||
* the file has been modified or deleted.
|
||||
*/
|
||||
public boolean needsUpdate () {
|
||||
return lastmod != file.lastModified () || !file.exists ();
|
||||
}
|
||||
|
||||
|
||||
public void update () {
|
||||
|
||||
if (!file.exists ()) {
|
||||
remove ();
|
||||
|
||||
} else {
|
||||
|
||||
lastmod = file.lastModified ();
|
||||
// app.typemgr.readFunctionFile (file, prototype.getName ());
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
FileReader fr = new FileReader(file);
|
||||
EvaluationSource es = new FileEvaluationSource(file.getPath(), null);
|
||||
updateRequestEvaluator (reval, fr, es);
|
||||
|
||||
} catch (Throwable ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public synchronized void updateRequestEvaluator (RequestEvaluator reval) {
|
||||
if (file != null) {
|
||||
try {
|
||||
FileReader fr = new FileReader (file);
|
||||
EvaluationSource es = new FileEvaluationSource (file.getPath (), null);
|
||||
updateRequestEvaluator (reval, fr, es);
|
||||
} catch (Exception ignore) {}
|
||||
} else {
|
||||
StringReader reader = new StringReader (content);
|
||||
StringEvaluationSource es = new StringEvaluationSource (content, null);
|
||||
updateRequestEvaluator (reval, reader, es);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void updateRequestEvaluator (RequestEvaluator reval, Reader reader, EvaluationSource source) {
|
||||
|
||||
HashMap priorProps = null;
|
||||
HashSet newProps = null;
|
||||
|
||||
try {
|
||||
|
||||
ObjectPrototype op = reval.getPrototype (prototype.getName());
|
||||
|
||||
// extract all properties from prototype _before_ evaluation, so we can compare afterwards
|
||||
// but only do this is declaredProps is not up to date yet
|
||||
if (declaredPropsTimestamp != lastmod) {
|
||||
priorProps = new HashMap ();
|
||||
// remember properties before evaluation, so we can tell what's new afterwards
|
||||
try {
|
||||
for (Enumeration en=op.getAllProperties(); en.hasMoreElements(); ) {
|
||||
String prop = (String) en.nextElement ();
|
||||
priorProps.put (prop, op.getProperty (prop, prop.hashCode()));
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
// do the update, evaluating the file
|
||||
reval.evaluator.evaluate(reader, op, source, false);
|
||||
|
||||
// check what's new
|
||||
if (declaredPropsTimestamp != lastmod) try {
|
||||
newProps = new HashSet ();
|
||||
for (Enumeration en=op.getAllProperties(); en.hasMoreElements(); ) {
|
||||
String prop = (String) en.nextElement ();
|
||||
if (priorProps.get (prop) == null || op.getProperty (prop, prop.hashCode()) != priorProps.get (prop))
|
||||
newProps.add (prop);
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
|
||||
} catch (Exception e) {
|
||||
// app.logEvent ("Error parsing function file "+app.getName()+":"+prototype.getName()+"/"+file.getName()+": "+e);
|
||||
app.logEvent ("Error parsing function file "+source+": "+e);
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignore) {}
|
||||
}
|
||||
|
||||
// now remove the props that were not refreshed, and set declared props to new collection
|
||||
if (declaredPropsTimestamp != lastmod) {
|
||||
declaredPropsTimestamp = lastmod;
|
||||
if (declaredProps != null) {
|
||||
declaredProps.removeAll (newProps);
|
||||
removeProperties (declaredProps);
|
||||
}
|
||||
declaredProps = newProps;
|
||||
// System.err.println ("DECLAREDPROPS = "+declaredProps);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void remove () {
|
||||
prototype.functions.remove (name);
|
||||
prototype.updatables.remove (file.getName());
|
||||
|
||||
// if we did not add anything to any evaluator, we're done
|
||||
if (declaredProps == null || declaredProps.size() == 0)
|
||||
return;
|
||||
|
||||
removeProperties (declaredProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the properties in the HashMap iff they're still the same as declared by this file.
|
||||
* This method is called by remove() with the latest props, and by update with the prior props
|
||||
* after the file has been reevaluated.
|
||||
*/
|
||||
void removeProperties (HashSet props) {
|
||||
// first loop through other function files in this prototype to make a set of properties
|
||||
// owned by other files.
|
||||
HashSet otherFiles = new HashSet ();
|
||||
for (Iterator it=prototype.functions.values ().iterator (); it.hasNext (); ) {
|
||||
FunctionFile other = (FunctionFile) it.next ();
|
||||
if (other != this && other.declaredProps != null)
|
||||
otherFiles.addAll (other.declaredProps);
|
||||
}
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
ObjectPrototype op = reval.getPrototype (prototype.getName());
|
||||
for (Iterator it = props.iterator (); it.hasNext (); ) {
|
||||
String fname = (String) it.next ();
|
||||
// check if this property has been declared by some other function file in the meantime
|
||||
if (otherFiles.contains (fname))
|
||||
continue;
|
||||
op.deleteProperty (fname, fname.hashCode());
|
||||
// System.err.println ("REMOVING PROP: "+fname);
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
if (file == null)
|
||||
return "[Zipped script file]";
|
||||
else
|
||||
return prototype.getName()+"/"+file.getName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,85 +0,0 @@
|
|||
// NodeConstructor.java
|
||||
// Copyright (c) Hannes Wallnöfer 2000
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import helma.objectmodel.db.Node;
|
||||
import FESI.Data.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* A constructor for user defined data types. This first constructs a node, sets its prototype
|
||||
* and invokes the scripted constructor function on it.
|
||||
*/
|
||||
|
||||
public class NodeConstructor extends BuiltinFunctionObject {
|
||||
|
||||
RequestEvaluator reval;
|
||||
String typename;
|
||||
|
||||
public NodeConstructor (String name, FunctionPrototype fp, RequestEvaluator reval) {
|
||||
super(fp, reval.evaluator, name, 1);
|
||||
typename = name;
|
||||
this.reval = reval;
|
||||
}
|
||||
|
||||
public ESValue callFunction(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
return doConstruct(thisObject, arguments);
|
||||
}
|
||||
|
||||
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
ESNode node = null;
|
||||
if ("Node".equals (typename) || "hopobject".equalsIgnoreCase (typename)) {
|
||||
if (arguments.length == 0) {
|
||||
Node n = new Node ((String) null, (String) null, reval.app.nmgr.safe);
|
||||
node = new ESNode (reval.esNodePrototype, this.evaluator, n, reval);
|
||||
reval.objectcache.put (node.getNode (), node);
|
||||
} else {
|
||||
Node n = new Node (arguments[0].toString(), (String) null, reval.app.nmgr.safe);
|
||||
node = new ESNode (reval.esNodePrototype, this.evaluator, n, reval);
|
||||
reval.objectcache.put (node.getNode (), node);
|
||||
}
|
||||
} else {
|
||||
// Typed nodes are instantiated as helma.objectmodel.db.Node from the beginning
|
||||
// even if we don't know yet if they are going to be stored in a database. The reason
|
||||
// is that we want to be able to use the specail features like subnode relations even for
|
||||
// transient nodes.
|
||||
ObjectPrototype op = reval.getPrototype (typename);
|
||||
Node n = new Node (typename, typename, reval.app.nmgr.safe);
|
||||
node = new ESNode (op, reval.evaluator, n, reval);
|
||||
node.setPrototype (typename);
|
||||
node.getNode ().setDbMapping (reval.app.getDbMapping (typename));
|
||||
try {
|
||||
// first try calling "constructor", if that doesn't work, try calling a function
|
||||
// with the name of the type.
|
||||
// HACK: There is an incompatibility problem here, because the property
|
||||
// constructor is defined as the constructor of the object by EcmaScript.
|
||||
if (op.getProperty("constructor", "constructor".hashCode()) instanceof ConstructedFunctionObject)
|
||||
node.doIndirectCall (reval.evaluator, node, "constructor", arguments);
|
||||
else
|
||||
node.doIndirectCall (reval.evaluator, node, typename, arguments);
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash) throws EcmaScriptException {
|
||||
return super.getPropertyInScope (propertyName, previousScope, hash);
|
||||
}
|
||||
|
||||
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||
if ("prototype".equals (propertyName))
|
||||
return reval.getPrototype (typename);
|
||||
return super.getProperty(propertyName, hash);
|
||||
}
|
||||
|
||||
public String[] getSpecialPropertyNames() {
|
||||
String ns[] = {};
|
||||
return ns;
|
||||
}
|
||||
|
||||
} // class NodeConstructor
|
||||
|
||||
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
// Template.java
|
||||
// Copyright (c) Hannes Wallnöfer 1998-2000
|
||||
|
||||
package helma.framework.core;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
import helma.framework.*;
|
||||
import FESI.Data.*;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
|
||||
/**
|
||||
* This represents a HOP template, i.e. a file with the extension .hsp
|
||||
* (HOP server page) that contains both parts that are to be evaluated
|
||||
* as EcmaScript and parts that are to be delivered to the client as-is.
|
||||
* Internally, templates are regular functions.
|
||||
* HOP templates are callable via URL, but this is just a leftover from the
|
||||
* days when there were no .hac (action) files. The recommended way
|
||||
* now is to have a .hac file with all the logic which in turn calls one or more
|
||||
* template files to do the formatting.
|
||||
*/
|
||||
|
||||
public class Template extends Action {
|
||||
|
||||
// this is the *_as_string function, which is in addition to the normal one
|
||||
TypeUpdater psfunc;
|
||||
|
||||
|
||||
public Template (File file, String name, Prototype proto) {
|
||||
super (file, name, proto);
|
||||
}
|
||||
|
||||
|
||||
public void update (String content) throws Exception {
|
||||
// IServer.getLogger().log ("Reading text template " + name);
|
||||
|
||||
Vector partBuffer = new Vector ();
|
||||
int l = content.length ();
|
||||
char cnt[] = new char[l];
|
||||
content.getChars (0, l, cnt, 0);
|
||||
|
||||
// if last charackter is whitespace, swallow it. this is necessary for some inner templates to look ok.
|
||||
if (Character.isWhitespace (cnt[l-1]))
|
||||
l -= 1;
|
||||
|
||||
int lastIdx = 0;
|
||||
for (int i = 0; i < l-1; i++) {
|
||||
if (cnt[i] == '<' && cnt[i+1] == '%') {
|
||||
int j = i+2;
|
||||
while (j < l-1 && (cnt[j] != '%' || cnt[j+1] != '>')) {
|
||||
j++;
|
||||
}
|
||||
if (j > i+2) {
|
||||
if (i - lastIdx > 0)
|
||||
partBuffer.addElement (new Part (this, new String (cnt, lastIdx, i - lastIdx), true));
|
||||
String script = new String (cnt, i+2, (j-i)-2);
|
||||
partBuffer.addElement (new Part (this, script, false));
|
||||
lastIdx = j+2;
|
||||
}
|
||||
i = j+1;
|
||||
}
|
||||
}
|
||||
if (lastIdx < l)
|
||||
partBuffer.addElement (new Part (this, new String (cnt, lastIdx, l - lastIdx), true));
|
||||
|
||||
StringBuffer templateBody = new StringBuffer ();
|
||||
int nparts = partBuffer.size();
|
||||
|
||||
for (int k = 0; k < nparts; k++) {
|
||||
Part nextPart = (Part) partBuffer.elementAt (k);
|
||||
|
||||
if (nextPart.isStatic || nextPart.content.trim ().startsWith ("=")) {
|
||||
// check for <%= ... %> statements
|
||||
if (!nextPart.isStatic) {
|
||||
nextPart.content = nextPart.content.trim ().substring (1).trim ();
|
||||
// cut trailing ";"
|
||||
while (nextPart.content.endsWith (";"))
|
||||
nextPart.content = nextPart.content.substring (0, nextPart.content.length()-1);
|
||||
}
|
||||
|
||||
StringTokenizer st = new StringTokenizer (nextPart.content, "\r\n", true);
|
||||
String nextLine = st.hasMoreTokens () ? st.nextToken () : null;
|
||||
|
||||
// count newLines we "swallow", see explanation below
|
||||
int newLineCount = 0;
|
||||
|
||||
templateBody.append ("res.write (");
|
||||
if (nextPart.isStatic) {
|
||||
templateBody.append ("\"");
|
||||
}
|
||||
|
||||
while (nextLine != null) {
|
||||
|
||||
if ("\n".equals (nextLine)) {
|
||||
// append a CRLF
|
||||
newLineCount++;
|
||||
templateBody.append ("\\r\\n");
|
||||
} else if (!"\r".equals (nextLine)){
|
||||
StringReader lineReader = new StringReader (nextLine);
|
||||
int c = lineReader.read ();
|
||||
while (c > -1) {
|
||||
if (nextPart.isStatic && ((char)c == '"' || (char)c == '\\')) {
|
||||
templateBody.append ('\\');
|
||||
}
|
||||
templateBody.append ((char) c);
|
||||
c = lineReader.read ();
|
||||
}
|
||||
}
|
||||
|
||||
nextLine = st.hasMoreTokens () ? st.nextToken () : null;
|
||||
|
||||
}
|
||||
|
||||
if (nextPart.isStatic) {
|
||||
templateBody.append ("\"");
|
||||
}
|
||||
|
||||
templateBody.append ("); ");
|
||||
|
||||
// append the number of lines we have "swallowed" into
|
||||
// one write statement, so error messages will *approximately*
|
||||
// give correct line numbers.
|
||||
for (int i=0; i<newLineCount; i++) {
|
||||
templateBody.append ("\r\n");
|
||||
}
|
||||
|
||||
} else {
|
||||
templateBody.append (nextPart.content);
|
||||
if (!nextPart.content.trim ().endsWith (";")) {
|
||||
templateBody.append (";");
|
||||
}
|
||||
}
|
||||
}
|
||||
// templateBody.append ("\r\nreturn null;\r\n");
|
||||
|
||||
functionName = name;
|
||||
String fname = name+"_as_string";
|
||||
String body = templateBody.toString ();
|
||||
|
||||
try {
|
||||
pfunc = parseFunction (name,
|
||||
"arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10",
|
||||
body+"\r\nreturn null;\r\n");
|
||||
} catch (Throwable x) {
|
||||
String message = x.getMessage ();
|
||||
pfunc = new ErrorFeedback (name, message);
|
||||
}
|
||||
try {
|
||||
psfunc = parseFunction (fname,
|
||||
"arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10",
|
||||
"res.pushStringBuffer(); "+body+"\r\nreturn res.popStringBuffer();\r\n");
|
||||
} catch (Throwable x) {
|
||||
String message = x.getMessage ();
|
||||
psfunc = new ErrorFeedback (fname, message);
|
||||
}
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
updateRequestEvaluator (reval);
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
void remove () {
|
||||
prototype.templates.remove (name);
|
||||
prototype.updatables.remove (file.getName());
|
||||
|
||||
Iterator evals = app.typemgr.getRegisteredRequestEvaluators ();
|
||||
while (evals.hasNext ()) {
|
||||
try {
|
||||
RequestEvaluator reval = (RequestEvaluator) evals.next ();
|
||||
ObjectPrototype op = reval.getPrototype (prototype.getName());
|
||||
functionName = name;
|
||||
ESValue esv = (ESValue) op.getProperty (functionName, functionName.hashCode());
|
||||
if (esv instanceof ConstructedFunctionObject || esv instanceof ThrowException) {
|
||||
op.deleteProperty (functionName, functionName.hashCode());
|
||||
}
|
||||
String fname = name+"_as_string";
|
||||
esv = (ESValue) op.getProperty (fname, fname.hashCode());
|
||||
if (esv instanceof ConstructedFunctionObject || esv instanceof ThrowException) {
|
||||
op.deleteProperty (fname, fname.hashCode());
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void updateRequestEvaluator (RequestEvaluator reval) throws EcmaScriptException {
|
||||
if (pfunc != null)
|
||||
pfunc.updateRequestEvaluator (reval);
|
||||
if (psfunc != null)
|
||||
psfunc.updateRequestEvaluator (reval);
|
||||
}
|
||||
|
||||
class Part {
|
||||
|
||||
String content;
|
||||
Template parent;
|
||||
boolean isPart;
|
||||
boolean isStatic;
|
||||
|
||||
|
||||
public Part (Template parent, String content, boolean isStatic) {
|
||||
isPart = false;
|
||||
this.parent = parent;
|
||||
this.content = content;
|
||||
this.isStatic = isStatic;
|
||||
}
|
||||
|
||||
public String getName () {
|
||||
return isStatic ? null : content;
|
||||
}
|
||||
|
||||
|
||||
public String toString () {
|
||||
return "Template.Part ["+content+","+isStatic+"]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue