01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo;
12:
13: import com.versant.core.common.Utils;
14:
15: import java.util.EventObject;
16:
17: /**
18: * For JDO 2 LifeCycle support.
19: *
20: * @see VersantPersistenceManagerFactory#addLifecycleListener
21: * @see VersantPersistenceManagerFactory#removeLifecycleListener
22: */
23: public class LifecycleEvent extends EventObject {
24:
25: public static final int CREATE = 0;
26: public static final int LOAD = 1;
27: public static final int PRESTORE = 2;
28: public static final int POSTSTORE = 3;
29: public static final int CLEAR = 4;
30: public static final int DELETE = 5;
31: public static final int DIRTY = 6;
32: public static final int DETACH = 7;
33: public static final int ATTACH = 8;
34:
35: private int type;
36: private Object target;
37:
38: public LifecycleEvent(Object source, int type) {
39: super (source);
40: this .type = type;
41: }
42:
43: public LifecycleEvent(Object source, int type, Object target) {
44: this (source, type);
45: this .target = target;
46: }
47:
48: /**
49: * This method returns the event type that triggered the event.
50: */
51: public int getEventType() {
52: return type;
53: }
54:
55: /**
56: * This method returns the other object associated withthe event.
57: * Specifically, the target object is the detached instance in the case
58: * of postAttach, and the persistent instance in the case of postDetach.
59: */
60: public Object getTarget() {
61: return target;
62: }
63:
64: public static String toTypeString(int type) {
65: switch (type) {
66: case CREATE:
67: return "CREATE";
68: case LOAD:
69: return "LOAD";
70: case PRESTORE:
71: return "PRESTORE";
72: case POSTSTORE:
73: return "POSTSTORE";
74: case CLEAR:
75: return "CLEAR";
76: case DELETE:
77: return "DELETE";
78: case DIRTY:
79: return "DIRTY";
80: case DETACH:
81: return "DETACH";
82: case ATTACH:
83: return "ATTACH";
84: }
85: return "UNKNOWN(" + type + ")";
86: }
87:
88: public String toString() {
89: return "LifecycleEvent[source=" + Utils.toString(source) + ", "
90: + toTypeString(type) + ", target="
91: + Utils.toString(target) + "]";
92: }
93:
94: }
|