cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r327143 - in /cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event: ./ impl/ user/
Date Fri, 21 Oct 2005 10:12:59 GMT
Author: cziegeler
Date: Fri Oct 21 03:12:49 2005
New Revision: 327143

URL: http://svn.apache.org/viewcvs?rev=327143&view=rev
Log:
Events have now a lifetime of the session

Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/EventConverter.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventConverter.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserDidLoginEvent.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserEvent.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserIsAccessingEvent.java
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserWillLogoutEvent.java

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/EventConverter.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/EventConverter.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/EventConverter.java (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/EventConverter.java Fri
Oct 21 03:12:49 2005
@@ -16,7 +16,10 @@
 package org.apache.cocoon.portal.event;
 
 /**
- * Convert events from and into strings.
+ * This component converts {@link Event} objects from and into strings.
+ * If the event is a {@link ConvertableEvent} the event itself does the
+ * converting, if not it's up to the implementation of this component
+ * to do the conversion.
  *
  * @version $Id$
  */

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java
Fri Oct 21 03:12:49 2005
@@ -17,6 +17,7 @@
 
 import org.apache.cocoon.portal.aspect.Aspectalizable;
 import org.apache.cocoon.portal.event.ComparableEvent;
+import org.apache.commons.lang.ObjectUtils;
 
 /**
  * This events set the aspect data for an {@link Aspectalizable} object:
@@ -68,10 +69,33 @@
     public boolean equalsEvent(ComparableEvent event) {
         if ( event instanceof ChangeAspectDataEvent ) {
             ChangeAspectDataEvent other = (ChangeAspectDataEvent)event;
-            return (this.getTarget().equals(other.getTarget())
-                     && this.getAspectName().equals(other.getAspectName()));
+            return ObjectUtils.equals(this.getTarget(), other.getTarget())
+                   && ObjectUtils.equals(this.aspectName, other.aspectName);
         }
 
         return false;
     }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object obj) {
+        if ( obj instanceof ChangeAspectDataEvent ) {
+            final ChangeAspectDataEvent other = (ChangeAspectDataEvent)obj;
+            return ObjectUtils.equals(this.getTarget(), other.getTarget())
+                   && ObjectUtils.equals(this.aspectName, other.aspectName)
+                   && ObjectUtils.equals(this.data, other.data);
+        }
+        return false;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        return ObjectUtils.hashCode(this.getTarget())
+               + ObjectUtils.hashCode(this.aspectName)
+               + ObjectUtils.hashCode(this.data);
+    }
+
 }

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventConverter.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventConverter.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventConverter.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventConverter.java
Fri Oct 21 03:12:49 2005
@@ -35,6 +35,12 @@
 import org.apache.cocoon.util.HashUtil;
 
 /**
+ * This implementation stores the events that can't be converted to strings (which don't
+ * support the {@link org.apache.cocoon.portal.event.ConvertableEvent} interface) in
+ * the current user session. Each event is then converted to a string just containing
+ * the index of the event in this list. This list is cleared when the session is closed.
+ *
+ * TODO - What happens if two event classes have the same hash?
  *
  * @version $Id$
  */
@@ -42,10 +48,17 @@
     extends AbstractComponent
     implements EventConverter, Configurable {
 
-    protected static final String DECODE_LIST = DefaultEventConverter.class.getName() + "D";
-    protected static final String ENCODE_LIST = DefaultEventConverter.class.getName() + "E";
+    protected static final String EVENT_LIST = DefaultEventConverter.class.getName();
 
-    /** All factories mapped by a key. */
+    /** All factories mapped by a key.
+     * The key is either the hash if the class name or a configured mapping.
+     * If there is no configured mapping for an event class, the value
+     * is the constructor to construct the event.
+     * If there is a configured mapping, then this map contains two entries:
+     * The first entry has the hash of the class name as the key and the value
+     * is the configured mapping name. The second entry has the configured mapping
+     * name as the key and the Constructor as the value.
+     */
     protected Map factories = new HashMap();
 
     /**
@@ -99,15 +112,15 @@
             }
             return o.toString() + ':' + data;
         }
-        List list = (List)this.portalService.getAttribute(ENCODE_LIST);
+        List list = (List)this.portalService.getAttribute(EVENT_LIST);
         if ( null == list ) {
             list = new ArrayList();
-            this.portalService.setAttribute(ENCODE_LIST, list);
         }
         int index = list.indexOf(event);
         if ( index == -1 ) {
             list.add(event);
             index = list.size() - 1;
+            this.portalService.setAttribute(EVENT_LIST, list);
         }
         return String.valueOf(index);
     }
@@ -124,6 +137,9 @@
                 final String data = value.substring(pos+1);
                 Object o = this.factories.get(hashKey);
                 Constructor c;
+                // if the value is a constructor we simply use it
+                // if the value is a string we simply use this string
+                // to lookup the constructor (another lookup in the map).
                 if ( o instanceof Constructor) {
                     c = (Constructor)o;
                 } else {
@@ -141,7 +157,7 @@
                     }
                 }
             }
-            List list = (List)this.portalService.getAttribute(DECODE_LIST);
+            List list = (List)this.portalService.getAttribute(EVENT_LIST);
             if ( null != list ) {
                 int index = new Integer(value).intValue();
                 if (index < list.size()) {
@@ -156,17 +172,13 @@
      * @see org.apache.cocoon.portal.event.EventConverter#start()
      */
     public void start() {
-        List list = (List)this.portalService.getAttribute(ENCODE_LIST);
-        if ( null != list ) {
-            this.portalService.setAttribute(DECODE_LIST, list);
-            this.portalService.removeAttribute(ENCODE_LIST);
-        }
+        // nothing to do
     }
 
     /**
      * @see org.apache.cocoon.portal.event.EventConverter#finish()
      */
     public void finish() {
-        this.portalService.removeAttribute(DECODE_LIST);
+        // nothing to do
     }
 }

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserDidLoginEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserDidLoginEvent.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserDidLoginEvent.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserDidLoginEvent.java
Fri Oct 21 03:12:49 2005
@@ -23,14 +23,9 @@
  * @version $Id$
  * @since 2.2
  */
-public class UserDidLoginEvent implements UserEvent {
-
-    protected final PortalUser portalUser;
+public class UserDidLoginEvent extends UserEvent {
 
     public UserDidLoginEvent(PortalUser pu) {
-        this.portalUser = pu;
-    }
-    public PortalUser getPortalUser() {
-        return portalUser;
+        super(pu);
     }
 }

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserEvent.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserEvent.java (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserEvent.java Fri
Oct 21 03:12:49 2005
@@ -15,7 +15,7 @@
  */
 package org.apache.cocoon.portal.event.user;
 
-import org.apache.cocoon.portal.event.Event;
+import org.apache.cocoon.portal.event.ActionEvent;
 import org.apache.cocoon.portal.profile.PortalUser;
 
 /**
@@ -24,7 +24,23 @@
  * @version $Id$
  * @since 2.2
  */
-public interface UserEvent extends Event {
+public abstract class UserEvent implements ActionEvent {
+
+    protected PortalUser portalUser;
+
+    public UserEvent(PortalUser user) {
+        this.portalUser = user;
+    }
+
+    public PortalUser getPortalUser() {
+        return this.portalUser;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.event.ActionEvent#getTarget()
+     */
+    public Object getTarget() {
+        return this.getPortalUser();
+    }
 
-    PortalUser getPortalUser();
 }

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserIsAccessingEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserIsAccessingEvent.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserIsAccessingEvent.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserIsAccessingEvent.java
Fri Oct 21 03:12:49 2005
@@ -23,14 +23,9 @@
  * @version $Id$
  * @since 2.2
  */
-public class UserIsAccessingEvent implements UserEvent {
-
-    protected final PortalUser portalUser;
+public class UserIsAccessingEvent extends UserEvent {
 
     public UserIsAccessingEvent(PortalUser pu) {
-        this.portalUser = pu;
-    }
-    public PortalUser getPortalUser() {
-        return portalUser;
+        super(pu);
     }
 }

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserWillLogoutEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserWillLogoutEvent.java?rev=327143&r1=327142&r2=327143&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserWillLogoutEvent.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/user/UserWillLogoutEvent.java
Fri Oct 21 03:12:49 2005
@@ -25,14 +25,9 @@
  * @version $Id$
  * @since 2.2
  */
-public class UserWillLogoutEvent implements UserEvent {
-
-    protected final PortalUser portalUser;
+public class UserWillLogoutEvent extends UserEvent {
 
     public UserWillLogoutEvent(PortalUser pu) {
-        this.portalUser = pu;
-    }
-    public PortalUser getPortalUser() {
-        return portalUser;
+        super(pu);
     }
 }



Mime
View raw message