major update to xt
authoradam <adam@megacz.com>
Tue, 19 Oct 2004 07:49:36 +0000 (07:49 +0000)
committeradam <adam@megacz.com>
Tue, 19 Oct 2004 07:49:36 +0000 (07:49 +0000)
darcs-hash:20041019074936-5007d-3975051f2a9242bfa1277407be2b90e670397941.gz

src/org/ibex/xt/Prevalence.java
src/org/ibex/xt/Servlet.java

index ef87147..2057f23 100644 (file)
@@ -46,6 +46,7 @@ public class Prevalence {
                     String base = cx.getRealPath("/") + "WEB-INF" + File.separatorChar + "prevalent";
                     System.err.println("prevayling to " + base);
                     pf.configurePrevalenceBase(base);
                     String base = cx.getRealPath("/") + "WEB-INF" + File.separatorChar + "prevalent";
                     System.err.println("prevayling to " + base);
                     pf.configurePrevalenceBase(base);
+                    /*
                     XStreamSnapshotManager manager = new XStreamSnapshotManager(new JS(), base, null) {
                             protected XStream createXStream() {
                                 XStream xstream = new XStream();
                     XStreamSnapshotManager manager = new XStreamSnapshotManager(new JS(), base, null) {
                             protected XStream createXStream() {
                                 XStream xstream = new XStream();
@@ -56,6 +57,8 @@ public class Prevalence {
                         };
                     System.err.println("configuring with " + manager);
                     pf.configureSnapshotManager(manager);
                         };
                     System.err.println("configuring with " + manager);
                     pf.configureSnapshotManager(manager);
+                    */
+                    pf.configureSnapshotManager(new SnapshotManager(new JS(), base));
                     //pf.configureClassLoader(JSTransaction.class.getClassLoader());
                     prevayler = pf.create();
                     prevaylers.put(cx, prevayler);
                     //pf.configureClassLoader(JSTransaction.class.getClassLoader());
                     prevayler = pf.create();
                     prevaylers.put(cx, prevayler);
@@ -68,10 +71,27 @@ public class Prevalence {
     public static class JSTransaction implements Transaction {
         public static final long serialVersionUid = 0xfb2aa281;
         private JS js;
     public static class JSTransaction implements Transaction {
         public static final long serialVersionUid = 0xfb2aa281;
         private JS js;
-        public JSTransaction(JS js) { this.js = js; }
+        JSScope newscope;
+        Vec v;
+        public JSTransaction(JS js) throws JSExn {
+            newscope = new JSScope(null);
+            this.js = JS.cloneWithNewParentScope(js, newscope);
+            v = JS.getFormalArgs(this.js);
+            for(int i=0; i<v.size(); i++) {
+                if ("prevalent".equals(v.elementAt(i))) continue;
+                newscope.put(v.elementAt(i), JS.getParentScope(js).get(v.elementAt(i)));
+            }
+        }
         public void executeOn(Object o, Date now) {
             try {
         public void executeOn(Object o, Date now) {
             try {
-                js.call(o, new JSDate(now.getTime()), null, null, 2);
+                newscope.put("prevalent", o);
+                newscope.put("now", new JSDate(now.getTime()));
+                Object a = v.size() <= 0 ? null : newscope.get(v.elementAt(0));
+                Object b = v.size() <= 1 ? null : newscope.get(v.elementAt(1));
+                Object c = v.size() <= 2 ? null : newscope.get(v.elementAt(2));
+                Object[] rest = v.size() <= 3 ? null : new Object[v.size() - 3];
+                for(int i=3; i<v.size(); i++) rest[i-3] = v.elementAt(i);
+                js.call(a, b, c, rest, v.size());
             } catch (Exception e) { throw new RuntimeException(e); }
         }
     }
             } catch (Exception e) { throw new RuntimeException(e); }
         }
     }
@@ -79,10 +99,11 @@ public class Prevalence {
     public static class JSQuery implements Query {
         public static final long serialVersionUid = 0xfb2aa282;
         private JS js;
     public static class JSQuery implements Query {
         public static final long serialVersionUid = 0xfb2aa282;
         private JS js;
-        public JSQuery(JS js) { this.js = js; }
+        private Object a;
+        public JSQuery(JS js, Object a) { this.js = JS.cloneWithNewParentScope(js, null); this.a = a; }
         public Object query(Object o, Date now) {
             try {
         public Object query(Object o, Date now) {
             try {
-                return js.call(o, new JSDate(now.getTime()), null, null, 2);
+                return js.call(o, a, new JSDate(now.getTime()), null, 3);
             } catch (Exception e) { throw new RuntimeException(e); }
         }
     }
             } catch (Exception e) { throw new RuntimeException(e); }
         }
     }
index be36ac8..1d18563 100644 (file)
@@ -31,6 +31,7 @@ public class Servlet extends HttpServlet {
     public void init(ServletConfig sc) throws ServletException {
         cx = sc.getServletContext();
         prevayler = Prevalence.getPrevayler(cx);
     public void init(ServletConfig sc) throws ServletException {
         cx = sc.getServletContext();
         prevayler = Prevalence.getPrevayler(cx);
+        prevalent = (JS)prevayler.prevalentSystem();
     }
 
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { doGet(request, response); }
     }
 
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { doGet(request, response); }
@@ -98,13 +99,6 @@ public class Servlet extends HttpServlet {
 
         public Object callMethod(Object method, final Object a, final Object b, Object c, Object[] rest, int nargs) throws JSExn {
             //#switch(method)
 
         public Object callMethod(Object method, final Object a, final Object b, Object c, Object[] rest, int nargs) throws JSExn {
             //#switch(method)
-            case "prevalent.query":
-                try {
-                    return prevayler.execute(new Prevalence.JSQuery(JS.cloneWithNewParentScope((JS)a, null)));
-                } catch (Exception e) {
-                    e.printStackTrace();
-                    throw new RuntimeException(e); }
-
             case "session.invalidate":    request.getSession(true).invalidate(); return null;
             case "context.list":
                 String path = JS.toString(a);
             case "session.invalidate":    request.getSession(true).invalidate(); return null;
             case "context.list":
                 String path = JS.toString(a);
@@ -122,7 +116,7 @@ public class Servlet extends HttpServlet {
             //#switch(key)
             case "body":
             case "arg":                   return null;
             //#switch(key)
             case "body":
             case "arg":                   return null;
-            case "prevalent":             return prevalent;
+            case "prevalent":             return prevayler.prevalentSystem();
             case "request":               return getSub("request");
             case "request.user":          return request.getRemoteUser();
             case "request.header":        return requestHeader;
             case "request":               return getSub("request");
             case "request.user":          return request.getRemoteUser();
             case "request.header":        return requestHeader;
@@ -151,12 +145,12 @@ public class Servlet extends HttpServlet {
         public void put(Object key, Object val) throws JSExn {
             try {
             //#switch(JS.toString(key))
         public void put(Object key, Object val) throws JSExn {
             try {
             //#switch(JS.toString(key))
+            case "transaction":
+                try { prevayler.execute(new Prevalence.JSTransaction((JS)val));
+                } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); }
             case "response.code":         response.setStatus(JS.toInt(val));
             case "response.redirect":     response.sendRedirect(JS.toString(val));
             case "response.contentType":  response.setContentType(JS.toString(val));
             case "response.code":         response.setStatus(JS.toInt(val));
             case "response.redirect":     response.sendRedirect(JS.toString(val));
             case "response.contentType":  response.setContentType(JS.toString(val));
-            case "prevalent":             
-                try { prevayler.execute(new Prevalence.JSTransaction(JS.cloneWithNewParentScope((JS)val, null)));
-                } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); }
             //#end
             } catch (IOException e) {
                 throw new JSExn(e);
             //#end
             } catch (IOException e) {
                 throw new JSExn(e);