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/06/15 01:09:17 UTC

svn commit: r954666 - in /myfaces/extensions/cdi/trunk/jee-modules/jsf-module: api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/ impl/src/main/config/ impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/

Author: gpetracek
Date: Mon Jun 14 23:09:16 2010
New Revision: 954666

URL: http://svn.apache.org/viewvc?rev=954666&view=rev
Log:
EXTCDI-23 initial draft

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/AfterFacesRequest.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/BeforeFacesRequest.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/config/faces-config.xml
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/BeforeAfterFacesRequestBroadcaster.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextFactory.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextWrapper.java

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/AfterFacesRequest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/AfterFacesRequest.java?rev=954666&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/AfterFacesRequest.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/AfterFacesRequest.java Mon Jun 14 23:09:16 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.api.request;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * @author Gerhard Petracek
+ */
+
+@Target({PARAMETER, FIELD})
+@Retention(RUNTIME)
+@Documented
+
+@Qualifier
+public @interface AfterFacesRequest
+{
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/BeforeFacesRequest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/BeforeFacesRequest.java?rev=954666&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/BeforeFacesRequest.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/request/BeforeFacesRequest.java Mon Jun 14 23:09:16 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.api.request;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * @author Gerhard Petracek
+ */
+
+@Target({PARAMETER, FIELD})
+@Retention(RUNTIME)
+@Documented
+
+@Qualifier
+public @interface BeforeFacesRequest
+{
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/config/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/config/faces-config.xml?rev=954666&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/config/faces-config.xml (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/config/faces-config.xml Mon Jun 14 23:09:16 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.
+-->
+
+<faces-config version="1.2"
+    xmlns="http://java.sun.com/xml/ns/javaee"
+    xmlns:xi="http://www.w3.org/2001/XInclude"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
+
+    <factory>
+        <faces-context-factory>org.apache.myfaces.extensions.cdi.javaee.jsf.impl.request.CodiFacesContextFactory</faces-context-factory>
+    </factory>
+</faces-config>
\ 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/request/BeforeAfterFacesRequestBroadcaster.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/BeforeAfterFacesRequestBroadcaster.java?rev=954666&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/BeforeAfterFacesRequestBroadcaster.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/BeforeAfterFacesRequestBroadcaster.java Mon Jun 14 23:09:16 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.request;
+
+import org.apache.myfaces.extensions.cdi.javaee.jsf.api.request.BeforeFacesRequest;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.api.request.AfterFacesRequest;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class BeforeAfterFacesRequestBroadcaster
+{
+    @Inject
+    @BeforeFacesRequest
+    private Event<FacesContext> beforeFacesRequestEvent;
+
+    @Inject
+    @AfterFacesRequest
+    private Event<FacesContext> afterFacesRequestEvent;
+
+    void broadcastBeforeFacesRequestEvent(FacesContext facesContext)
+    {
+        this.beforeFacesRequestEvent.fire(facesContext);
+    }
+
+    void broadcastAfterFacesRequestEvent(FacesContext facesContext)
+    {
+        this.afterFacesRequestEvent.fire(facesContext);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextFactory.java?rev=954666&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextFactory.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextFactory.java Mon Jun 14 23:09:16 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.request;
+
+import javax.faces.context.FacesContextFactory;
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.FacesException;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class CodiFacesContextFactory extends FacesContextFactory
+{
+    private FacesContextFactory wrappedFacesContextFactory;
+
+    public CodiFacesContextFactory(FacesContextFactory wrappedFacesContextFactory)
+    {
+        this.wrappedFacesContextFactory = wrappedFacesContextFactory;
+    }
+
+    public FacesContext getFacesContext(Object context,
+                                        Object request,
+                                        Object response,
+                                        Lifecycle lifecycle) throws FacesException
+    {
+        FacesContext facesContext =
+                this.wrappedFacesContextFactory.getFacesContext(context, request, response, lifecycle);
+
+        if (facesContext == null)
+        {
+            return null;
+        }
+
+        return new CodiFacesContextWrapper(facesContext);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextWrapper.java?rev=954666&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextWrapper.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/request/CodiFacesContextWrapper.java Mon Jun 14 23:09:16 2010
@@ -0,0 +1,190 @@
+/*
+ * 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.request;
+
+import org.apache.myfaces.extensions.cdi.core.api.manager.BeanManagerProvider;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.render.RenderKit;
+import javax.faces.component.UIViewRoot;
+import javax.el.ELContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.context.spi.CreationalContext;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ */
+class CodiFacesContextWrapper extends FacesContext
+{
+    private FacesContext wrappedFacesContext;
+
+    private BeanManager beanManager;
+
+    private BeforeAfterFacesRequestBroadcaster beforeAfterFacesRequestBroadcaster;
+
+    CodiFacesContextWrapper(FacesContext wrappedFacesContext)
+    {
+        this.wrappedFacesContext = wrappedFacesContext;
+        this.beanManager = BeanManagerProvider.getInstance().getBeanManager();
+
+        initBroadcaster();
+
+        broadcastBeforeFacesRequestEvent();
+    }
+
+    private void broadcastBeforeFacesRequestEvent()
+    {
+        this.beforeAfterFacesRequestBroadcaster.broadcastBeforeFacesRequestEvent(this);
+    }
+
+    private void broadcastAfterFacesRequestEvent()
+    {
+        this.beforeAfterFacesRequestBroadcaster.broadcastAfterFacesRequestEvent(this);
+    }
+
+    public ELContext getELContext()
+    {
+        return wrappedFacesContext.getELContext();
+    }
+
+    public Application getApplication()
+    {
+        return wrappedFacesContext.getApplication();
+    }
+
+    public Iterator<String> getClientIdsWithMessages()
+    {
+        return wrappedFacesContext.getClientIdsWithMessages();
+    }
+
+    public ExternalContext getExternalContext()
+    {
+        return wrappedFacesContext.getExternalContext();
+    }
+
+    public FacesMessage.Severity getMaximumSeverity()
+    {
+        return wrappedFacesContext.getMaximumSeverity();
+    }
+
+    public Iterator<FacesMessage> getMessages()
+    {
+        return wrappedFacesContext.getMessages();
+    }
+
+    public Iterator<FacesMessage> getMessages(String s)
+    {
+        return wrappedFacesContext.getMessages(s);
+    }
+
+    public RenderKit getRenderKit()
+    {
+        return wrappedFacesContext.getRenderKit();
+    }
+
+    public boolean getRenderResponse()
+    {
+        return wrappedFacesContext.getRenderResponse();
+    }
+
+    public boolean getResponseComplete()
+    {
+        return wrappedFacesContext.getResponseComplete();
+    }
+
+    public ResponseStream getResponseStream()
+    {
+        return wrappedFacesContext.getResponseStream();
+    }
+
+    public void setResponseStream(ResponseStream responseStream)
+    {
+        wrappedFacesContext.setResponseStream(responseStream);
+    }
+
+    public ResponseWriter getResponseWriter()
+    {
+        return wrappedFacesContext.getResponseWriter();
+    }
+
+    public void setResponseWriter(ResponseWriter responseWriter)
+    {
+        wrappedFacesContext.setResponseWriter(responseWriter);
+    }
+
+    public UIViewRoot getViewRoot()
+    {
+        return wrappedFacesContext.getViewRoot();
+    }
+
+    public void setViewRoot(UIViewRoot uiViewRoot)
+    {
+        wrappedFacesContext.setViewRoot(uiViewRoot);
+    }
+
+    public void addMessage(String s, FacesMessage facesMessage)
+    {
+        //TODO
+        wrappedFacesContext.addMessage(s, facesMessage);
+    }
+
+    public void release()
+    {
+        broadcastAfterFacesRequestEvent();
+        wrappedFacesContext.release();
+    }
+
+    public void renderResponse()
+    {
+        wrappedFacesContext.renderResponse();
+    }
+
+    public void responseComplete()
+    {
+        wrappedFacesContext.responseComplete();
+    }
+
+    private void initBroadcaster()
+    {
+        Set<? extends Bean> broadcasterBeans = this.beanManager.getBeans(BeforeAfterFacesRequestBroadcaster.class);
+
+        if(broadcasterBeans.size() != 1)
+        {
+            //TODO add an exception to the exception context
+            return;
+        }
+
+        CreationalContext<BeforeAfterFacesRequestBroadcaster> creationalContext;
+
+        for(Bean<BeforeAfterFacesRequestBroadcaster> requestHandlerBean : broadcasterBeans)
+        {
+            creationalContext = beanManager.createCreationalContext(requestHandlerBean);
+
+            this.beforeAfterFacesRequestBroadcaster = requestHandlerBean.create(creationalContext);
+        }
+    }
+}