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/11 18:10:01 UTC
svn commit: r963097 - in /myfaces/extensions/cdi/trunk:
core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/
core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/
examples/jsf-examples/...
Author: gpetracek
Date: Sun Jul 11 16:10:00 2010
New Revision: 963097
URL: http://svn.apache.org/viewvc?rev=963097&view=rev
Log:
EXTCDI-1, EXTCDI-2 and EXTCDI-3 minor refactorings and qualifiers for conversations (optional)
Added:
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/BeanAccessedListener.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBeanWithQualifier.java
- copied, changed from r963054, myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean1.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier1.java
- copied, changed from r963026, myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/qualifier/ClientQualifier.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier2.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationKey.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationKey.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/DeactivationAwareWindowContext.java
- copied, changed from r963026, myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/InactiveConversationsAwareWindowContext.java
Removed:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/InactiveConversationsAwareWindowContext.java
Modified:
myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/WindowContext.java
myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/ConversationBeanEntry.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean4.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/listener/phase/FacesDemoBean.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/ClientManager.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/GroupedConversationContextAdapter.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
Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/WindowContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/WindowContext.java?rev=963097&r1=963096&r2=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/WindowContext.java (original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/WindowContext.java Sun Jul 11 16:10:00 2010
@@ -21,7 +21,7 @@ package org.apache.myfaces.extensions.cd
import org.apache.myfaces.extensions.cdi.core.api.config.AttributeAware;
import java.io.Serializable;
-import java.util.Map;
+import java.lang.annotation.Annotation;
/**
* @author Gerhard Petracek
@@ -43,26 +43,24 @@ public interface WindowContext extends A
/**
* @param conversationGroup group of the conversation in question
+ * @param qualifiers optional qualifiers for the conversation
* @return a new conversation for the given group
*/
- Conversation createConversation(Class conversationGroup);
+ Conversation createConversation(Class conversationGroup, Annotation... qualifiers);
/**
* @param conversationGroup group of the conversation in question
+ * @param qualifiers optional qualifiers for the conversation
* @return a new conversation for the given group
*/
- Conversation getConversation(Class conversationGroup);
+ Conversation getConversation(Class conversationGroup, Annotation... qualifiers);
/**
* @param conversationGroup group of the conversation in question
+ * @param qualifiers optional qualifiers for the conversation
* @return the removed conversation - null otherwise
*/
- Conversation endConversation(Class conversationGroup);
-
- /**
- * @return all active conversations of the current context
- */
- Map<Class /*conversation group*/, Conversation> getConversations();
+ Conversation endConversation(Class conversationGroup, Annotation... qualifiers);
/**
* @return configuration of the current context
Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/ConversationBeanEntry.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/ConversationBeanEntry.java?rev=963097&r1=963096&r2=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/ConversationBeanEntry.java (original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/scope/conversation/ConversationBeanEntry.java Sun Jul 11 16:10:00 2010
@@ -31,7 +31,7 @@ class ConversationBeanEntry<T> implement
{
private static final long serialVersionUID = -4756851133555458294L;
- private Bean<T> bean;
+ private final Bean<T> bean;
private T currentBeanInstance;
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/BeanAccessedListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/BeanAccessedListener.java?rev=963097&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/BeanAccessedListener.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/BeanAccessedListener.java Sun Jul 11 16:10:00 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.blank.conversation.grouped;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.BeanAccessedEvent;
+
+import javax.enterprise.event.Observes;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class BeanAccessedListener
+{
+ public void accessed(@Observes BeanAccessedEvent beanAccessedEvent)
+ {
+ System.out.println("");
+ }
+}
Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean4.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean4.java?rev=963097&r1=963096&r2=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean4.java (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean4.java Sun Jul 11 16:10:00 2010
@@ -20,8 +20,11 @@ package org.apache.myfaces.blank.convers
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationScoped;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessGroup;
+import org.apache.myfaces.blank.conversation.grouped.qualifier.Qualifier1;
+import org.apache.myfaces.blank.conversation.grouped.qualifier.Qualifier2;
import javax.inject.Named;
+import javax.inject.Inject;
import javax.annotation.PostConstruct;
import java.io.Serializable;
import java.util.Date;
@@ -37,14 +40,25 @@ public class ConversationDemoBean4 imple
private Date createdAt;
private static final long serialVersionUID = -4238520498463300564L;
+ @Inject
+ @Qualifier1
+ private ConversationDemoBeanWithQualifier bean1;
+
+ @Inject
+ @Qualifier2
+ private ConversationDemoBeanWithQualifier bean2;
+
@PostConstruct
public void init()
{
this.createdAt = new Date();
+ this.bean1.getValue();
+ this.bean2.getValue();
}
public String getValue()
{
- return value + createdAt.toLocaleString();
+ return value + " bean1: " + this.bean1.getValue() + " bean2: " + this.bean2.getValue() + " "
+ + createdAt.toLocaleString();
}
}
\ No newline at end of file
Copied: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBeanWithQualifier.java (from r963054, myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean1.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBeanWithQualifier.java?p2=myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBeanWithQualifier.java&p1=myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean1.java&r1=963054&r2=963097&rev=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBean1.java (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/ConversationDemoBeanWithQualifier.java Sun Jul 11 16:10:00 2010
@@ -19,31 +19,47 @@
package org.apache.myfaces.blank.conversation.grouped;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationScoped;
+import org.apache.myfaces.blank.conversation.grouped.qualifier.Qualifier1;
+import org.apache.myfaces.blank.conversation.grouped.qualifier.Qualifier2;
-import javax.inject.Named;
-import javax.annotation.PostConstruct;
+import javax.enterprise.inject.Produces;
import java.io.Serializable;
-import java.util.Date;
/**
* @author Gerhard Petracek
*/
-@Named
-@ConversationScoped(ConversationGroup1.class)
-public class ConversationDemoBean1 implements Serializable
+public class ConversationDemoBeanWithQualifier implements Serializable
{
- private String value = "Hello grouped conversation1! ";
- private Date createdAt;
+ private String value = "";
private static final long serialVersionUID = -4238520498463300564L;
- @PostConstruct
- public void init()
+ protected ConversationDemoBeanWithQualifier()
{
- this.createdAt = new Date();
+ }
+
+ private ConversationDemoBeanWithQualifier(String value)
+ {
+ this.value = value;
+ }
+
+ @Produces
+ @Qualifier1
+ @ConversationScoped
+ public ConversationDemoBeanWithQualifier createConversationDemoBean1WithQ1()
+ {
+ return new ConversationDemoBeanWithQualifier("Q1");
+ }
+
+ @Produces
+ @Qualifier2
+ @ConversationScoped
+ public ConversationDemoBeanWithQualifier createConversationDemoBean1WithQ2()
+ {
+ return new ConversationDemoBeanWithQualifier("Q2");
}
public String getValue()
{
- return value + createdAt.toLocaleString();
+ return value;
}
-}
+}
\ No newline at end of file
Copied: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier1.java (from r963026, myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/qualifier/ClientQualifier.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier1.java?p2=myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier1.java&p1=myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/qualifier/ClientQualifier.java&r1=963026&r2=963097&rev=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/qualifier/ClientQualifier.java (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier1.java Sun Jul 11 16:10:00 2010
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.myfaces.blank.message.client.qualifier;
+package org.apache.myfaces.blank.conversation.grouped.qualifier;
import javax.inject.Qualifier;
import java.lang.annotation.Target;
@@ -36,6 +36,6 @@ import static java.lang.annotation.Eleme
@Documented
@Qualifier
-public @interface ClientQualifier
+public @interface Qualifier1
{
}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier2.java?rev=963097&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier2.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/conversation/grouped/qualifier/Qualifier2.java Sun Jul 11 16:10:00 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.blank.conversation.grouped.qualifier;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({PARAMETER, FIELD, METHOD, CONSTRUCTOR})
+@Retention(RUNTIME)
+@Documented
+
+@Qualifier
+public @interface Qualifier2
+{
+}
\ No newline at end of file
Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/listener/phase/FacesDemoBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/listener/phase/FacesDemoBean.java?rev=963097&r1=963096&r2=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/listener/phase/FacesDemoBean.java (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/listener/phase/FacesDemoBean.java Sun Jul 11 16:10:00 2010
@@ -23,6 +23,7 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.PhaseId;
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.JsfLifecyclePhaseInformation;
import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.BeforePhase;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.api.request.RequestTypeResolver;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Model;
@@ -44,6 +45,9 @@ public class FacesDemoBean
@Inject
private ConfigDemoBean configDemoBean;
+ @Inject
+ private RequestTypeResolver requestTypeResolver;
+
private String text;
@PostConstruct
Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/ClientManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/ClientManager.java?rev=963097&r1=963096&r2=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/ClientManager.java (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/blank/message/client/ClientManager.java Sun Jul 11 16:10:00 2010
@@ -29,6 +29,7 @@ import javax.inject.Named;
import javax.faces.event.ValueChangeEvent;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
+import javax.annotation.PostConstruct;
import java.util.List;
import java.util.ArrayList;
import java.io.Serializable;
@@ -46,7 +47,8 @@ public class ClientManager implements Se
private List<SelectItem> clients = new ArrayList<SelectItem>();
- protected ClientManager()
+ @PostConstruct
+ protected void init()
{
for (ClientId value : ClientId.values())
{
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=963097&r1=963096&r2=963097&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 Sun Jul 11 16:10:00 2010
@@ -24,6 +24,7 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationScoped;
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 javax.faces.context.FacesContext;
import java.io.Serializable;
@@ -39,7 +40,7 @@ public class DefaultConversation impleme
//for easier debugging
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
- private final Class groupKey;
+ private final ConversationKey conversationKey;
private final boolean windowScoped;
@@ -53,12 +54,12 @@ public class DefaultConversation impleme
private Date lastAccess;
- public DefaultConversation(Class<?> groupKey, int conversationTimeoutInMinutes)
+ public DefaultConversation(ConversationKey conversationKey, int conversationTimeoutInMinutes)
{
- this.groupKey = groupKey;
- this.windowScoped = WindowGroup.class.isAssignableFrom(groupKey);
+ this.conversationKey = conversationKey;
+ this.windowScoped = WindowGroup.class.isAssignableFrom(conversationKey.getConversationGroup());
- tryToProcessAccessViewScope(groupKey);
+ tryToProcessViewAccessScope(conversationKey.getConversationGroup());
this.beanStorage = new BeanStorage();
this.conversationTimeoutInMs = conversationTimeoutInMinutes * 60000;
@@ -111,7 +112,7 @@ public class DefaultConversation impleme
public <T> void addBean(Class<?> beanClass, BeanEntry<T> beanEntry)
{
- tryToProcessAccessViewScope(beanClass);
+ tryToProcessViewAccessScope(beanClass);
//TODO check if conversation is active
touchConversation(false);
@@ -168,7 +169,7 @@ public class DefaultConversation impleme
return FacesContext.getCurrentInstance().getViewRoot().getViewId();
}
- private void tryToProcessAccessViewScope(Class<?> groupKey)
+ private void tryToProcessViewAccessScope(Class<?> groupKey)
{
ConversationScoped conversationScoped = groupKey.getAnnotation(ConversationScoped.class);
if (conversationScoped != null && ViewAccessGroup.class.isAssignableFrom(conversationScoped.value()))
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationKey.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/DefaultConversationKey.java?rev=963097&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationKey.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationKey.java Sun Jul 11 16:10:00 2010
@@ -0,0 +1,144 @@
+/*
+ * 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.ConversationKey;
+import org.apache.myfaces.extensions.cdi.core.api.tools.annotate.DefaultAnnotation;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowGroup;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessGroup;
+
+import javax.enterprise.inject.Default;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author Gerhard Petracek
+ */
+class DefaultConversationKey implements ConversationKey
+{
+ private static final long serialVersionUID = 3577945095460042939L;
+
+ private static final String INVALID_WINDOW_SCOPE_DEFINITION =
+ ": It isn't allowed to use qualifiers in combination with " + WindowGroup.class.getName();
+
+ private static final String INVALID_VIEW_ACCESS_SCOPE_DEFINITION =
+ ": It isn't allowed to use qualifiers in combination with " + WindowGroup.class.getName();
+
+ private final Class<?> groupKey;
+ private final Set<Annotation> qualifiers = new HashSet<Annotation>();
+
+ DefaultConversationKey(Class<?> groupKey, Annotation... qualifiers)
+ {
+ this.groupKey = groupKey;
+
+ this.qualifiers.addAll(Arrays.asList(qualifiers));
+
+ //for easier manual usage of the WindowContextManager
+ if(this.qualifiers.isEmpty())
+ {
+ this.qualifiers.add(DefaultAnnotation.of(Default.class));
+ }
+
+ validate();
+ }
+
+ private void validate()
+ {
+ boolean defaultQualifierUsed = isDefaultQualifier();
+
+ if(isWindowScope() && !defaultQualifierUsed)
+ {
+ throw new IllegalStateException(this.groupKey.getName() + INVALID_WINDOW_SCOPE_DEFINITION);
+ }
+
+ if(isViewAccessScope() && !defaultQualifierUsed)
+ {
+ throw new IllegalStateException(this.groupKey.getName() + INVALID_VIEW_ACCESS_SCOPE_DEFINITION);
+ }
+ }
+
+ private boolean isWindowScope()
+ {
+ return WindowGroup.class.isAssignableFrom(this.groupKey.getClass());
+ }
+
+ private boolean isViewAccessScope()
+ {
+ return ViewAccessGroup.class.isAssignableFrom(this.groupKey.getClass());
+ }
+
+ private boolean isDefaultQualifier()
+ {
+ for(Annotation qualifier : this.qualifiers)
+ {
+ if(Default.class.isAssignableFrom(qualifier.getClass()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Class<?> getConversationGroup()
+ {
+ return groupKey;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return Collections.unmodifiableSet(this.qualifiers);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (!(o instanceof DefaultConversationKey))
+ {
+ return false;
+ }
+
+ DefaultConversationKey that = (DefaultConversationKey) o;
+
+ if (!groupKey.equals(that.groupKey))
+ {
+ return false;
+ }
+ if (!qualifiers.equals(that.qualifiers))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = groupKey.hashCode();
+ result = 31 * result + qualifiers.hashCode();
+ return result;
+ }
+}
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=963097&r1=963096&r2=963097&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 Sun Jul 11 16:10:00 2010
@@ -29,7 +29,7 @@ import org.apache.myfaces.extensions.cdi
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 org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.InactiveConversationsAwareWindowContext;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.DeactivationAwareWindowContext;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
@@ -105,7 +105,8 @@ public class DefaultWindowContextManager
for (WindowContext windowContext : this.windowContextMap.values())
{
- for (Conversation conversation : windowContext.getConversations().values())
+ for (Conversation conversation :
+ ((DeactivationAwareWindowContext)windowContext).getConversations().values())
{
//TODO
if (!((EditableConversation)conversation).isActive())
@@ -115,7 +116,7 @@ public class DefaultWindowContextManager
}
//TODO
- ((InactiveConversationsAwareWindowContext)windowContext).removeInactiveConversations();
+ ((DeactivationAwareWindowContext)windowContext).removeInactiveConversations();
}
}
@@ -189,7 +190,7 @@ public class DefaultWindowContextManager
public void resetWindowContext(WindowContext windowContext)
{
- for (Conversation conversation : windowContext.getConversations().values())
+ for (Conversation conversation : ((DeactivationAwareWindowContext)windowContext).getConversations().values())
{
conversation.restart();
}
@@ -207,7 +208,7 @@ public class DefaultWindowContextManager
public void resetConversations(WindowContext windowContext)
{
- for (Conversation conversation : windowContext.getConversations().values())
+ for (Conversation conversation : ((DeactivationAwareWindowContext)windowContext).getConversations().values())
{
//TODO
((EditableConversation)conversation).deactivate();
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/GroupedConversationContextAdapter.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/GroupedConversationContextAdapter.java?rev=963097&r1=963096&r2=963097&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/GroupedConversationContextAdapter.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/GroupedConversationContextAdapter.java Sun Jul 11 16:10:00 2010
@@ -32,6 +32,8 @@ import org.apache.myfaces.extensions.cdi
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.faces.context.FacesContext;
+import java.lang.annotation.Annotation;
+import java.util.Set;
/**
* jsf specific parts for managing grouped conversations
@@ -91,16 +93,29 @@ public class GroupedConversationContextA
((EditableConversation) foundConversation).addBean(bean.getBeanClass(), beanEntry);
}
- private Conversation getConversation(WindowContextManager conversationManager, Bean<?> beanClass)
+ private Conversation getConversation(WindowContextManager conversationManager, Bean<?> bean)
{
- Class conversationGroup = getConversationGroup(beanClass);
+ Class conversationGroup = getConversationGroup(bean);
- return conversationManager.getCurrentWindowContext().getConversation(conversationGroup);
+ Set<Annotation> qualifiers = bean.getQualifiers();
+ return conversationManager.getCurrentWindowContext()
+ .getConversation(conversationGroup, qualifiers.toArray(new Annotation[qualifiers.size()]));
}
private Class getConversationGroup(Bean<?> bean)
{
- Class groupClass = bean.getBeanClass().getAnnotation(ConversationScoped.class).value();
+ ConversationScoped conversationAnnotation = bean.getBeanClass().getAnnotation(ConversationScoped.class);
+
+ if(conversationAnnotation == null)
+ {
+ //in this case we have e.g. a producer method -> there is no official api to get the method
+ //-> it isn't possible to extract the group
+ //TODO if we keep the group approach we should perform a check via reflection here and throw an exception
+ //(if the user used a group) or we use a workaround (via reflection)
+ return DefaultGroup.class;
+ }
+
+ Class groupClass = conversationAnnotation.value();
if(DefaultGroup.class.isAssignableFrom(groupClass) || ViewAccessGroup.class.isAssignableFrom(groupClass))
{
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=963097&r1=963096&r2=963097&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 Sun Jul 11 16:10:00 2010
@@ -22,19 +22,21 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContext;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContextConfig;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.EditableConversation;
-import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.InactiveConversationsAwareWindowContext;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.DeactivationAwareWindowContext;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.ConversationKey;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.lang.annotation.Annotation;
/**
* TODO
*
* @author Gerhard Petracek
*/
-public class JsfWindowContext implements WindowContext, InactiveConversationsAwareWindowContext
+public class JsfWindowContext implements WindowContext, DeactivationAwareWindowContext
{
private static final long serialVersionUID = 5272798129165017829L;
@@ -42,7 +44,8 @@ public class JsfWindowContext implements
private final WindowContextConfig config;
- private final Map<Class, Conversation> groupedConversations = new ConcurrentHashMap<Class, Conversation>();
+ private final Map<ConversationKey, Conversation> groupedConversations
+ = new ConcurrentHashMap<ConversationKey, Conversation>();
public JsfWindowContext(Long windowContextId, WindowContextConfig config)
{
@@ -57,38 +60,42 @@ public class JsfWindowContext implements
public synchronized void endConversations()
{
- for (Map.Entry<Class, Conversation> conversationEntry : this.groupedConversations.entrySet())
+ for (Map.Entry<ConversationKey, Conversation> conversationEntry : this.groupedConversations.entrySet())
{
endAndRemoveConversation(conversationEntry.getKey(), conversationEntry.getValue());
}
}
- public Conversation getConversation(Class conversationGroupKey)
+ public Conversation getConversation(Class conversationGroupKey, Annotation... qualifiers)
{
- Conversation conversation = this.groupedConversations.get(conversationGroupKey);
+ ConversationKey conversationKey = new DefaultConversationKey(conversationGroupKey, qualifiers);
+
+ Conversation conversation = this.groupedConversations.get(conversationKey);
//TODO
if (conversation != null && !((EditableConversation)conversation).isActive())
{
- endAndRemoveConversation(conversationGroupKey, conversation);
+ endAndRemoveConversation(conversationKey, conversation);
conversation = null;
}
if (conversation == null)
{
- conversation = createConversation(conversationGroupKey);
- this.groupedConversations.put(conversationGroupKey, conversation);
+ conversation = createConversation(conversationGroupKey, qualifiers);
+ this.groupedConversations.put(conversationKey, conversation);
}
return conversation;
}
- public Conversation endConversation(Class conversationGroupKey)
+ public Conversation endConversation(Class conversationGroupKey, Annotation... qualifiers)
{
- Conversation conversation = this.groupedConversations.get(conversationGroupKey);
- return endAndRemoveConversation(conversationGroupKey, conversation);
+ ConversationKey conversationKey = new DefaultConversationKey(conversationGroupKey, qualifiers);
+
+ Conversation conversation = this.groupedConversations.get(conversationKey);
+ return endAndRemoveConversation(conversationKey, conversation);
}
- public Conversation endAndRemoveConversation(Class conversationGroupKey, Conversation conversation)
+ private Conversation endAndRemoveConversation(ConversationKey conversationKey, Conversation conversation)
{
//TODO
if (((EditableConversation)conversation).isActive())
@@ -96,15 +103,17 @@ public class JsfWindowContext implements
conversation.end();
}
- return this.groupedConversations.remove(conversationGroupKey);
+ return this.groupedConversations.remove(conversationKey);
}
- public Conversation createConversation(Class conversationGroup)
+ public Conversation createConversation(Class conversationGroupKey, Annotation... qualifiers)
{
- return new DefaultConversation(conversationGroup, this.config.getConversationTimeoutInMinutes());
+ ConversationKey conversationKey = new DefaultConversationKey(conversationGroupKey, qualifiers);
+
+ return new DefaultConversation(conversationKey, this.config.getConversationTimeoutInMinutes());
}
- public Map<Class /*conversation group*/, Conversation> getConversations()
+ public Map<ConversationKey /*conversation group*/, Conversation> getConversations()
{
return Collections.unmodifiableMap(this.groupedConversations);
}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/ConversationKey.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/ConversationKey.java?rev=963097&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/ConversationKey.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/ConversationKey.java Sun Jul 11 16:10:00 2010
@@ -0,0 +1,33 @@
+/*
+ * 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 java.lang.annotation.Annotation;
+import java.util.Set;
+import java.io.Serializable;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationKey extends Serializable
+{
+ Class<?> getConversationGroup();
+
+ Set<Annotation> getQualifiers();
+}
Copied: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/DeactivationAwareWindowContext.java (from r963026, myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/InactiveConversationsAwareWindowContext.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/DeactivationAwareWindowContext.java?p2=myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/DeactivationAwareWindowContext.java&p1=myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/InactiveConversationsAwareWindowContext.java&r1=963026&r2=963097&rev=963097&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/InactiveConversationsAwareWindowContext.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/DeactivationAwareWindowContext.java Sun Jul 11 16:10:00 2010
@@ -18,10 +18,21 @@
*/
package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
+
+import java.util.Map;
+
/**
* @author Gerhard Petracek
*/
-public interface InactiveConversationsAwareWindowContext
+public interface DeactivationAwareWindowContext
{
void removeInactiveConversations();
+
+ /**
+ * TODO
+ * @return all active conversations of the current context
+ */
+ Map<ConversationKey /*conversation group*/, Conversation> getConversations();
+
}