Source Code Cross Referenced for CompositeListener.java in  » Profiler » JAMon » com » jamonapi » 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 » Profiler » JAMon » com.jamonapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jamonapi;
002:
003:        import java.util.*;
004:
005:        import com.jamonapi.utils.*;
006:
007:        /** A class that can contain other listeners that can listen to jamon events of interest.
008:         * These classes will all implement the JAMonListener interface too.  This is an example of the 
009:         * Gang of 4 Composite design pattern.
010:         * @author steve souza
011:         *
012:         */
013:        public class CompositeListener implements  JAMonListener, DetailData {
014:
015:            // A variable that will hold the list of Listeners
016:            private List listenerList = new ArrayList();
017:            // The name of the composite listener
018:            private String name;
019:
020:            /** Uses the CompositeListener name */
021:            public CompositeListener() {
022:                this ("CompositeJAMonListener");
023:            }
024:
025:            /** Pass in a Listener name that allows you to differentiate this listener from others */
026:            public CompositeListener(String name) {
027:                this .name = name;
028:            }
029:
030:            /** Add a listener to the composite and return this object */
031:            public CompositeListener addListener(JAMonListener listener) {
032:                listenerList.add(listener);
033:                return this ;
034:            }
035:
036:            /* Return the listener associated with the passed in name */
037:            public JAMonListener getListener(String listenerName) {
038:                int rows = getNumListeners();
039:
040:                for (int i = 0; i < rows; i++) {
041:                    JAMonListener listener = (JAMonListener) listenerList
042:                            .get(i);
043:                    String name = listener.getName();
044:                    if (listenerName.equalsIgnoreCase(name))
045:                        return listener;
046:                    else if (listener instanceof  CompositeListener) {
047:                        listener = ((CompositeListener) listener)
048:                                .getListener(listenerName);
049:                        if (listener != null)
050:                            return listener;
051:                    }
052:                }
053:
054:                return null;
055:            }
056:
057:            /** Return the listener associated with the index */
058:            public JAMonListener getListener(int index) {
059:                return (JAMonListener) listenerList.get(index);
060:            }
061:
062:            /** Remove the named listener from this CompositeListener */
063:            public CompositeListener removeListener(String listenerName) {
064:                int rows = getNumListeners();
065:
066:                for (int i = 0; i < rows; i++) {
067:                    JAMonListener listener = (JAMonListener) listenerList
068:                            .get(i);
069:                    String name = listener.getName();
070:                    if (listenerName.equalsIgnoreCase(name)) {
071:                        listenerList.remove(i);
072:                        break;
073:                    } else if (listener instanceof  CompositeListener
074:                            && ((CompositeListener) listener)
075:                                    .hasListener(listenerName)) {
076:                        ((CompositeListener) listener)
077:                                .removeListener(listenerName);
078:                        break;
079:                    }
080:
081:                }
082:
083:                return this ;
084:            }
085:
086:            /** return true if the named listener exists */
087:            public boolean hasListener(String listenerName) {
088:                int rows = getNumListeners();
089:
090:                for (int i = 0; i < rows; i++) {
091:                    JAMonListener listener = (JAMonListener) listenerList
092:                            .get(i);
093:                    String name = listener.getName();
094:                    if (listenerName.equalsIgnoreCase(name))
095:                        return true;
096:                    else if (listener instanceof  CompositeListener) {
097:                        return ((CompositeListener) listener)
098:                                .hasListener(listenerName);
099:                    }
100:                }
101:
102:                return false;
103:            }
104:
105:            /** Return the number of listeners */
106:            public int getNumListeners() {
107:                return listenerList.size();
108:            }
109:
110:            /** Also returns the number of listeners */
111:            public int getRowCount() {
112:                return getNumListeners();
113:            }
114:
115:            /** Return the name of this instance */
116:            public String getName() {
117:                return name;
118:            }
119:
120:            public void setName(String name) {
121:                this .name = name;
122:
123:            }
124:
125:            /** Notify all listeners that are part of this composite of a jamon event and pass them the
126:             *  monitor that triggered the event.
127:             */
128:            public void processEvent(Monitor mon) {
129:                Iterator iter = listenerList.iterator();
130:
131:                while (iter.hasNext()) {
132:                    JAMonListener listener = (JAMonListener) iter.next();
133:                    listener.processEvent(mon);
134:                }
135:
136:            }
137:
138:            /** Get an iterator that will conatain the Composite's JAMonListener objects.  The objects will
139:             * be safe cast to JAMonListener */
140:            public Iterator iterator() {
141:                return listenerList.iterator();
142:            }
143:
144:            public boolean isEmpty() {
145:                return listenerList.isEmpty();
146:            }
147:
148:            public boolean hasData() {
149:                return !isEmpty();
150:            }
151:
152:            public Object[][] getData() {
153:                if (isEmpty())
154:                    return null;
155:
156:                int numListeners = getNumListeners();
157:                List list = new ArrayList();
158:                for (int i = 0; i < numListeners; i++) {
159:                    add(list, getListenerData(getListener(i)));
160:                }
161:
162:                return toArray(list);
163:
164:            }
165:
166:            private void add(List list, Object[][] data) {
167:                int dataSize = (data == null) ? 0 : data.length;
168:                for (int i = 0; i < dataSize; i++)
169:                    list.add(data[i]);
170:
171:            }
172:
173:            private Object[][] getListenerData(JAMonListener listener) {
174:                if (listener instanceof  CompositeListener)
175:                    return ((CompositeListener) listener).getData();
176:                else
177:                    return new Object[][] { { listener.getName() } };
178:            }
179:
180:            private Object[][] toArray(List list) {
181:                if (list.size() == 0)
182:                    return null;
183:                else {
184:                    Object[][] listenerArray = new Object[list.size()][];
185:                    list.toArray(listenerArray);
186:                    return listenerArray;
187:                }
188:            }
189:
190:            private static final String[] HEADER = { "ListenerName" };
191:
192:            public String[] getHeader() {
193:                return HEADER;
194:            }
195:
196:            public static Object[][] getData(JAMonListener listener) {
197:                if (listener == null)
198:                    return null;
199:                // don't need to wrap listener if it is already a compositelistener, but
200:                // it makes the following code easier.
201:                return new CompositeListener().addListener(listener).getData();
202:            }
203:
204:            public static String[] getHeader(JAMonListener listener) {
205:                // At this point all headers are the same.
206:                return HEADER;
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.