Source Code Cross Referenced for EventRouter.java in  » Web-Framework » Millstone » org » millstone » base » 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 » Millstone » org.millstone.base.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* *************************************************************************
002:         
003:                                        Millstone(TM) 
004:                           Open Sourced User Interface Library for
005:                               Internet Development with Java
006:
007:                     Millstone is a registered trademark of IT Mill Ltd
008:                          Copyright (C) 2000-2005 IT Mill Ltd
009:                             
010:         *************************************************************************
011:
012:           This library is free software; you can redistribute it and/or
013:           modify it under the terms of the GNU Lesser General Public
014:           license version 2.1 as published by the Free Software Foundation.
015:
016:           This library is distributed in the hope that it will be useful,
017:           but WITHOUT ANY WARRANTY; without even the implied warranty of
018:           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:           Lesser General Public License for more details.
020:
021:           You should have received a copy of the GNU Lesser General Public
022:           License along with this library; if not, write to the Free Software
023:           Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024:
025:         *************************************************************************
026:           
027:           For more information, contact:
028:           
029:           IT Mill Ltd                           phone: +358 2 4802 7180
030:           Ruukinkatu 2-4                        fax:  +358 2 4802 7181
031:           20540, Turku                          email: info@itmill.com
032:           Finland                               company www: www.itmill.com
033:           
034:           Primary source for MillStone information and releases: www.millstone.org
035:
036:         ********************************************************************** */
037:
038:        package org.millstone.base.event;
039:
040:        import java.util.EventObject;
041:        import java.util.LinkedList;
042:        import java.util.Iterator;
043:        import java.lang.reflect.Method;
044:
045:        /** Event router class implementing the MillStone inheritable event
046:         * listening model. For more information on the event model see the
047:         * {@link org.millstone.base.event package documentation}.
048:         *
049:         * @author IT Mill Ltd.
050:         * @version 3.1.1
051:         * @since 3.0
052:         */
053:        public class EventRouter implements  MethodEventSource {
054:
055:            /** List of registered listeners. */
056:            private LinkedList listenerList = null;
057:
058:            /* Registers a new listener with the specified activation method to
059:             * listen events generated by this component.
060:             * Don't add a JavaDoc comment here, we use the default documentation
061:             * from implemented interface.
062:             */
063:            public void addListener(Class eventType, Object object,
064:                    Method method) {
065:
066:                if (listenerList == null)
067:                    listenerList = new LinkedList();
068:
069:                listenerList.add(new ListenerMethod(eventType, object, method));
070:            }
071:
072:            /* Registers a new listener with the specified named activation method
073:             * to listen events generated by this component.
074:             * Don't add a JavaDoc comment here, we use the default documentation
075:             * from implemented interface.
076:             */
077:            public void addListener(Class eventType, Object object,
078:                    String methodName) {
079:
080:                if (listenerList == null)
081:                    listenerList = new LinkedList();
082:
083:                listenerList.add(new ListenerMethod(eventType, object,
084:                        methodName));
085:            }
086:
087:            /* Removes all registered listeners matching the given parameters.
088:             * Don't add a JavaDoc comment here, we use the default documentation
089:             * from implemented interface.
090:             */
091:            public void removeListener(Class eventType, Object target) {
092:
093:                if (listenerList != null) {
094:                    Iterator i = listenerList.iterator();
095:                    while (i.hasNext()) {
096:                        try {
097:                            ListenerMethod lm = (ListenerMethod) i.next();
098:                            if (lm.matches(eventType, target))
099:                                i.remove();
100:                        } catch (java.lang.ClassCastException e) {
101:                            // Class cast exceptions are ignored
102:                        }
103:                    }
104:                }
105:            }
106:
107:            /* Removes the event listener methods matching the given given
108:             * paramaters.
109:             * Don't add a JavaDoc comment here, we use the default documentation
110:             * from implemented interface.
111:             */
112:            public void removeListener(Class eventType, Object target,
113:                    Method method) {
114:
115:                if (listenerList != null) {
116:                    Iterator i = listenerList.iterator();
117:                    while (i.hasNext()) {
118:                        try {
119:                            ListenerMethod lm = (ListenerMethod) i.next();
120:                            if (lm.matches(eventType, target, method))
121:                                i.remove();
122:                        } catch (java.lang.ClassCastException e) {
123:                            // Class cast exceptions are ignored
124:                        }
125:                    }
126:                }
127:            }
128:
129:            /* Removes the event listener method matching the given given
130:             * paramaters.
131:             * Don't add a JavaDoc comment here, we use the default documentation
132:             * from implemented interface.
133:             */
134:            public void removeListener(Class eventType, Object target,
135:                    String methodName) {
136:
137:                // Find the correct method
138:                Method[] methods = target.getClass().getMethods();
139:                Method method = null;
140:                for (int i = 0; i < methods.length; i++)
141:                    if (methods[i].getName().equals(methodName))
142:                        method = methods[i];
143:                if (method == null)
144:                    throw new IllegalArgumentException();
145:
146:                // Remove the listeners
147:                if (listenerList != null) {
148:                    Iterator i = listenerList.iterator();
149:                    while (i.hasNext()) {
150:                        try {
151:                            ListenerMethod lm = (ListenerMethod) i.next();
152:                            if (lm.matches(eventType, target, method))
153:                                i.remove();
154:                        } catch (java.lang.ClassCastException e) {
155:                            // Class cast exceptions are ignored
156:                        }
157:                    }
158:                }
159:            }
160:
161:            /** Remove all listeners from event router */
162:            public void removeAllListeners() {
163:                listenerList = null;
164:            }
165:
166:            /** Send an event to all registered listeners. The listeners will decide
167:             * if the activation method should be called or not.
168:             * 
169:             * @param event Event to be sent to all listeners
170:             */
171:            public void fireEvent(EventObject event) {
172:
173:                // It is not necessary to send any events if there are no listeners
174:                if (listenerList != null) {
175:
176:                    // Send the event to all listeners. The listeners themselves
177:                    // will filter out unwanted events.            
178:                    Iterator i = new LinkedList(listenerList).iterator();
179:                    while (i.hasNext())
180:                        ((ListenerMethod) i.next()).receiveEvent(event);
181:                }
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.