1 28 29 package com.caucho.es; 30 31 import com.caucho.java.LineMap; 32 import com.caucho.util.Exit; 33 import com.caucho.vfs.Path; 34 35 import java.util.HashMap ; 36 37 71 72 abstract public class Script { 73 protected Path scriptPath; 74 protected Path classDir; 75 76 79 public boolean isModified() 80 { 81 return true; 82 } 83 84 88 public void setScriptPath(Path scriptPath) 89 { 90 this.scriptPath = scriptPath; 91 } 92 93 97 public void setClassDir(Path classDir) 98 { 99 this.classDir = classDir; 100 } 101 102 106 public LineMap getLineMap() 107 { 108 return null; 109 } 110 111 138 public String execute(HashMap properties, Object proto) throws Throwable 139 { 140 Global oldGlobal = Global.getGlobalProto(); 141 boolean doExit = Exit.addExit(); 142 143 try { 144 Global resin = new Global(properties, proto, classDir, 145 scriptPath, getClass().getClassLoader()); 146 147 resin.begin(); 148 149 ESGlobal global = initClass(resin); 150 151 ESBase value = global.execute(); 152 153 if (value == null) 154 return null; 155 else 156 return value.toStr().toString(); 157 } finally { 158 Global.end(oldGlobal); 159 160 if (doExit) 161 Exit.exit(); 162 } 163 } 164 165 179 public ScriptClosure executeClosure(HashMap properties, Object proto) 180 throws Throwable 181 { 182 Global resin = new Global(properties, proto, classDir, 183 scriptPath, getClass().getClassLoader()); 184 boolean doExit = Exit.addExit(); 185 Global oldGlobal = resin.begin(); 186 187 try { 188 ESGlobal global = initClass(resin); 189 190 global.execute(); 191 192 return new ScriptClosure(resin, global, this); 193 } finally { 194 resin.end(oldGlobal); 195 if (doExit) 196 Exit.exit(); 197 } 198 } 199 200 203 public ESGlobal initClass(Global resin, ESObject global) 204 throws Throwable 205 { 206 return initClass(resin); 207 } 208 209 212 public abstract ESGlobal initClass(Global resin) 213 throws Throwable ; 214 215 218 public void export(ESObject dest, ESObject src) 219 throws Throwable 220 { 221 } 222 } 223 | Popular Tags |