KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > context > ResourceContainerContextImpl


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.annotation.context;
24
25 import java.lang.annotation.ElementType JavaDoc;
26 import java.lang.reflect.AnnotatedElement JavaDoc;
27
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30
31 import com.sun.enterprise.deployment.Descriptor;
32 import com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor;
33 import com.sun.enterprise.deployment.EntityManagerReferenceDescriptor;
34 import com.sun.enterprise.deployment.EnvironmentProperty;
35 import com.sun.enterprise.deployment.JndiNameEnvironment;
36 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
37 import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor;
38 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor;
39 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
40 import com.sun.enterprise.deployment.WritableJndiNameEnvironment;
41 import com.sun.enterprise.deployment.annotation.ProcessingContext;
42 import com.sun.enterprise.deployment.types.EjbReference;
43 import com.sun.enterprise.deployment.types.EjbReferenceContainer;
44 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer;
45 import com.sun.enterprise.deployment.types.ResourceReferenceContainer;
46 import com.sun.enterprise.deployment.types.ServiceReferenceContainer;
47 import com.sun.enterprise.deployment.types.HandlerChainContainer;
48
49 /**
50  * This provides an abstraction for handle resource references.
51  *
52  * @Author Shing Wai Chan
53  */

54 public class ResourceContainerContextImpl extends AnnotationContext
55         implements ResourceContainerContext, ComponentContext,
56                    ServiceReferenceContainerContext, HandlerContext {
57
58     protected Descriptor descriptor = null;
59     protected String JavaDoc componentClassName = null;
60
61     public ResourceContainerContextImpl() {
62     }
63
64     public ResourceContainerContextImpl(Descriptor descriptor) {
65         this.descriptor = descriptor;
66     }
67     
68     /**
69      * Add a reference to an ejb.
70      *
71      * @param ejbReference the ejb reference
72      */

73     public void addEjbReferenceDescriptor(EjbReference ejbReference) {
74         getEjbReferenceContainer().addEjbReferenceDescriptor(ejbReference);
75     }
76                                                                                
77     /**
78      * Looks up an ejb reference with the given name.
79      * Return null if it is not found.
80      *
81      * @param the name of the ejb-reference
82      */

83     public EjbReference getEjbReference(String JavaDoc name) {
84         EjbReference ejbRef = null;
85         try {
86             ejbRef = getEjbReferenceContainer().getEjbReference(name);
87             // annotation has a corresponding ejb-local-ref/ejb-ref
88
// in xml. Just add annotation info and continue.
89
// This logic might change depending on overriding rules
90
// and order in which annotations are read w.r.t. to xml.
91
// E.g. sparse overriding in xml or loading annotations
92
// first.
93
} catch(IllegalArgumentException JavaDoc e) {
94             // DOL API is (unfortunately) defined to return
95
// IllegalStateException if name doesn't exist.
96
}
97         return ejbRef;
98     }
99
100     protected EjbReferenceContainer getEjbReferenceContainer() {
101         return (EjbReferenceContainer)descriptor;
102     }
103
104     public void addResourceReferenceDescriptor(ResourceReferenceDescriptor
105                                                resReference) {
106         getResourceReferenceContainer().addResourceReferenceDescriptor
107             (resReference);
108     }
109                                                                                
110     /**
111      * Looks up an resource reference with the given name.
112      * Return null if it is not found.
113      *
114      * @param the name of the resource-reference
115      */

116     public ResourceReferenceDescriptor getResourceReference(String JavaDoc name) {
117         ResourceReferenceDescriptor resourceRef = null;
118         try {
119             resourceRef = getResourceReferenceContainer().
120                 getResourceReferenceByName(name);
121             // annotation has a corresponding resource-ref
122
// in xml. Just add annotation info and continue.
123
// This logic might change depending on overriding rules
124
// and order in which annotations are read w.r.t. to xml.
125
// E.g. sparse overriding in xml or loading annotations
126
// first.
127
} catch(IllegalArgumentException JavaDoc e) {
128             // DOL API is (unfortunately) defined to return
129
// IllegalStateException if name doesn't exist.
130
}
131         return resourceRef;
132     }
133
134     protected ResourceReferenceContainer getResourceReferenceContainer() {
135         return (ResourceReferenceContainer)descriptor;
136     }
137
138
139     public void addMessageDestinationReferenceDescriptor
140         (MessageDestinationReferenceDescriptor msgDestReference) {
141         getMessageDestinationReferenceContainer(
142         ).addMessageDestinationReferenceDescriptor(msgDestReference);
143     }
144                                                
145                                                                                
146     public MessageDestinationReferenceDescriptor getMessageDestinationReference
147         (String JavaDoc name) {
148         MessageDestinationReferenceDescriptor msgDestRef = null;
149         try {
150             msgDestRef = getMessageDestinationReferenceContainer().
151                 getMessageDestinationReferenceByName(name);
152             // annotation has a corresponding message-destination-ref
153
// in xml. Just add annotation info and continue.
154
// This logic might change depending on overriding rules
155
// and order in which annotations are read w.r.t. to xml.
156
// E.g. sparse overriding in xml or loading annotations
157
// first.
158
} catch(IllegalArgumentException JavaDoc e) {
159             // DOL API is (unfortunately) defined to return
160
// IllegalStateException if name doesn't exist.
161
}
162         return msgDestRef;
163     }
164
165     protected MessageDestinationReferenceContainer
166         getMessageDestinationReferenceContainer()
167     {
168         return (MessageDestinationReferenceContainer)descriptor;
169     }
170
171     public void addJmsDestinationReferenceDescriptor
172         (JmsDestinationReferenceDescriptor jmsDestReference) {
173         getJmsDestinationReferenceContainer(
174         ).addJmsDestinationReferenceDescriptor(jmsDestReference);
175     }
176                                                
177     public JmsDestinationReferenceDescriptor getJmsDestinationReference
178         (String JavaDoc name) {
179         JmsDestinationReferenceDescriptor jmsDestRef = null;
180         try {
181             jmsDestRef = getJmsDestinationReferenceContainer().
182                 getJmsDestinationReferenceByName(name);
183             // annotation has a corresponding resource-env-ref
184
// in xml. Just add annotation info and continue.
185
// This logic might change depending on overriding rules
186
// and order in which annotations are read w.r.t. to xml.
187
// E.g. sparse overriding in xml or loading annotations
188
// first.
189
} catch(IllegalArgumentException JavaDoc e) {
190             // DOL API is (unfortunately) defined to return
191
// IllegalStateException if name doesn't exist.
192
}
193         return jmsDestRef;
194     }
195
196     protected WritableJndiNameEnvironment
197         getJmsDestinationReferenceContainer()
198     {
199         return (WritableJndiNameEnvironment)descriptor;
200     }
201
202     public void addEnvEntryDescriptor(EnvironmentProperty envEntry) {
203
204         getEnvEntryContainer().addEnvironmentProperty(envEntry);
205
206     }
207                                                
208     public EnvironmentProperty getEnvEntry(String JavaDoc name) {
209         EnvironmentProperty envEntry = null;
210         try {
211             envEntry = getEnvEntryContainer().
212                 getEnvironmentPropertyByName(name);
213             // annotation has a corresponding env-entry
214
// in xml. Just add annotation info and continue.
215
// This logic might change depending on overriding rules
216
// and order in which annotations are read w.r.t. to xml.
217
// E.g. sparse overriding in xml or loading annotations
218
// first.
219
} catch(IllegalArgumentException JavaDoc e) {
220             // DOL API is (unfortunately) defined to return
221
// IllegalStateException if name doesn't exist.
222
}
223         return envEntry;
224
225     }
226     
227     protected WritableJndiNameEnvironment getEnvEntryContainer()
228     {
229         return (WritableJndiNameEnvironment)descriptor;
230     }
231
232     public void addEntityManagerFactoryReferenceDescriptor
233         (EntityManagerFactoryReferenceDescriptor emfRefDesc) {
234
235         getEmfRefContainer().addEntityManagerFactoryReferenceDescriptor
236             (emfRefDesc);
237
238     }
239                                                
240     public EntityManagerFactoryReferenceDescriptor
241         getEntityManagerFactoryReference(String JavaDoc name) {
242
243         EntityManagerFactoryReferenceDescriptor emfRefDesc = null;
244
245         try {
246             emfRefDesc = getEmfRefContainer().
247                 getEntityManagerFactoryReferenceByName(name);
248             // annotation has a corresponding entry
249
// in xml. Just add annotation info and continue.
250
// This logic might change depending on overriding rules
251
// and order in which annotations are read w.r.t. to xml.
252
// E.g. sparse overriding in xml or loading annotations
253
// first.
254
} catch(IllegalArgumentException JavaDoc e) {
255             // DOL API is (unfortunately) defined to return
256
// IllegalStateException if name doesn't exist.
257
}
258
259         return emfRefDesc;
260
261     }
262     
263     protected WritableJndiNameEnvironment getEmfRefContainer()
264     {
265         return (WritableJndiNameEnvironment)descriptor;
266     }
267
268
269     public void addEntityManagerReferenceDescriptor
270         (EntityManagerReferenceDescriptor emRefDesc) {
271
272         getEmRefContainer().addEntityManagerReferenceDescriptor
273             (emRefDesc);
274
275     }
276                                                
277     public EntityManagerReferenceDescriptor
278         getEntityManagerReference(String JavaDoc name) {
279
280         EntityManagerReferenceDescriptor emRefDesc = null;
281
282         try {
283             emRefDesc = getEmRefContainer().
284                 getEntityManagerReferenceByName(name);
285             // annotation has a corresponding entry
286
// in xml. Just add annotation info and continue.
287
// This logic might change depending on overriding rules
288
// and order in which annotations are read w.r.t. to xml.
289
// E.g. sparse overriding in xml or loading annotations
290
// first.
291
} catch(IllegalArgumentException JavaDoc e) {
292             // DOL API is (unfortunately) defined to return
293
// IllegalStateException if name doesn't exist.
294
}
295
296         return emRefDesc;
297
298     }
299     
300     protected WritableJndiNameEnvironment getEmRefContainer()
301     {
302         return (WritableJndiNameEnvironment)descriptor;
303     }
304
305    /**
306      * @param postConstructDesc
307      */

308     public void addPostConstructDescriptor(
309             LifecycleCallbackDescriptor postConstructDesc) {
310         getPostConstructContainer().addPostConstructDescriptor(postConstructDesc);
311     }
312
313     /**
314      * Look up an post-construct LifecycleCallbackDescriptor with the
315      * given name. Return null if it is not found
316      * @param className
317      */

318     public LifecycleCallbackDescriptor getPostConstruct(String JavaDoc className) {
319         LifecycleCallbackDescriptor postConstructDesc =
320             getPostConstructContainer().getPostConstructDescriptorByClass(className);
321         return postConstructDesc;
322     }
323
324     protected WritableJndiNameEnvironment getPostConstructContainer() {
325         return (WritableJndiNameEnvironment)descriptor;
326     }
327
328    /**
329      * @param preDestroyDesc
330      */

331     public void addPreDestroyDescriptor(
332             LifecycleCallbackDescriptor preDestroyDesc) {
333         getPreDestroyContainer().addPreDestroyDescriptor(preDestroyDesc);
334     }
335
336     /**
337      * Look up an pre-destroy LifecycleCallbackDescriptor with the
338      * given name. Return null if it is not found
339      * @param className
340      */

341     public LifecycleCallbackDescriptor getPreDestroy(String JavaDoc className) {
342         LifecycleCallbackDescriptor preDestroyDesc =
343             getPreDestroyContainer().getPreDestroyDescriptorByClass(className);
344         return preDestroyDesc;
345     }
346
347     protected WritableJndiNameEnvironment getPreDestroyContainer() {
348         return (WritableJndiNameEnvironment)descriptor;
349     }
350
351     public String JavaDoc getComponentClassName() {
352         return componentClassName;
353     }
354     
355     public HandlerChainContainer[]
356             getHandlerChainContainers(boolean serviceSideHandlerChain, Class JavaDoc declaringClass) {
357         // by default return null; appropriate contextx should override this
358
return null;
359     }
360     
361     public ServiceReferenceContainer[] getServiceRefContainers() {
362         // by default we return our descriptor;
363
ServiceReferenceContainer[] containers = new ServiceReferenceContainer[1];
364         containers[0] = (ServiceReferenceContainer) descriptor;
365         return containers;
366     }
367 }
368
Popular Tags