You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/07/20 17:32:39 UTC
svn commit: r965881 - in /myfaces/extensions/cdi/trunk:
core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/spi/
jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/
jee...
Author: gpetracek
Date: Tue Jul 20 15:32:38 2010
New Revision: 965881
URL: http://svn.apache.org/viewvc?rev=965881&view=rev
Log:
EXTCDI-1, EXTCDI-2 and EXTCDI-3 refactored to window-context attributes
Removed:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/UuidEntry.java
Modified:
myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/spi/WindowContextManager.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/DefaultRedirectHandler.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversation.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/InterceptedResponseWriter.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfWindowContext.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/RedirectHandler.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf2/impl/request/DefaultRedirectHandler.java
Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/spi/WindowContextManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/spi/WindowContextManager.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/spi/WindowContextManager.java (original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/spi/WindowContextManager.java Tue Jul 20 15:32:38 2010
@@ -27,6 +27,8 @@ import java.io.Serializable;
*/
public interface WindowContextManager extends Serializable
{
+ String WINDOW_CONTEXT_MANAGER_BEAN_NAME = "windowContextManager";
+
String WINDOW_CONTEXT_ID_PARAMETER_KEY = "windowContextId";
WindowContext getCurrentWindowContext();
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/DefaultRedirectHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/DefaultRedirectHandler.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/DefaultRedirectHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/DefaultRedirectHandler.java Tue Jul 20 15:32:38 2010
@@ -18,8 +18,10 @@
*/
package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.request;
+import static org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager
+ .WINDOW_CONTEXT_ID_PARAMETER_KEY;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.RedirectHandler;
-import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.UUID_ID_KEY;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.parseWindowId;
import javax.faces.context.ExternalContext;
import java.io.IOException;
@@ -31,11 +33,11 @@ public class DefaultRedirectHandler impl
{
private static final long serialVersionUID = -103516988654873089L;
- public void sendRedirect(ExternalContext externalContext, String url, String requestIdKey) throws IOException
+ public void sendRedirect(ExternalContext externalContext, String url, Long windowId) throws IOException
{
- if (requestIdKey != null)
+ if (windowId != null)
{
- url = url + "?" + UUID_ID_KEY + "=" + requestIdKey;
+ url = url + "?" + WINDOW_CONTEXT_ID_PARAMETER_KEY + "=" + windowId;
url = externalContext.encodeActionURL(url);
}
@@ -43,8 +45,8 @@ public class DefaultRedirectHandler impl
externalContext.redirect(url);
}
- public String restoreRequestIdKey(ExternalContext externalContext)
+ public Long restoreWindowId(ExternalContext externalContext)
{
- return externalContext.getRequestParameterMap().get(UUID_ID_KEY);
+ return parseWindowId(externalContext.getRequestParameterMap().get(WINDOW_CONTEXT_ID_PARAMETER_KEY));
}
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversation.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversation.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversation.java Tue Jul 20 15:32:38 2010
@@ -42,7 +42,8 @@ public class DefaultConversation impleme
this.conversationKey = conversationKey;
this.expirationEvaluator = expirationEvaluator;
- this.expirationEvaluator.touch();
+ //TODO remove it after further tests
+ //this.expirationEvaluator.touch();
}
//just for a better performance to avoid frequent calls to the {@link #expirationEvaluator}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java Tue Jul 20 15:32:38 2010
@@ -24,12 +24,15 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContextConfig;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.EditableConversation;
+import static org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager
+ .WINDOW_CONTEXT_MANAGER_BEAN_NAME;
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.AfterPhase;
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.PhaseId;
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.request.RequestTypeResolver;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils;
import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.resolveWindowContextId;
import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.restoreInformationOfRequest;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.cacheWindowId;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.EditableWindowContext;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.RedirectHandler;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.JsfAwareWindowContextConfig;
@@ -59,7 +62,7 @@ import java.lang.annotation.Annotation;
*
* @author Gerhard Petracek
*/
-@Named("windowContextManager")
+@Named(WINDOW_CONTEXT_MANAGER_BEAN_NAME)
@SessionScoped
public class DefaultWindowContextManager implements WindowContextManager
{
@@ -88,12 +91,9 @@ public class DefaultWindowContextManager
//don't change/optimize this observer!!!
protected void cleanup(@Observes @AfterPhase(PhaseId.RESTORE_VIEW) PhaseEvent phaseEvent,
RequestTypeResolver requestTypeResolver,
- ConfigResolver configResolver)
+ WindowContextManager windowContextManager)
{
- processConversationAwareRedirectsAndForwards(phaseEvent,
- requestTypeResolver,
- configResolver.resolve(
- JsfAwareWindowContextConfig.class).getRedirectHandler());
+ restoreInformationOfRequest(phaseEvent.getFacesContext(), windowContextManager);
//for performance reasons + cleanup at the beginning of the request (check timeout,...)
//+ we aren't allowed to cleanup in case of redirects
@@ -106,16 +106,6 @@ public class DefaultWindowContextManager
cleanupInactiveConversations();
}
- private void processConversationAwareRedirectsAndForwards(
- PhaseEvent phaseEvent, RequestTypeResolver requestTypeResolver, RedirectHandler redirectHandler)
- {
- //restore view-id in case of a get request - we need it esp. for redirects
- if (!requestTypeResolver.isPostRequest())
- {
- restoreInformationOfRequest(phaseEvent.getFacesContext(), redirectHandler);
- }
- }
-
private boolean isPartialOrGetRequest(RequestTypeResolver requestTypeResolver)
{
return requestTypeResolver.isPartialRequest() || !requestTypeResolver.isPostRequest();
@@ -192,6 +182,7 @@ public class DefaultWindowContextManager
if (windowContextId == null)
{
windowContextId = this.lastWindowContextId.incrementAndGet();
+ cacheWindowId(windowContextId);
}
return getWindowContext(windowContextId);
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/InterceptedResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/InterceptedResponseWriter.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/InterceptedResponseWriter.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/InterceptedResponseWriter.java Tue Jul 20 15:32:38 2010
@@ -20,11 +20,13 @@ package org.apache.myfaces.extensions.cd
import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils
.addWindowContextIdHolderComponent;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils
+ .storeCurrentViewIdAsOldViewId;
-import javax.faces.component.UIComponent;
import javax.faces.context.ResponseWriter;
+import javax.faces.context.ResponseWriterWrapper;
+import javax.faces.context.FacesContext;
import java.io.IOException;
-import java.io.Writer;
/**
* Adds
@@ -33,7 +35,7 @@ import java.io.Writer;
*
* @author Gerhard Petracek
*/
-class InterceptedResponseWriter extends ResponseWriter
+class InterceptedResponseWriter extends ResponseWriterWrapper
{
private ResponseWriter wrapped;
@@ -42,22 +44,7 @@ class InterceptedResponseWriter extends
this.wrapped = wrapped;
}
- public String getContentType()
- {
- return wrapped.getContentType();
- }
-
- public String getCharacterEncoding()
- {
- return wrapped.getCharacterEncoding();
- }
-
- public void flush()
- throws IOException
- {
- wrapped.flush();
- }
-
+ @Override
public void startDocument()
throws IOException
{
@@ -66,116 +53,17 @@ class InterceptedResponseWriter extends
wrapped.startDocument();
}
+ @Override
public void endDocument()
throws IOException
{
- wrapped.endDocument();
- }
-
- public void startElement(String s, UIComponent uiComponent)
- throws IOException
- {
- wrapped.startElement(s, uiComponent);
- }
-
- public void endElement(String s)
- throws IOException
- {
- wrapped.endElement(s);
- }
-
- public void writeAttribute(String s, Object o, String s1)
- throws IOException
- {
- wrapped.writeAttribute(s, o, s1);
- }
-
- public void writeURIAttribute(String s, Object o, String s1)
- throws IOException
- {
- wrapped.writeURIAttribute(s, o, s1);
- }
-
- public void writeComment(Object o)
- throws IOException
- {
- wrapped.writeComment(o);
- }
-
- public void writeText(Object o, String s)
- throws IOException
- {
- wrapped.writeText(o, s);
- }
-
- public void writeText(char[] chars, int i, int i1)
- throws IOException
- {
- wrapped.writeText(chars, i, i1);
- }
-
- public ResponseWriter cloneWithWriter(Writer writer)
- {
- return wrapped.cloneWithWriter(writer);
- }
-
- public void writeText(Object o, UIComponent uiComponent, String s)
- throws IOException
- {
- wrapped.writeText(o, uiComponent, s);
- }
-
- public void close()
- throws IOException
- {
- wrapped.close();
- }
-
- public Writer append(char c)
- throws IOException
- {
- return wrapped.append(c);
- }
-
- public Writer append(CharSequence csq, int start, int end)
- throws IOException
- {
- return wrapped.append(csq, start, end);
- }
+ storeCurrentViewIdAsOldViewId(FacesContext.getCurrentInstance());
- public Writer append(CharSequence csq)
- throws IOException
- {
- return wrapped.append(csq);
- }
-
- public void write(String str, int off, int len)
- throws IOException
- {
- wrapped.write(str, off, len);
- }
-
- public void write(String str)
- throws IOException
- {
- wrapped.write(str);
- }
-
- public void write(char[] cbuf, int off, int len)
- throws IOException
- {
- wrapped.write(cbuf, off, len);
- }
-
- public void write(char[] cbuf)
- throws IOException
- {
- wrapped.write(cbuf);
+ wrapped.endDocument();
}
- public void write(int c)
- throws IOException
+ protected ResponseWriter getWrapped()
{
- wrapped.write(c);
+ return this.wrapped;
}
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfWindowContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfWindowContext.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfWindowContext.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfWindowContext.java Tue Jul 20 15:32:38 2010
@@ -54,6 +54,8 @@ public class JsfWindowContext implements
private Map<ConversationKey, Conversation> groupedConversations
= new ConcurrentHashMap<ConversationKey, Conversation>();
+ private Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
+
public JsfWindowContext(Long windowContextId, WindowContextConfig config)
{
this.id = windowContextId;
@@ -180,21 +182,27 @@ public class JsfWindowContext implements
public boolean setAttribute(String name, Object value)
{
- throw new IllegalStateException("not implemented");
+ return setAttribute(name, value, true);
}
public boolean setAttribute(String name, Object value, boolean forceOverride)
{
- throw new IllegalStateException("not implemented");
+ if(value == null || (!forceOverride && containsAttribute(name)))
+ {
+ return false;
+ }
+ this.attributes.put(name, value);
+ return true;
}
public boolean containsAttribute(String name)
{
- throw new IllegalStateException("not implemented");
+ return this.attributes.containsKey(name);
}
public <T> T getAttribute(String name, Class<T> targetType)
{
- throw new IllegalStateException("not implemented");
+ //noinspection unchecked
+ return (T)this.attributes.get(name);
}
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java Tue Jul 20 15:32:38 2010
@@ -18,8 +18,8 @@
*/
package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation;
-import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.getOldViewIdFromRequest;
-import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.getNewViewIdFromRequest;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.getOldViewId;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.getNewViewId;
import javax.faces.context.FacesContext;
@@ -37,14 +37,13 @@ class ViewAccessConversationExpirationEv
return true;
}
- FacesContext facesContext = FacesContext.getCurrentInstance();
- String fromViewId = getOldViewIdFromRequest(facesContext);
+ String oldViewId = getOldViewId();
- if (fromViewId != null && fromViewId.endsWith(this.lastViewId))
+ if (oldViewId != null && oldViewId.equals(this.lastViewId))
{
- this.lastViewId = getNewViewIdFromRequest(facesContext);
+ this.lastViewId = getNewViewId();
}
- return !this.lastViewId.equals(getCurrentViewId());
+ return !getCurrentViewId().equals(this.lastViewId);
}
public void touch()
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/RedirectHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/RedirectHandler.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/RedirectHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/RedirectHandler.java Tue Jul 20 15:32:38 2010
@@ -27,7 +27,7 @@ import java.io.Serializable;
*/
public interface RedirectHandler extends Serializable
{
- void sendRedirect(ExternalContext externalContext, String url, String requestIdKey) throws IOException;
+ void sendRedirect(ExternalContext externalContext, String url, Long windowId) throws IOException;
- String restoreRequestIdKey(ExternalContext externalContext);
+ Long restoreWindowId(ExternalContext externalContext);
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java Tue Jul 20 15:32:38 2010
@@ -20,29 +20,29 @@ package org.apache.myfaces.extensions.cd
import org.apache.myfaces.extensions.cdi.core.api.manager.BeanManagerProvider;
import static org.apache.myfaces.extensions.cdi.core.api.manager.BeanManagerProvider.getInstance;
-import org.apache.myfaces.extensions.cdi.core.api.tools.annotate.DefaultAnnotation;
+import org.apache.myfaces.extensions.cdi.core.api.resolver.ConfigResolver;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationGroup;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContext;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowScoped;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationGroup;
-import org.apache.myfaces.extensions.cdi.core.api.resolver.ConfigResolver;
+import org.apache.myfaces.extensions.cdi.core.api.tools.annotate.DefaultAnnotation;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager;
import org.apache.myfaces.extensions.cdi.core.impl.utils.CodiUtils;
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.qualifier.Jsf;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.WindowContextIdHolderComponent;
-import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.RedirectHandler;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.JsfAwareWindowContextConfig;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.RedirectHandler;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.lang.annotation.Annotation;
-import java.io.IOException;
/**
* internal! utils
@@ -50,8 +50,6 @@ import java.io.IOException;
*/
public class ConversationUtils
{
- public static final String UUID_ID_KEY = "uuid";
-
private static final ViewAccessScoped VIEW_ACCESS_SCOPED = DefaultAnnotation.of(ViewAccessScoped.class);
private static final Jsf JSF_QUALIFIER = DefaultAnnotation.of(Jsf.class);
@@ -162,55 +160,22 @@ public class ConversationUtils
Map<String, String> requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
- String uuidKey = null;
-
- if(redirectHandler != null)
- {
- uuidKey = redirectHandler.restoreRequestIdKey(facesContext.getExternalContext());
- }
-
- if(uuidKey == null)
- {
- uuidKey = requestParameterMap.get(UUID_ID_KEY);
- }
-
- //try to restore {@link UuidEntry}
- if(uuidKey != null)
- {
- UuidEntry uuidEntry = getUuidEntryMap(facesContext.getExternalContext().getSessionMap()).remove(uuidKey);
-
- if (uuidEntry != null)
- {
- restoreInformationFromUuidEntry(requestMap, uuidEntry);
- }
- }
-
- //try to restore get-request parameter
- String idViaGetRequest = null;
+ //try to find id in request map
+ Long id = tryToFindWindowIdInRequestMap(requestMap);
- if (requestParameterSupported)
+ if(id == null && redirectHandler != null)
{
- idViaGetRequest = requestParameterMap.get(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY);
+ id = redirectHandler.restoreWindowId(facesContext.getExternalContext());
}
- Long id = null;
- if (idViaGetRequest != null)
+ if(id == null)
{
- try
- {
- id = Long.parseLong(idViaGetRequest);
- }
- catch (NumberFormatException e)
- {
- id = null;
- }
+ id = tryToRestoreWindowIdFromRequestParameterMap(requestParameterSupported, requestParameterMap);
}
- //TODO test if we can move it to the beginning
- //try to find id in request map
- if (id == null)
+ if(id != null)
{
- id = tryToFindWindowIdInRequestMap(requestMap);
+ cacheWindowId(requestMap, id);
}
if (id != null)
@@ -233,103 +198,90 @@ public class ConversationUtils
return null;
}
- private static void restoreInformationFromUuidEntry(Map<String, Object> requestMap, UuidEntry uuidEntry)
+ private static Long tryToRestoreWindowIdFromRequestParameterMap(
+ boolean requestParameterSupported, Map<String, String> requestParameterMap)
{
- requestMap.put(OLD_VIEW_ID_KEY, uuidEntry.getViewId());
+ //try to restore get-request parameter
+ String idViaGetRequest = null;
- requestMap.put(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY, uuidEntry.getWindowContextId());
+ if (requestParameterSupported)
+ {
+ idViaGetRequest = requestParameterMap.get(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY);
+ }
+
+ return parseWindowId(idViaGetRequest);
}
- private static Long tryToFindWindowIdInRequestMap(Map<String, Object> requestMap)
+ public static Long parseWindowId(String windowIdAsString)
{
- return (Long) requestMap.get(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY);
+ if (windowIdAsString != null)
+ {
+ try
+ {
+ return Long.parseLong(windowIdAsString);
+ }
+ catch (NumberFormatException e)
+ {
+ return null;
+ }
+ }
+ return null;
}
- public static UuidEntry storeUuidEntry(Map<String, Object> sessionMap, Long windowContextId, String oldViewId)
+ public static void cacheWindowId(Long id)
{
- UuidEntry uuidEntry = new UuidEntry(windowContextId, oldViewId);
- getUuidEntryMap(sessionMap).put(uuidEntry.getUuid(), uuidEntry);
- return uuidEntry;
+ cacheWindowId(FacesContext.getCurrentInstance().getExternalContext().getRequestMap(), id);
}
-
- private static Map<String, UuidEntry> getUuidEntryMap(Map<String, Object> sessionMap)
+
+ private static void cacheWindowId(Map<String, Object> requestMap, Long id)
{
- String key = ConversationUtils.class.getName() + ":uuid:map";
- if(!sessionMap.containsKey(key))
- {
- sessionMap.put(key, new ConcurrentHashMap<String, UuidEntry>());
- }
-
- //noinspection unchecked
- return (Map<String, UuidEntry>)sessionMap.get(key);
+ requestMap.put(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY, id);
}
- //TODO
- public static void restoreInformationOfRequest(FacesContext facesContext, RedirectHandler redirectHandler)
+ private static Long tryToFindWindowIdInRequestMap(Map<String, Object> requestMap)
{
- Map<String, String> requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
- Map<String, Object> requstMap = facesContext.getExternalContext().getRequestMap();
- Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap();
-
- requstMap.put(NEW_VIEW_ID_KEY, facesContext.getViewRoot().getViewId());
-
- String uuidKey = null;
-
- if(redirectHandler != null)
- {
- uuidKey = redirectHandler.restoreRequestIdKey(facesContext.getExternalContext());
- }
-
- if(uuidKey == null)
- {
- uuidKey = requestParameterMap.get(UUID_ID_KEY);
- }
-
- if(uuidKey != null)
- {
- UuidEntry uuidEntry = getUuidEntryMap(sessionMap).remove(uuidKey);
-
- if (uuidEntry != null)
- {
- requstMap.put(OLD_VIEW_ID_KEY, uuidEntry.getViewId());
-
- requstMap.put(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY, uuidEntry.getWindowContextId());
- }
- }
+ return (Long) requestMap.get(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY);
+ }
- String oldViewId = requestParameterMap.get(OLD_VIEW_ID_KEY);
+ public static void restoreInformationOfRequest(FacesContext facesContext,
+ WindowContextManager windowContextManager)
+ {
+ WindowContext windowContext = windowContextManager.getCurrentWindowContext();
+ windowContext.setAttribute(NEW_VIEW_ID_KEY, facesContext.getViewRoot().getViewId());
+ }
- if (oldViewId != null)
- {
- requstMap.put(OLD_VIEW_ID_KEY, oldViewId);
- }
+ public static void storeCurrentViewIdAsOldViewId(FacesContext facesContext
+ /*TODO add window context as parameter and test it in combination with redirects*/)
+ {
+ storeCurrentViewIdAsOldViewId(facesContext, getWindowContextManager());
}
- public static void storeCurrentViewIdAsOldViewId(FacesContext facesContext)
+ public static void storeCurrentViewIdAsOldViewId(
+ FacesContext facesContext, WindowContextManager windowContextManager)
{
String oldViewId = facesContext.getViewRoot().getViewId();
- facesContext.getExternalContext().getRequestMap().put(OLD_VIEW_ID_KEY, oldViewId);
+ windowContextManager.getCurrentWindowContext().setAttribute(OLD_VIEW_ID_KEY, oldViewId);
}
public static void storeCurrentViewIdAsNewViewId(FacesContext facesContext)
{
- String newViewId = facesContext.getViewRoot().getViewId();
- facesContext.getExternalContext().getRequestMap().put(NEW_VIEW_ID_KEY, newViewId);
+ storeCurrentViewIdAsNewViewId(facesContext, getWindowContextManager().getCurrentWindowContext());
}
- public static String getOldViewIdFromRequest(FacesContext facesContext)
+ public static void storeCurrentViewIdAsNewViewId(FacesContext facesContext, WindowContext windowContext)
{
- return getOldViewIdFromRequest(facesContext.getExternalContext().getRequestMap());
+ String newViewId = facesContext.getViewRoot().getViewId();
+ windowContext.setAttribute(NEW_VIEW_ID_KEY, newViewId);
}
- public static String getOldViewIdFromRequest(Map<String, Object> requstMap)
+ public static String getOldViewId()
{
- return (String)requstMap.get(OLD_VIEW_ID_KEY);
+ return getWindowContextManager().getCurrentWindowContext().getAttribute(OLD_VIEW_ID_KEY, String.class);
}
- public static String getNewViewIdFromRequest(FacesContext facesContext)
+ public static String getNewViewId()
{
- return (String)facesContext.getExternalContext().getRequestMap().get(NEW_VIEW_ID_KEY);
+ return getWindowContextManager().getCurrentWindowContext().getAttribute(NEW_VIEW_ID_KEY, String.class);
}
public static WindowContextIdHolderComponent getWindowContextIdHolderComponent(FacesContext facesContext)
@@ -375,21 +327,12 @@ public class ConversationUtils
String url,
RedirectHandler redirectHandler) throws IOException
{
+ storeCurrentViewIdAsOldViewId(FacesContext.getCurrentInstance());
+
if(redirectHandler != null)
{
- Long windowContextId = resolveWindowContextId(redirectHandler);
-
- String uniqueRequestId = null;
- if (windowContextId != null)
- {
- UuidEntry uuidEntry = storeUuidEntry(externalContext.getSessionMap(),
- windowContextId,
- getOldViewIdFromRequest(externalContext.getRequestMap()));
-
- uniqueRequestId = uuidEntry.getUuid();
- }
-
- redirectHandler.sendRedirect(externalContext, url, uniqueRequestId);
+ redirectHandler.sendRedirect(
+ externalContext, url, getWindowContextManager().getCurrentWindowContext().getId());
}
else
{
@@ -398,13 +341,6 @@ public class ConversationUtils
}
}
- private static Long resolveWindowContextId(RedirectHandler redirectHandler)
- {
- return ConversationUtils.resolveWindowContextId(false
- /*TODO log warning if request parameter is disabled - we have to use false here*/,
- redirectHandler);
- }
-
public static RedirectHandler getRedirectHandler()
{
Set<Bean<?>> configResolvers = getInstance().getBeanManager().getBeans(ConfigResolver.class);
@@ -415,4 +351,10 @@ public class ConversationUtils
return configResolver.resolve(JsfAwareWindowContextConfig.class).getRedirectHandler();
}
+
+ public static WindowContextManager getWindowContextManager()
+ {
+ return CodiUtils.getOrCreateScopedInstanceOfBeanByName(
+ WindowContextManager.WINDOW_CONTEXT_MANAGER_BEAN_NAME, WindowContextManager.class);
+ }
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf2/impl/request/DefaultRedirectHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf2/impl/request/DefaultRedirectHandler.java?rev=965881&r1=965880&r2=965881&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf2/impl/request/DefaultRedirectHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf2/impl/request/DefaultRedirectHandler.java Tue Jul 20 15:32:38 2010
@@ -18,8 +18,9 @@
*/
package org.apache.myfaces.extensions.cdi.javaee.jsf2.impl.request;
-import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.UUID_ID_KEY;
import static org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils.tryToLoadClassForName;
+import static org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager
+ .WINDOW_CONTEXT_ID_PARAMETER_KEY;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@@ -42,33 +43,33 @@ public class DefaultRedirectHandler exte
}
@Override
- public void sendRedirect(ExternalContext externalContext, String url, String requestIdKey) throws IOException
+ public void sendRedirect(ExternalContext externalContext, String url, Long windowId) throws IOException
{
if(this.useFallback ||
//here we have an ajax nav. - currently it doesn't work in combination with the flash scope
FacesContext.getCurrentInstance().getPartialViewContext().isPartialRequest())
{
- super.sendRedirect(externalContext, url, requestIdKey);
+ super.sendRedirect(externalContext, url, windowId);
return;
}
- if (requestIdKey != null)
+ if (windowId != null)
{
- externalContext.getRequestMap().put(UUID_ID_KEY, requestIdKey);
- externalContext.getFlash().keep(UUID_ID_KEY);
+ externalContext.getRequestMap().put(WINDOW_CONTEXT_ID_PARAMETER_KEY, windowId);
+ externalContext.getFlash().keep(WINDOW_CONTEXT_ID_PARAMETER_KEY);
}
externalContext.redirect(url);
}
@Override
- public String restoreRequestIdKey(ExternalContext externalContext)
+ public Long restoreWindowId(ExternalContext externalContext)
{
if(this.useFallback)
{
- return super.restoreRequestIdKey(externalContext);
+ return super.restoreWindowId(externalContext);
}
- return (String)externalContext.getFlash().remove(UUID_ID_KEY);
+ return (Long)externalContext.getFlash().remove(WINDOW_CONTEXT_ID_PARAMETER_KEY);
}
}