Source Code Cross Referenced for PBLifeCycleEvent.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » 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 » Database ORM » db ojb » org.apache.ojb.broker 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker;
002:
003:        /* Copyright 2003-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import org.apache.commons.lang.builder.ToStringBuilder;
019:        import org.apache.commons.lang.builder.ToStringStyle;
020:
021:        /**
022:         * The <code>PBLifeCycleEvent</code> encapsulates information about
023:         * the life-cycle of a persistent object.
024:         * <br/>
025:         * NOTE:
026:         * <br/>
027:         * Because of performance reasons OJB intern reuse instances of this class
028:         * by reset target object.
029:         *
030:         * @author Armin Waibel
031:         * @version $Id: PBLifeCycleEvent.java,v 1.5.2.1 2005/12/21 22:22:07 tomdz Exp $
032:         */
033:        public final class PBLifeCycleEvent extends PersistenceBrokerEvent {
034:            /** Denotes an event that happens before the insertion of an object. */
035:            public static final int TYPE_BEFORE_INSERT = 1;
036:            /** Denotes an event that happens before the deletion of an object. */
037:            public static final int TYPE_BEFORE_DELETE = 2;
038:            /** Denotes an event that happens before the update of an object. */
039:            public static final int TYPE_BEFORE_UPDATE = 3;
040:            /** Denotes an event that happens after the update of an object. */
041:            public static final int TYPE_AFTER_UPDATE = 4;
042:            /** Denotes an event that happens after the deletion of an object. */
043:            public static final int TYPE_AFTER_DELETE = 5;
044:            /** Denotes an event that happens after the lookup of an object. */
045:            public static final int TYPE_AFTER_LOOKUP = 6;
046:            /** Denotes an event that happens after the insertion of an object. */
047:            public static final int TYPE_AFTER_INSERT = 7;
048:
049:            private Type eventType;
050:            private Object target;
051:
052:            /**
053:             * Creates a new event instance.
054:             * 
055:             * @param broker    The broker
056:             * @param target    The object which caused the event
057:             * @param eventType The type of the event
058:             */
059:            public PBLifeCycleEvent(PersistenceBroker broker, Object target,
060:                    Type eventType) {
061:                super (broker);
062:                this .target = target;
063:                this .eventType = eventType;
064:            }
065:
066:            /**
067:             * Creates a new event instance.
068:             * 
069:             * @param broker The broker
070:             * @param type   The type of the event
071:             */
072:            public PBLifeCycleEvent(PersistenceBroker broker, Type type) {
073:                super (broker);
074:                this .eventType = type;
075:            }
076:
077:            /**
078:             * Returns the target object as an instance of {@link PersistenceBrokerAware} if possible.
079:             * 
080:             * @return The {@link PersistenceBrokerAware} instance if there is a target and it implements
081:             *         this interface
082:             */
083:            public PersistenceBrokerAware getPersitenceBrokerAware() {
084:                if ((target != null)
085:                        && (target instanceof  PersistenceBrokerAware)) {
086:                    return (PersistenceBrokerAware) target;
087:                } else {
088:                    return null;
089:                }
090:            }
091:
092:            /**
093:             * Set the object that caused the event.
094:             * 
095:             * @param obj The object
096:             */
097:            public void setTarget(Object obj) {
098:                this .target = obj;
099:            }
100:
101:            /**
102:             * Returns the object that caused the event.
103:             * 
104:             * @return The object
105:             */
106:            public Object getTarget() {
107:                return target;
108:            }
109:
110:            /**
111:             * {@inheritDoc}
112:             */
113:            public String toString() {
114:                ToStringBuilder buf = new ToStringBuilder(this ,
115:                        ToStringStyle.MULTI_LINE_STYLE);
116:                buf.append("target object", target).append("source object",
117:                        getSource()).append("eventType", eventType.toString());
118:                return buf.toString();
119:            }
120:
121:            /**
122:             * Returns the event type.
123:             * 
124:             * @return The event type
125:             */
126:            public Type getEventType() {
127:                return eventType;
128:            }
129:
130:            /**
131:             * Enum-like class for the event types.
132:             */
133:            public static class Type {
134:                /** Denotes an event that happens before the insertion of an object. */
135:                public static final Type BEFORE_INSERT = new Type(
136:                        TYPE_BEFORE_INSERT);
137:                /** Denotes an event that happens before the update of an object. */
138:                public static final Type BEFORE_UPDATE = new Type(
139:                        TYPE_BEFORE_UPDATE);
140:                /** Denotes an event that happens after the insertion of an object. */
141:                public static final Type AFTER_INSERT = new Type(
142:                        TYPE_AFTER_INSERT);
143:                /** Denotes an event that happens after the update of an object. */
144:                public static final Type AFTER_UPDATE = new Type(
145:                        TYPE_AFTER_UPDATE);
146:                /** Denotes an event that happens before the deletion of an object. */
147:                public static final Type BEFORE_DELETE = new Type(
148:                        TYPE_BEFORE_DELETE);
149:                /** Denotes an event that happens after the deletion of an object. */
150:                public static final Type AFTER_DELETE = new Type(
151:                        TYPE_AFTER_DELETE);
152:                /** Denotes an event that happens after the lookup of an object. */
153:                public static final Type AFTER_LOOKUP = new Type(
154:                        TYPE_AFTER_LOOKUP);
155:
156:                private int type;
157:
158:                /**
159:                 * Creates a new instance.
160:                 * 
161:                 * @param type The type value
162:                 */
163:                protected Type(int type) {
164:                    this .type = type;
165:                }
166:
167:                /**
168:                 * {@inheritDoc}
169:                 */
170:                public final boolean equals(Object obj) {
171:                    if (obj == this ) {
172:                        return true;
173:                    }
174:                    if (!(obj instanceof  PBStateEvent)) {
175:                        return false;
176:                    }
177:
178:                    return type == ((Type) obj).type;
179:                }
180:
181:                /**
182:                 * {@inheritDoc}
183:                 */
184:                public final int hashCode() {
185:                    return type;
186:                }
187:
188:                /**
189:                 * Returns the type id.
190:                 * 
191:                 * @return The type id
192:                 */
193:                public final int typeId() {
194:                    return type;
195:                }
196:
197:                /**
198:                 * {@inheritDoc}
199:                 */
200:                public String toString() {
201:                    return this .getClass().getName() + " [type= "
202:                            + typeAsName(type) + "]";
203:                }
204:
205:                private static String typeAsName(int type) {
206:                    if (type == TYPE_AFTER_DELETE) {
207:                        return "AFTER_DELETE";
208:                    } else if (type == TYPE_AFTER_LOOKUP) {
209:                        return "AFTER_LOOKUP";
210:                    } else if (type == TYPE_AFTER_INSERT) {
211:                        return "AFTER_INSERT";
212:                    } else if (type == TYPE_AFTER_UPDATE) {
213:                        return "AFTER_UPDATE";
214:                    } else if (type == TYPE_BEFORE_DELETE) {
215:                        return "BEFORE_DELETE";
216:                    } else if (type == TYPE_BEFORE_INSERT) {
217:                        return "BEFORE_INSERT";
218:                    } else if (type == TYPE_BEFORE_UPDATE) {
219:                        return "BEFORE_UPDATE";
220:                    } else {
221:                        throw new OJBRuntimeException(
222:                                "Could not find type with typeId " + type);
223:                    }
224:                }
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.