KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > map > CallbackMap


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.map;
20
21 import java.io.Serializable JavaDoc;
22
23 import org.apache.cayenne.LifecycleListener;
24
25 /**
26  * A generic descriptor of a set of standard lifecycle callbacks.
27  *
28  * @author Andrus Adamchik
29  * @since 3.0
30  */

31 public class CallbackMap implements Serializable JavaDoc {
32
33     // these int constants correspond to indexes in array in LifecycleCallbackRegistry, so
34
// they must start with 0 and increment by 1.
35

36     /**
37      * An array containing all valid callbacks with each callback int value corresponding
38      * to its index in the array.
39      */

40     public static final int[] CALLBACKS = new int[] {
41             LifecycleListener.PRE_PERSIST, LifecycleListener.PRE_REMOVE,
42             LifecycleListener.PRE_UPDATE, LifecycleListener.POST_PERSIST,
43             LifecycleListener.POST_REMOVE, LifecycleListener.POST_UPDATE,
44             LifecycleListener.POST_LOAD
45     };
46
47     protected CallbackDescriptor prePersist;
48     protected CallbackDescriptor postPersist;
49     protected CallbackDescriptor preUpdate;
50     protected CallbackDescriptor postUpdate;
51     protected CallbackDescriptor preRemove;
52     protected CallbackDescriptor postRemove;
53     protected CallbackDescriptor postLoad;
54
55     public CallbackMap() {
56         this.prePersist = new CallbackDescriptor(LifecycleListener.PRE_PERSIST);
57         this.postPersist = new CallbackDescriptor(LifecycleListener.POST_PERSIST);
58         this.preUpdate = new CallbackDescriptor(LifecycleListener.PRE_UPDATE);
59         this.postUpdate = new CallbackDescriptor(LifecycleListener.POST_UPDATE);
60         this.preRemove = new CallbackDescriptor(LifecycleListener.PRE_REMOVE);
61         this.postRemove = new CallbackDescriptor(LifecycleListener.POST_REMOVE);
62         this.postLoad = new CallbackDescriptor(LifecycleListener.POST_LOAD);
63     }
64
65     /**
66      * Returns all event callbacks in a single array ordered by event type, following the
67      * order in {@link CallbackMap#CALLBACKS} array.
68      */

69     public CallbackDescriptor[] getCallbacks() {
70         return new CallbackDescriptor[] {
71                 prePersist, preRemove, preUpdate, postPersist, postRemove, postUpdate,
72                 postLoad
73         };
74     }
75
76     public CallbackDescriptor getPostLoad() {
77         return postLoad;
78     }
79
80     public CallbackDescriptor getPostPersist() {
81         return postPersist;
82     }
83
84     public CallbackDescriptor getPostRemove() {
85         return postRemove;
86     }
87
88     public CallbackDescriptor getPostUpdate() {
89         return postUpdate;
90     }
91
92     public CallbackDescriptor getPrePersist() {
93         return prePersist;
94     }
95
96     public CallbackDescriptor getPreRemove() {
97         return preRemove;
98     }
99
100     public CallbackDescriptor getPreUpdate() {
101         return preUpdate;
102     }
103 }
104
Popular Tags