Source Code Cross Referenced for EventFirer.java in  » Web-Framework » RSF » uk » org » ponder » event » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » RSF » uk.org.ponder.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        package uk.org.ponder.event;
02:
03:        import uk.org.ponder.arrayutil.ArrayUtil;
04:        import uk.org.ponder.util.AssertionException;
05:        import uk.org.ponder.util.Logger;
06:
07:        import java.util.ArrayList;
08:
09:        ///  Event handling
10:
11:        /**
12:         * @package <numode.event The package event contains the tag interface EventTag,
13:         * which is implemented
14:         * by all event classes. The interface Listener has to be implemented by classes
15:         * wishing to receive events. An object of the class EventFirer is responsible
16:         * for managing Listeners and firing events.
17:         */
18:
19:        /** An object of the class EventFirer is responsible for managing Listeners registered
20:         * to receive events and to fire events on demand. Upon construction, the object
21:         * receives information about which classes of events will be fired. For each class,
22:         * it manages an ArrayList of Listeners. 
23:         */
24:
25:        public class EventFirer {
26:            /// An array of ArrayLists containing the Listeners registered to receive events.
27:            private ArrayList[] listenervectors;
28:
29:            /// The array of event classes handled by this firer.
30:            private Class[] registeredclasses;
31:
32:            /// Constructs an EventFirer with the specified classes of events to be fired.
33:            public EventFirer(Class[] classvector) {
34:                registeredclasses = classvector;
35:                listenervectors = new ArrayList[classvector.length];
36:                for (int i = 0; i < classvector.length; ++i) {
37:                    listenervectors[i] = new ArrayList();
38:                }
39:            }
40:
41:            public EventFirer(Class clazz) {
42:                this (new Class[] { clazz });
43:            }
44:
45:            public void addListener(Class[] eventclasses, Listener listener) {
46:                for (int i = 0; i < eventclasses.length; ++i) {
47:                    addListener(eventclasses[i], listener);
48:                }
49:            }
50:
51:            /// Register a Listener to receive events of the specified class
52:            public void addListener(Class eventclass, Listener listener) {
53:                if (listener == null) {
54:                    throw new AssertionException(
55:                            "Null listener added to EventFirer for class "
56:                                    + eventclass);
57:                }
58:                int classindex = ArrayUtil.indexOf(registeredclasses,
59:                        eventclass);
60:                if (classindex != -1) {
61:                    ArrayList listeners = listenervectors[classindex];
62:                    listeners.add(listener);
63:                } else {
64:                    throw new AssertionException("Unknown event class "
65:                            + eventclass + " added to EventFirer");
66:                }
67:            }
68:
69:            /// Unregister a Listener from receiving events of the specified class
70:            public void removeListener(Class eventclass, Listener listener) {
71:                int classindex = ArrayUtil.indexOf(registeredclasses,
72:                        eventclass);
73:                if (classindex != -1) {
74:                    ArrayList listeners = listenervectors[classindex];
75:                    listeners.remove(listener);
76:                }
77:            }
78:
79:            /// Fire the supplied event object to any registered listeners. The listeners are chosen based on the class of the supplied object.
80:
81:            public void fireEvent(EventTag tofire) {
82:                for (int classindex = 0; classindex < registeredclasses.length; ++classindex) {
83:                    if (registeredclasses[classindex].isInstance(tofire)) {
84:                        ArrayList listeners = listenervectors[classindex];
85:                        for (int i = listeners.size() - 1; i >= 0; --i) {
86:                            try {
87:                                ((Listener) listeners.get(i))
88:                                        .receiveEvent(tofire);
89:                            } catch (Throwable t) {
90:                                Logger.log.warn("Error propagating event", t);
91:                            }
92:                        }
93:                    }
94:                }
95:            }
96:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.