You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2005/03/01 16:37:12 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/event EventDispatcher.java

luetzkendorf    2005/03/01 07:37:12

  Modified:    src/share/org/apache/slide/event EventDispatcher.java
  Log:
  Switched initialization order of events and listeners, so listeners can check
  whether required events are enabled.
  
  Revision  Changes    Path
  1.7       +26 -25    jakarta-slide/src/share/org/apache/slide/event/EventDispatcher.java
  
  Index: EventDispatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/event/EventDispatcher.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EventDispatcher.java	21 Feb 2005 08:58:51 -0000	1.6
  +++ EventDispatcher.java	1 Mar 2005 15:37:12 -0000	1.7
  @@ -75,6 +75,28 @@
       }
   
       public void configure(Configuration config) throws ConfigurationException {
  +        Enumeration enableConfigs = config.getConfigurations("event");
  +        while (enableConfigs.hasMoreElements()) {
  +            Configuration enableConfig = (Configuration)enableConfigs.nextElement();
  +            String classname = enableConfig.getAttribute("classname");
  +            String method = enableConfig.getAttribute("method", null);
  +            boolean enable = enableConfig.getAttributeAsBoolean("enable", true);
  +            try {
  +                Class eventClass = Class.forName(classname);
  +                Field methodsField = eventClass.getField("methods");
  +                AbstractEventMethod[] methods = (AbstractEventMethod [])methodsField.get(null);
  +                for ( int i = 0; i < methods.length; i++ ) {
  +                    if ( method == null || methods[i].getName().equals(method) ) {
  +                        methods[i].setEnabled(enable);
  +                    }
  +                }
  +            } catch (NoSuchFieldException e) {
  +                throw new ConfigurationException("Event '"+classname+"' does not provide the required static member 'methods'", config);
  +            } catch (Exception e) {
  +                throw new ConfigurationException("Event '"+classname+"' could not be loaded (" + e + ")", config);
  +            }
  +        }
  +        
           Enumeration listenerConfigs = config.getConfigurations("listener");
           while (listenerConfigs.hasMoreElements()) {
               Configuration listenerConfig = (Configuration)listenerConfigs.nextElement();
  @@ -106,26 +128,5 @@
                   throw new ConfigurationException("Event listener '"+classname+"' could not be loaded (" + e + ")", config);
               }
           }
  -        Enumeration enableConfigs = config.getConfigurations("event");
  -        while (enableConfigs.hasMoreElements()) {
  -            Configuration enableConfig = (Configuration)enableConfigs.nextElement();
  -            String classname = enableConfig.getAttribute("classname");
  -            String method = enableConfig.getAttribute("method", null);
  -            boolean enable = enableConfig.getAttributeAsBoolean("enable", true);
  -            try {
  -                Class eventClass = Class.forName(classname);
  -                Field methodsField = eventClass.getField("methods");
  -                AbstractEventMethod[] methods = (AbstractEventMethod [])methodsField.get(null);
  -                for ( int i = 0; i < methods.length; i++ ) {
  -                    if ( method == null || methods[i].getName().equals(method) ) {
  -                        methods[i].setEnabled(enable);
  -                    }
  -                }
  -            } catch (NoSuchFieldException e) {
  -                throw new ConfigurationException("Event '"+classname+"' does not provide the required static member 'methods'", config);
  -            } catch (Exception e) {
  -                throw new ConfigurationException("Event '"+classname+"' could not be loaded (" + e + ")", config);
  -            }
  -        }
       }
   }
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org