Author: julien(a)jboss.com
Date: 2007-04-30 05:31:30 -0400 (Mon, 30 Apr 2007)
New Revision: 7140
Added:
trunk/core/src/main/org/jboss/portal/core/impl/api/event/ServletEventBridge.java
Removed:
trunk/core/src/main/org/jboss/portal/core/impl/api/event/EventBridge.java
Modified:
trunk/core/src/resources/portal-server-war/WEB-INF/web.xml
Log:
renamed EventBridge to ServletEventBridge as we bridge servlet events to portal events
Deleted: trunk/core/src/main/org/jboss/portal/core/impl/api/event/EventBridge.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/api/event/EventBridge.java 2007-04-30
09:25:49 UTC (rev 7139)
+++ trunk/core/src/main/org/jboss/portal/core/impl/api/event/EventBridge.java 2007-04-30
09:31:30 UTC (rev 7140)
@@ -1,145 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.impl.api.event;
-
-import org.jboss.mx.util.MBeanProxy;
-import org.jboss.mx.util.MBeanProxyCreationException;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.mx.util.ObjectNameFactory;
-import org.jboss.portal.api.event.PortalEvent;
-import org.jboss.portal.api.event.PortalEventContext;
-import org.jboss.portal.api.event.PortalEventListener;
-import org.jboss.portal.api.user.event.UserAuthenticationEvent;
-import org.jboss.portal.api.session.event.PortalSessionEvent;
-import org.jboss.portal.core.event.PortalEventListenerRegistry;
-import org.jboss.portal.core.impl.api.PortalRuntimeContextImpl;
-import org.jboss.portal.core.impl.api.event.PortalEventContextImpl;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
-import java.util.Iterator;
-
-/**
- * Bridge
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class EventBridge implements HttpSessionListener, ServletContextListener,
HttpSessionAttributeListener
-{
-
- /** . */
- private PortalEventListenerRegistry listenerRegistry;
-
- // ServletContextListener implementation
****************************************************************************
-
- public void contextInitialized(ServletContextEvent event)
- {
- try
- {
- listenerRegistry =
(PortalEventListenerRegistry)MBeanProxy.get(PortalEventListenerRegistry.class,
ObjectNameFactory.create("portal:service=ListenerRegistry"),
MBeanServerLocator.locateJBoss());
- }
- catch (MBeanProxyCreationException e)
- {
- e.printStackTrace();
- }
- }
-
- public void contextDestroyed(ServletContextEvent event)
- {
- listenerRegistry = null;
- }
-
- // HttpSessionListener implementation
*******************************************************************************
-
- public void sessionCreated(HttpSessionEvent event)
- {
- PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession());
- PortalEventContextImpl uec = new PortalEventContextImpl(rt);
- PortalSessionEvent use = new
PortalSessionEvent(PortalSessionEvent.SESSION_CREATED);
- fireEvent(uec, use);
- }
-
- public void sessionDestroyed(HttpSessionEvent event)
- {
- PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession());
- PortalEventContextImpl uec = new PortalEventContextImpl(rt);
- PortalSessionEvent use = new
PortalSessionEvent(PortalSessionEvent.SESSION_DESTROYED);
- fireEvent(uec, use);
- }
-
- // HttpSessionAttributeListener implementation
**********************************************************************
-
-
- public void attributeAdded(HttpSessionBindingEvent event)
- {
- if ("PRINCIPAL_TOKEN".equals(event.getName()))
- {
- String userId = (String)event.getValue();
- PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession(),
userId);
- PortalEventContextImpl uec = new PortalEventContextImpl(rt);
- UserAuthenticationEvent uae = new UserAuthenticationEvent(userId,
UserAuthenticationEvent.SIGN_IN);
- fireEvent(uec, uae);
- }
- }
-
- public void attributeRemoved(HttpSessionBindingEvent event)
- {
- if ("PRINCIPAL_TOKEN".equals(event.getName()))
- {
- String userId = (String)event.getValue();
- PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession(),
userId);
- PortalEventContextImpl uec = new PortalEventContextImpl(rt);
- UserAuthenticationEvent uae = new UserAuthenticationEvent(userId,
UserAuthenticationEvent.SIGN_OUT);
- fireEvent(uec, uae);
- }
- }
-
- public void attributeReplaced(HttpSessionBindingEvent event)
- {
- }
-
- private void fireEvent(PortalEventContext eventContext, PortalEvent event)
- {
- for (Iterator i = listenerRegistry.getListeners().iterator(); i.hasNext();)
- {
- Object o = i.next();
- if (o instanceof PortalEventListener)
- {
- PortalEventListener listener = (PortalEventListener)o;
- try
- {
- listener.onEvent(eventContext, event);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- }
-}
Copied: trunk/core/src/main/org/jboss/portal/core/impl/api/event/ServletEventBridge.java
(from rev 7134,
trunk/core/src/main/org/jboss/portal/core/impl/api/event/EventBridge.java)
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/api/event/ServletEventBridge.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/impl/api/event/ServletEventBridge.java 2007-04-30
09:31:30 UTC (rev 7140)
@@ -0,0 +1,145 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.impl.api.event;
+
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanProxyCreationException;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.portal.api.event.PortalEvent;
+import org.jboss.portal.api.event.PortalEventContext;
+import org.jboss.portal.api.event.PortalEventListener;
+import org.jboss.portal.api.user.event.UserAuthenticationEvent;
+import org.jboss.portal.api.session.event.PortalSessionEvent;
+import org.jboss.portal.core.event.PortalEventListenerRegistry;
+import org.jboss.portal.core.impl.api.PortalRuntimeContextImpl;
+import org.jboss.portal.core.impl.api.event.PortalEventContextImpl;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import java.util.Iterator;
+
+/**
+ * Bridge servlet event to portal events.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServletEventBridge implements HttpSessionListener, ServletContextListener,
HttpSessionAttributeListener
+{
+
+ /** . */
+ private PortalEventListenerRegistry listenerRegistry;
+
+ // ServletContextListener implementation
****************************************************************************
+
+ public void contextInitialized(ServletContextEvent event)
+ {
+ try
+ {
+ listenerRegistry =
(PortalEventListenerRegistry)MBeanProxy.get(PortalEventListenerRegistry.class,
ObjectNameFactory.create("portal:service=ListenerRegistry"),
MBeanServerLocator.locateJBoss());
+ }
+ catch (MBeanProxyCreationException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent event)
+ {
+ listenerRegistry = null;
+ }
+
+ // HttpSessionListener implementation
*******************************************************************************
+
+ public void sessionCreated(HttpSessionEvent event)
+ {
+ PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession());
+ PortalEventContextImpl uec = new PortalEventContextImpl(rt);
+ PortalSessionEvent use = new
PortalSessionEvent(PortalSessionEvent.SESSION_CREATED);
+ fireEvent(uec, use);
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event)
+ {
+ PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession());
+ PortalEventContextImpl uec = new PortalEventContextImpl(rt);
+ PortalSessionEvent use = new
PortalSessionEvent(PortalSessionEvent.SESSION_DESTROYED);
+ fireEvent(uec, use);
+ }
+
+ // HttpSessionAttributeListener implementation
**********************************************************************
+
+
+ public void attributeAdded(HttpSessionBindingEvent event)
+ {
+ if ("PRINCIPAL_TOKEN".equals(event.getName()))
+ {
+ String userId = (String)event.getValue();
+ PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession(),
userId);
+ PortalEventContextImpl uec = new PortalEventContextImpl(rt);
+ UserAuthenticationEvent uae = new UserAuthenticationEvent(userId,
UserAuthenticationEvent.SIGN_IN);
+ fireEvent(uec, uae);
+ }
+ }
+
+ public void attributeRemoved(HttpSessionBindingEvent event)
+ {
+ if ("PRINCIPAL_TOKEN".equals(event.getName()))
+ {
+ String userId = (String)event.getValue();
+ PortalRuntimeContextImpl rt = new PortalRuntimeContextImpl(event.getSession(),
userId);
+ PortalEventContextImpl uec = new PortalEventContextImpl(rt);
+ UserAuthenticationEvent uae = new UserAuthenticationEvent(userId,
UserAuthenticationEvent.SIGN_OUT);
+ fireEvent(uec, uae);
+ }
+ }
+
+ public void attributeReplaced(HttpSessionBindingEvent event)
+ {
+ }
+
+ private void fireEvent(PortalEventContext eventContext, PortalEvent event)
+ {
+ for (Iterator i = listenerRegistry.getListeners().iterator(); i.hasNext();)
+ {
+ Object o = i.next();
+ if (o instanceof PortalEventListener)
+ {
+ PortalEventListener listener = (PortalEventListener)o;
+ try
+ {
+ listener.onEvent(eventContext, event);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
Modified: trunk/core/src/resources/portal-server-war/WEB-INF/web.xml
===================================================================
--- trunk/core/src/resources/portal-server-war/WEB-INF/web.xml 2007-04-30 09:25:49 UTC
(rev 7139)
+++ trunk/core/src/resources/portal-server-war/WEB-INF/web.xml 2007-04-30 09:31:30 UTC
(rev 7140)
@@ -33,7 +33,7 @@
<!-- Bridge portal user events -->
<listener>
-
<listener-class>org.jboss.portal.core.impl.api.event.EventBridge</listener-class>
+
<listener-class>org.jboss.portal.core.impl.api.event.ServletEventBridgetBridge</listener-class>
</listener>
<!-- The portal servlet is the main entrance point -->