KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > LifecycleEvent


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo;
13
14 import com.versant.core.common.Utils;
15
16 import java.util.EventObject JavaDoc;
17
18 /**
19  * For JDO 2 LifeCycle support.
20  *
21  * @see VersantPersistenceManagerFactory#addLifecycleListener
22  * @see VersantPersistenceManagerFactory#removeLifecycleListener
23  */

24 public class LifecycleEvent extends EventObject JavaDoc {
25
26     public static final int CREATE = 0;
27     public static final int LOAD = 1;
28     public static final int PRESTORE = 2;
29     public static final int POSTSTORE = 3;
30     public static final int CLEAR = 4;
31     public static final int DELETE = 5;
32     public static final int DIRTY = 6;
33     public static final int DETACH = 7;
34     public static final int ATTACH = 8;
35
36     private int type;
37     private Object JavaDoc target;
38
39     public LifecycleEvent(Object JavaDoc source, int type) {
40         super(source);
41         this.type = type;
42     }
43
44     public LifecycleEvent(Object JavaDoc source, int type, Object JavaDoc target) {
45         this(source, type);
46         this.target = target;
47     }
48
49     /**
50      * This method returns the event type that triggered the event.
51      */

52     public int getEventType() {
53         return type;
54     }
55
56     /**
57      * This method returns the other object associated withthe event.
58      * Specifically, the target object is the detached instance in the case
59      * of postAttach, and the persistent instance in the case of postDetach.
60      */

61     public Object JavaDoc getTarget() {
62         return target;
63     }
64
65     public static String JavaDoc toTypeString(int type) {
66         switch (type) {
67             case CREATE: return "CREATE";
68             case LOAD: return "LOAD";
69             case PRESTORE: return "PRESTORE";
70             case POSTSTORE: return "POSTSTORE";
71             case CLEAR: return "CLEAR";
72             case DELETE: return "DELETE";
73             case DIRTY: return "DIRTY";
74             case DETACH: return "DETACH";
75             case ATTACH: return "ATTACH";
76         }
77         return "UNKNOWN(" + type + ")";
78     }
79
80     public String JavaDoc toString() {
81         return "LifecycleEvent[source=" + Utils.toString(source) +
82                 ", " + toTypeString(type) + ", target=" +
83                 Utils.toString(target) + "]";
84     }
85
86 }
87
88
Popular Tags