Source Code Cross Referenced for LifecycleListenerManager.java in  » Testing » PolePosition-0.20 » com » versant » core » jdo » 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 » Testing » PolePosition 0.20 » com.versant.core.jdo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998 - 2005 Versant Corporation
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         * Versant Corporation - initial API and implementation
010:         */
011:        package com.versant.core.jdo;
012:
013:        /**
014:         * This keeps track of lists of LifecycleListener's for the different
015:         * LifecycleEvent's. It implements a copy-on-write scheme so the lists on the
016:         * PMF can be shared by all PMs until first modified. Any modification to
017:         * a LifecycleListenerManager via add or remove will return a reference
018:         * to a new LifecycleListenerManager with the change applied. If a
019:         * LifecycleListenerManager becomes empty then null is returned.
020:         */
021:        public class LifecycleListenerManager {
022:
023:            private PreStoreNode preStoreList;
024:            private PostStoreNode postStoreList;
025:            private DeleteNode deleteList;
026:
027:            /**
028:             * Create new LifecycleListenerManager containinhg toAdd.
029:             */
030:            public LifecycleListenerManager(LifecycleListener toAdd) {
031:                addImp(toAdd);
032:            }
033:
034:            /**
035:             * Copy constructor.
036:             */
037:            private LifecycleListenerManager(LifecycleListenerManager toCopy) {
038:                preStoreList = toCopy.preStoreList == null ? null
039:                        : toCopy.preStoreList.copy();
040:                postStoreList = toCopy.postStoreList == null ? null
041:                        : toCopy.postStoreList.copy();
042:                deleteList = toCopy.deleteList == null ? null
043:                        : toCopy.deleteList.copy();
044:            }
045:
046:            /**
047:             * Return a copy of this LifecycleListenerManager with l added.
048:             */
049:            public LifecycleListenerManager add(LifecycleListener l) {
050:                return new LifecycleListenerManager(this ).addImp(l);
051:            }
052:
053:            private LifecycleListenerManager addImp(LifecycleListener l) {
054:                if (l instanceof  PreStoreLifecycleListener) {
055:                    preStoreList = new PreStoreNode(
056:                            (PreStoreLifecycleListener) l, preStoreList);
057:                }
058:                if (l instanceof  PostStoreLifecycleListener) {
059:                    postStoreList = new PostStoreNode(
060:                            (PostStoreLifecycleListener) l, postStoreList);
061:                }
062:                if (l instanceof  DeleteLifecycleListener) {
063:                    deleteList = new DeleteNode((DeleteLifecycleListener) l,
064:                            deleteList);
065:                }
066:                return this ;
067:            }
068:
069:            /**
070:             * Return a copy of this LifecycleListenerManager with l removed or
071:             * null if the resulting LifecycleListenerManager would contain no
072:             * listeners.
073:             */
074:            public LifecycleListenerManager remove(LifecycleListener l) {
075:                return new LifecycleListenerManager(this ).removeImp(l);
076:            }
077:
078:            private LifecycleListenerManager removeImp(LifecycleListener l) {
079:                if (l instanceof  PreStoreLifecycleListener) {
080:                    PreStoreNode prev = null;
081:                    for (PreStoreNode i = preStoreList; i != null; i = i.next) {
082:                        if (i.listener == l) {
083:                            if (prev == null) {
084:                                preStoreList = i.next;
085:                            } else {
086:                                prev.next = i.next;
087:                            }
088:                        }
089:                        prev = i;
090:                    }
091:                }
092:                if (l instanceof  DeleteLifecycleListener) {
093:                    DeleteNode prev = null;
094:                    for (DeleteNode i = deleteList; i != null; i = i.next) {
095:                        if (i.listener == l) {
096:                            if (prev == null) {
097:                                deleteList = i.next;
098:                            } else {
099:                                prev.next = i.next;
100:                            }
101:                        }
102:                        prev = i;
103:                    }
104:                }
105:                if (preStoreList == null && deleteList == null) {
106:                    return null;
107:                }
108:                return this ;
109:            }
110:
111:            /**
112:             * Fire a preStore event returning true if there were any listeners.
113:             */
114:            public boolean firePreStore(Object o) {
115:                if (preStoreList == null) {
116:                    return false;
117:                }
118:                LifecycleEvent ev = new LifecycleEvent(o,
119:                        LifecycleEvent.PRESTORE);
120:                for (PreStoreNode i = preStoreList; i != null; i = i.next) {
121:                    i.listener.preStore(ev);
122:                }
123:                return true;
124:            }
125:
126:            /**
127:             * Fire a postStore event.
128:             */
129:            public void firePostStore(Object o) {
130:                if (postStoreList == null) {
131:                    return;
132:                }
133:                LifecycleEvent ev = new LifecycleEvent(o,
134:                        LifecycleEvent.POSTSTORE);
135:                for (PostStoreNode i = postStoreList; i != null; i = i.next) {
136:                    i.listener.postStore(ev);
137:                }
138:            }
139:
140:            /**
141:             * Fire a delete event.
142:             */
143:            public void fireDelete(Object o) {
144:                if (deleteList == null) {
145:                    return;
146:                }
147:                LifecycleEvent ev = new LifecycleEvent(o, LifecycleEvent.DELETE);
148:                for (DeleteNode i = deleteList; i != null; i = i.next) {
149:                    i.listener.delete(ev);
150:                }
151:            }
152:
153:            /**
154:             * Do we have any postStore listeners?
155:             */
156:            public boolean hasPostStoreListeners() {
157:                return postStoreList != null;
158:            }
159:
160:            private static class PreStoreNode {
161:
162:                public PreStoreLifecycleListener listener;
163:                public PreStoreNode next;
164:
165:                public PreStoreNode(PreStoreLifecycleListener listener,
166:                        PreStoreNode next) {
167:                    this .listener = listener;
168:                    this .next = next;
169:                }
170:
171:                public PreStoreNode copy() {
172:                    return new PreStoreNode(listener, next == null ? null
173:                            : next.copy());
174:                }
175:            }
176:
177:            private static class PostStoreNode {
178:
179:                public PostStoreLifecycleListener listener;
180:                public PostStoreNode next;
181:
182:                public PostStoreNode(PostStoreLifecycleListener listener,
183:                        PostStoreNode next) {
184:                    this .listener = listener;
185:                    this .next = next;
186:                }
187:
188:                public PostStoreNode copy() {
189:                    return new PostStoreNode(listener, next == null ? null
190:                            : next.copy());
191:                }
192:            }
193:
194:            private static class DeleteNode {
195:
196:                public DeleteLifecycleListener listener;
197:                public DeleteNode next;
198:
199:                public DeleteNode(DeleteLifecycleListener listener,
200:                        DeleteNode next) {
201:                    this .listener = listener;
202:                    this .next = next;
203:                }
204:
205:                public DeleteNode copy() {
206:                    return new DeleteNode(listener, next == null ? null : next
207:                            .copy());
208:                }
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.