KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > LifecycleCallbackDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.lang.reflect.Method JavaDoc;
26
27 /**
28  * Deployment object representing the lifecycle-callback.
29  *
30  * @author Shing Wai Chan
31  */

32 public class LifecycleCallbackDescriptor extends Descriptor {
33
34     private String JavaDoc lifecycleCallbackClass;
35     private String JavaDoc lifecycleCallbackMethod;
36     private String JavaDoc defaultLifecycleCallbackClass;
37
38     public enum CallbackType {
39
40         POST_CONSTRUCT,
41         PRE_DESTROY,
42         PRE_PASSIVATE,
43         POST_ACTIVATE
44
45     }
46
47     public void setLifecycleCallbackClass(String JavaDoc clazz) {
48         lifecycleCallbackClass = clazz;
49     }
50
51     public String JavaDoc getLifecycleCallbackClass() {
52         if (lifecycleCallbackClass == null ||
53             lifecycleCallbackClass.trim().equals("")) {
54             return defaultLifecycleCallbackClass;
55         } else {
56             return lifecycleCallbackClass;
57         }
58     }
59
60     public void setDefaultLifecycleCallbackClass(String JavaDoc clazz) {
61         defaultLifecycleCallbackClass = clazz;
62     }
63
64     public String JavaDoc getDefaultLifecycleCallbackClass() {
65         return defaultLifecycleCallbackClass;
66     }
67
68     public void setLifecycleCallbackMethod(String JavaDoc method) {
69         lifecycleCallbackMethod = method;
70     }
71
72     public String JavaDoc getLifecycleCallbackMethod() {
73         return lifecycleCallbackMethod;
74     }
75
76     /**
77      * Given a classloader, find the Method object corresponding to this
78      * lifecycle callback.
79      *
80      * @throw Exception if no method found
81      */

82     public Method JavaDoc getLifecycleCallbackMethodObject(ClassLoader JavaDoc loader)
83         throws Exception JavaDoc {
84
85         Method JavaDoc m = null;
86
87         if( getLifecycleCallbackClass() == null ) {
88             throw new IllegalArgumentException JavaDoc("no lifecycle class defined");
89         }
90
91         Class JavaDoc clazz = loader.loadClass(getLifecycleCallbackClass());
92         
93         // Check for the method within this class only.
94
// This does not include super-classses.
95
for(Method JavaDoc next : clazz.getDeclaredMethods()) {
96             
97             // Overloading is not allowed for AroundInvoke or
98
// Callback methods so match by name only.
99
if( next.getName().equals(lifecycleCallbackMethod) ) {
100                 m = next;
101                 break;
102             }
103         }
104
105         if( m == null ) {
106             throw new NoSuchMethodException JavaDoc("no method matching " +
107                                             lifecycleCallbackMethod);
108         }
109
110         return m;
111     }
112 }
113
Popular Tags