KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.LinkedList JavaDoc;
35 import java.util.Set JavaDoc;
36
37 import com.sun.enterprise.util.LocalStringManagerImpl;
38 import com.sun.enterprise.deployment.types.EjbReference;
39 import com.sun.enterprise.deployment.types.EjbReferenceContainer;
40 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer;
41 import com.sun.enterprise.deployment.types.ResourceReferenceContainer;
42 import com.sun.enterprise.deployment.util.LogDomains;
43 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
44
45 /**
46  * Contains information about jndiEnvironmentRefsGroup.
47  */

48
49 public abstract class JndiEnvironmentRefsGroupDescriptor extends Descriptor
50         implements EjbReferenceContainer, ResourceReferenceContainer,
51         MessageDestinationReferenceContainer, WritableJndiNameEnvironment
52 {
53     private static LocalStringManagerImpl localStrings =
54         new LocalStringManagerImpl(JndiEnvironmentRefsGroupDescriptor.class);
55
56     private static final Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER);
57
58     protected Map JavaDoc<CallbackType,
59                 Set JavaDoc<LifecycleCallbackDescriptor>> callbackDescriptors
60         = new HashMap JavaDoc<CallbackType, Set JavaDoc<LifecycleCallbackDescriptor>>();
61
62     protected EjbBundleDescriptor bundleDescriptor;
63
64     protected Set JavaDoc environmentProperties;
65     protected Set JavaDoc ejbReferences;
66     protected Set JavaDoc jmsDestReferences;
67     protected Set JavaDoc messageDestReferences;
68     protected Set JavaDoc resourceReferences;
69     protected Set JavaDoc serviceReferences;
70     protected Set JavaDoc<EntityManagerFactoryReferenceDescriptor>
71         entityManagerFactoryReferences;
72     protected Set JavaDoc<EntityManagerReferenceDescriptor>
73         entityManagerReferences;
74
75     // callbacks
76
public void addCallbackDescriptor(CallbackType type,
77             LifecycleCallbackDescriptor llcDesc) {
78         Set JavaDoc<LifecycleCallbackDescriptor> llcDescs =
79             getCallbackDescriptors(type);
80         boolean found = false;
81         for (LifecycleCallbackDescriptor llcD : llcDescs) {
82             if ((llcDesc.getLifecycleCallbackClass() != null) &&
83                 llcDesc.getLifecycleCallbackClass().equals(
84                     llcD.getLifecycleCallbackClass())) {
85                 found = true;
86             }
87         }
88
89         if (!found) {
90             llcDescs.add(llcDesc);
91         }
92     }
93
94     public void addCallbackDescriptors(CallbackType type,
95                                   Set JavaDoc<LifecycleCallbackDescriptor> lccSet) {
96         for (LifecycleCallbackDescriptor lcc : lccSet) {
97             addCallbackDescriptor(type, lcc);
98         }
99     }
100
101     public Set JavaDoc<LifecycleCallbackDescriptor> getCallbackDescriptors(
102             CallbackType type)
103     {
104         Set JavaDoc<LifecycleCallbackDescriptor> lccDescs =
105             callbackDescriptors.get(type);
106         if (lccDescs == null) {
107             lccDescs = new HashSet JavaDoc<LifecycleCallbackDescriptor>();
108             callbackDescriptors.put(type, lccDescs);
109         }
110         return lccDescs;
111     }
112
113     public boolean hasCallbackDescriptor(CallbackType type) {
114         return (getCallbackDescriptors(type).size() > 0);
115     }
116
117     public void addPostConstructDescriptor(LifecycleCallbackDescriptor lcDesc) {
118         addCallbackDescriptor(CallbackType.POST_CONSTRUCT, lcDesc);
119     }
120
121     public LifecycleCallbackDescriptor getPostConstructDescriptorByClass(String JavaDoc className) {
122         throw new UnsupportedOperationException JavaDoc();
123     }
124
125     public Set JavaDoc<LifecycleCallbackDescriptor> getPostConstructDescriptors() {
126         return getCallbackDescriptors(CallbackType.POST_CONSTRUCT);
127     }
128
129     public void addPreDestroyDescriptor(LifecycleCallbackDescriptor lcDesc) {
130         addCallbackDescriptor(CallbackType.PRE_DESTROY, lcDesc);
131     }
132
133     public LifecycleCallbackDescriptor getPreDestroyDescriptorByClass(String JavaDoc className) {
134         throw new UnsupportedOperationException JavaDoc();
135     }
136
137     public Set JavaDoc<LifecycleCallbackDescriptor> getPreDestroyDescriptors() {
138         return getCallbackDescriptors(CallbackType.PRE_DESTROY);
139     }
140
141     
142     public EjbBundleDescriptor getEjbBundleDescriptor() {
143     return this.bundleDescriptor;
144     }
145     
146     public void setEjbBundleDescriptor(EjbBundleDescriptor bundleDescriptor) {
147     this.bundleDescriptor = bundleDescriptor;
148     }
149
150     // ejb ref
151
public void addEjbReferenceDescriptor(EjbReference ejbReference) {
152     this.getEjbReferenceDescriptors().add(ejbReference);
153     ejbReference.setReferringBundleDescriptor(getEjbBundleDescriptor());
154     }
155
156     public EjbReference getEjbReference(String JavaDoc name) {
157     for (Iterator JavaDoc itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) {
158         EjbReference er = (EjbReference) itr.next();
159         if (er.getName().equals(name)) {
160         return er;
161         }
162     }
163     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
164                 "enterprise.deployment.exceptionhasnoejbrefbyname",
165                 "This class has no ejb reference by the name of {0}",
166                 new Object JavaDoc[] {name}));
167     }
168
169     public Set JavaDoc getEjbReferenceDescriptors() {
170     if (this.ejbReferences == null) {
171         this.ejbReferences = new OrderedSet();
172     }
173     return this.ejbReferences = new OrderedSet(this.ejbReferences);
174     }
175
176     public void removeEjbReferenceDescriptor(EjbReference ejbReference) {
177     this.getEjbReferenceDescriptors().remove(ejbReference);
178     ejbReference.setReferringBundleDescriptor(null);
179     }
180
181     // message destination ref
182
public void addMessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor msgDestReference) {
183         if( getEjbBundleDescriptor() != null ) {
184             msgDestReference.setReferringBundleDescriptor
185                 (getEjbBundleDescriptor());
186         }
187         this.getMessageDestinationReferenceDescriptors().add(msgDestReference);
188     }
189
190     public MessageDestinationReferenceDescriptor getMessageDestinationReferenceByName(String JavaDoc name) {
191     for (Iterator JavaDoc itr =
192                  this.getMessageDestinationReferenceDescriptors().iterator();
193              itr.hasNext();) {
194         MessageDestinationReferenceDescriptor mdr =
195                 (MessageDestinationReferenceDescriptor) itr.next();
196         if (mdr.getName().equals(name)) {
197         return mdr;
198         }
199     }
200     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
201                 "enterprise.deployment.exceptionhasnomsgdestrefbyname",
202                 "This class has no message destination reference by the name of {0}",
203                 new Object JavaDoc[] {name}));
204     }
205
206     public Set JavaDoc getMessageDestinationReferenceDescriptors() {
207         if( this.messageDestReferences == null ) {
208             this.messageDestReferences = new OrderedSet();
209         }
210         return this.messageDestReferences =
211             new OrderedSet(this.messageDestReferences);
212     }
213
214     public void removeMessageDestinationReferenceDescriptor
215         (MessageDestinationReferenceDescriptor msgDestRef) {
216         this.getMessageDestinationReferenceDescriptors().remove(msgDestRef);
217     }
218
219     // env property
220
public void addEnvironmentProperty(EnvironmentProperty environmentProperty) {
221     this.getEnvironmentProperties().add(environmentProperty);
222     }
223
224     public Set JavaDoc getEnvironmentProperties() {
225     if (this.environmentProperties == null) {
226         this.environmentProperties = new OrderedSet();
227     }
228     return this.environmentProperties = new OrderedSet(this.environmentProperties);
229     }
230
231     public EnvironmentProperty getEnvironmentPropertyByName(String JavaDoc name) {
232     for (Iterator JavaDoc itr = this.getEnvironmentProperties().iterator(); itr.hasNext();) {
233         EnvironmentProperty ev = (EnvironmentProperty) itr.next();
234         if (ev.getName().equals(name)) {
235         return ev;
236         }
237     }
238     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
239                 "enterprise.deployment.exceptionhasnoenvpropertybyname",
240                 "This class has no environment property by the name of {0}",
241                 new Object JavaDoc[] {name}));
242     }
243
244     public void removeEnvironmentProperty(
245             EnvironmentProperty environmentProperty) {
246     this.getEnvironmentProperties().remove(environmentProperty);
247     }
248
249     // service ref
250
public void addServiceReferenceDescriptor(
251             ServiceReferenceDescriptor serviceReference) {
252         serviceReference.setBundleDescriptor(getEjbBundleDescriptor());
253         this.getServiceReferenceDescriptors().add(serviceReference);
254     }
255
256     public Set JavaDoc getServiceReferenceDescriptors() {
257         if( this.serviceReferences == null ) {
258             this.serviceReferences = new OrderedSet();
259         }
260         return this.serviceReferences = new OrderedSet(this.serviceReferences);
261     }
262
263     public ServiceReferenceDescriptor getServiceReferenceByName(String JavaDoc name) {
264     for (Iterator JavaDoc itr = this.getServiceReferenceDescriptors().iterator();
265              itr.hasNext();) {
266         ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor)
267                 itr.next();
268         if (srd.getName().equals(name)) {
269         return srd;
270         }
271     }
272     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
273                 "enterprise.deployment.exceptionhasnoservicerefbyname",
274                 "This class has no service reference by the name of {0}",
275                 new Object JavaDoc[] {name}));
276     }
277
278     public void removeServiceReferenceDescriptor(
279         ServiceReferenceDescriptor serviceReference) {
280         this.getServiceReferenceDescriptors().remove(serviceReference);
281     }
282
283     // resource ref
284
public void addResourceReferenceDescriptor(
285             ResourceReferenceDescriptor resourceReference) {
286     this.getResourceReferenceDescriptors().add(resourceReference);
287     }
288
289     public Set JavaDoc getResourceReferenceDescriptors() {
290     if (this.resourceReferences == null) {
291         this.resourceReferences = new OrderedSet();
292     }
293     return this.resourceReferences = new OrderedSet(this.resourceReferences);
294     }
295
296     public ResourceReferenceDescriptor getResourceReferenceByName(String JavaDoc name) {
297     for (Iterator JavaDoc itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) {
298         ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next();
299         if (next.getName().equals(name)) {
300         return next;
301         }
302     }
303     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
304                 "enterprise.deployment.exceptionhasnoresourcerefbyname",
305                 "This class has no resource reference by the name of {0}",
306                 new Object JavaDoc[] {name}));
307     }
308
309     public void removeResourceReferenceDescriptor(
310             ResourceReferenceDescriptor resourceReference) {
311     this.getResourceReferenceDescriptors().remove(resourceReference);
312     }
313
314     // jms destination ref
315
public void addJmsDestinationReferenceDescriptor(
316         JmsDestinationReferenceDescriptor jmsDestinationReference) {
317     this.getJmsDestinationReferenceDescriptors().add(jmsDestinationReference);
318     }
319
320     public Set JavaDoc getJmsDestinationReferenceDescriptors() {
321     if (this.jmsDestReferences == null) {
322         this.jmsDestReferences = new OrderedSet();
323     }
324     return this.jmsDestReferences = new OrderedSet(this.jmsDestReferences);
325     }
326
327     public JmsDestinationReferenceDescriptor getJmsDestinationReferenceByName(String JavaDoc name) {
328     for (Iterator JavaDoc itr = this.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext();) {
329         JmsDestinationReferenceDescriptor jdr = (JmsDestinationReferenceDescriptor) itr.next();
330         if (jdr.getName().equals(name)) {
331         return jdr;
332         }
333     }
334     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
335                 "enterprise.deployment.exceptionhasnojmsdestrefbyname",
336                 "This class has no JMS destination reference by the name of {0}",
337                 new Object JavaDoc[] {name}));
338     }
339
340     public void removeJmsDestinationReferenceDescriptor(
341         JmsDestinationReferenceDescriptor jmsDestinationReference) {
342     this.getJmsDestinationReferenceDescriptors().remove(jmsDestinationReference);
343     }
344
345     // entity manager factory ref
346
public void addEntityManagerFactoryReferenceDescriptor(
347                 EntityManagerFactoryReferenceDescriptor reference) {
348         if( getEjbBundleDescriptor() != null ) {
349             reference.setReferringBundleDescriptor
350                 (getEjbBundleDescriptor());
351         }
352         this.getEntityManagerFactoryReferenceDescriptors().add(reference);
353     }
354
355     public Set JavaDoc<EntityManagerFactoryReferenceDescriptor> getEntityManagerFactoryReferenceDescriptors() {
356         if( this.entityManagerFactoryReferences == null ) {
357             this.entityManagerFactoryReferences =
358                 new HashSet JavaDoc<EntityManagerFactoryReferenceDescriptor>();
359         }
360         return this.entityManagerFactoryReferences =
361             new HashSet JavaDoc<EntityManagerFactoryReferenceDescriptor>
362             (entityManagerFactoryReferences);
363     }
364
365     public EntityManagerFactoryReferenceDescriptor getEntityManagerFactoryReferenceByName(String JavaDoc name) {
366     for (EntityManagerFactoryReferenceDescriptor next :
367              getEntityManagerFactoryReferenceDescriptors()) {
368
369         if (next.getName().equals(name)) {
370         return next;
371         }
372     }
373     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
374                 "enterprise.deployment.exceptionhasnoentitymgrfactoryrefbyname",
375                 "This class has no entity manager factory reference by the name of {0}",
376                 new Object JavaDoc[] {name}));
377     }
378
379     // entity manager ref
380
public void addEntityManagerReferenceDescriptor(
381                 EntityManagerReferenceDescriptor reference) {
382         if( getEjbBundleDescriptor() != null ) {
383             reference.setReferringBundleDescriptor
384                 (getEjbBundleDescriptor());
385         }
386         this.getEntityManagerReferenceDescriptors().add(reference);
387     }
388
389     public Set JavaDoc<EntityManagerReferenceDescriptor> getEntityManagerReferenceDescriptors() {
390         if( this.entityManagerReferences == null ) {
391             this.entityManagerReferences =
392                 new HashSet JavaDoc<EntityManagerReferenceDescriptor>();
393         }
394         return this.entityManagerReferences =
395             new HashSet JavaDoc<EntityManagerReferenceDescriptor>
396             (this.entityManagerReferences);
397     }
398
399     public EntityManagerReferenceDescriptor getEntityManagerReferenceByName(String JavaDoc name) {
400     for (EntityManagerReferenceDescriptor next :
401              getEntityManagerReferenceDescriptors()) {
402
403         if (next.getName().equals(name)) {
404         return next;
405         }
406     }
407     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
408                 "enterprise.deployment.exceptionhasnoentitymgrrefbyname",
409                 "This class has no entity manager reference by the name of {0}",
410                 new Object JavaDoc[] {name}));
411     }
412
413     public List JavaDoc<InjectionCapable> getInjectableResourcesByClass(String JavaDoc className) {
414         throw new UnsupportedOperationException JavaDoc();
415     }
416
417     public InjectionInfo getInjectionInfoByClass(String JavaDoc className) {
418         throw new UnsupportedOperationException JavaDoc();
419     }
420 }
421
Popular Tags