X-Git-Url: http://git.megacz.com/?p=org.ibex.xt.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fxt%2FPrevalence.java;h=2bfbfb191c165c7c7ae3b26ac114d53bb1ee65fd;hp=ef871474e9cc694058d1623e62a257eeb4ffb387;hb=895124c1bfbfb35522477936af38d250bcc65f4c;hpb=5365f47787b1b4eeca31ad5da2373237371e264e diff --git a/src/org/ibex/xt/Prevalence.java b/src/org/ibex/xt/Prevalence.java index ef87147..2bfbfb1 100644 --- a/src/org/ibex/xt/Prevalence.java +++ b/src/org/ibex/xt/Prevalence.java @@ -1,3 +1,7 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.xt; import org.ibex.js.*; import org.ibex.util.*; @@ -9,10 +13,30 @@ import javax.servlet.*; import javax.servlet.http.*; import com.thoughtworks.xstream.*; import org.prevayler.*; -import org.prevayler.implementation.snapshot.*; +import org.prevayler.implementation.snapshot.XmlSnapshotManager; public class Prevalence { + public static abstract class PrevalentServlet extends HttpServlet { + protected Hashtable prevalent; + protected Prevayler prevayler; + protected ServletContext cx = null; + public void destroy() { try { + synchronized(this.getClass()) { + Prevayler privatePrevayler = prevayler; + if (prevayler == null) return; + prevayler = null; + Prevalence.destroy(cx, prevayler); + } + } catch (Exception e) { e.printStackTrace(); } } + + public void init(ServletConfig sc) throws ServletException { + cx = sc.getServletContext(); + prevayler = Prevalence.getPrevayler(cx); + prevalent = (Hashtable)prevayler.prevalentSystem(); + } + } + static final Hashtable prevaylers = new Hashtable(); public static void destroy(ServletContext cx, Prevayler prevayler) { try { @@ -43,20 +67,12 @@ public class Prevalence { prevayler = (Prevayler)prevaylers.get(cx); if (prevayler == null) { PrevaylerFactory pf = new PrevaylerFactory(); - String base = cx.getRealPath("/") + "WEB-INF" + File.separatorChar + "prevalent"; + String base = cx.getRealPath("/") + File.separatorChar + "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(); - xstream.alias("js", JS.class); - xstream.alias("jsdate", JSDate.class); - return xstream; - } - }; + XmlSnapshotManager manager = new XmlSnapshotManager(new Hashtable(), base); System.err.println("configuring with " + manager); pf.configureSnapshotManager(manager); - //pf.configureClassLoader(JSTransaction.class.getClassLoader()); prevayler = pf.create(); prevaylers.put(cx, prevayler); new SnapshotThread(cx).start(); @@ -68,10 +84,24 @@ public class Prevalence { public static class JSTransaction implements Transaction { public static final long serialVersionUid = 0xfb2aa281; private JS js; - public JSTransaction(JS js) { this.js = js; } + Scope newscope; + String[] v; + public JSTransaction(JS js) throws JSExn { + newscope = new Scope(null); + this.js = JSU.cloneWithNewGlobalScope(js, newscope); + v = this.js.getFormalArgs(); + for(int i=0; i