Author: knopp
Date: Mon Apr 6 01:52:10 2009
New Revision: 762196
URL: http://svn.apache.org/viewvc?rev=762196&view=rev
Log:
works but needs cleanup
Added:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Session.java
(with props)
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/HttpSessionStore.java
(with props)
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/SessionStore.java
(with props)
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Application.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Page.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/PageFactory.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/ThreadContext.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/AbstractPageManager.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/PageManager.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/DefaultPageStore.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PageStore.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PersistentPageManager.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/handler/PageProvider.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/ServletWebRequest.java
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/WebRequest.java
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Application.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Application.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Application.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Application.java
Mon Apr 6 01:52:10 2009
@@ -1,10 +1,19 @@
package org.apache.wicket;
+import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.wicket.application.ClassResolver;
import org.apache.wicket.application.DefaultClassResolver;
+import org.apache.wicket.page.PageManager;
+import org.apache.wicket.page.persistent.DataStore;
+import org.apache.wicket.page.persistent.DefaultPageStore;
+import org.apache.wicket.page.persistent.PageStore;
+import org.apache.wicket.page.persistent.PersistentPageManager;
+import org.apache.wicket.page.persistent.disk.DiskDataStore;
+import org.apache.wicket.session.HttpSessionStore;
+import org.apache.wicket.session.SessionStore;
import org.apache.wicket.settings.ApplicationSettings;
import org.apache.wicket.settings.RequestCycleSettings;
import org.apache.wicket.util.lang.Check;
@@ -14,27 +23,33 @@
private String name;
public Application()
- {
+ {
}
-
+
public void internalInit()
{
-
+ this.sessionStore = newSessionStore();
+ this.pageManager = newPageManager();
}
-
+
public void init()
{
-
+
}
-
+
public void setName(String name)
{
Check.argumentNotEmpty(name, "name");
+ if (this.name != null)
+ {
+ throw new IllegalStateException("Application name can
only be set once.");
+ }
+
this.name = name;
applications.put(name, this);
}
-
+
public String getName()
{
return name;
@@ -60,64 +75,183 @@
}
return application;
}
-
+
public static boolean exists()
{
return ThreadContext.getApplication() != null;
}
-
+
public void set()
{
ThreadContext.setApplication(this);
}
- private RequestCycleSettings settings = new RequestCycleSettings()
+ // TODO - Do properly
+ private RequestCycleSettings settings = new RequestCycleSettings()
{
private RenderStrategy strategy =
RenderStrategy.REDIRECT_TO_BUFFER;
private String responseEncoding = "UTF-8";
-
+
public RenderStrategy getRenderStrategy()
{
return strategy;
}
-
+
public String getResponseRequestEncoding()
{
return responseEncoding;
}
+
public void setRenderStrategy(RenderStrategy renderStrategy)
{
- this.strategy = renderStrategy;
+ this.strategy = renderStrategy;
}
+
public void setResponseRequestEncoding(String
responseRequestEncoding)
{
this.responseEncoding = responseRequestEncoding;
}
- };
-
+ };
+
+ // TODO: - Do properly
private ApplicationSettings applicationSettings = new
ApplicationSettings()
{
private ClassResolver resolver = new DefaultClassResolver();
-
+
public ClassResolver getClassResolver()
{
return resolver;
}
+
public void setClassResolver(ClassResolver defaultClassResolver)
{
resolver = defaultClassResolver;
}
};
-
+
public RequestCycleSettings getRequestCycleSettings()
{
return settings;
}
-
+
public ApplicationSettings getApplicationSettings()
{
return applicationSettings;
}
private static Map<String, Application> applications = new
ConcurrentHashMap<String, Application>();
+
+ // // Session Store
+
+ protected SessionStore newSessionStore()
+ {
+ return new HttpSessionStore(this);
+ }
+
+ private SessionStore sessionStore;
+
+ public SessionStore getSessionStore()
+ {
+ return sessionStore;
+ }
+
+ public void sessionUnbound(String sessionId)
+ {
+ getPageManager().sessionExpired(sessionId);
+ }
+
+ // // Session
+
+ protected Session newSession(RequestCycle requestCycle)
+ {
+ return new Session(requestCycle);
+ }
+
+ public Session fetchCreateAndSetSession(RequestCycle requestCycle)
+ {
+ Check.argumentNotNull(requestCycle, "requestCycle");
+
+ Session session =
getSessionStore().lookup(requestCycle.getRequest());
+ if (session == null)
+ {
+ session = newSession(requestCycle);
+ ThreadContext.setSession(session);
+
getPageManager().newSessionCreated(getPageManagerContext());
+ }
+ else
+ {
+ ThreadContext.setSession(session);
+ }
+ return session;
+ }
+
+ // // PageManager
+
+ protected PageManager newPageManager()
+ {
+ int cacheSize = 50;
+ int fileChannelPoolCapacity = 50;
+ DataStore dataStore = new DiskDataStore(getName(), 1000000,
fileChannelPoolCapacity);
+ PageStore pageStore = new DefaultPageStore(getName(),
dataStore, cacheSize);
+ return new PersistentPageManager(this.getName(), pageStore);
+ }
+
+ private PageManager pageManager;
+
+ private PageManager.Context pageManagerContext = new
PageManager.Context()
+ {
+ public void bind()
+ {
+ Session.get().bind();
+ }
+
+ private MetaDataKey<Object> requestCycleMetaDataKey = new
MetaDataKey<Object>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ public Object getRequestData()
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+ if (requestCycle == null)
+ {
+ throw new IllegalStateException("Not a request
thread.");
+ }
+ return
requestCycle.getMetaData(requestCycleMetaDataKey);
+ }
+
+ public Serializable getSessionAttribute(String key)
+ {
+ return Session.get().getAttribute(key);
+ }
+
+ public String getSessionId()
+ {
+ return Session.get().getId();
+ }
+
+ public void setRequestData(Object data)
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+ if (requestCycle == null)
+ {
+ throw new IllegalStateException("Not a request
thread.");
+ }
+ requestCycle.setMetaData(requestCycleMetaDataKey, data);
+ }
+ public void setSessionAttribute(String key, Serializable value)
+ {
+ Session.get().setAttribute(key, value);
+ }
+ };
+
+ public PageManager getPageManager()
+ {
+ return pageManager;
+ }
+
+ public PageManager.Context getPageManagerContext()
+ {
+ return pageManagerContext;
+ }
}
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Page.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Page.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Page.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Page.java
Mon Apr 6 01:52:10 2009
@@ -1,8 +1,5 @@
package org.apache.wicket;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.wicket.request.response.Response;
public class Page extends Component implements IPage
@@ -22,7 +19,6 @@
{
super("");
pageId = pageIdCounter++;
- pages.add(this);
if (parameters == null)
{
this.pageParameters = new PageParameters();
@@ -33,18 +29,10 @@
}
}
- private static final List<Page> pages = new ArrayList<Page>();
-
public static Page get(int id)
{
- for (Page p : pages)
- {
- if (p.getPageId() == id)
- {
- return p;
- }
- }
- return null;
+ Application app = Application.get();
+ return (Page)
app.getPageManager().getPage(app.getPageManagerContext(), id);
}
public int getPageId()
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/PageFactory.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/PageFactory.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/PageFactory.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/PageFactory.java
Mon Apr 6 01:52:10 2009
@@ -45,7 +45,7 @@
* @throws WicketRuntimeException
* Thrown if the page cannot be constructed
*/
- <C extends IPage> Page newPage(final Class<C> pageClass);
+ <C extends IPage> IPage newPage(final Class<C> pageClass);
/**
* Creates a new Page, passing PageParameters to the Page constructor
if such a constructor
@@ -62,5 +62,5 @@
* @throws WicketRuntimeException
* Thrown if the page cannot be constructed
*/
- <C extends IPage> Page newPage(final Class<C> pageClass, final
PageParameters parameters);
+ <C extends IPage> IPage newPage(final Class<C> pageClass, final
PageParameters parameters);
}
Added:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Session.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Session.java?rev=762196&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Session.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Session.java
Mon Apr 6 01:52:10 2009
@@ -0,0 +1,158 @@
+package org.apache.wicket;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.wicket.request.request.Request;
+import org.apache.wicket.session.SessionStore;
+
+public class Session implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ public Session(RequestCycle requestCycle)
+ {
+
+ }
+
+ protected SessionStore getSessionStore()
+ {
+ return Application.get().getSessionStore();
+ }
+
+ private Request getRequest()
+ {
+ return RequestCycle.get().getRequest();
+ }
+
+ public void invalidateNow()
+ {
+ getSessionStore().invalidate(getRequest());
+ }
+
+ public void invalidate()
+ {
+ if (!invalidated)
+ {
+ RequestCycle.get().registerDetachCallback(new
RequestCycle.DetachCallback()
+ {
+ public void onDetach(RequestCycle requestCycle)
+ {
+
getSessionStore().invalidate(getRequest());
+ }
+ });
+ }
+ invalidated = true;
+ }
+
+ private boolean invalidated = false;
+
+ public static Session get()
+ {
+ Session session = ThreadContext.getSession();
+ if (session != null)
+ {
+ return session;
+ }
+ else
+ {
+ return
Application.get().fetchCreateAndSetSession(RequestCycle.get());
+ }
+ }
+
+ public boolean isTemporary()
+ {
+ return getSessionStore().getSessionId(getRequest(), false) ==
null;
+ }
+
+ public String getId()
+ {
+ return getSessionStore().getSessionId(getRequest(), false);
+ }
+
+ public void hasBeenBound()
+ {
+ if (temporarySessionAttributes != null)
+ {
+ for (Map.Entry<String, Serializable> entry :
temporarySessionAttributes.entrySet())
+ {
+ getSessionStore().setAttribute(getRequest(),
entry.getKey(), entry.getValue());
+ }
+ temporarySessionAttributes = null;
+ }
+ }
+
+ public void bind()
+ {
+ getSessionStore().getSessionId(getRequest(), true);
+ getSessionStore().bind(getRequest(), this);
+ }
+
+ protected void setAttribute(String name, Serializable value)
+ {
+ if (isTemporary())
+ {
+ if (temporarySessionAttributes == null)
+ {
+ temporarySessionAttributes = new
HashMap<String, Serializable>();
+ temporarySessionAttributes.put(name, value);
+ }
+ }
+ else
+ {
+ getSessionStore().setAttribute(getRequest(), name,
value);
+ }
+ }
+
+ protected Serializable getAttribute(String name)
+ {
+ if (isTemporary())
+ {
+ if (temporarySessionAttributes != null)
+ {
+ return temporarySessionAttributes.get(name);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return getSessionStore().getAttribute(getRequest(),
name);
+ }
+ }
+
+ protected Set<String> getAttributeNames()
+ {
+ if (isTemporary())
+ {
+ if (temporarySessionAttributes != null)
+ {
+ return
Collections.unmodifiableSet(temporarySessionAttributes.keySet());
+ }
+ else
+ {
+ return Collections.emptySet();
+ }
+ }
+ else
+ {
+ return
Collections.unmodifiableSet(getSessionStore().getAttributeNames(getRequest()));
+ }
+ }
+
+ /**
+ * Holds attributes for sessions that are still temporary/ not bound to
a session store. Only
+ * used when {...@link #isTemporary()} is true.
+ * <p>
+ * Note: this doesn't have to be synchronized, as the only time when
this map is used is when a
+ * session is temporary, in which case it won't be shared between
requests (it's a per request
+ * instance).
+ * </p>
+ */
+ private transient Map<String, Serializable> temporarySessionAttributes;
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/Session.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/ThreadContext.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/ThreadContext.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/ThreadContext.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/ThreadContext.java
Mon Apr 6 01:52:10 2009
@@ -1,20 +1,20 @@
package org.apache.wicket;
-
public class ThreadContext
{
private ThreadContext()
{
-
+
}
-
+
private Application application;
-
+
private RequestCycle requestCycle;
-
-
+
+ private Session session;
+
private static ThreadLocal<ThreadContext> threadLocal = new
ThreadLocal<ThreadContext>();
-
+
private static ThreadContext get(boolean createIfDoesNotExist)
{
ThreadContext context = threadLocal.get();
@@ -25,31 +25,43 @@
}
return context;
}
-
+
public static Application getApplication()
{
ThreadContext context = get(false);
return context != null ? context.application : null;
}
-
+
public static void setApplication(Application application)
{
ThreadContext context = get(true);
context.application = application;
}
-
+
public static RequestCycle getRequestCycle()
{
ThreadContext context = get(false);
- return context != null ? context.requestCycle: null;
+ return context != null ? context.requestCycle : null;
}
-
+
public static void setRequestCycle(RequestCycle requestCycle)
{
ThreadContext context = get(true);
context.requestCycle = requestCycle;
}
+
+ public static Session getSession()
+ {
+ ThreadContext context = get(false);
+ return context != null ? context.session : null;
+ }
+ public static void setSession(Session session)
+ {
+ ThreadContext context = get(true);
+ context.session = session;
+ }
+
public static void detach()
{
threadLocal.remove();
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/AbstractPageManager.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/AbstractPageManager.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/AbstractPageManager.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/AbstractPageManager.java
Mon Apr 6 01:52:10 2009
@@ -53,12 +53,20 @@
* @param touchedPages
*/
protected abstract void storeTouchedPages(List<IPage>
touchedPages);
-
+
/**
* Notification on new session being created.
*/
protected abstract void newSessionCreated();
+ /**
+ * Bind the session
+ */
+ protected void bind()
+ {
+ context.bind();
+ }
+
public void setSessionAttribute(String key, Serializable value)
{
context.setSessionAttribute(key, value);
@@ -146,14 +154,14 @@
List<IPage> pages = new ArrayList<IPage>();
};
- protected abstract RequestAdapter newRequestAdater(Context context);
+ protected abstract RequestAdapter newRequestAdapter(Context context);
protected RequestAdapter getRequestAdapter(Context context)
{
RequestAdapter adapter = (RequestAdapter)
context.getRequestData();
if (adapter == null)
{
- adapter = newRequestAdater(context);
+ adapter = newRequestAdapter(context);
context.setRequestData(adapter);
}
return adapter;
@@ -168,7 +176,12 @@
public IPage getPage(Context context, int id)
{
RequestAdapter adapter = getRequestAdapter(context);
- return adapter.getPage(id);
+ IPage page = adapter.getPage(id);
+ if (page != null)
+ {
+ touchPage(context, page);
+ }
+ return page;
}
public void newSessionCreated(Context context)
@@ -181,6 +194,7 @@
public void touchPage(Context context, IPage page)
{
+ context.bind();
RequestAdapter adapter = getRequestAdapter(context);
adapter.touch(page);
}
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/PageManager.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/PageManager.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/PageManager.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/PageManager.java
Mon Apr 6 01:52:10 2009
@@ -71,9 +71,9 @@
/**
* Invoked when the session has been expired.
*
- * @param context
+ * @param sessionId
*/
- public void sessionExpired(String sesionId);
+ public void sessionExpired(String sessionId);
/**
* Destroy the page manager.
@@ -97,6 +97,8 @@
public Serializable getSessionAttribute(String key);
+ public void bind();
+
public String getSessionId();
};
}
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/DefaultPageStore.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/DefaultPageStore.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/DefaultPageStore.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/DefaultPageStore.java
Mon Apr 6 01:52:10 2009
@@ -90,7 +90,7 @@
{
SerializedPage serialized = serializePage(sessionId, page);
serializedPagesCache.storePage(serialized);
- storePage(sessionId, page);
+ storePageData(sessionId, serialized.getPageId(),
serialized.getData());
}
public void unbind(String sessionId)
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PageStore.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PageStore.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PageStore.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PageStore.java
Mon Apr 6 01:52:10 2009
@@ -55,7 +55,7 @@
/**
* Process the page before the it gets serialized. The page can be
either real page instance
- * of object returned by {...@link
#restoreAfterSerialization(Serializable)}.
+ * or object returned by {...@link
#restoreAfterSerialization(Serializable)}.
*
* @param sessionId
* @param page
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PersistentPageManager.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PersistentPageManager.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PersistentPageManager.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/page/persistent/PersistentPageManager.java
Mon Apr 6 01:52:10 2009
@@ -1,45 +1,212 @@
package org.apache.wicket.page.persistent;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.wicket.IPage;
import org.apache.wicket.page.AbstractPageManager;
public class PersistentPageManager extends AbstractPageManager
{
- public PersistentPageManager()
+ private final PageStore pageStore;
+ private final String applicationName;
+
+ public PersistentPageManager(String applicationName, PageStore
pageStore)
{
+ this.applicationName = applicationName;
+ this.pageStore = pageStore;
+ managers.put(applicationName, this);
}
+ private static Map<String, PersistentPageManager> managers = new
ConcurrentHashMap<String, PersistentPageManager>();
+
+ private static class SessionEntry implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ private final String applicationName;
+ private final String sessionId;
+
+ public SessionEntry(String applicationName, String sessionId)
+ {
+ this.applicationName = applicationName;
+ this.sessionId = sessionId;
+ }
+
+ private PageStore getPageStore()
+ {
+ PersistentPageManager manager =
managers.get(applicationName);
+ if (manager == null)
+ {
+ throw new IllegalStateException("PageManager
for application " + applicationName + " not registered.");
+ }
+ return manager.pageStore;
+ }
+
+ private void addPage(IPage page)
+ {
+ if (page != null)
+ {
+ for (IPage p : pages)
+ {
+ if (p.getId() == page.getId())
+ {
+ return;
+ }
+ }
+ }
+ pages.add(page);
+ }
+
+
+ private void convertAfterReadObjects()
+ {
+ if (pages == null)
+ {
+ pages = new ArrayList<IPage>();
+ }
+
+ for (Object o : afterReadObject)
+ {
+ IPage page = getPageStore().convertToPage(o);
+ addPage(page);
+ }
+
+ afterReadObject = null;
+ }
+
+ public synchronized IPage getPage(int id)
+ {
+ if (afterReadObject != null &&
afterReadObject.isEmpty() == false)
+ {
+ convertAfterReadObjects();
+ }
+ if (pages != null)
+ {
+ for (IPage page : pages)
+ {
+ if (page.getPageId() == id)
+ {
+ return page;
+ }
+ }
+ }
+ return getPageStore().getPage(sessionId, id);
+ }
+
+ public synchronized void setPages(List<IPage> pages)
+ {
+ this.pages = new ArrayList<IPage>(pages);
+ afterReadObject = null;
+ }
+
+ private transient List<IPage> pages;
+ private transient List<Object> afterReadObject;
+
+ private void writeObject(java.io.ObjectOutputStream s) throws
IOException
+ {
+ s.defaultWriteObject();
+ List<Serializable> l = new ArrayList<Serializable>();
+ for (IPage p : pages)
+ {
+
l.add(getPageStore().prepareForSerialization(sessionId, p));
+ }
+ s.writeObject(l);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream s) throws
IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+
+ List<Serializable> l = (List<Serializable>)
s.readObject();
+
+ for (Serializable ser : l)
+ {
+
afterReadObject.add(getPageStore().restoreAfterSerialization(ser));
+ }
+
+ afterReadObject = new ArrayList<Object>();
+ }
+ };
+
protected class PersitentRequestAdapter extends RequestAdapter
{
public PersitentRequestAdapter(Context context)
{
super(context);
}
-
+
@Override
protected IPage getPage(int id)
{
- // TODO Auto-generated method stub
- return null;
+ SessionEntry entry = getSessionEntry(false);
+ IPage page = entry.getPage(id);
+ if (page != null)
+ {
+ return page;
+ }
+ else if (getSessionId() != null)
+ {
+ return pageStore.getPage(getSessionId(), id);
+ }
+ else
+ {
+ return null;
+ }
}
+
+ private static final String ATTRIBUTE_NAME =
"wicket:persistentPageManagerData";
+
+ private SessionEntry getSessionEntry(boolean create)
+ {
+ SessionEntry entry = (SessionEntry)
getSessionAttribute(ATTRIBUTE_NAME);
+ if (entry == null && create)
+ {
+ bind();
+ entry = new SessionEntry(applicationName,
getSessionId());
+ }
+ if (entry != null)
+ {
+ synchronized (entry)
+ {
+ setSessionAttribute(ATTRIBUTE_NAME,
null);
+ setSessionAttribute(ATTRIBUTE_NAME,
entry);
+ }
+ }
+ return entry;
+ }
+
@Override
protected void newSessionCreated()
{
- // TODO Auto-generated method stub
-
+ if (getSessionId() != null)
+ {
+ getSessionEntry(true);
+ }
}
+
@Override
protected void storeTouchedPages(List<IPage> touchedPages)
{
- // TODO Auto-generated method stub
-
+ if (!touchedPages.isEmpty())
+ {
+ SessionEntry entry = getSessionEntry(true);
+ entry.setPages(touchedPages);
+ for (IPage page : touchedPages)
+ {
+ pageStore.storePage(getSessionId(),
page);
+ }
+ }
}
};
-
+
@Override
- protected RequestAdapter newRequestAdater(Context context)
+ protected RequestAdapter newRequestAdapter(Context context)
{
return new PersitentRequestAdapter(context);
}
@@ -50,16 +217,14 @@
return true;
}
- public void sessionExpired(String sesionId)
+ public void sessionExpired(String sessionId)
{
- // TODO Auto-generated method stub
-
+ pageStore.unbind(sessionId);
}
-
+
public void destroy()
{
- // TODO Auto-generated method stub
-
+ managers.remove(applicationName);
}
}
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WebApplication.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
Mon Apr 6 01:52:10 2009
@@ -56,14 +56,14 @@
@Override
public void internalInit()
{
+ super.internalInit();
+
mount(new PageInstanceEncoder());
mount(new BookmarkableEncoder());
mount(new ResourceReferenceEncoder());
mount(new BufferedResponseEncoder());
}
-
-
protected RequestCycleContext newRequestCycleContext()
{
RequestCycleContext context = new RequestCycleContext()
@@ -105,6 +105,19 @@
return new RequestCycle(request, response, context);
};
+ public final RequestCycle createRequestCycle(Request request, Response
response)
+ {
+ RequestCycle requestCycle = newRequestCycle(request, response);
+ requestCycle.registerDetachCallback(new
RequestCycle.DetachCallback()
+ {
+ public void onDetach(RequestCycle requestCycle)
+ {
+
getPageManager().commitRequest(getPageManagerContext());
+ }
+ });
+ return requestCycle;
+ }
+
private RequestHandlerEncoderRegistry requestHandlerEncoderRegistry;
public RequestHandlerEncoderRegistry getRequestHandlerEncoderRegistry()
@@ -203,7 +216,31 @@
return resourceReferenceRegistry;
}
- private PageFactory pageFactory = new DefaultPageFactory();
+ private PageFactory pageFactory = new PageFactoryWrapper(new
DefaultPageFactory());
+
+ private class PageFactoryWrapper implements PageFactory
+ {
+ private final PageFactory factory;
+
+ PageFactoryWrapper(PageFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ public <C extends IPage> IPage newPage(Class<C> pageClass)
+ {
+ IPage p = factory.newPage(pageClass);
+ getPageManager().touchPage(getPageManagerContext(), p);
+ return p;
+ }
+
+ public <C extends IPage> IPage newPage(Class<C> pageClass,
PageParameters parameters)
+ {
+ IPage p = factory.newPage(pageClass, parameters);
+ getPageManager().touchPage(getPageManagerContext(), p);
+ return p;
+ }
+ };
public PageFactory getPageFactory()
{
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
Mon Apr 6 01:52:10 2009
@@ -137,7 +137,7 @@
ServletWebRequest req = new
ServletWebRequest(httpServletRequest, filterPath);
ServletWebResponse resp = new
ServletWebResponse(httpServletResponse);
- RequestCycle requestCycle =
webApplication.newRequestCycle(req, resp);
+ RequestCycle requestCycle =
webApplication.createRequestCycle(req, resp);
if (requestCycle.processRequest())
{
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/handler/PageProvider.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/handler/PageProvider.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/handler/PageProvider.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/handler/PageProvider.java
Mon Apr 6 01:52:10 2009
@@ -1,5 +1,6 @@
package org.apache.wicket.request.handler;
+import org.apache.wicket.Application;
import org.apache.wicket.IPage;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
@@ -129,6 +130,7 @@
Check.argumentNotNull(page, "page");
this.pageInstance = page;
+ touchPageInstance();
}
/**
@@ -265,4 +267,9 @@
this.pageParameters = pageParameters;
}
+
+ private void touchPageInstance()
+ {
+
Application.get().getPageManager().touchPage(Application.get().getPageManagerContext(),
pageInstance);
+ }
}
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/ServletWebRequest.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/ServletWebRequest.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/ServletWebRequest.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/ServletWebRequest.java
Mon Apr 6 01:52:10 2009
@@ -23,6 +23,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -102,6 +103,12 @@
return httpServletRequest.getCookies();
}
+
+ @Override
+ public Locale getLocale()
+ {
+ return httpServletRequest.getLocale();
+ }
@Override
public long getDateHeader(String name)
{
Modified:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/WebRequest.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/WebRequest.java?rev=762196&r1=762195&r2=762196&view=diff
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/WebRequest.java
(original)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/request/request/WebRequest.java
Mon Apr 6 01:52:10 2009
@@ -18,6 +18,7 @@
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import javax.servlet.http.Cookie;
@@ -58,6 +59,12 @@
}
/**
+ * Returns locale for this request.
+ * @return locale
+ */
+ public abstract Locale getLocale();
+
+ /**
* Returns all the values of the specified request header.
*
* @param name
@@ -153,6 +160,12 @@
}
@Override
+ public Locale getLocale()
+ {
+ return WebRequest.this.getLocale();
+ }
+
+ @Override
public String getHeader(String name)
{
return WebRequest.this.getHeader(name);
Added:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/HttpSessionStore.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/HttpSessionStore.java?rev=762196&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/HttpSessionStore.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/HttpSessionStore.java
Mon Apr 6 01:52:10 2009
@@ -0,0 +1,346 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.session;
+
+import java.io.Serializable;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.Session;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.request.request.Request;
+import org.apache.wicket.request.request.ServletWebRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract implementation of {...@link ISessionStore} that works with web
applications and that
+ * provided some specific http servlet/ session related functionality.
+ *
+ * @author jcompagner
+ * @author Eelco Hillenius
+ * @author Matej Knopp
+ */
+public class HttpSessionStore implements SessionStore
+{
+
+ /**
+ * Reacts on unbinding from the session by cleaning up the session
related application data.
+ */
+ protected static final class SessionBindingListener implements
HttpSessionBindingListener, Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ /** The unique key of the application within this web
application. */
+ private final String applicationKey;
+
+ /** Session id. */
+ private final String sessionId;
+
+ /**
+ * Construct.
+ *
+ * @param applicationKey
+ * The unique key of the application within this web
application
+ * @param sessionId
+ * The session's id
+ */
+ public SessionBindingListener(String applicationKey, String
sessionId)
+ {
+ this.applicationKey = applicationKey;
+ this.sessionId = sessionId;
+ }
+
+ /**
+ * @see
javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
+ */
+ public void valueBound(HttpSessionBindingEvent evg)
+ {
+ }
+
+ /**
+ * @see
javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
+ */
+ public void valueUnbound(HttpSessionBindingEvent evt)
+ {
+ log.debug("Session unbound: " + sessionId);
+ Application application =
Application.get(applicationKey);
+ if (application != null)
+ {
+ application.sessionUnbound(sessionId);
+ }
+ }
+ }
+
+ /** Name of session attribute under which this session is stored */
+ public static final String SESSION_ATTRIBUTE_NAME = "session";
+
+ /** log. */
+ private static Logger log =
LoggerFactory.getLogger(HttpSessionStore.class);
+
+ /** The web application for this store. Is never null. */
+ protected final WebApplication application;
+
+ /**
+ * Construct.
+ *
+ * @param application
+ * The application to construct this store for
+ */
+ public HttpSessionStore(Application application)
+ {
+ if (application == null)
+ {
+ throw new IllegalArgumentException("the application
object must be provided");
+ }
+ // sanity check
+ if (!(application instanceof WebApplication))
+ {
+ throw new IllegalStateException(getClass().getName()
+ + " can only operate in the context of
web applications");
+ }
+ this.application = (WebApplication) application;
+ }
+
+ protected HttpServletRequest getHttpServletRequest(Request request)
+ {
+ if (request instanceof ServletWebRequest == false)
+ {
+ throw new IllegalArgumentException("Request must be
HttpServletRequest");
+ }
+ ServletWebRequest servletWebRequest = (ServletWebRequest)
request;
+ return servletWebRequest.getHttpServletRequest();
+ }
+
+ HttpSession getHttpSession(Request request, boolean create)
+ {
+ HttpServletRequest httpServletRequest =
getHttpServletRequest(request);
+ return httpServletRequest.getSession(create);
+ }
+
+ /**
+ * @see
org.apache.wicket.session.ISessionStore#bind(org.apache.wicket.Request,
+ * org.apache.wicket.Session)
+ */
+ public final void bind(Request request, Session newSession)
+ {
+ if (getAttribute(request, SESSION_ATTRIBUTE_NAME) != newSession)
+ {
+ // call template method
+ onBind(request, newSession);
+
+ HttpSession httpSession = getHttpSession(request,
false);
+
+ // register an unbinding listener for cleaning up
+ String applicationKey = application.getName();
+
httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey,
new SessionBindingListener(
+ applicationKey, httpSession.getId()));
+
+ // register the session object itself
+ setAttribute(request, SESSION_ATTRIBUTE_NAME,
newSession);
+
+ newSession.hasBeenBound();
+ }
+ }
+
+ /**
+ * @see org.apache.wicket.session.ISessionStore#destroy()
+ */
+ public void destroy()
+ {
+ // nop
+ }
+
+ /**
+ * @see
org.apache.wicket.session.ISessionStore#getSessionId(org.apache.wicket.Request,
boolean)
+ */
+ public final String getSessionId(Request request, boolean create)
+ {
+ String id = null;
+
+ HttpSession httpSession = getHttpSession(request, false);
+ if (httpSession != null)
+ {
+ id = httpSession.getId();
+ }
+ else if (create)
+ {
+ httpSession = getHttpSession(request, true);
+ id = httpSession.getId();
+ // TODO: RequestLogger
+ // IRequestLogger logger =
application.getRequestLogger();
+ // if (logger != null)
+ // {
+ // logger.sessionCreated(id);
+ // }
+ }
+ return id;
+ }
+
+ /**
+ * @see org.apache.wicket.session.ISessionStore#invalidate(Request)
+ */
+ public final void invalidate(Request request)
+ {
+ HttpSession httpSession = getHttpSession(request, false);
+ if (httpSession != null)
+ {
+ // tell the app server the session is no longer valid
+ httpSession.invalidate();
+ }
+ }
+
+ /**
+ * @see
org.apache.wicket.session.ISessionStore#lookup(org.apache.wicket.Request)
+ */
+ public Session lookup(Request request)
+ {
+ String sessionId = getSessionId(request, false);
+ if (sessionId != null)
+ {
+ return (Session) getAttribute(request,
SESSION_ATTRIBUTE_NAME);
+ }
+ return null;
+ }
+
+ /**
+ * Template method that is called when a session is being bound to the
session store. It is
+ * called <strong>before</strong> the session object itself is added to
this store (which is
+ * done by calling {...@link ISessionStore#setAttribute(Request,
String, Object)} with key
+ * {...@link Session#SESSION_ATTRIBUTE_NAME}.
+ *
+ * @param request
+ * The request
+ * @param newSession
+ * The new session
+ */
+ protected void onBind(Request request, Session newSession)
+ {
+ }
+
+ /**
+ * Template method that is called when the session is being detached
from the store, which
+ * typically happens when the httpsession was invalidated.
+ *
+ * @param sessionId
+ * The session id of the session that was invalidated.
+ */
+ protected void onUnbind(String sessionId)
+ {
+ }
+
+ /**
+ * Gets the prefix for storing variables in the actual session
(typically {...@link HttpSession}
+ * for this application instance.
+ *
+ * @param request
+ * the request
+ *
+ * @return the prefix for storing variables in the actual session
+ */
+ private String getSessionAttributePrefix(final Request request)
+ {
+ return "wicket";
+ // TODO:
+ // return application.getSessionAttributePrefix(request);
+ }
+
+
+ public Serializable getAttribute(Request request, String name)
+ {
+ HttpSession httpSession = getHttpSession(request, false);
+ if (httpSession != null)
+ {
+ return (Serializable)
httpSession.getAttribute(getSessionAttributePrefix(request) + name);
+ }
+ return null;
+ }
+
+ public Set<String> getAttributeNames(Request request)
+ {
+ Set<String> list = new HashSet<String>();
+ HttpSession httpSession = getHttpSession(request, false);
+ if (httpSession != null)
+ {
+ @SuppressWarnings("unchecked")
+ final Enumeration<String> names =
httpSession.getAttributeNames();
+ final String prefix =
getSessionAttributePrefix(request);
+ while (names.hasMoreElements())
+ {
+ final String name = names.nextElement();
+ if (name.startsWith(prefix))
+ {
+
list.add(name.substring(prefix.length()));
+ }
+ }
+ }
+ return list;
+ }
+
+ public void removeAttribute(Request request, String name)
+ {
+ HttpSession httpSession = getHttpSession(request, false);
+ if (httpSession != null)
+ {
+ String attributeName =
getSessionAttributePrefix(request) + name;
+ // TODO: Request Logger
+// IRequestLogger logger = application.getRequestLogger();
+// if (logger != null)
+// {
+// Object value =
httpSession.getAttribute(attributeName);
+// if (value != null)
+// {
+// logger.objectRemoved(value);
+// }
+// }
+ httpSession.removeAttribute(attributeName);
+ }
+ }
+
+ public void setAttribute(Request request, String name, Serializable
value)
+ {
+ // ignore call if the session was marked invalid
+ HttpSession httpSession = getHttpSession(request, false);
+ if (httpSession != null)
+ {
+ String attributeName =
getSessionAttributePrefix(request) + name;
+ // TODO: RequestLogger
+// IRequestLogger logger = application.getRequestLogger();
+// if (logger != null)
+// {
+// if (httpSession.getAttribute(attributeName) ==
null)
+// {
+// logger.objectCreated(value);
+// }
+// else
+// {
+// logger.objectUpdated(value);
+// }
+// }
+ httpSession.setAttribute(attributeName, value);
+ }
+ }
+
+
+}
\ No newline at end of file
Propchange:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/HttpSessionStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/SessionStore.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/SessionStore.java?rev=762196&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/SessionStore.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/SessionStore.java
Mon Apr 6 01:52:10 2009
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.session;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.servlet.http.HttpSession;
+
+import org.apache.wicket.Session;
+import org.apache.wicket.request.request.Request;
+
+
+/**
+ * The actual store that is used by {...@link org.apache.wicket.Session} to
store its attributes.
+ *
+ * @author Eelco Hillenius
+ * @author Johan Compagner
+ */
+public interface SessionStore
+{
+ /**
+ * Gets the attribute value with the given name
+ *
+ * @param request
+ * the current request
+ * @param name
+ * The name of the attribute to store
+ * @return The value of the attribute
+ */
+ Serializable getAttribute(Request request, final String name);
+
+ /**
+ * @param request
+ * the current request
+ *
+ * @return List of attributes for this session
+ */
+ Set<String> getAttributeNames(Request request);
+
+ /**
+ * Adds or replaces the attribute with the given name and value.
+ *
+ * @param request
+ * the current request
+ * @param name
+ * the name of the attribute
+ * @param value
+ * the value of the attribute
+ */
+ void setAttribute(Request request, String name, Serializable value);
+
+ /**
+ * Removes the attribute with the given name.
+ *
+ * @param request
+ * the current request
+ * @param name
+ * the name of the attribute to remove
+ */
+ void removeAttribute(Request request, String name);
+
+ /**
+ * Invalidates the session.
+ *
+ * @param request
+ * the current request
+ */
+ void invalidate(Request request);
+
+ /**
+ * Get the session id for the provided request. If create is false and
the creation of the
+ * actual session is deferred, this method should return null to
reflect it doesn't have one.
+ *
+ * @param request
+ * The request
+ * @param create
+ * Whether to create an actual session (typically an
instance of {...@link HttpSession})
+ * when not already done so
+ * @return The session id for the provided request, possibly null if
create is false and the
+ * creation of the actual session was deferred
+ */
+ String getSessionId(Request request, boolean create);
+
+ /**
+ * Retrieves the session for the provided request from this facade.
+ * <p>
+ * This method should return null if it is not bound yet, so that
Wicket can recognize that it
+ * should create a session and call {...@link #bind(Request, Session)}
right after that.
+ * </p>
+ *
+ * @param request
+ * The current request
+ * @return The session for the provided request or null if the session
was not bound
+ */
+ Session lookup(Request request);
+
+ /**
+ * Adds the provided new session to this facade using the provided
request.
+ *
+ * @param request
+ * The request that triggered making a new session
+ * @param newSession
+ * The new session
+ */
+ void bind(Request request, Session newSession);
+
+ /**
+ * Called when the WebApplication is destroyed.
+ */
+ void destroy();
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket-ng/src/main/java/org/apache/wicket/session/SessionStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain