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/19 11:50:13 UTC
svn commit: r965407 - in
/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl:
config/ scope/conversation/ scope/conversation/spi/
Author: gpetracek
Date: Mon Jul 19 09:50:12 2010
New Revision: 965407
URL: http://svn.apache.org/viewvc?rev=965407&view=rev
Log:
EXTCDI-1, EXTCDI-2 and EXTCDI-3 ConversationExpirationEvaluator
Added:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ConversationExpirationEvaluator.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfAwareConversationFactory.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/TimeoutConversationExpirationEvaluator.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/WindowConversationExpirationEvaluator.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationConfiguration.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationFactory.java
Modified:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.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/JsfWindowContext.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.java
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.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/config/DefaultWindowContextConfig.java?rev=965407&r1=965406&r2=965407&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java Mon Jul 19 09:50:12 2010
@@ -23,6 +23,8 @@ import org.apache.myfaces.extensions.cdi
import static org.apache.myfaces.extensions.cdi.javaee.jsf.api.ConfigParameter.*;
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 org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationFactory;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.JsfAwareConversationFactory;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.request.DefaultRedirectHandler;
import javax.enterprise.context.Dependent;
@@ -182,4 +184,9 @@ public class DefaultWindowContextConfig
{
return new DefaultRedirectHandler();
}
+
+ public ConversationFactory getConversationFactory()
+ {
+ return new JsfAwareConversationFactory();
+ }
}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ConversationExpirationEvaluator.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/ConversationExpirationEvaluator.java?rev=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ConversationExpirationEvaluator.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ConversationExpirationEvaluator.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationExpirationEvaluator
+{
+ boolean isExpired();
+
+ void touch();
+
+ void expire();
+}
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=965407&r1=965406&r2=965407&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 Mon Jul 19 09:50:12 2010
@@ -19,16 +19,10 @@
package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowScoped;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.BeanEntry;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.EditableConversation;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationKey;
-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 javax.faces.context.FacesContext;
import java.io.Serializable;
-import java.util.Date;
/**
* @author Gerhard Petracek
@@ -37,40 +31,32 @@ public class DefaultConversation impleme
{
private static final long serialVersionUID = -2958548175169003298L;
- //for easier debugging
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
private final ConversationKey conversationKey;
-
- private final boolean windowScoped;
-
- private String lastViewId; //for access scope
+ private ConversationExpirationEvaluator expirationEvaluator;
private final BeanStorage beanStorage = new BeanStorage();
- private final long conversationTimeoutInMs;
-
- private boolean active;
-
- private Date lastAccess;
-
- public DefaultConversation(ConversationKey conversationKey, int conversationTimeoutInMinutes)
+ public DefaultConversation(ConversationKey conversationKey, ConversationExpirationEvaluator expirationEvaluator)
{
this.conversationKey = conversationKey;
- this.windowScoped = WindowScoped.class.isAssignableFrom(conversationKey.getConversationGroup());
-
- tryToProcessViewAccessScope();
+ this.expirationEvaluator = expirationEvaluator;
- this.conversationTimeoutInMs = conversationTimeoutInMinutes * 60000;
+ this.expirationEvaluator.touch();
}
+ //just for a better performance to avoid frequent calls to the {@link #expirationEvaluator}
+ private boolean active;
+
public boolean isActive()
{
- return !isConversationTimedout() && this.active;
+ return !isConversationExpired() && this.active;
}
public void deactivate()
{
- if (!this.windowScoped)
+ this.expirationEvaluator.expire();
+ if (this.expirationEvaluator.isExpired())
{
this.active = false;
}
@@ -87,7 +73,7 @@ public class DefaultConversation impleme
public void restart()
{
- touchConversation(true);
+ touchConversation();
this.beanStorage.resetStorage();
}
@@ -99,7 +85,7 @@ public class DefaultConversation impleme
return null;
}
- touchConversation(true);
+ touchConversation();
BeanEntry scopedBean = this.beanStorage.getBean(key);
@@ -113,68 +99,29 @@ public class DefaultConversation impleme
public <T> void addBean(BeanEntry<T> beanEntry)
{
- tryToProcessViewAccessScope();
-
//TODO check if conversation is active
- touchConversation(false);
+ touchConversation();
//TODO
//noinspection unchecked
this.beanStorage.addBean((BeanEntry<Serializable>) beanEntry);
}
- private boolean isConversationTimedout()
- {
- if (this.windowScoped)
- {
- return false;
- }
-
- if (this.lastViewId != null)
- {
- return isInvalidConversationForCurrentView();
- }
-
- return this.lastAccess == null ||
- (this.lastAccess.getTime() + this.conversationTimeoutInMs) < System.currentTimeMillis();
- }
-
- private boolean isInvalidConversationForCurrentView()
+ private boolean isConversationExpired()
{
- FacesContext facesContext = FacesContext.getCurrentInstance();
- String fromViewId = getOldViewIdFromRequest(facesContext);
-
- if (fromViewId != null && fromViewId.endsWith(this.lastViewId))
- {
- this.lastViewId = getNewViewIdFromRequest(facesContext);
- }
- return !this.lastViewId.equals(getCurrentViewId());
+ return this.expirationEvaluator.isExpired();
}
- private void touchConversation(boolean updateViewId)
+ private void touchConversation()
{
this.active = true;
- this.lastAccess = new Date();
- //just update it if it is a view-access scope (= there is already a value)
- if (updateViewId && this.lastViewId != null)
- {
- this.lastViewId = getCurrentViewId();
- }
+ this.expirationEvaluator.touch();
}
- private String getCurrentViewId()
+ //just for test-cases (to expire a conversation manually)
+ public ConversationExpirationEvaluator getExpirationEvaluator()
{
- return FacesContext.getCurrentInstance().getViewRoot().getViewId();
- }
-
- private void tryToProcessViewAccessScope()
- {
- //workaround
- if(this.conversationKey instanceof DefaultConversationKey &&
- ((DefaultConversationKey)this.conversationKey).isViewAccessScopedAnnotationPresent())
- {
- this.lastViewId = getCurrentViewId();
- }
+ return expirationEvaluator;
}
}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfAwareConversationFactory.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/JsfAwareConversationFactory.java?rev=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfAwareConversationFactory.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/JsfAwareConversationFactory.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationFactory;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationKey;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationConfiguration;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowScoped;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class JsfAwareConversationFactory implements ConversationFactory
+{
+ enum ConversationPropertyKeys
+ {
+ TIMEOUT("timeout");
+
+ private String key;
+
+ ConversationPropertyKeys(String key)
+ {
+ this.key = key;
+ }
+
+ String getKey()
+ {
+ return key;
+ }
+ }
+
+ public Conversation createConversation(ConversationKey conversationKey, ConversationConfiguration configuration)
+ {
+ if(WindowScoped.class.isAssignableFrom(conversationKey.getConversationGroup()))
+ {
+ return new DefaultConversation(conversationKey, new WindowConversationExpirationEvaluator());
+ }
+
+ //workaround
+ if(conversationKey instanceof DefaultConversationKey &&
+ ((DefaultConversationKey)conversationKey).isViewAccessScopedAnnotationPresent())
+ {
+ return new DefaultConversation(conversationKey, new ViewAccessConversationExpirationEvaluator());
+ }
+
+ return new DefaultConversation(
+ conversationKey,
+ new TimeoutConversationExpirationEvaluator(
+ configuration.getValue(ConversationPropertyKeys.TIMEOUT.getKey(), Integer.class)));
+ }
+}
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=965407&r1=965406&r2=965407&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 Mon Jul 19 09:50:12 2010
@@ -24,6 +24,11 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.EditableConversation;
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.ConversationKey;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationFactory;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationConfiguration;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.JsfAwareWindowContextConfig;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation
+ .JsfAwareConversationFactory.ConversationPropertyKeys.TIMEOUT;
import java.util.Collections;
import java.util.Iterator;
@@ -126,7 +131,24 @@ public class JsfWindowContext implements
{
ConversationKey conversationKey = new DefaultConversationKey(conversationGroupKey, qualifiers);
- return new DefaultConversation(conversationKey, this.config.getConversationTimeoutInMinutes());
+ ConversationFactory conversationFactory = ((JsfAwareWindowContextConfig)this.config).getConversationFactory();
+
+ return conversationFactory.createConversation(conversationKey, transformConfiguration(this.config));
+ }
+
+ private ConversationConfiguration transformConfiguration(final WindowContextConfig config)
+ {
+ return new ConversationConfiguration()
+ {
+ public <T> T getValue(String key, Class<T> targetType)
+ {
+ if(TIMEOUT.getKey().equals(key))
+ {
+ return (T)(Integer)config.getConversationTimeoutInMinutes();
+ }
+ throw new IllegalArgumentException(key + " isn't a supported key");
+ }
+ };
}
public Map<ConversationKey /*conversation group*/, Conversation> getConversations()
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/TimeoutConversationExpirationEvaluator.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/TimeoutConversationExpirationEvaluator.java?rev=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/TimeoutConversationExpirationEvaluator.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/TimeoutConversationExpirationEvaluator.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation;
+
+import java.util.Date;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TimeoutConversationExpirationEvaluator implements ConversationExpirationEvaluator
+{
+ private final long conversationTimeoutInMs;
+
+ private Date lastAccess;
+
+ TimeoutConversationExpirationEvaluator(int conversationTimeoutInMinutes)
+ {
+ this.conversationTimeoutInMs = conversationTimeoutInMinutes * 60000;
+ }
+
+ public boolean isExpired()
+ {
+
+ return this.lastAccess == null ||
+ (this.lastAccess.getTime() + this.conversationTimeoutInMs) < System.currentTimeMillis();
+ }
+
+ public void touch()
+ {
+ this.lastAccess = new Date();
+ }
+
+ public void expire()
+ {
+ this.lastAccess = null;
+ }
+}
Added: 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=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.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 javax.faces.context.FacesContext;
+
+/**
+ * @author Gerhard Petracek
+ */
+class ViewAccessConversationExpirationEvaluator implements ConversationExpirationEvaluator
+{
+ private String lastViewId; //for access scope
+
+ public boolean isExpired()
+ {
+ if(this.lastViewId == null)
+ {
+ return true;
+ }
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ String fromViewId = getOldViewIdFromRequest(facesContext);
+
+ if (fromViewId != null && fromViewId.endsWith(this.lastViewId))
+ {
+ this.lastViewId = getNewViewIdFromRequest(facesContext);
+ }
+ return !this.lastViewId.equals(getCurrentViewId());
+ }
+
+ public void touch()
+ {
+ this.lastViewId = getCurrentViewId();
+ }
+
+ public void expire()
+ {
+ this.lastViewId = null;
+ }
+
+ private String getCurrentViewId()
+ {
+ return FacesContext.getCurrentInstance().getViewRoot().getViewId();
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/WindowConversationExpirationEvaluator.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/WindowConversationExpirationEvaluator.java?rev=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/WindowConversationExpirationEvaluator.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/WindowConversationExpirationEvaluator.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+class WindowConversationExpirationEvaluator implements ConversationExpirationEvaluator
+{
+ public boolean isExpired()
+ {
+ return false;
+ }
+
+ public void touch()
+ {
+ //not needed
+ }
+
+ public void expire()
+ {
+ //isn't supported
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationConfiguration.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/ConversationConfiguration.java?rev=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationConfiguration.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationConfiguration.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,27 @@
+/*
+ * 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.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationConfiguration
+{
+ public <T> T getValue(String key, Class<T> targetType);
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationFactory.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/ConversationFactory.java?rev=965407&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationFactory.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationFactory.java Mon Jul 19 09:50:12 2010
@@ -0,0 +1,29 @@
+/*
+ * 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.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationFactory
+{
+ Conversation createConversation(ConversationKey conversationKey, ConversationConfiguration config);
+}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.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/JsfAwareWindowContextConfig.java?rev=965407&r1=965406&r2=965407&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/JsfAwareWindowContextConfig.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/JsfAwareWindowContextConfig.java Mon Jul 19 09:50:12 2010
@@ -26,4 +26,6 @@ import org.apache.myfaces.extensions.cdi
public abstract class JsfAwareWindowContextConfig extends WindowContextConfig
{
public abstract RedirectHandler getRedirectHandler();
+
+ public abstract ConversationFactory getConversationFactory();
}