Remove unused import statements.
Changed TypeInfo variable name from "info" to "type"
This commit is contained in:
parent
0ca20d5842
commit
33175a07c8
1 changed files with 45 additions and 51 deletions
|
@ -17,18 +17,12 @@
|
||||||
package helma.scripting.rhino;
|
package helma.scripting.rhino;
|
||||||
|
|
||||||
import helma.scripting.rhino.extensions.*;
|
import helma.scripting.rhino.extensions.*;
|
||||||
import helma.framework.*;
|
|
||||||
import helma.framework.core.*;
|
import helma.framework.core.*;
|
||||||
import helma.main.Server;
|
|
||||||
import helma.objectmodel.*;
|
import helma.objectmodel.*;
|
||||||
import helma.objectmodel.db.DbMapping;
|
|
||||||
import helma.objectmodel.db.Relation;
|
|
||||||
import helma.scripting.*;
|
import helma.scripting.*;
|
||||||
import helma.util.CacheMap;
|
import helma.util.CacheMap;
|
||||||
import helma.util.SystemMap;
|
import helma.util.SystemMap;
|
||||||
import helma.util.WrappedMap;
|
import helma.util.WrappedMap;
|
||||||
import helma.util.SystemProperties;
|
|
||||||
import helma.util.Updatable;
|
|
||||||
import org.mozilla.javascript.*;
|
import org.mozilla.javascript.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -193,43 +187,43 @@ public final class RhinoCore {
|
||||||
* Set up a prototype, parsing and compiling all its script files.
|
* Set up a prototype, parsing and compiling all its script files.
|
||||||
*
|
*
|
||||||
* @param prototype the prototype to update/evaluate/compile
|
* @param prototype the prototype to update/evaluate/compile
|
||||||
* @param info the info, containing the object proto, last update time and
|
* @param type the info, containing the object proto, last update time and
|
||||||
* the set of compiled functions properties
|
* the set of compiled functions properties
|
||||||
*/
|
*/
|
||||||
synchronized void evaluatePrototype(Prototype prototype, TypeInfo info) {
|
synchronized void evaluatePrototype(Prototype prototype, TypeInfo type) {
|
||||||
// System.err.println("EVALUATING PROTO: "+prototype);
|
// System.err.println("EVALUATING PROTO: "+prototype);
|
||||||
Scriptable op = info.objectPrototype;
|
Scriptable op = type.objectPrototype;
|
||||||
|
|
||||||
// set the parent prototype in case it hasn't been done before
|
// set the parent prototype in case it hasn't been done before
|
||||||
// or it has changed...
|
// or it has changed...
|
||||||
setParentPrototype(prototype, op);
|
setParentPrototype(prototype, op);
|
||||||
|
|
||||||
globalError = info.error = null;
|
globalError = type.error = null;
|
||||||
|
|
||||||
// loop through the prototype's code elements and evaluate them
|
// loop through the prototype's code elements and evaluate them
|
||||||
// first the zipped ones ...
|
// first the zipped ones ...
|
||||||
for (Iterator it = prototype.getZippedCode().values().iterator(); it.hasNext();) {
|
for (Iterator it = prototype.getZippedCode().values().iterator(); it.hasNext();) {
|
||||||
Object code = it.next();
|
Object code = it.next();
|
||||||
|
|
||||||
evaluate(prototype, info, code);
|
evaluate(type, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// then the unzipped ones (this is to make sure unzipped code overwrites zipped code)
|
// then the unzipped ones (this is to make sure unzipped code overwrites zipped code)
|
||||||
for (Iterator it = prototype.getCode().values().iterator(); it.hasNext();) {
|
for (Iterator it = prototype.getCode().values().iterator(); it.hasNext();) {
|
||||||
Object code = it.next();
|
Object code = it.next();
|
||||||
|
|
||||||
evaluate(prototype, info, code);
|
evaluate(type, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop through function properties defined for this proto and
|
// loop through function properties defined for this proto and
|
||||||
// remove those which are left over from the previous generation
|
// remove those which are left over from the previous generation
|
||||||
// and haven't been renewed in this pass.
|
// and haven't been renewed in this pass.
|
||||||
Set oldFunctions = info.compiledFunctions;
|
Set oldFunctions = type.compiledFunctions;
|
||||||
Set newFunctions = new HashSet();
|
Set newFunctions = new HashSet();
|
||||||
Object[] keys = ((ScriptableObject) op).getAllIds();
|
Object[] keys = ((ScriptableObject) op).getAllIds();
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
String key = keys[i].toString();
|
String key = keys[i].toString();
|
||||||
if (info.predefinedProperties.contains(key)) {
|
if (type.predefinedProperties.contains(key)) {
|
||||||
// don't mess with properties we didn't set
|
// don't mess with properties we didn't set
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -249,8 +243,8 @@ public final class RhinoCore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info.compiledFunctions = newFunctions;
|
type.compiledFunctions = newFunctions;
|
||||||
info.lastUpdate = prototype.getLastUpdate();
|
type.lastUpdate = prototype.getLastUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,26 +312,26 @@ public final class RhinoCore {
|
||||||
|
|
||||||
for (Iterator i = protos.iterator(); i.hasNext();) {
|
for (Iterator i = protos.iterator(); i.hasNext();) {
|
||||||
Prototype proto = (Prototype) i.next();
|
Prototype proto = (Prototype) i.next();
|
||||||
TypeInfo info = (TypeInfo) prototypes.get(proto.getName());
|
TypeInfo type = (TypeInfo) prototypes.get(proto.getName());
|
||||||
|
|
||||||
if (info == null) {
|
if (type == null) {
|
||||||
// a prototype we don't know anything about yet. Init local update info.
|
// a prototype we don't know anything about yet. Init local update info.
|
||||||
initPrototype(proto);
|
initPrototype(proto);
|
||||||
info = (TypeInfo) prototypes.get(proto.getName());
|
type = (TypeInfo) prototypes.get(proto.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// only update prototype if it has already been initialized.
|
// only update prototype if it has already been initialized.
|
||||||
// otherwise, this will be done on demand
|
// otherwise, this will be done on demand
|
||||||
// System.err.println ("CHECKING PROTO "+proto+": "+info);
|
// System.err.println ("CHECKING PROTO "+proto+": "+type);
|
||||||
if (info.lastUpdate > 0) {
|
if (type.lastUpdate > 0) {
|
||||||
Prototype p = app.typemgr.getPrototype(info.protoName);
|
Prototype p = app.typemgr.getPrototype(type.protoName);
|
||||||
|
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
// System.err.println ("UPDATING PROTO: "+p);
|
// System.err.println ("UPDATING PROTO: "+p);
|
||||||
app.typemgr.updatePrototype(p);
|
app.typemgr.updatePrototype(p);
|
||||||
|
|
||||||
if (p.getLastUpdate() > info.lastUpdate) {
|
if (p.getLastUpdate() > type.lastUpdate) {
|
||||||
evaluatePrototype(p, info);
|
evaluatePrototype(p, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,9 +349,9 @@ public final class RhinoCore {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeInfo info = (TypeInfo) prototypes.get(protoName);
|
TypeInfo type = (TypeInfo) prototypes.get(protoName);
|
||||||
|
|
||||||
return (info == null) ? null : info.objectPrototype;
|
return (type == null) ? null : type.objectPrototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -369,11 +363,11 @@ public final class RhinoCore {
|
||||||
if (globalError != null) {
|
if (globalError != null) {
|
||||||
throw new RuntimeException(globalError.toString());
|
throw new RuntimeException(globalError.toString());
|
||||||
}
|
}
|
||||||
TypeInfo info = getPrototypeInfo(protoName);
|
TypeInfo type = getPrototypeInfo(protoName);
|
||||||
if (info != null && info.error != null) {
|
if (type != null && type.error != null) {
|
||||||
throw new RuntimeException(info.error.toString());
|
throw new RuntimeException(type.error.toString());
|
||||||
}
|
}
|
||||||
return info == null ? null : info.objectPrototype;
|
return type == null ? null : type.objectPrototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,8 +377,8 @@ public final class RhinoCore {
|
||||||
* by updatePrototypes(), which is called for each request.
|
* by updatePrototypes(), which is called for each request.
|
||||||
*/
|
*/
|
||||||
public Scriptable getPrototype(String protoName) {
|
public Scriptable getPrototype(String protoName) {
|
||||||
TypeInfo info = getPrototypeInfo(protoName);
|
TypeInfo type = getPrototypeInfo(protoName);
|
||||||
return info == null ? null : info.objectPrototype;
|
return type == null ? null : type.objectPrototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -397,28 +391,28 @@ public final class RhinoCore {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeInfo info = (TypeInfo) prototypes.get(protoName);
|
TypeInfo type = (TypeInfo) prototypes.get(protoName);
|
||||||
|
|
||||||
if ((info != null) && (info.lastUpdate == 0)) {
|
if ((type != null) && (type.lastUpdate == 0)) {
|
||||||
Prototype p = app.typemgr.getPrototype(protoName);
|
Prototype p = app.typemgr.getPrototype(protoName);
|
||||||
|
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
app.typemgr.updatePrototype(p);
|
app.typemgr.updatePrototype(p);
|
||||||
|
|
||||||
if (p.getLastUpdate() > info.lastUpdate) {
|
if (p.getLastUpdate() > type.lastUpdate) {
|
||||||
evaluatePrototype(p, info);
|
evaluatePrototype(p, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set info.lastUpdate to 1 if it is 0 so we know we
|
// set type.lastUpdate to 1 if it is 0 so we know we
|
||||||
// have initialized this prototype already, even if
|
// have initialized this prototype already, even if
|
||||||
// it is empty (i.e. doesn't contain any scripts/skins/actions)
|
// it is empty (i.e. doesn't contain any scripts/skins/actions)
|
||||||
if (info.lastUpdate == 0) {
|
if (type.lastUpdate == 0) {
|
||||||
info.lastUpdate = 1;
|
type.lastUpdate = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -749,7 +743,7 @@ public final class RhinoCore {
|
||||||
// private evaluation/compilation methods
|
// private evaluation/compilation methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private synchronized void evaluate(Prototype prototype, TypeInfo info, Object code) {
|
private synchronized void evaluate(TypeInfo type, Object code) {
|
||||||
if (code instanceof FunctionFile) {
|
if (code instanceof FunctionFile) {
|
||||||
FunctionFile funcfile = (FunctionFile) code;
|
FunctionFile funcfile = (FunctionFile) code;
|
||||||
File file = funcfile.getFile();
|
File file = funcfile.getFile();
|
||||||
|
@ -758,25 +752,25 @@ public final class RhinoCore {
|
||||||
try {
|
try {
|
||||||
FileReader fr = new FileReader(file);
|
FileReader fr = new FileReader(file);
|
||||||
|
|
||||||
updateEvaluator(prototype, info, fr, funcfile.getSourceName(), 1);
|
updateEvaluator(type, fr, funcfile.getSourceName(), 1);
|
||||||
} catch (IOException iox) {
|
} catch (IOException iox) {
|
||||||
app.logEvent("Error updating function file: " + iox);
|
app.logEvent("Error updating function file: " + iox);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StringReader reader = new StringReader(funcfile.getContent());
|
StringReader reader = new StringReader(funcfile.getContent());
|
||||||
|
|
||||||
updateEvaluator(prototype, info, reader, funcfile.getSourceName(), 1);
|
updateEvaluator(type, reader, funcfile.getSourceName(), 1);
|
||||||
}
|
}
|
||||||
} else if (code instanceof ActionFile) {
|
} else if (code instanceof ActionFile) {
|
||||||
ActionFile action = (ActionFile) code;
|
ActionFile action = (ActionFile) code;
|
||||||
RhinoActionAdapter fa = new RhinoActionAdapter(action);
|
RhinoActionAdapter fa = new RhinoActionAdapter(action);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
updateEvaluator(prototype, info, new StringReader(fa.function),
|
updateEvaluator(type, new StringReader(fa.function),
|
||||||
action.getSourceName(), 0);
|
action.getSourceName(), 0);
|
||||||
if (fa.functionAsString != null) {
|
if (fa.functionAsString != null) {
|
||||||
// templates have an _as_string variant that needs to be compiled
|
// templates have an _as_string variant that needs to be compiled
|
||||||
updateEvaluator(prototype, info, new StringReader(fa.functionAsString),
|
updateEvaluator(type, new StringReader(fa.functionAsString),
|
||||||
action.getSourceName(), 0);
|
action.getSourceName(), 0);
|
||||||
}
|
}
|
||||||
} catch (Exception esx) {
|
} catch (Exception esx) {
|
||||||
|
@ -785,14 +779,14 @@ public final class RhinoCore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateEvaluator(Prototype prototype, TypeInfo info,
|
private synchronized void updateEvaluator(TypeInfo type, Reader reader,
|
||||||
Reader reader, String sourceName, int firstline) {
|
String sourceName, int firstline) {
|
||||||
// System.err.println("UPDATE EVALUATOR: "+prototype+" - "+sourceName);
|
// System.err.println("UPDATE EVALUATOR: "+prototype+" - "+sourceName);
|
||||||
try {
|
try {
|
||||||
// get the current context
|
// get the current context
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
|
|
||||||
Scriptable op = info.objectPrototype;
|
Scriptable op = type.objectPrototype;
|
||||||
|
|
||||||
// do the update, evaluating the file
|
// do the update, evaluating the file
|
||||||
cx.evaluateReader(op, reader, sourceName, firstline, null);
|
cx.evaluateReader(op, reader, sourceName, firstline, null);
|
||||||
|
@ -804,11 +798,11 @@ public final class RhinoCore {
|
||||||
System.err.println("Error parsing file " + sourceName + ": " + e);
|
System.err.println("Error parsing file " + sourceName + ": " + e);
|
||||||
}
|
}
|
||||||
// mark prototype as broken
|
// mark prototype as broken
|
||||||
if (info.error == null && e instanceof EcmaError) {
|
if (type.error == null && e instanceof EcmaError) {
|
||||||
if ("global".equals(info.protoName)) {
|
if ("global".equals(type.protoName)) {
|
||||||
globalError = (EcmaError) e;
|
globalError = (EcmaError) e;
|
||||||
} else {
|
} else {
|
||||||
info.error = (EcmaError) e;
|
type.error = (EcmaError) e;
|
||||||
}
|
}
|
||||||
wrappercache.clear();
|
wrappercache.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue