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/09/22 19:39:04 UTC

svn commit: r1000102 - in /myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main: java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/ resources/META-INF/

Author: gpetracek
Date: Wed Sep 22 17:39:03 2010
New Revision: 1000102

URL: http://svn.apache.org/viewvc?rev=1000102&view=rev
Log:
EXTCDI-61 support for PostConstructApplicationEvent

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/CodiStartupListener.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/SystemEventBroadcaster.java
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/CodiStartupListener.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/system/CodiStartupListener.java?rev=1000102&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/CodiStartupListener.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/CodiStartupListener.java Wed Sep 22 17:39:03 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.jsf2.impl.listener.system;
+
+import static org.apache.myfaces.extensions.cdi.core.impl.utils.CodiUtils.getOrCreateScopedInstanceOfBeanByName;
+
+import javax.faces.event.SystemEventListener;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.application.Application;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class CodiStartupListener implements SystemEventListener
+{
+    public boolean isListenerForSource(Object source)
+    {
+        return source instanceof Application;
+    }
+
+    public void processEvent(SystemEvent systemEvent)
+    {
+        if(systemEvent instanceof PostConstructApplicationEvent)
+        {
+            resolveBroadcaster().broadcastApplicationStartupEvent((PostConstructApplicationEvent)systemEvent);
+        }
+        else
+        {
+            resolveBroadcaster().logError(systemEvent);
+        }
+    }
+
+    private SystemEventBroadcaster resolveBroadcaster()
+    {
+        //cdi has to inject the event
+        return getOrCreateScopedInstanceOfBeanByName(SystemEventBroadcaster.BEAN_NAME, SystemEventBroadcaster.class);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/SystemEventBroadcaster.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/system/SystemEventBroadcaster.java?rev=1000102&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/SystemEventBroadcaster.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/system/SystemEventBroadcaster.java Wed Sep 22 17:39:03 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.jsf2.impl.listener.system;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.enterprise.event.Event;
+import javax.enterprise.context.Dependent;
+import java.util.logging.Logger;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Dependent
+@Named
+public class SystemEventBroadcaster
+{
+    static final String BEAN_NAME = "systemEventBroadcaster";
+
+    private final Logger logger = Logger.getLogger(SystemEventBroadcaster.class.getName());
+
+    @Inject
+    private Event<PostConstructApplicationEvent> postConstructApplicationEventEvent;
+
+    @Inject
+    private ProjectStage projectStage;
+
+    protected SystemEventBroadcaster()
+    {
+    }
+
+    void broadcastApplicationStartupEvent(PostConstructApplicationEvent postConstructApplicationEvent)
+    {
+        this.postConstructApplicationEventEvent.fire(postConstructApplicationEvent);
+    }
+
+    void logError(SystemEvent systemEvent)
+    {
+        if(ProjectStage.Development.equals(this.projectStage))
+        {
+            String messageText = "failed to fire " + PostConstructApplicationEvent.class.getName();
+
+            if(systemEvent == null)
+            {
+                this.logger.severe(messageText + " - the event is null.");
+            }
+            else
+            {
+                this.logger.severe(messageText + " - the event is of type: " + systemEvent.getClass().getName());
+            }
+        }
+    }
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml?rev=1000102&r1=1000101&r2=1000102&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml Wed Sep 22 17:39:03 2010
@@ -28,6 +28,11 @@
         <navigation-handler>org.apache.myfaces.extensions.cdi.jsf2.impl.scope.conversation.AccessScopeAwareNavigationHandler</navigation-handler>
 
         <view-handler>org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.WindowContextAwareViewHandler</view-handler>
+
+        <system-event-listener>
+            <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
+            <system-event-listener-class>org.apache.myfaces.extensions.cdi.jsf2.impl.listener.system.CodiStartupListener</system-event-listener-class>
+        </system-event-listener>
     </application>
 
     <factory>