KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Arrays JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Set JavaDoc;
27
28 /**
29  * A mapping descriptor of a single callback event.
30  *
31  * @since 3.0
32  * @author Andrus Adamchik
33  */

34 public class CallbackDescriptor implements Serializable JavaDoc {
35     
36    
37
38     protected int callbackType;
39     protected Set JavaDoc callbackMethods;
40
41     public CallbackDescriptor(int callbackType) {
42         setCallbackType(callbackType);
43         this.callbackMethods = new HashSet JavaDoc(3);
44     }
45
46     /**
47      * Removes all callback methods.
48      */

49     public void clear() {
50         callbackMethods.clear();
51     }
52
53     /**
54      * Returns all callback methods for this callback event.
55      */

56     public Collection JavaDoc getCallbackMethods() {
57         return Collections.unmodifiableCollection(callbackMethods);
58     }
59
60     public void addCallbackMethod(String JavaDoc methodName) {
61         callbackMethods.add(methodName);
62     }
63
64     public void removeCallbackMethod(String JavaDoc methodName) {
65         callbackMethods.remove(methodName);
66     }
67
68     public int getCallbackType() {
69         return callbackType;
70     }
71
72     void setCallbackType(int callbackType) {
73         if (Arrays.binarySearch(CallbackMap.CALLBACKS, callbackType) != callbackType) {
74             throw new IllegalArgumentException JavaDoc("Invalid callback: " + callbackType);
75         }
76
77         this.callbackType = callbackType;
78     }
79 }
80
Popular Tags