Source Code Cross Referenced for EventManager.java in  » Development » jgap » org » jgap » 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 » Development » jgap » org.jgap.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of JGAP.
003:         *
004:         * JGAP offers a dual license model containing the LGPL as well as the MPL.
005:         *
006:         * For licensing information please see the file license.txt included with JGAP
007:         * or have a look at the top of class org.jgap.Chromosome which representatively
008:         * includes the JGAP license policy applicable for any file delivered with JGAP.
009:         */
010:        package org.jgap.event;
011:
012:        import java.util.*;
013:        import org.jgap.util.*;
014:
015:        /**
016:         * Manages event notification in the system. Observers that desire to be
017:         * notified of genetic events should subscribe to this class via the
018:         * addEventListener() method. To unsubscribe, use the removeEventListener()
019:         * method. To generate a genetic event, use the fireGeneticEvent() method,
020:         * which will take care of notifying the appropriate subscribers.
021:         *
022:         * @author Neil Rotstan
023:         * @author Klaus Meffert
024:         * @since 1.0
025:         */
026:        public class EventManager implements  IEventManager, ICloneable {
027:            /** String containing the CVS revision. Read out via reflection!*/
028:            private final static String CVS_REVISION = "$Revision: 1.8 $";
029:
030:            /**
031:             * References a Map of subscribed event listeners. Each key is an event
032:             * name, and each value is a List of listeners subscribed to that event.
033:             */
034:            private HashMap m_listeners = new HashMap();
035:
036:            /**
037:             * Adds a new listener that will be notified when the event represented
038:             * by the given name is fired.
039:             *
040:             * @param a_eventName the name of the event to which the given listener
041:             * should be subscribed. Standard events are represented by constants in the
042:             * GeneticEvent class
043:             * @param a_eventListenerToAdd the genetic listener to subscribe to
044:             * notifications of the given event
045:             *
046:             * @author Neil Rotstan
047:             * @since 1.0
048:             */
049:            public synchronized void addEventListener(final String a_eventName,
050:                    final GeneticEventListener a_eventListenerToAdd) {
051:                List eventListeners = (List) m_listeners.get(a_eventName);
052:                if (eventListeners == null) {
053:                    eventListeners = new LinkedList();
054:                    m_listeners.put(a_eventName, eventListeners);
055:                }
056:                eventListeners.add(a_eventListenerToAdd);
057:            }
058:
059:            /**
060:             * Removes the given listener from subscription of the indicated event.
061:             * The listener will no longer be notified when the given event occurs.
062:             *
063:             * @param a_eventName the name of the event to which the given listener
064:             * should be removed. Standard events are represented by constants in the
065:             * GeneticEvent class
066:             * @param a_eventListenerToRemove the genetic listener to unsubscribe from
067:             * notifications of the given event
068:             *
069:             * @author Neil Rotstan
070:             * @since 1.0
071:             */
072:            public synchronized void removeEventListener(
073:                    final String a_eventName,
074:                    final GeneticEventListener a_eventListenerToRemove) {
075:                List eventListeners = (List) m_listeners.get(a_eventName);
076:                if (eventListeners != null) {
077:                    eventListeners.remove(a_eventListenerToRemove);
078:                }
079:            }
080:
081:            /**
082:             * Fires a genetic event. All subscribers of that particular event type
083:             * (as determined by the name of the event) will be notified of it
084:             * having been fired.
085:             *
086:             * @param a_eventToFire the representation of the GeneticEvent to fire
087:             *
088:             * @author Neil Rotstan
089:             * @since 1.0
090:             */
091:            public synchronized void fireGeneticEvent(
092:                    final GeneticEvent a_eventToFire) {
093:                List eventListeners = (List) m_listeners.get(a_eventToFire
094:                        .getEventName());
095:                if (eventListeners != null) {
096:                    // Iterate over the listeners and notify each one of the event.
097:                    // ------------------------------------------------------------
098:                    Iterator listenerIterator = eventListeners.iterator();
099:                    while (listenerIterator.hasNext()) {
100:                        ((GeneticEventListener) listenerIterator.next())
101:                                .geneticEventFired(a_eventToFire);
102:                    }
103:                }
104:            }
105:
106:            /**
107:             * @return hashcode
108:             *
109:             * @author Klaus Meffert
110:             * @since 3.0
111:             */
112:            public int hashCode() {
113:                int result = m_listeners.hashCode();
114:                return result;
115:            }
116:
117:            /**
118:             * @return cloned instance
119:             *
120:             * @author Klaus Meffert
121:             * @since 3.2
122:             */
123:            public Object clone() {
124:                EventManager result = new EventManager();
125:                if (!m_listeners.isEmpty()) {
126:                    result.m_listeners = (HashMap) m_listeners.clone();
127:                }
128:                return result;
129:            }
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.