myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1059918 - /myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/
Date Mon, 17 Jan 2011 13:28:29 GMT
Author: gpetracek
Date: Mon Jan 17 13:28:29 2011
New Revision: 1059918

URL: http://svn.apache.org/viewvc?rev=1059918&view=rev
Log:
EXTCDI-118 workaround for the producer method issue of weld and improved support for glassfish

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/InstanceProducer.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java?rev=1059918&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
Mon Jan 17 13:28:29 2011
@@ -0,0 +1,155 @@
+/*
+ * 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.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContext;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig;
+import org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageProducer;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
+import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableWindowContext;
+import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableWindowContextManager;
+import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.WindowContextManagerFactory;
+import org.apache.myfaces.extensions.cdi.jsf.impl.util.RequestCache;
+
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import java.util.Collection;
+
+import static org.apache.myfaces.extensions.cdi.core.impl.CoreModuleBeanNames.WINDOW_CONTEXT_MANAGER_BEAN_NAME;
+
+/**
+ * @author Gerhard Petracek
+ */
+@SessionScoped
+@Named(WINDOW_CONTEXT_MANAGER_BEAN_NAME)
+public class EditableWindowContextManagerProxy implements EditableWindowContextManager
+{
+    private static final long serialVersionUID = -7650399459577468233L;
+
+    private EditableWindowContextManager editableWindowContextManager;
+
+    protected EditableWindowContextManagerProxy()
+    {
+    }
+
+    /**
+     * Workaround for a producer-method which produces a session-scoped instance.
+     * Workaround for Weld 1.x
+     *
+     * @param windowContextConfig current windowContextConfig
+     * @param conversationConfig current conversationConfig
+     * @param beanManager current beanManager
+     */
+    @Inject
+    public EditableWindowContextManagerProxy(WindowContextConfig windowContextConfig,
+                                             ConversationConfig conversationConfig,
+                                             BeanManager beanManager)
+    {
+        WindowContextManagerFactory windowContextManagerFactory =
+                CodiUtils.getContextualReferenceByClass(beanManager, WindowContextManagerFactory.class,
true);
+
+        if(windowContextManagerFactory != null)
+        {
+            this.editableWindowContextManager =
+                    windowContextManagerFactory.createWindowContextManager(windowContextConfig,
conversationConfig);
+        }
+        else
+        {
+            this.editableWindowContextManager =
+                    new DefaultWindowContextManager(windowContextConfig, conversationConfig,
+                            ProjectStageProducer.getInstance().getProjectStage() /*due to
a weld issue*/,
+                            beanManager);
+        }
+    }
+
+    @PreDestroy
+    protected void preDestroy()
+    {
+        this.editableWindowContextManager.closeAllWindowContexts();
+        RequestCache.resetCache();
+    }
+
+    /*
+     * generated
+     */
+    public boolean activateWindowContext(String windowContextId)
+    {
+        return editableWindowContextManager.activateWindowContext(windowContextId);
+    }
+
+    public boolean activateWindowContext(EditableWindowContext windowContext)
+    {
+        return editableWindowContextManager.activateWindowContext(windowContext);
+    }
+
+    public void restartConversations()
+    {
+        editableWindowContextManager.restartConversations();
+    }
+
+    public void restartConversations(String windowContextId)
+    {
+        editableWindowContextManager.restartConversations(windowContextId);
+    }
+
+    public void restartConversations(EditableWindowContext windowContext)
+    {
+        editableWindowContextManager.restartConversations(windowContext);
+    }
+
+    public void closeCurrentWindowContext()
+    {
+        editableWindowContextManager.closeCurrentWindowContext();
+    }
+
+    public void closeWindowContext(String windowContextId)
+    {
+        editableWindowContextManager.closeWindowContext(windowContextId);
+    }
+
+    public void closeWindowContext(EditableWindowContext windowContext)
+    {
+        editableWindowContextManager.closeWindowContext(windowContext);
+    }
+
+    public Collection<EditableWindowContext> getWindowContexts()
+    {
+        return editableWindowContextManager.getWindowContexts();
+    }
+
+    public void closeAllWindowContexts()
+    {
+        editableWindowContextManager.closeAllWindowContexts();
+    }
+
+    public WindowContext getCurrentWindowContext()
+    {
+        return editableWindowContextManager.getCurrentWindowContext();
+    }
+
+    public WindowContext getWindowContext(String windowContextId)
+    {
+        return editableWindowContextManager.getWindowContext(windowContextId);
+    }
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/InstanceProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/InstanceProducer.java?rev=1059918&r1=1059917&r2=1059918&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/InstanceProducer.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/InstanceProducer.java
Mon Jan 17 13:28:29 2011
@@ -19,27 +19,16 @@
 package org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation;
 
 import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContext;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig;
-import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
 import static org.apache.myfaces.extensions.cdi.core.api.CoreModuleBeanNames.*;
-import static org.apache.myfaces.extensions.cdi.core.impl.CoreModuleBeanNames.*;
 import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager;
-import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
 import org.apache.myfaces.extensions.cdi.core.impl.util.UnmodifiableMap;
-import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.WindowContextManagerFactory;
-import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableWindowContextManager;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableWindowContext;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableConversation;
 import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ExceptionUtils.*;
-import org.apache.myfaces.extensions.cdi.jsf.impl.util.RequestCache;
 
 import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.context.RequestScoped;
-import javax.enterprise.context.SessionScoped;
 import javax.enterprise.context.Dependent;
 import javax.inject.Named;
 import java.util.Map;
@@ -50,34 +39,6 @@ import java.util.Map;
 final class InstanceProducer
 {
     @Produces
-    @SessionScoped
-    @Named(WINDOW_CONTEXT_MANAGER_BEAN_NAME)
-    protected EditableWindowContextManager createWindowContextManager(WindowContextConfig
windowContextConfig,
-                                                                      ConversationConfig
conversationConfig,
-                                                                      ProjectStage projectStage,
-                                                                      BeanManager beanManager)
-    {
-        WindowContextManagerFactory windowContextManagerFactory =
-                CodiUtils.getContextualReferenceByClass(beanManager, WindowContextManagerFactory.class,
true);
-
-        if(windowContextManagerFactory != null)
-        {
-            return windowContextManagerFactory.createWindowContextManager(windowContextConfig,
conversationConfig);
-        }
-        return new DefaultWindowContextManager(windowContextConfig, conversationConfig, projectStage,
beanManager);
-    }
-
-    protected void destroyAllConversations(
-            @Disposes @Named(WINDOW_CONTEXT_MANAGER_BEAN_NAME)WindowContextManager windowContextManager)
-    {
-        if(windowContextManager instanceof EditableWindowContextManager)
-        {
-            ((EditableWindowContextManager)windowContextManager).closeAllWindowContexts();
-        }
-        RequestCache.resetCache();
-    }
-
-    @Produces
     @Named(CURRENT_WINDOW_CONTEXT_BEAN_NAME)
     @RequestScoped
     protected EditableWindowContext currentWindowContext(WindowContextManager windowContextManager)

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java?rev=1059918&r1=1059917&r2=1059918&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java
Mon Jan 17 13:28:29 2011
@@ -18,11 +18,12 @@
  */
 package org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation;
 
-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.jsf.impl.scope.conversation.spi.EditableWindowContext;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.faces.context.FacesContext;
 import javax.inject.Inject;
 import java.io.Serializable;
 import java.util.List;
@@ -37,7 +38,7 @@ public class ViewAccessConversationExpir
     private static final long serialVersionUID = -1783266839383634211L;
 
     @Inject
-    private WindowContext windowContext;
+    private EditableWindowContext windowContext;
 
     protected ViewAccessConversationExpirationEvaluatorRegistry()
     {
@@ -67,6 +68,11 @@ public class ViewAccessConversationExpir
     @PreDestroy
     protected void save()
     {
+        if(FacesContext.getCurrentInstance() == null || !this.windowContext.isActive())
+        {
+            //here we are outside a request -> currently that's not supported -> TODO
+            return;
+        }
         this.windowContext.setAttribute(ViewAccessConversationExpirationEvaluatorRegistry.class.getName(),
                 this.viewAccessConversationExpirationEvaluatorList, true);
     }
@@ -74,6 +80,11 @@ public class ViewAccessConversationExpir
     @PostConstruct
     protected void restore()
     {
+        if(FacesContext.getCurrentInstance() == null || !this.windowContext.isActive())
+        {
+            //here we are outside a request -> currently that's not supported -> TODO
+            return;
+        }
         List<ViewAccessConversationExpirationEvaluator> restoredList =
             this.windowContext.getAttribute(ViewAccessConversationExpirationEvaluatorRegistry.class.getName(),
                     List.class);



Mime
View raw message