cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r312478 - /cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java
Date Sun, 09 Oct 2005 17:14:53 GMT
Author: cziegeler
Date: Sun Oct  9 10:14:27 2005
New Revision: 312478

URL: http://svn.apache.org/viewcvs?rev=312478&view=rev
Log:
Start reflection based registering of event receivers (not finished yet)

Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java?rev=312478&r1=312477&r2=312478&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java
Sun Oct  9 10:14:27 2005
@@ -53,7 +53,7 @@
  * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
  * 
- * @version CVS $Id$
+ * @version $Id$
  */
 public class DefaultEventManager 
     extends AbstractLogEnabled
@@ -64,9 +64,6 @@
                 Configurable,
                 Disposable,
                 Contextualizable {
-                    
-    private final String rootEventType = Event.class.getName();
-    private Class eventClass;
 
     /** The list of all receivers */
     private Map receivers = new HashMap();
@@ -92,6 +89,9 @@
     /** Additional receivers if we are currenlty sending events. */
     protected List additionalReceiverClasses = new ArrayList();
 
+    /** Map of all event classes and their corresponding receivers. */
+    protected Map eventHierarchy = new HashMap();
+
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
@@ -136,10 +136,8 @@
      */
     public void initialize()
     throws Exception {
-        this.eventClass = Class.forName( rootEventType );
-        if ( this.getLogger().isDebugEnabled() ) {
-            this.getLogger().debug("Initialising eventClass " + eventClass);
-        }
+        // create tree of all Events
+        //this.getHierarchyInfo(Event.class);
 
         // subscribe all configured receiver roles
         Configuration roles = this.configuration.getChild("receiver-roles", false);
@@ -291,11 +289,13 @@
                     final Class[] params = current.getParameterTypes();
                     if ( params.length == 2 
                          && params[1].getName().equals(PortalService.class.getName()))
{
-                        if ( eventClass.isAssignableFrom( params[0] ) ) {
+                        if ( Event.class.isAssignableFrom( params[0] ) ) {
                             MethodInfo info = new MethodInfo();
                             info.eventClass = params[0];
                             info.method = current;
                             result.add(info);
+                            //HierarchyInfo hi = this.getHierarchyInfo(info.eventClass);
+                            //this.print(hi);
                         }
                     }
                 }
@@ -347,4 +347,81 @@
         this.receivers.remove(receiver);
     }
 
+    /**
+     * Create a hierarchy information.
+     */
+    protected HierarchyInfo getHierarchyInfo(Class c) {
+        HierarchyInfo info = (HierarchyInfo) this.eventHierarchy.get(c.getName());
+        if ( info == null ) {
+            info = new HierarchyInfo(c.getName());
+            this.eventHierarchy.put(c.getName(), info);
+            final Class parent = c.getSuperclass();
+            this.addToHierarchy(info, parent);
+            Class[] interfaces = c.getInterfaces();
+            for (int i=0; i<interfaces.length; i++) {
+                if ( parent == null || !interfaces[i].isAssignableFrom(parent) ) {
+                    this.addToHierarchy(info, interfaces[i]);
+                }
+            }
+        }
+        return info;
+    }
+
+    protected void print(HierarchyInfo info) {
+        if ( info.className.equals(Event.class.getName())) return;
+        System.out.println("-------------------------------- " + info.className);
+        if ( info.getParents() == null ) return;
+        System.out.println("Parents: ");
+        Iterator i = info.getParents().iterator();
+        while ( i.hasNext() ) {
+            HierarchyInfo c = (HierarchyInfo)i.next();
+            System.out.println("  " + c.className);
+        }
+        System.out.println("===============================================================");
+        System.out.println();
+        i = info.getParents().iterator();
+        while ( i.hasNext() ) {
+            HierarchyInfo c = (HierarchyInfo)i.next();
+            this.print(c);
+        }
+    }
+    protected void addToHierarchy(HierarchyInfo info, Class c) {
+        if ( c != null && Event.class.isAssignableFrom(c) ) {
+            info.addToParents(this.getHierarchyInfo(c));
+        }
+    }
+    protected static final class HierarchyInfo {
+
+        protected final String className;
+        protected List receivers;
+        protected List parents;
+
+        public HierarchyInfo(String className) {
+            this.className = className;
+        }
+
+        public synchronized void addToReceivers(Receiver r) {
+            if ( this.receivers == null ) {
+                this.receivers = new ArrayList();
+            }
+            this.receivers.add(r);
+        }
+
+        public synchronized void addToParents(HierarchyInfo i) {
+            if ( this.parents == null ) {
+                this.parents = new ArrayList();
+            }
+            if ( !this.parents.contains(i) ) {
+                this.parents.add(i);
+            }
+        }
+
+        public List getReceivers() {
+            return this.receivers;
+        }
+
+        public List getParents() {
+            return this.parents;
+        }
+    }
 }



Mime
View raw message