Source Code Cross Referenced for ContextHandler.java in  » Content-Management-System » harmonise » org » openharmonise » vfs » context » 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 » Content Management System » harmonise » org.openharmonise.vfs.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.vfs.context;
020:
021:        import java.util.ArrayList;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:
025:        /**
026:         * The context handler acts as the hub for context events. They are fired
027:         * at the handler and the handler then routes them to all the listeners
028:         * for that specific context type and the ALL context type.
029:         * 
030:         * @author Matthew Large
031:         * @version $Revision: 1.1 $
032:         *
033:         */
034:        public class ContextHandler {
035:
036:            /**
037:             * Handler instance, following singleton pattern.
038:             */
039:            private static ContextHandler m_instance = null;
040:
041:            /**
042:             * Map of {@link ContextType} to {@link Context} objects.
043:             */
044:            private HashMap m_contexts = new HashMap(5);
045:
046:            /**
047:             * 
048:             */
049:            private ContextHandler() {
050:                super ();
051:                this .setup();
052:            }
053:
054:            /**
055:             * Configures the context handler.
056:             *
057:             */
058:            private void setup() {
059:                this .m_contexts.put(ContextType.CONTEXT_ALL, new Context(
060:                        ContextType.CONTEXT_ALL));
061:                this .m_contexts.put(ContextType.CONTEXT_TABS, new Context(
062:                        ContextType.CONTEXT_TABS));
063:                this .m_contexts.put(ContextType.CONTEXT_FILES, new Context(
064:                        ContextType.CONTEXT_FILES));
065:                this .m_contexts.put(ContextType.CONTEXT_DIRS, new Context(
066:                        ContextType.CONTEXT_DIRS));
067:            }
068:
069:            /**
070:             * Returns the instance of the context handler, following the
071:             * singleton patter.
072:             * 
073:             * @return Context handler
074:             */
075:            public static ContextHandler getInstance() {
076:                if (m_instance == null) {
077:                    m_instance = new ContextHandler();
078:                }
079:                return m_instance;
080:            }
081:
082:            /**
083:             * Adds a context listener to a specified context type.
084:             * 
085:             * @param contextType Context type
086:             * @param listener Context listener
087:             */
088:            public synchronized void addListener(ContextType contextType,
089:                    ContextListener listener) {
090:                if (!this .m_contexts.keySet().contains(contextType)) {
091:                    this .m_contexts.put(contextType, new Context(contextType));
092:                }
093:                ((Context) this .m_contexts.get(contextType))
094:                        .addListener(listener);
095:            }
096:
097:            /**
098:             * Removes a context listener from a specified context type.
099:             * 
100:             * @param contextType Context type
101:             * @param listener Context listener
102:             */
103:            public void removeListener(ContextType contextType,
104:                    ContextListener listener) {
105:                if (this .m_contexts.keySet().contains(contextType)) {
106:                    ((Context) this .m_contexts.get(contextType))
107:                            .removeListener(listener);
108:                }
109:            }
110:
111:            /**
112:             * Fires a context event to the relevant context listeners.
113:             * 
114:             * @param ce Context event
115:             */
116:            public void fireContextEvent(ContextEvent ce) {
117:                ContextType contextType = ce.CONTEXT_TYPE;
118:                if (ce != null
119:                        && this .m_contexts.keySet().contains(contextType)) {
120:                    ((Context) this .m_contexts.get(contextType))
121:                            .fireContextEvent(ce);
122:                    ((Context) this .m_contexts.get(contextType))
123:                            .setLastEvent(ce);
124:                }
125:                if (contextType == ContextType.CONTEXT_SHUTDOWN) {
126:                    System.exit(0);
127:                }
128:            }
129:
130:            /**
131:             * Returns the last recorded context event for a specified context
132:             * type.
133:             * 
134:             * @param contextType Context type
135:             * @return Context event
136:             */
137:            public ContextEvent getLastEvent(ContextType contextType) {
138:                ContextEvent lastEvent = null;
139:                if (this .m_contexts.keySet().contains(contextType)) {
140:                    lastEvent = ((Context) this .m_contexts.get(contextType))
141:                            .getLastEvent();
142:                }
143:                return lastEvent;
144:            }
145:
146:            /**
147:             * A context is a container for all the information specific to a
148:             * context type. It holds the listeners and the last context event.
149:             * 
150:             * @author Matthew Large
151:             * @version $Revision: 1.1 $
152:             *
153:             */
154:            private class Context {
155:
156:                /**
157:                 * Context type.
158:                 */
159:                private ContextType m_contextType = null;
160:
161:                /**
162:                 * List of {@link ContextListener} objects.
163:                 */
164:                private ArrayList m_aListeners = new ArrayList(5);
165:
166:                /**
167:                 * Last context event sent to this context.
168:                 */
169:                private ContextEvent m_ce = null;
170:
171:                /**
172:                 * Constructs a new context.
173:                 * 
174:                 * @param contextType Context type
175:                 */
176:                public Context(ContextType contextType) {
177:                    super ();
178:                    this .m_contextType = contextType;
179:                }
180:
181:                /**
182:                 * Returns the name of context type.
183:                 * 
184:                 * @return Name
185:                 */
186:                public String getName() {
187:                    return this .m_contextType.toString();
188:                }
189:
190:                /**
191:                 * Adds a listener to this context.
192:                 * 
193:                 * @param listener Listener to add
194:                 */
195:                public void addListener(ContextListener listener) {
196:                    this .m_aListeners.add(listener);
197:                }
198:
199:                /**
200:                 * Removes a listener from this context.
201:                 * 
202:                 * @param listener Listener to remove
203:                 */
204:                public void removeListener(ContextListener listener) {
205:                    this .m_aListeners.remove(listener);
206:                }
207:
208:                /**
209:                 * Fires a context event to all the listeners for this context.
210:                 * 
211:                 * @param ce Context event
212:                 */
213:                public void fireContextEvent(ContextEvent ce) {
214:                    Iterator itor = this .m_aListeners.iterator();
215:                    while (itor.hasNext()) {
216:                        ((ContextListener) itor.next()).contextMessage(ce);
217:                    }
218:                }
219:
220:                public ContextEvent getLastEvent() {
221:                    return this .m_ce;
222:                }
223:
224:                public void setLastEvent(ContextEvent ce) {
225:                    this.m_ce = ce;
226:                }
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.