You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/10/11 15:52:12 UTC
svn commit: r824074 [2/3] - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/ng/
main/java/org/apache/wicket/ng/markup/html/form/
main/java/org/apache/wicket/ng/markup/html/link/
main/java/org/apache/wicket/ng/mock/ main/java/org/apache/wicket/...
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/DefaultPageStore.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/DefaultPageStore.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/DefaultPageStore.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/DefaultPageStore.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.page.persistent;
import java.io.Serializable;
@@ -16,17 +32,17 @@
private final String applicationName;
private final SerializedPagesCache serializedPagesCache;
-
+
private final DataStore pageDataStore;
public DefaultPageStore(String applicationName, DataStore dataStore, int cacheSize)
{
Checks.argumentNotNull(applicationName, "applicationName");
Checks.argumentNotNull(dataStore, "DataStore");
-
+
this.applicationName = applicationName;
- this.pageDataStore = dataStore;
- this.serializedPagesCache = new SerializedPagesCache(cacheSize);
+ pageDataStore = dataStore;
+ serializedPagesCache = new SerializedPagesCache(cacheSize);
}
public void destroy()
@@ -107,7 +123,7 @@
}
else if (object instanceof SerializedPage)
{
- SerializedPage page = (SerializedPage) object;
+ SerializedPage page = (SerializedPage)object;
byte data[] = page.getData();
if (data == null)
{
@@ -129,17 +145,19 @@
else
{
String type = object != null ? object.getClass().getName() : null;
- throw new IllegalArgumentException("Unknown object type " + type);
+ throw new IllegalArgumentException("Unknown object type " + type);
}
}
private SerializedPage restoreStrippedSerializedPage(SerializedPage serializedPage)
{
- SerializedPage result = serializedPagesCache.getPage(serializedPage.getSessionId(), serializedPage.getPageId());
+ SerializedPage result = serializedPagesCache.getPage(serializedPage.getSessionId(),
+ serializedPage.getPageId());
if (result == null)
{
byte data[] = getPageData(serializedPage.getSessionId(), serializedPage.getPageId());
- return new SerializedPage(serializedPage.getSessionId(), serializedPage.getPageId(), data);
+ return new SerializedPage(serializedPage.getSessionId(), serializedPage.getPageId(),
+ data);
}
else
{
@@ -153,12 +171,12 @@
{
return null;
}
-
+
SerializedPage result = null;
-
+
if (object instanceof ManageablePage)
{
- ManageablePage page = (ManageablePage) object;
+ ManageablePage page = (ManageablePage)object;
result = serializedPagesCache.getPage(sessionId, page.getPageId());
if (result == null)
{
@@ -168,7 +186,7 @@
}
else if (object instanceof SerializedPage)
{
- SerializedPage page = (SerializedPage) object;
+ SerializedPage page = (SerializedPage)object;
if (page.getData() == null)
{
result = restoreStrippedSerializedPage(page);
@@ -178,17 +196,17 @@
result = page;
}
}
-
+
if (result != null)
{
return result;
}
else
{
- return (Serializable) object;
+ return (Serializable)object;
}
}
-
+
protected boolean storeAfterSessionReplication()
{
return true;
@@ -266,8 +284,9 @@
{
return false;
}
- SerializedPage rhs = (SerializedPage) obj;
- return Objects.equal(getPageId(), rhs.getPageId()) && Objects.equal(getSessionId(), rhs.getSessionId());
+ SerializedPage rhs = (SerializedPage)obj;
+ return Objects.equal(getPageId(), rhs.getPageId()) &&
+ Objects.equal(getSessionId(), rhs.getSessionId());
}
@Override
@@ -288,7 +307,7 @@
protected ManageablePage deserializePage(byte data[])
{
- return (ManageablePage) Objects.byteArrayToObject(data);
+ return (ManageablePage)Objects.byteArrayToObject(data);
}
/**
@@ -319,7 +338,7 @@
private final List<SoftReference<SerializedPage>> cache;
public SerializedPage removePage(String sessionId, int id)
- {
+ {
Checks.argumentNotNull(sessionId, "sessionId");
if (size > 0)
@@ -330,7 +349,8 @@
{
SoftReference<SerializedPage> ref = i.next();
SerializedPage entry = ref.get();
- if (entry != null && entry.getPageId() == id && entry.getSessionId().equals(sessionId))
+ if (entry != null && entry.getPageId() == id &&
+ entry.getSessionId().equals(sessionId))
{
i.remove();
return entry;
@@ -342,7 +362,7 @@
}
public void removePages(String sessionId)
- {
+ {
Checks.argumentNotNull(sessionId, "sessionId");
if (size > 0)
@@ -375,7 +395,8 @@
{
SoftReference<SerializedPage> ref = i.next();
SerializedPage entry = ref.get();
- if (entry != null && entry.getPageId() == id && entry.getSessionId().equals(sessionId))
+ if (entry != null && entry.getPageId() == id &&
+ entry.getSessionId().equals(sessionId))
{
i.remove();
result = entry;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PageStore.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PageStore.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PageStore.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PageStore.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.page.persistent;
import java.io.Serializable;
@@ -31,8 +47,8 @@
void removePage(String sessionId, int id);
/**
- * Stores the page to a persistent layer. The page should be stored under the id and the
- * version number.
+ * Stores the page to a persistent layer. The page should be stored under the id and the version
+ * number.
*
* @param sessionId
* @param page
@@ -45,17 +61,17 @@
* @param sessionId
*/
void unbind(String sessionId);
-
+
/*
* Some PageStores might want to preprocess page before serialization. For example if the
* PageStore serializes page, it might cache the serialized data after the request. So when the
* pagemap gets serialized (for session replication) in the request thread, the pagestore can
* provide the already serialized data.
*/
-
+
/**
- * Process the page before the it gets serialized. The page can be either real page instance
- * or object returned by {@link #restoreAfterSerialization(Serializable)}.
+ * Process the page before the it gets serialized. The page can be either real page instance or
+ * object returned by {@link #restoreAfterSerialization(Serializable)}.
*
* @param sessionId
* @param page
@@ -64,8 +80,8 @@
public Serializable prepareForSerialization(String sessionId, Object page);
/**
- * This method should restore the serialized page to intermediate object that can be
- * converted to real page instance using {@link #convertToPage(Object)}.
+ * This method should restore the serialized page to intermediate object that can be converted
+ * to real page instance using {@link #convertToPage(Object)}.
*
* @param sessionId
* @param serializable
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PersistentPageManager.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PersistentPageManager.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PersistentPageManager.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/PersistentPageManager.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.page.persistent;
import java.io.IOException;
@@ -14,248 +30,249 @@
public class PersistentPageManager extends AbstractPageManager
{
- private final PageStore pageStore;
- private final String applicationName;
+ 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>();
-
- /**
- * Represents entry for single session. This is stored as session attribute and caches pages
- * between requests.
- *
- * @author Matej Knopp
- */
- 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;
- }
-
- /**
- * Add the page to cached pages if page with same id is not already there
- *
- * @param page
- */
- private void addPage(ManageablePage page)
- {
- if (page != null)
- {
- for (ManageablePage p : pages)
- {
- if (p.getPageId() == page.getPageId())
- {
- return;
- }
- }
- }
- pages.add(page);
- }
-
- /**
- * If the pages are stored in temporary state (after deserialization) this method convert
- * them to list of "real" pages
- */
- private void convertAfterReadObjects()
- {
- if (pages == null)
- {
- pages = new ArrayList<ManageablePage>();
- }
-
- for (Object o : afterReadObject)
- {
- ManageablePage page = getPageStore().convertToPage(o);
- addPage(page);
- }
-
- afterReadObject = null;
- }
-
- public synchronized ManageablePage getPage(int id)
- {
- // check if pages are in deserialized state
- if (afterReadObject != null && afterReadObject.isEmpty() == false)
- {
- convertAfterReadObjects();
- }
-
- // try to find page with same id
- if (pages != null)
- {
- for (ManageablePage page : pages)
- {
- if (page.getPageId() == id)
- {
- return page;
- }
- }
- }
-
- // not found, ask pagestore for the page
- return getPageStore().getPage(sessionId, id);
- }
-
- // set the list of pages to remember after the request
- public synchronized void setPages(List<ManageablePage> pages)
- {
- this.pages = new ArrayList<ManageablePage>(pages);
- afterReadObject = null;
- }
-
- private transient List<ManageablePage> pages;
- private transient List<Object> afterReadObject;
-
- private void writeObject(java.io.ObjectOutputStream s) throws IOException
- {
- s.defaultWriteObject();
-
- // prepare for serialization and store the pages
- List<Serializable> l = new ArrayList<Serializable>();
- for (ManageablePage 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();
-
- // convert to temporary state after deserialization (will need to be processed
- // by convertAfterReadObject before the pages can be accessed)
- for (Serializable ser : l)
- {
- afterReadObject.add(getPageStore().restoreAfterSerialization(ser));
- }
-
- afterReadObject = new ArrayList<Object>();
- }
- };
-
- /**
- * {@link RequestAdapter} for {@link PersistentPageManager}
- *
- * @author Matej Knopp
- */
- protected class PersitentRequestAdapter extends RequestAdapter
- {
- public PersitentRequestAdapter(PageManagerContext context)
- {
- super(context);
- }
-
- @Override
- protected ManageablePage getPage(int id)
- {
- // try to get session entry for this session
- SessionEntry entry = getSessionEntry(false);
-
- if (entry != null)
- {
- return entry.getPage(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()
- {
- // if the session is not temporary bind a session entry to it
- if (getSessionId() != null)
- {
- getSessionEntry(true);
- }
- }
-
- @Override
- protected void storeTouchedPages(List<ManageablePage> touchedPages)
- {
- if (!touchedPages.isEmpty())
- {
- SessionEntry entry = getSessionEntry(true);
- entry.setPages(touchedPages);
- for (ManageablePage page : touchedPages)
- {
- pageStore.storePage(getSessionId(), page);
- }
- }
- }
- };
-
- @Override
- protected RequestAdapter newRequestAdapter(PageManagerContext context)
- {
- return new PersitentRequestAdapter(context);
- }
-
- @Override
- public boolean supportsVersioning()
- {
- return true;
- }
-
- public void sessionExpired(String sessionId)
- {
- pageStore.unbind(sessionId);
- }
-
- public void destroy()
- {
- managers.remove(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>();
+
+ /**
+ * Represents entry for single session. This is stored as session attribute and caches pages
+ * between requests.
+ *
+ * @author Matej Knopp
+ */
+ 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;
+ }
+
+ /**
+ * Add the page to cached pages if page with same id is not already there
+ *
+ * @param page
+ */
+ private void addPage(ManageablePage page)
+ {
+ if (page != null)
+ {
+ for (ManageablePage p : pages)
+ {
+ if (p.getPageId() == page.getPageId())
+ {
+ return;
+ }
+ }
+ }
+ pages.add(page);
+ }
+
+ /**
+ * If the pages are stored in temporary state (after deserialization) this method convert
+ * them to list of "real" pages
+ */
+ private void convertAfterReadObjects()
+ {
+ if (pages == null)
+ {
+ pages = new ArrayList<ManageablePage>();
+ }
+
+ for (Object o : afterReadObject)
+ {
+ ManageablePage page = getPageStore().convertToPage(o);
+ addPage(page);
+ }
+
+ afterReadObject = null;
+ }
+
+ public synchronized ManageablePage getPage(int id)
+ {
+ // check if pages are in deserialized state
+ if (afterReadObject != null && afterReadObject.isEmpty() == false)
+ {
+ convertAfterReadObjects();
+ }
+
+ // try to find page with same id
+ if (pages != null)
+ {
+ for (ManageablePage page : pages)
+ {
+ if (page.getPageId() == id)
+ {
+ return page;
+ }
+ }
+ }
+
+ // not found, ask pagestore for the page
+ return getPageStore().getPage(sessionId, id);
+ }
+
+ // set the list of pages to remember after the request
+ public synchronized void setPages(List<ManageablePage> pages)
+ {
+ this.pages = new ArrayList<ManageablePage>(pages);
+ afterReadObject = null;
+ }
+
+ private transient List<ManageablePage> pages;
+ private transient List<Object> afterReadObject;
+
+ private void writeObject(java.io.ObjectOutputStream s) throws IOException
+ {
+ s.defaultWriteObject();
+
+ // prepare for serialization and store the pages
+ List<Serializable> l = new ArrayList<Serializable>();
+ for (ManageablePage 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();
+
+ // convert to temporary state after deserialization (will need to be processed
+ // by convertAfterReadObject before the pages can be accessed)
+ for (Serializable ser : l)
+ {
+ afterReadObject.add(getPageStore().restoreAfterSerialization(ser));
+ }
+
+ afterReadObject = new ArrayList<Object>();
+ }
+ };
+
+ /**
+ * {@link RequestAdapter} for {@link PersistentPageManager}
+ *
+ * @author Matej Knopp
+ */
+ protected class PersitentRequestAdapter extends RequestAdapter
+ {
+ public PersitentRequestAdapter(PageManagerContext context)
+ {
+ super(context);
+ }
+
+ @Override
+ protected ManageablePage getPage(int id)
+ {
+ // try to get session entry for this session
+ SessionEntry entry = getSessionEntry(false);
+
+ if (entry != null)
+ {
+ return entry.getPage(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()
+ {
+ // if the session is not temporary bind a session entry to it
+ if (getSessionId() != null)
+ {
+ getSessionEntry(true);
+ }
+ }
+
+ @Override
+ protected void storeTouchedPages(List<ManageablePage> touchedPages)
+ {
+ if (!touchedPages.isEmpty())
+ {
+ SessionEntry entry = getSessionEntry(true);
+ entry.setPages(touchedPages);
+ for (ManageablePage page : touchedPages)
+ {
+ pageStore.storePage(getSessionId(), page);
+ }
+ }
+ }
+ };
+
+ @Override
+ protected RequestAdapter newRequestAdapter(PageManagerContext context)
+ {
+ return new PersitentRequestAdapter(context);
+ }
+
+ @Override
+ public boolean supportsVersioning()
+ {
+ return true;
+ }
+
+ @Override
+ public void sessionExpired(String sessionId)
+ {
+ pageStore.unbind(sessionId);
+ }
+
+ public void destroy()
+ {
+ managers.remove(applicationName);
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/disk/DiskDataStore.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/disk/DiskDataStore.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/disk/DiskDataStore.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/page/persistent/disk/DiskDataStore.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.page.persistent.disk;
import java.io.File;
@@ -35,20 +51,21 @@
private final ConcurrentMap<String, SessionEntry> sessionEntryMap = new ConcurrentHashMap<String, SessionEntry>();
public DiskDataStore(String applicationName, File fileStoreFolder, int maxSizePerSession,
- int fileChannelPoolCapacity)
+ int fileChannelPoolCapacity)
{
this.applicationName = applicationName;
this.fileStoreFolder = fileStoreFolder;
- this.maxSizePerPageSession = maxSizePerSession;
- this.fileChannelPool = new FileChannelPool(fileChannelPoolCapacity);
-
- this.fileStoreFolder.mkdirs();
+ maxSizePerPageSession = maxSizePerSession;
+ fileChannelPool = new FileChannelPool(fileChannelPoolCapacity);
+
+ this.fileStoreFolder.mkdirs();
loadIndex();
}
public DiskDataStore(String applicationName, int maxSizePerSession, int fileChannelPoolCapacity)
{
- this(applicationName, getDefaultFileStoreFolder(), maxSizePerSession, fileChannelPoolCapacity);
+ this(applicationName, getDefaultFileStoreFolder(), maxSizePerSession,
+ fileChannelPoolCapacity);
}
public void destroy()
@@ -66,8 +83,8 @@
}
else
{
- return null;
- }
+ return null;
+ }
}
public boolean isReplicated()
@@ -92,8 +109,8 @@
synchronized (sessionEntry)
{
sessionEntryMap.remove(sessionEntry.sessionId);
- sessionEntry.unbind();
- }
+ sessionEntry.unbind();
+ }
}
}
@@ -105,7 +122,7 @@
sessionEntry.savePage(id, data);
}
}
-
+
private SessionEntry getSessionEntry(String sessionId, boolean create)
{
if (!create)
@@ -121,7 +138,7 @@
}
private static final String INDEX_FILE_NAME = "DiskDataStoreIndex";
-
+
@SuppressWarnings("unchecked")
private void loadIndex()
{
@@ -136,7 +153,7 @@
Map<String, SessionEntry> map = (Map<String, SessionEntry>)ois.readObject();
sessionEntryMap.clear();
sessionEntryMap.putAll(map);
-
+
for (Iterator<Entry<String, SessionEntry>> entries = sessionEntryMap.entrySet()
.iterator(); entries.hasNext();)
{
@@ -154,7 +171,7 @@
}
index.delete();
}
-
+
private void saveIndex()
{
File storeFolder = getStoreFolder();
@@ -166,7 +183,8 @@
{
OutputStream stream = new FileOutputStream(index);
ObjectOutputStream oos = new ObjectOutputStream(stream);
- Map<String, SessionEntry> map = new HashMap<String, SessionEntry>(sessionEntryMap.size());
+ Map<String, SessionEntry> map = new HashMap<String, SessionEntry>(
+ sessionEntryMap.size());
for (Entry<String, SessionEntry> e : sessionEntryMap.entrySet())
{
if (e.getValue().unbound == false)
@@ -184,7 +202,7 @@
}
}
-
+
protected static class SessionEntry implements Serializable
{
private static final long serialVersionUID = 1L;
@@ -197,28 +215,30 @@
protected SessionEntry(DiskDataStore diskDataStore, String sessionId)
{
- this.diskDataStore = diskDataStore;
+ this.diskDataStore = diskDataStore;
this.sessionId = sessionId;
}
-
+
private PageWindowManager getManager()
{
if (manager == null)
{
- manager = new PageWindowManager(diskDataStore.maxSizePerPageSession);;
+ manager = new PageWindowManager(diskDataStore.maxSizePerPageSession);
+ ;
}
return manager;
}
-
+
private String getFileName()
{
if (fileName == null)
{
- fileName = diskDataStore.getSessionFileName(sessionId, true);;
+ fileName = diskDataStore.getSessionFileName(sessionId, true);
+ ;
}
return fileName;
}
-
+
/**
* @return session id
*/
@@ -245,7 +265,8 @@
PageWindow window = getManager().createPageWindow(pageId, data.length);
// take the filechannel from the pool
- FileChannel channel = diskDataStore.fileChannelPool.getFileChannel(getFileName(), true);
+ FileChannel channel = diskDataStore.fileChannelPool.getFileChannel(getFileName(),
+ true);
try
{
// write the content
@@ -286,7 +307,7 @@
* @return serialized page data
*/
public byte[] loadPage(PageWindow window)
- {
+ {
byte[] result = null;
FileChannel channel = diskDataStore.fileChannelPool.getFileChannel(getFileName(), false);
if (channel != null)
@@ -311,7 +332,7 @@
}
return result;
}
-
+
/**
* Loads the specified page data.
*
@@ -333,7 +354,7 @@
}
return result;
}
-
+
/**
* Deletes all files for this session.
*/
@@ -370,8 +391,8 @@
if (Application.exists())
{
- dir = (File) ((WebApplication) Application.get()).getServletContext().getAttribute(
- "javax.servlet.context.tempdir");
+ dir = (File)((WebApplication)Application.get()).getServletContext().getAttribute(
+ "javax.servlet.context.tempdir");
}
if (dir != null)
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/CompoundRequestMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/CompoundRequestMapper.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/CompoundRequestMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/CompoundRequestMapper.java Sun Oct 11 13:52:09 2009
@@ -1,21 +1,37 @@
+/*
+ * 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.ng.request;
public interface CompoundRequestMapper extends RequestMapper
{
- /**
- * Registers a {@link RequestMapper}
- *
- * @param encoder
- */
- void register(RequestMapper encoder);
+ /**
+ * Registers a {@link RequestMapper}
+ *
+ * @param encoder
+ */
+ void register(RequestMapper encoder);
- /**
- * Unregisters {@link RequestMapper}
- *
- * @param encoder
- */
- void unregister(RequestMapper encoder);
+ /**
+ * Unregisters {@link RequestMapper}
+ *
+ * @param encoder
+ */
+ void unregister(RequestMapper encoder);
}
\ No newline at end of file
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/component/PageParameters.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/component/PageParameters.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/component/PageParameters.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/component/PageParameters.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.component;
import java.io.Serializable;
@@ -45,10 +61,10 @@
Checks.argumentNotNull(copy, "copy");
if (copy.indexedParameters != null)
- this.indexedParameters = new ArrayList<String>(copy.indexedParameters);
+ indexedParameters = new ArrayList<String>(copy.indexedParameters);
if (copy.namedParameters != null)
- this.namedParameters = new ArrayList<Entry>(copy.namedParameters);
+ namedParameters = new ArrayList<Entry>(copy.namedParameters);
}
private List<String> indexedParameters = null;
@@ -200,7 +216,7 @@
public void removeNamedParameter(String name)
{
Checks.argumentNotNull(name, "name");
-
+
if (namedParameters != null)
{
for (Iterator<Entry> i = namedParameters.iterator(); i.hasNext();)
@@ -226,8 +242,8 @@
}
/**
- * Adds named parameter to a specified position. The {@link RequestMapper}s may or may
- * not take the order into account.
+ * Adds named parameter to a specified position. The {@link RequestMapper}s may or may not take
+ * the order into account.
*
* @param name
* @param value
@@ -251,8 +267,8 @@
}
/**
- * Sets the named parameter on specified position. The {@link RequestMapper}s may or
- * may not take the order into account.
+ * Sets the named parameter on specified position. The {@link RequestMapper}s may or may not
+ * take the order into account.
*
* @param name
* @param value
@@ -284,7 +300,7 @@
*/
public void clearIndexedParameters()
{
- this.indexedParameters = null;
+ indexedParameters = null;
}
/**
@@ -292,7 +308,7 @@
*/
public void clearNamedParameters()
{
- this.namedParameters = null;
+ namedParameters = null;
}
/**
@@ -304,8 +320,8 @@
{
if (this != other)
{
- this.indexedParameters = other.indexedParameters;
- this.namedParameters = other.namedParameters;
+ indexedParameters = other.indexedParameters;
+ namedParameters = other.namedParameters;
}
}
@@ -383,7 +399,7 @@
}
return false;
}
-
+
public boolean isEmpty()
{
return getIndexedParamsCount() == 0 && getNamedParameterKeys().isEmpty();
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/ExceptionMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/ExceptionMapper.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/ExceptionMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/ExceptionMapper.java Sun Oct 11 13:52:09 2009
@@ -1,8 +1,24 @@
+/*
+ * 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.ng.request.cycle;
import org.apache.wicket.ng.request.RequestHandler;
public interface ExceptionMapper
{
- RequestHandler map(Exception e);
+ RequestHandler map(Exception e);
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/RequestCycleContext.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/RequestCycleContext.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/RequestCycleContext.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/cycle/RequestCycleContext.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.cycle;
import org.apache.wicket.ng.request.Request;
@@ -17,61 +33,61 @@
*/
public final class RequestCycleContext
{
- private Request request;
- private Response response;
- private RequestMapper requestMapper;
- private ExceptionMapper exceptionMapper;
-
- public RequestCycleContext(Request request, Response response, RequestMapper requestMapper,
- ExceptionMapper exceptionMapper)
- {
- this.request = request;
- this.response = response;
- this.requestMapper = requestMapper;
- this.exceptionMapper = exceptionMapper;
- }
-
- public Request getRequest()
- {
- return request;
- }
-
- public Response getResponse()
- {
- return response;
- }
-
-
- public RequestMapper getRequestMapper()
- {
- return requestMapper;
- }
-
-
- public ExceptionMapper getExceptionMapper()
- {
- return exceptionMapper;
- }
-
- public void setRequest(Request request)
- {
- this.request = request;
- }
-
- public void setResponse(Response response)
- {
- this.response = response;
- }
-
- public void setRequestMapper(RequestMapper requestMapper)
- {
- this.requestMapper = requestMapper;
- }
-
- public void setExceptionMapper(ExceptionMapper exceptionMapper)
- {
- this.exceptionMapper = exceptionMapper;
- }
+ private Request request;
+ private Response response;
+ private RequestMapper requestMapper;
+ private ExceptionMapper exceptionMapper;
+
+ public RequestCycleContext(Request request, Response response, RequestMapper requestMapper,
+ ExceptionMapper exceptionMapper)
+ {
+ this.request = request;
+ this.response = response;
+ this.requestMapper = requestMapper;
+ this.exceptionMapper = exceptionMapper;
+ }
+
+ public Request getRequest()
+ {
+ return request;
+ }
+
+ public Response getResponse()
+ {
+ return response;
+ }
+
+
+ public RequestMapper getRequestMapper()
+ {
+ return requestMapper;
+ }
+
+
+ public ExceptionMapper getExceptionMapper()
+ {
+ return exceptionMapper;
+ }
+
+ public void setRequest(Request request)
+ {
+ this.request = request;
+ }
+
+ public void setResponse(Response response)
+ {
+ this.response = response;
+ }
+
+ public void setRequestMapper(RequestMapper requestMapper)
+ {
+ this.requestMapper = requestMapper;
+ }
+
+ public void setExceptionMapper(ExceptionMapper exceptionMapper)
+ {
+ this.exceptionMapper = exceptionMapper;
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFindException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFindException.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFindException.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFindException.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler;
import org.apache.wicket.ng.WicketRuntimeException;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFoundException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFoundException.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFoundException.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/ComponentNotFoundException.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler;
import org.apache.wicket.ng.WicketRuntimeException;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageAndComponentProvider.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageAndComponentProvider.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageAndComponentProvider.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageAndComponentProvider.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler;
import org.apache.wicket.ng.request.component.PageParameters;
@@ -38,10 +54,10 @@
*/
public PageAndComponentProvider(RequestablePage page, RequestableComponent component)
{
- super(page);
-
+ super(page);
+
Checks.argumentNotNull(component, "component");
-
+
this.component = component;
}
@@ -53,7 +69,7 @@
* @param componentPath
*/
public PageAndComponentProvider(Class<? extends RequestablePage> pageClass,
- PageParameters pageParameters, String componentPath)
+ PageParameters pageParameters, String componentPath)
{
super(pageClass, pageParameters);
setComponentPath(componentPath);
@@ -80,7 +96,7 @@
* @param componentPath
*/
public PageAndComponentProvider(int pageId, Class<? extends RequestablePage> pageClass,
- Integer renderCount, String componentPath)
+ Integer renderCount, String componentPath)
{
super(pageId, pageClass, renderCount);
setComponentPath(componentPath);
@@ -96,7 +112,7 @@
* @param componentPath
*/
public PageAndComponentProvider(int pageId, Class<? extends RequestablePage> pageClass,
- PageParameters pageParameters, Integer renderCount, String componentPath)
+ PageParameters pageParameters, Integer renderCount, String componentPath)
{
super(pageId, pageClass, pageParameters, renderCount);
setComponentPath(componentPath);
@@ -135,8 +151,8 @@
}
if (component == null)
{
- throw new ComponentNotFoundException("Could not find component '" + componentPath + "' on page '"
- + getPageClass());
+ throw new ComponentNotFoundException("Could not find component '" + componentPath +
+ "' on page '" + getPageClass());
}
return component;
}
@@ -161,7 +177,7 @@
private void setComponentPath(String componentPath)
{
Checks.argumentNotNull(componentPath, "componentPath");
-
+
this.componentPath = componentPath;
}
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageProvider.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageProvider.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageProvider.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/PageProvider.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler;
import org.apache.wicket.ng.Application;
@@ -18,14 +34,14 @@
* until {@link #getPageInstance()} is called.
* <p>
* Purpose of this class is to reduce complexity of both {@link RequestMapper}s and
- * {@link RequestHandler}s. {@link RequestMapper} examines the URL, gathers all relevant
- * information about the page in the URL (combination of page id, page class, page parameters and
- * render count), creates {@link PageProvider} object and creates a {@link RequestHandler} instance
- * that can use the {@link PageProvider} to access the page.
+ * {@link RequestHandler}s. {@link RequestMapper} examines the URL, gathers all relevant information
+ * about the page in the URL (combination of page id, page class, page parameters and render count),
+ * creates {@link PageProvider} object and creates a {@link RequestHandler} instance that can use
+ * the {@link PageProvider} to access the page.
* <p>
- * Apart from simplifying {@link RequestMapper}s and {@link RequestHandler}s
- * {@link PageProvider} also helps performance because creating or obtaining page from
- * {@link PageManager} is delayed until the {@link RequestHandler} actually requires the page.
+ * Apart from simplifying {@link RequestMapper}s and {@link RequestHandler}s {@link PageProvider}
+ * also helps performance because creating or obtaining page from {@link PageManager} is delayed
+ * until the {@link RequestHandler} actually requires the page.
*
* @author Matej Knopp
*/
@@ -78,7 +94,8 @@
* @param renderCount
* optional argument
*/
- public PageProvider(int pageId, Class<? extends RequestablePage> pageClass, PageParameters pageParameters, Integer renderCount)
+ public PageProvider(int pageId, Class<? extends RequestablePage> pageClass,
+ PageParameters pageParameters, Integer renderCount)
{
this.pageId = pageId;
setPageClass(pageClass);
@@ -120,7 +137,7 @@
{
Checks.argumentNotNull(page, "page");
- this.pageInstance = page;
+ pageInstance = page;
}
/**
@@ -199,12 +216,13 @@
else
{
throw new IllegalStateException(
- "No application is bound to current thread. Call setPageSource() to manually assign pageSource to this provider.");
+ "No application is bound to current thread. Call setPageSource() to manually assign pageSource to this provider.");
}
}
- private RequestablePage getPageInstance(Integer pageId, Class<? extends RequestablePage> pageClass, PageParameters pageParameters,
- Integer renderCount)
+ private RequestablePage getPageInstance(Integer pageId,
+ Class<? extends RequestablePage> pageClass, PageParameters pageParameters,
+ Integer renderCount)
{
RequestablePage page = null;
@@ -230,7 +248,7 @@
freshCreated = true;
if (prepareForRenderNewPage() && page instanceof Page)
{
- ((Page) page).prepareForRender(false);
+ ((Page)page).prepareForRender(false);
}
}
}
@@ -247,8 +265,9 @@
}
/**
- * Detaches the page if it has been loaded (that means either {@link #PageProvider(RequestablePage)}
- * constructor has been used or {@link #getPageInstance()} has been called).
+ * Detaches the page if it has been loaded (that means either
+ * {@link #PageProvider(RequestablePage)} constructor has been used or
+ * {@link #getPageInstance()} has been called).
*/
public void detach()
{
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/BufferedResponseRequestHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/BufferedResponseRequestHandler.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/BufferedResponseRequestHandler.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/BufferedResponseRequestHandler.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler.impl;
import org.apache.wicket.ng.request.RequestHandler;
@@ -8,12 +24,12 @@
public class BufferedResponseRequestHandler implements RequestHandler
{
private final BufferedWebResponse bufferedWebResponse;
-
+
public BufferedResponseRequestHandler(BufferedWebResponse bufferedWebResponse)
{
this.bufferedWebResponse = bufferedWebResponse;
}
-
+
public void detach(RequestCycle requestCycle)
{
@@ -21,7 +37,7 @@
public void respond(RequestCycle requestCycle)
{
- bufferedWebResponse.writeTo((WebResponse) requestCycle.getResponse());
+ bufferedWebResponse.writeTo((WebResponse)requestCycle.getResponse());
}
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/RenderPageRequestHandlerDelegate.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/RenderPageRequestHandlerDelegate.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/RenderPageRequestHandlerDelegate.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/RenderPageRequestHandlerDelegate.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler.impl.render;
import org.apache.wicket.ng.request.cycle.RequestCycle;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/WebRenderPageRequestHandlerDelegate.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/WebRenderPageRequestHandlerDelegate.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/WebRenderPageRequestHandlerDelegate.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/handler/impl/render/WebRenderPageRequestHandlerDelegate.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.handler.impl.render;
import org.apache.wicket.ng.Application;
@@ -110,21 +126,22 @@
private void redirectTo(Url url, RequestCycle requestCycle)
{
- WebResponse response = (WebResponse) requestCycle.getResponse();
+ WebResponse response = (WebResponse)requestCycle.getResponse();
String relativeUrl = requestCycle.getUrlRenderer().renderUrl(url);
response.sendRedirect(relativeUrl);
}
+ @Override
public void respond(RequestCycle requestCycle)
{
Url currentUrl = requestCycle.getRequest().getUrl();
Url targetUrl = requestCycle.urlFor(getRenderPageRequestHandler());
//
- // the code below is little hairy but we have to handle 3 redirect policies
+ // the code below is little hairy but we have to handle 3 redirect policies
// and 3 rendering strategies
//
-
+
// try to get an already rendered buffered response for current URL
BufferedWebResponse bufferedResponse = getAndRemoveBufferedResponse(currentUrl);
@@ -132,11 +149,14 @@
{
logger.warn("The Buffered response should be handled by BufferedResponseRequestHandler");
// if there is saved response for this URL render it
- bufferedResponse.writeTo((WebResponse) requestCycle.getResponse());
+ bufferedResponse.writeTo((WebResponse)requestCycle.getResponse());
}
- else if (getRedirectPolicy() == RedirectPolicy.NEVER_REDIRECT || isOnePassRender() //
- || (targetUrl.equals(currentUrl) && !getPage().isPageStateless()) //
- || (targetUrl.equals(currentUrl) && isRedirectToRender() && getPage().isPageStateless()))
+ else if (getRedirectPolicy() == RedirectPolicy.NEVER_REDIRECT ||
+ isOnePassRender() //
+ ||
+ (targetUrl.equals(currentUrl) && !getPage().isPageStateless()) //
+ ||
+ (targetUrl.equals(currentUrl) && isRedirectToRender() && getPage().isPageStateless()))
{
// if the policy is never to redirect
// or one pass render mode is on
@@ -146,22 +166,29 @@
renderPage();
}
else if (!targetUrl.equals(currentUrl) //
- && (getRedirectPolicy() == RedirectPolicy.ALWAYS_REDIRECT || isRedirectToRender()))
+ &&
+ (getRedirectPolicy() == RedirectPolicy.ALWAYS_REDIRECT || isRedirectToRender()))
{
// if target URL is different
// and render policy is always-redirect or it's redirect-to-render
redirectTo(targetUrl, requestCycle);
}
else if (!targetUrl.equals(currentUrl) //
- && isSessionTemporary() && getPage().isPageStateless())
+ &&
+ isSessionTemporary() && getPage().isPageStateless())
{
// if target URL is different and session is temporary and page is stateless
- // this is special case when page is stateless but there is no session so we can't render it to buffer
-
- // note: if we had session here we would render the page to buffer and then redirect to URL generated
- // *after* page has been rendered (the statelessness may change during render). this would save one redirect
- // because now we have to render to URL generated *before* page is rendered, render the page, get URL
- // after render and if the URL is different (meaning page is not stateless), save the buffer and redirect again
+ // this is special case when page is stateless but there is no session so we can't
+ // render it to buffer
+
+ // note: if we had session here we would render the page to buffer and then redirect to
+ // URL generated
+ // *after* page has been rendered (the statelessness may change during render). this
+ // would save one redirect
+ // because now we have to render to URL generated *before* page is rendered, render the
+ // page, get URL
+ // after render and if the URL is different (meaning page is not stateless), save the
+ // buffer and redirect again
// (which is pretty much what the next step does)
redirectTo(targetUrl, requestCycle);
}
@@ -172,7 +199,7 @@
// check if the url hasn't changed after page has been rendered
// (i.e. the stateless flag might have changed which could result in different page url)
- Url targetUrl2 = requestCycle.urlFor(this.getRenderPageRequestHandler());
+ Url targetUrl2 = requestCycle.urlFor(getRenderPageRequestHandler());
if (targetUrl.getSegments().equals(targetUrl2.getSegments()) == false)
{
@@ -194,7 +221,7 @@
// also for listener interface on stateful page we want to redirect
// after the listener is invoked, but on stateless page the user
// must ask for redirect explicitely
- response.writeTo((WebResponse) requestCycle.getResponse());
+ response.writeTo((WebResponse)requestCycle.getResponse());
}
else
{
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/BufferedResponseMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/BufferedResponseMapper.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/BufferedResponseMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/BufferedResponseMapper.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.mapper;
import org.apache.wicket.ng.Session;
@@ -37,21 +53,21 @@
else
{
return false;
- }
+ }
}
protected BufferedWebResponse getAndRemoveBufferedResponse(Url url)
{
return WebApplication.get().getAndRemoveBufferedResponse(getSessionId(), url);
}
-
+
private Request getRequest(Request original)
{
// The buffers are stored under "real" URL which can be different
// than the URL handlers get due to global URL pre/postprocessing
// (i.e. prepending URL with language segment).
// Because of that we need find out the real URL from request cycle
-
+
if (RequestCycle.get() != null)
{
return RequestCycle.get().getRequest();
@@ -61,11 +77,11 @@
return original;
}
}
-
+
public RequestHandler mapRequest(Request request)
- {
+ {
request = getRequest(request);
-
+
BufferedWebResponse response = getAndRemoveBufferedResponse(request.getUrl());
if (response != null)
{
@@ -85,7 +101,7 @@
public int getCompatibilityScore(Request request)
{
request = getRequest(request);
-
+
if (hasBufferedResponse(request.getUrl()))
{
return Integer.MAX_VALUE;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/PageSource.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/PageSource.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/PageSource.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/PageSource.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.mapper;
import org.apache.wicket.ng.request.component.PageParameters;
@@ -15,14 +31,15 @@
/**
* Creates new page instance of page with given class. The page should be marked as create
- * bookmarkable, so subsequent calls to {@link RequestablePage#wasCreatedBookmarkable()} must return
- * <code>true</code>
+ * bookmarkable, so subsequent calls to {@link RequestablePage#wasCreatedBookmarkable()} must
+ * return <code>true</code>
*
* @param pageMapName
* @param pageClass
* @param pageParameters
* @return new page instance
*/
- public RequestablePage newPageInstance(Class<? extends RequestablePage> pageClass, PageParameters pageParameters);
+ public RequestablePage newPageInstance(Class<? extends RequestablePage> pageClass,
+ PageParameters pageParameters);
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/SystemMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/SystemMapper.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/SystemMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/SystemMapper.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.mapper;
import org.apache.wicket.ng.request.Request;
@@ -13,36 +29,36 @@
*/
public class SystemMapper implements RequestMapper
{
- private ThreadsafeCompoundRequestMapper mapper = new ThreadsafeCompoundRequestMapper();
+ private final ThreadsafeCompoundRequestMapper mapper = new ThreadsafeCompoundRequestMapper();
- /**
- * Constructor
- */
- public SystemMapper()
- {
- mapper.register(new PageInstanceMapper());
- mapper.register(new BookmarkableMapper());
- mapper.register(new ResourceReferenceMapper());
- mapper.register(new BufferedResponseMapper());
- }
-
- /** {@inheritDoc} */
- public int getCompatibilityScore(Request request)
- {
- return mapper.getCompatibilityScore(request);
- }
-
- /** {@inheritDoc} */
- public Url mapHandler(RequestHandler handler)
- {
- return mapper.mapHandler(handler);
- }
-
- /** {@inheritDoc} */
- public RequestHandler mapRequest(Request request)
- {
- return mapper.mapRequest(request);
- }
+ /**
+ * Constructor
+ */
+ public SystemMapper()
+ {
+ mapper.register(new PageInstanceMapper());
+ mapper.register(new BookmarkableMapper());
+ mapper.register(new ResourceReferenceMapper());
+ mapper.register(new BufferedResponseMapper());
+ }
+
+ /** {@inheritDoc} */
+ public int getCompatibilityScore(Request request)
+ {
+ return mapper.getCompatibilityScore(request);
+ }
+
+ /** {@inheritDoc} */
+ public Url mapHandler(RequestHandler handler)
+ {
+ return mapper.mapHandler(handler);
+ }
+
+ /** {@inheritDoc} */
+ public RequestHandler mapRequest(Request request)
+ {
+ return mapper.mapRequest(request);
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/Mount.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/Mount.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/Mount.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/Mount.java Sun Oct 11 13:52:09 2009
@@ -1,31 +1,47 @@
+/*
+ * 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.ng.request.mapper.mount;
import org.apache.wicket.ng.request.Url;
public class Mount
{
- private final Url url;
- private MountParameters mountParameters = new MountParameters();
+ private final Url url;
+ private MountParameters mountParameters = new MountParameters();
- public Mount(Url url)
- {
- this.url = url;
- }
-
- public void setMountParameters(MountParameters mountParameters)
- {
- this.mountParameters = mountParameters;
- }
-
- public MountParameters getMountParameters()
- {
- return mountParameters;
- }
-
- public Url getUrl()
- {
- return url;
- }
+ public Mount(Url url)
+ {
+ this.url = url;
+ }
+
+ public void setMountParameters(MountParameters mountParameters)
+ {
+ this.mountParameters = mountParameters;
+ }
+
+ public MountParameters getMountParameters()
+ {
+ return mountParameters;
+ }
+
+ public Url getUrl()
+ {
+ return url;
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountMapper.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountMapper.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.mapper.mount;
import org.apache.wicket.ng.request.Request;
@@ -15,111 +31,111 @@
*/
public class MountMapper extends AbstractMapper
{
- private final String[] mountSegments;
- private final MountedRequestMapper mapper;
+ private final String[] mountSegments;
+ private final MountedRequestMapper mapper;
- public MountMapper(String mountPath, MountedRequestMapper mapper)
- {
- Checks.argumentNotEmpty(mountPath, "mountPath");
- Checks.argumentNotNull(mapper, "mapper");
-
- this.mountSegments = getMountSegments(mountPath);
- this.mapper = mapper;
- }
-
- public MountMapper(String mountPath, RequestMapper mapper)
- {
- Checks.argumentNotEmpty(mountPath, "mountPath");
- Checks.argumentNotNull(mapper, "mapper");
-
- this.mountSegments = getMountSegments(mountPath);
- this.mapper = new UnmountedMapperAdapter(mapper);
- }
-
- public MountMapper(String mountPath, RequestHandler handler)
- {
- Checks.argumentNotEmpty(mountPath, "mountPath");
- Checks.argumentNotNull(handler, "handler");
-
- this.mountSegments = getMountSegments(mountPath);
- this.mapper = new UnmountedRequestHandlerAdapter(handler);
- }
-
- public int getCompatibilityScore(Request request)
- {
- if (urlStartsWith(request.getUrl(), mountSegments))
- {
- return mountSegments.length + mapper.getCompatibilityScore(dismountRequest(request));
- }
- else
- {
- return 0;
- }
- }
-
- private Request dismountRequest(Request request)
- {
- Url dismountedUrl = new Url(request.getUrl());
- dismountedUrl.removeLeadingSegments(mountSegments.length);
- return request.requestWithUrl(dismountedUrl);
- }
-
-
- public final RequestHandler mapRequest(Request request)
- {
- final Url url = request.getUrl();
-
- if (url.getSegments().size() >= mountSegments.length && urlStartsWith(url, mountSegments))
- {
- MountParameters params = new MountParameters();
- for (int i = 0; i < mountSegments.length; i++)
- {
- String placeholder = getPlaceholder(mountSegments[i]);
- if (placeholder != null)
- {
- params.setValue(placeholder, StringValue.valueOf(url.getSegments().get(i)));
- }
- }
-
- return mapper.mapRequest(dismountRequest(request), params);
- }
-
- return null;
- }
-
- public Url mapHandler(RequestHandler handler)
- {
- Mount mount = mapper.mapHandler(handler);
-
- if (mount == null)
- {
- return null;
- }
-
- // TODO
- // Check.notNull(mount.getUrl());
- // Check.notNull(mount.getMountParameters());
-
- for (int i = mountSegments.length; i > 0; i--)
- {
- String segment = mountSegments[i - 1];
- String placeholder = getPlaceholder(segment);
- String replacement = segment;
-
- if (placeholder != null)
- {
- replacement = mount.getMountParameters().getValue(placeholder).toString();
- if (replacement == null)
- {
- throw new IllegalStateException();// TODO message
- }
- }
+ public MountMapper(String mountPath, MountedRequestMapper mapper)
+ {
+ Checks.argumentNotEmpty(mountPath, "mountPath");
+ Checks.argumentNotNull(mapper, "mapper");
+
+ mountSegments = getMountSegments(mountPath);
+ this.mapper = mapper;
+ }
+
+ public MountMapper(String mountPath, RequestMapper mapper)
+ {
+ Checks.argumentNotEmpty(mountPath, "mountPath");
+ Checks.argumentNotNull(mapper, "mapper");
+
+ mountSegments = getMountSegments(mountPath);
+ this.mapper = new UnmountedMapperAdapter(mapper);
+ }
+
+ public MountMapper(String mountPath, RequestHandler handler)
+ {
+ Checks.argumentNotEmpty(mountPath, "mountPath");
+ Checks.argumentNotNull(handler, "handler");
+
+ mountSegments = getMountSegments(mountPath);
+ mapper = new UnmountedRequestHandlerAdapter(handler);
+ }
+
+ public int getCompatibilityScore(Request request)
+ {
+ if (urlStartsWith(request.getUrl(), mountSegments))
+ {
+ return mountSegments.length + mapper.getCompatibilityScore(dismountRequest(request));
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ private Request dismountRequest(Request request)
+ {
+ Url dismountedUrl = new Url(request.getUrl());
+ dismountedUrl.removeLeadingSegments(mountSegments.length);
+ return request.requestWithUrl(dismountedUrl);
+ }
+
+
+ public final RequestHandler mapRequest(Request request)
+ {
+ final Url url = request.getUrl();
+
+ if (url.getSegments().size() >= mountSegments.length && urlStartsWith(url, mountSegments))
+ {
+ MountParameters params = new MountParameters();
+ for (int i = 0; i < mountSegments.length; i++)
+ {
+ String placeholder = getPlaceholder(mountSegments[i]);
+ if (placeholder != null)
+ {
+ params.setValue(placeholder, StringValue.valueOf(url.getSegments().get(i)));
+ }
+ }
+
+ return mapper.mapRequest(dismountRequest(request), params);
+ }
+
+ return null;
+ }
+
+ public Url mapHandler(RequestHandler handler)
+ {
+ Mount mount = mapper.mapHandler(handler);
+
+ if (mount == null)
+ {
+ return null;
+ }
+
+ // TODO
+ // Check.notNull(mount.getUrl());
+ // Check.notNull(mount.getMountParameters());
+
+ for (int i = mountSegments.length; i > 0; i--)
+ {
+ String segment = mountSegments[i - 1];
+ String placeholder = getPlaceholder(segment);
+ String replacement = segment;
+
+ if (placeholder != null)
+ {
+ replacement = mount.getMountParameters().getValue(placeholder).toString();
+ if (replacement == null)
+ {
+ throw new IllegalStateException();// TODO message
+ }
+ }
- mount.getUrl().getSegments().add(0, replacement);
- }
+ mount.getUrl().getSegments().add(0, replacement);
+ }
- return mount.getUrl();
- }
+ return mount.getUrl();
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountParameters.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountParameters.java?rev=824074&r1=824073&r2=824074&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountParameters.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/request/mapper/mount/MountParameters.java Sun Oct 11 13:52:09 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.ng.request.mapper.mount;
import java.util.Collection;
@@ -16,59 +32,57 @@
*/
public class MountParameters
{
- private final Map<String, String> map = new HashMap<String, String>();
+ private final Map<String, String> map = new HashMap<String, String>();
+
+ public final StringValue getValue(String parameterName)
+ {
+ return StringValue.valueOf(map.get(parameterName));
+ }
+
+ public final void setValue(String parameterName, StringValue value)
+ {
+ map.put(parameterName, value.toString());
+ }
+
+ public final Collection<String> getParameterNames()
+ {
+ return map.keySet();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((map == null) ? 0 : map.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MountParameters other = (MountParameters)obj;
+ if (map == null)
+ {
+ if (other.map != null)
+ return false;
+ }
+ else if (!map.equals(other.map))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "MountParameters [" + map + "]";
+ }
+
- public final StringValue getValue(String parameterName)
- {
- return StringValue.valueOf(map.get(parameterName));
- }
-
- public final void setValue(String parameterName, StringValue value)
- {
- map.put(parameterName, value.toString());
- }
-
- public final Collection<String> getParameterNames()
- {
- return map.keySet();
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((map == null) ? 0 : map.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- MountParameters other = (MountParameters)obj;
- if (map == null)
- {
- if (other.map != null)
- return false;
- }
- else if (!map.equals(other.map))
- return false;
- return true;
- }
-
- @Override
- public String toString()
- {
- return "MountParameters [" + map + "]";
- }
-
-
-
-
}