You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2011/02/19 16:48:29 UTC

svn commit: r1072363 - in /myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation: WindowBeanProducers.java WindowContextManagerObserver.java

Author: struberg
Date: Sat Feb 19 15:48:29 2011
New Revision: 1072363

URL: http://svn.apache.org/viewvc?rev=1072363&view=rev
Log:
EXTCDI-140 @Dependent removal continued

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowBeanProducers.java   (with props)
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowBeanProducers.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/WindowBeanProducers.java?rev=1072363&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowBeanProducers.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowBeanProducers.java Sat Feb 19 15:48:29 2011
@@ -0,0 +1,97 @@
+/*
+ * 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 static org.apache.myfaces.extensions.cdi.core.api.CoreModuleBeanNames.*;
+import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager;
+import org.apache.myfaces.extensions.cdi.core.impl.util.UnmodifiableMap;
+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 javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.Dependent;
+import javax.inject.Named;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Dependent
+public class WindowBeanProducers
+{
+    @Produces
+    @Named(CURRENT_WINDOW_CONTEXT_BEAN_NAME)
+    @RequestScoped
+    protected EditableWindowContext currentWindowContext(WindowContextManager windowContextManager)
+    {
+        WindowContext windowContext = windowContextManager.getCurrentWindowContext();
+
+        if(windowContext instanceof EditableWindowContext)
+        {
+            return (EditableWindowContext)windowContext;
+        }
+
+        throw windowContextNotEditableException(windowContext);
+    }
+
+    @Produces
+    @Named(CURRENT_WINDOW_BEAN_NAME)
+    @RequestScoped
+    protected Map<String, Object> currentWindow(final WindowContextManager windowContextManager)
+    {
+        return new UnmodifiableMap<String, Object>() {
+            private static final long serialVersionUID = 2356468240049980467L;
+
+            @Override
+            public Object get(Object key)
+            {
+                if(key == null || !(key instanceof String))
+                {
+                    return null;
+                }
+
+                String attributeKey = key.toString();
+
+                if("id".equalsIgnoreCase(attributeKey))
+                {
+                    return windowContextManager.getCurrentWindowContext().getId();
+                }
+
+                if("useNewId".equalsIgnoreCase(key.toString()))
+                {
+                    return ""; //return an empty string as signal for ConversationUtils#resolveWindowContextId
+                }
+                return windowContextManager.getCurrentWindowContext().getAttribute(attributeKey, Object.class);
+            }
+        };
+    }
+
+    @Produces
+    @Dependent
+    protected EditableConversation currentConversation(InjectionPoint injectionPoint,
+                                               WindowContextManager windowContextManager)
+    {
+        //for @Inject Conversation conversation;
+        return new InjectableConversation(injectionPoint.getBean(), windowContextManager);
+    }
+}

Propchange: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowBeanProducers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.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/WindowContextManagerObserver.java?rev=1072363&r1=1072362&r2=1072363&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java Sat Feb 19 15:48:29 2011
@@ -35,6 +35,7 @@ import static org.apache.myfaces.extensi
 import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.resolveWindowContextId;
 import org.apache.myfaces.extensions.cdi.message.api.Message;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Observes;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
@@ -51,7 +52,8 @@ import org.apache.myfaces.extensions.cdi
  * @author Gerhard Petracek
  */
 @SuppressWarnings({"UnusedDeclaration"})
-final class WindowContextManagerObserver
+@RequestScoped
+public class WindowContextManagerObserver
 {
     /**
      * tries to restore the window-id and the window-context as early as possible