KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package com.sun.enterprise.deployment;
25
26 import java.util.logging.*;
27 import com.sun.logging.*;
28
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.LinkedList JavaDoc;
35
36 import com.sun.enterprise.util.LocalStringManagerImpl;
37 import com.sun.enterprise.deployment.util.LogDomains;
38 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
39
40 /**
41  * Contains information about 1 ejb interceptor.
42  */

43
44 public class EjbInterceptor extends JndiEnvironmentRefsGroupDescriptor
45 {
46     private static LocalStringManagerImpl localStrings =
47         new LocalStringManagerImpl(EjbInterceptor.class);
48
49     private static final Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER);
50
51     private Set JavaDoc<LifecycleCallbackDescriptor> aroundInvokeDescriptors;
52     private String JavaDoc interceptorClassName;
53
54     // true if the AroundInvoke/Callback methods for this
55
// descriptor were defined on the bean class itself (or one of its
56
// super-classes). false if the methods are defined
57
// on a separate interceptor class (or one of its super-classes).
58
private boolean fromBeanClass = false;
59
60     public String JavaDoc getInterceptorClassName() {
61         return interceptorClassName;
62     }
63
64     public void setInterceptorClassName(String JavaDoc className) {
65         interceptorClassName = className;
66     }
67
68     public Set JavaDoc<LifecycleCallbackDescriptor> getAroundInvokeDescriptors() {
69         if (aroundInvokeDescriptors == null) {
70             aroundInvokeDescriptors =
71                 new HashSet JavaDoc<LifecycleCallbackDescriptor>();
72         }
73         return aroundInvokeDescriptors;
74     }
75
76     /**
77      * Some clients need the AroundInvoke methods for this inheritance
78      * hierarchy in the spec-defined "least derived --> most derived" order.
79      */

80     public List JavaDoc<LifecycleCallbackDescriptor> getOrderedAroundInvokeDescriptors
81         (ClassLoader JavaDoc loader) throws Exception JavaDoc {
82
83         return orderDescriptors(getAroundInvokeDescriptors(), loader);
84
85     }
86
87     public void setFromBeanClass(boolean flag) {
88         fromBeanClass = flag;
89     }
90
91     public boolean getFromBeanClass() {
92         return fromBeanClass;
93     }
94
95     public void addAroundInvokeDescriptor(LifecycleCallbackDescriptor aroundInvokeDesc) {
96         Set JavaDoc<LifecycleCallbackDescriptor> aroundInvokeDescs =
97             getAroundInvokeDescriptors();
98         boolean found = false;
99         for (LifecycleCallbackDescriptor ai : aroundInvokeDescs) {
100             if ((aroundInvokeDesc.getLifecycleCallbackClass() != null) &&
101                 aroundInvokeDesc.getLifecycleCallbackClass().equals(
102                     ai.getLifecycleCallbackClass())) {
103                 found = true;
104             }
105         }
106
107         if (!found) {
108             aroundInvokeDescs.add(aroundInvokeDesc);
109         }
110     }
111
112     public void addAroundInvokeDescriptors(
113         Set JavaDoc<LifecycleCallbackDescriptor> aroundInvokes) {
114         for (LifecycleCallbackDescriptor ai : aroundInvokes) {
115             addAroundInvokeDescriptor(ai);
116         }
117     }
118
119     public boolean hasAroundInvokeDescriptor() {
120         return (getAroundInvokeDescriptors().size() > 0);
121     }
122
123     /**
124      * Some clients need the Callback methods for this inheritance
125      * hierarchy in the spec-defined "least derived --> most derived" order.
126      */

127     public List JavaDoc<LifecycleCallbackDescriptor> getOrderedCallbackDescriptors
128         (CallbackType type, ClassLoader JavaDoc loader) throws Exception JavaDoc {
129
130         return orderDescriptors(getCallbackDescriptors(type), loader);
131     }
132
133     public void addPostActivateDescriptor(LifecycleCallbackDescriptor lcDesc) {
134         addCallbackDescriptor(CallbackType.POST_ACTIVATE, lcDesc);
135     }
136
137     public void addPrePassivateDescriptor(LifecycleCallbackDescriptor lcDesc) {
138         addCallbackDescriptor(CallbackType.PRE_PASSIVATE, lcDesc);
139     }
140
141     /**
142      * Order a set of lifecycle method descriptors for a particular
143      * inheritance hierarchy with highest precedence assigned to the
144      * least derived class.
145      */

146     private List JavaDoc<LifecycleCallbackDescriptor> orderDescriptors
147         (Set JavaDoc<LifecycleCallbackDescriptor> lcds, ClassLoader JavaDoc loader)
148         throws Exception JavaDoc
149     {
150
151         LinkedList JavaDoc<LifecycleCallbackDescriptor> orderedDescs =
152             new LinkedList JavaDoc<LifecycleCallbackDescriptor>();
153
154         Map JavaDoc<String JavaDoc, LifecycleCallbackDescriptor> map =
155             new HashMap JavaDoc<String JavaDoc, LifecycleCallbackDescriptor>();
156
157         for(LifecycleCallbackDescriptor next : lcds) {
158             map.put(next.getLifecycleCallbackClass(), next);
159         }
160
161         Class JavaDoc nextClass = loader.loadClass(getInterceptorClassName());
162
163         while((nextClass != Object JavaDoc.class) && (nextClass != null)) {
164             String JavaDoc nextClassName = nextClass.getName();
165             if( map.containsKey(nextClassName) ) {
166                 LifecycleCallbackDescriptor lcd = map.get(nextClassName);
167                 orderedDescs.addFirst(lcd);
168             }
169
170             nextClass = nextClass.getSuperclass();
171         }
172
173
174         return orderedDescs;
175
176     }
177
178     public String JavaDoc toString() {
179         return "EjbInterceptor class = " + getInterceptorClassName();
180     }
181 }
182
Popular Tags