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/12/30 19:20:43 UTC

svn commit: r1053961 - in /myfaces/extensions/cdi/trunk: core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/ core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/ examples/jsf-examples/hello_myfaces-cod...

Author: gpetracek
Date: Thu Dec 30 18:20:43 2010
New Revision: 1053961

URL: http://svn.apache.org/viewvc?rev=1053961&view=rev
Log:
EXTCDI-112 first draft

Added:
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/StartupEvent.java
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/listener/startup/
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/listener/startup/StartupObserver.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/ApplicationStartupBroadcaster.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/JsfStartupEvent.java
Modified:
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/WEB-INF/web.xml
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/phase/CodiLifecycleWrapper.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/phase/CodiLifecycleWrapper.java

Added: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/StartupEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/StartupEvent.java?rev=1053961&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/StartupEvent.java (added)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/event/StartupEvent.java Thu Dec 30 18:20:43 2010
@@ -0,0 +1,30 @@
+/*
+ * 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.core.api.startup.event;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface StartupEvent
+{
+    Map<String, Serializable> getApplicationProperties();
+}

Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/listener/startup/StartupObserver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/listener/startup/StartupObserver.java?rev=1053961&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/listener/startup/StartupObserver.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/listener/startup/StartupObserver.java Thu Dec 30 18:20:43 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.examples.codi.jsf12.listener.startup;
+
+import org.apache.myfaces.extensions.cdi.core.api.logging.Logger;
+import org.apache.myfaces.extensions.cdi.core.api.startup.event.StartupEvent;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+@ApplicationScoped
+public class StartupObserver
+{
+    @Inject
+    private Logger logger;
+
+    protected void logApplicationProperties(@Observes StartupEvent startupEvent)
+    {
+        for(Map.Entry<String, Serializable> property : startupEvent.getApplicationProperties().entrySet())
+        {
+            this.logger.info("key: " + property.getKey() + " value: " + property.getValue());
+        }
+    }
+}

Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/WEB-INF/web.xml?rev=1053961&r1=1053960&r2=1053961&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/WEB-INF/web.xml Thu Dec 30 18:20:43 2010
@@ -25,6 +25,12 @@
 
     <description>Hello MyFaces CODI JSF 1.2</description>
 
+    <context-param>
+        <description>This parameter is just a demo parameter used by the StartupObserver</description>
+        <param-name>demoName</param-name>
+        <param-value>MyFaces CODI JSF 1.2 Demo</param-value>
+    </context-param>
+
     <listener>
         <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
     </listener>

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/phase/CodiLifecycleWrapper.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/listener/phase/CodiLifecycleWrapper.java?rev=1053961&r1=1053960&r2=1053961&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/phase/CodiLifecycleWrapper.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/phase/CodiLifecycleWrapper.java Thu Dec 30 18:20:43 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.extensions.cd
 
 import org.apache.myfaces.extensions.cdi.core.impl.util.ClassDeactivation;
 import org.apache.myfaces.extensions.cdi.jsf.impl.listener.request.BeforeAfterFacesRequestBroadcaster;
+import org.apache.myfaces.extensions.cdi.jsf.impl.listener.startup.ApplicationStartupBroadcaster;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.WindowHandler;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.LifecycleAwareWindowHandler;
 import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
@@ -44,6 +45,8 @@ class CodiLifecycleWrapper extends Lifec
 
     private Boolean initialized;
 
+    private Boolean applicationInitialized;
+
     CodiLifecycleWrapper(Lifecycle wrapped, List<PhaseListener> phaseListeners)
     {
         this.wrapped = wrapped;
@@ -62,6 +65,7 @@ class CodiLifecycleWrapper extends Lifec
     public void execute(FacesContext facesContext)
             throws FacesException
     {
+        broadcastApplicationStartupBroadcaster();
         broadcastBeforeFacesRequestEvent(facesContext);
 
         WindowHandler windowHandler = CodiUtils.getContextualReferenceByClass(WindowHandler.class);
@@ -95,6 +99,18 @@ class CodiLifecycleWrapper extends Lifec
         wrapped.render(facesContext);
     }
 
+    private void broadcastApplicationStartupBroadcaster()
+    {
+        //just an !additional! check to improve the performance
+        if(applicationInitialized == null)
+        {
+            applicationInitialized = true;
+            ApplicationStartupBroadcaster applicationStartupBroadcaster =
+                    CodiUtils.getContextualReferenceByClass(ApplicationStartupBroadcaster.class);
+            applicationStartupBroadcaster.broadcastStartupEvent();
+        }
+    }
+
     private void broadcastBeforeFacesRequestEvent(FacesContext facesContext)
     {
         lazyInit();

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/ApplicationStartupBroadcaster.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/listener/startup/ApplicationStartupBroadcaster.java?rev=1053961&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/ApplicationStartupBroadcaster.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/ApplicationStartupBroadcaster.java Thu Dec 30 18:20:43 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.jsf.impl.listener.startup;
+
+import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.faces.context.FacesContext;
+import javax.inject.Inject;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Gerhard Petracek
+ */
+@ApplicationScoped
+public class ApplicationStartupBroadcaster
+{
+    private static Map<ClassLoader, Boolean> initialized =
+            new ConcurrentHashMap<ClassLoader, Boolean>();
+
+    @Inject
+    private Event<JsfStartupEvent> applicationStartupEvent;
+
+    public void broadcastStartupEvent()
+    {
+        if(initialized.containsKey(getClassLoader()))
+        {
+            return;
+        }
+
+        //noinspection SynchronizeOnNonFinalField
+        synchronized (initialized)
+        {
+            // switch into paranoia mode
+            if(initialized.containsKey(getClassLoader()))
+            {
+                return;
+            }
+
+            initialized.put(getClassLoader(), Boolean.TRUE);
+        }
+
+        this.applicationStartupEvent.fire(new JsfStartupEvent(FacesContext.getCurrentInstance()));
+    }
+
+    private ClassLoader getClassLoader()
+    {
+        return ClassUtils.getClassLoader(null);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/JsfStartupEvent.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/listener/startup/JsfStartupEvent.java?rev=1053961&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/JsfStartupEvent.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/listener/startup/JsfStartupEvent.java Thu Dec 30 18:20:43 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.listener.startup;
+
+import org.apache.myfaces.extensions.cdi.core.api.startup.event.StartupEvent;
+
+import javax.faces.context.FacesContext;
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+class JsfStartupEvent implements StartupEvent
+{
+    private FacesContext facesContext;
+
+    JsfStartupEvent(FacesContext facesContext)
+    {
+        this.facesContext = facesContext;
+    }
+
+    public Map<String, Serializable> getApplicationProperties()
+    {
+        return this.facesContext.getExternalContext().getInitParameterMap();
+    }
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/phase/CodiLifecycleWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/phase/CodiLifecycleWrapper.java?rev=1053961&r1=1053960&r2=1053961&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/phase/CodiLifecycleWrapper.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/phase/CodiLifecycleWrapper.java Thu Dec 30 18:20:43 2010
@@ -21,6 +21,7 @@ package org.apache.myfaces.extensions.cd
 import org.apache.myfaces.extensions.cdi.core.impl.util.ClassDeactivation;
 import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
 import org.apache.myfaces.extensions.cdi.jsf.impl.listener.request.BeforeAfterFacesRequestBroadcaster;
+import org.apache.myfaces.extensions.cdi.jsf.impl.listener.startup.ApplicationStartupBroadcaster;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.WindowHandler;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.LifecycleAwareWindowHandler;
 
@@ -44,6 +45,8 @@ class CodiLifecycleWrapper extends Lifec
 
     private Boolean initialized;
 
+    private Boolean applicationInitialized;
+
     CodiLifecycleWrapper(Lifecycle wrapped, List<PhaseListener> phaseListeners)
     {
         this.wrapped = wrapped;
@@ -62,6 +65,7 @@ class CodiLifecycleWrapper extends Lifec
     public void execute(FacesContext facesContext)
             throws FacesException
     {
+        broadcastApplicationStartupBroadcaster();
         broadcastBeforeFacesRequestEvent(facesContext);
 
         WindowHandler windowHandler = CodiUtils.getContextualReferenceByClass(WindowHandler.class);
@@ -95,6 +99,18 @@ class CodiLifecycleWrapper extends Lifec
         wrapped.render(facesContext);
     }
 
+    private void broadcastApplicationStartupBroadcaster()
+    {
+        //just an !additional! check to improve the performance
+        if(applicationInitialized == null)
+        {
+            applicationInitialized = true;
+            ApplicationStartupBroadcaster applicationStartupBroadcaster =
+                    CodiUtils.getContextualReferenceByClass(ApplicationStartupBroadcaster.class);
+            applicationStartupBroadcaster.broadcastStartupEvent();
+        }
+    }
+
     private void broadcastBeforeFacesRequestEvent(FacesContext facesContext)
     {
         lazyInit();