1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.plus.webapp;
20
21 import java.util.Iterator;
22
23 import javax.naming.Context;
24 import javax.naming.InitialContext;
25 import javax.naming.NameNotFoundException;
26
27 import org.eclipse.jetty.jndi.NamingUtil;
28 import org.eclipse.jetty.plus.annotation.Injection;
29 import org.eclipse.jetty.plus.annotation.InjectionCollection;
30 import org.eclipse.jetty.plus.annotation.LifeCycleCallback;
31 import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;
32 import org.eclipse.jetty.plus.annotation.PostConstructCallback;
33 import org.eclipse.jetty.plus.annotation.PreDestroyCallback;
34 import org.eclipse.jetty.plus.annotation.RunAsCollection;
35 import org.eclipse.jetty.plus.jndi.EnvEntry;
36 import org.eclipse.jetty.plus.jndi.Link;
37 import org.eclipse.jetty.plus.jndi.NamingEntry;
38 import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
39 import org.eclipse.jetty.util.TypeUtil;
40 import org.eclipse.jetty.util.log.Log;
41 import org.eclipse.jetty.util.log.Logger;
42 import org.eclipse.jetty.webapp.Descriptor;
43 import org.eclipse.jetty.webapp.FragmentDescriptor;
44 import org.eclipse.jetty.webapp.IterativeDescriptorProcessor;
45 import org.eclipse.jetty.webapp.Origin;
46 import org.eclipse.jetty.webapp.WebAppContext;
47 import org.eclipse.jetty.xml.XmlParser;
48
49
50
51
52
53
54
55 public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
56 {
57 private static final Logger LOG = Log.getLogger(PlusDescriptorProcessor.class);
58
59 public PlusDescriptorProcessor ()
60 {
61 try
62 {
63 registerVisitor("env-entry", getClass().getDeclaredMethod("visitEnvEntry", __signature));
64 registerVisitor("resource-ref", getClass().getDeclaredMethod("visitResourceRef", __signature));
65 registerVisitor("resource-env-ref", getClass().getDeclaredMethod("visitResourceEnvRef", __signature));
66 registerVisitor("message-destination-ref", getClass().getDeclaredMethod("visitMessageDestinationRef", __signature));
67 registerVisitor("post-construct", getClass().getDeclaredMethod("visitPostConstruct", __signature));
68 registerVisitor("pre-destroy", getClass().getDeclaredMethod("visitPreDestroy", __signature));
69 }
70 catch (Exception e)
71 {
72 throw new IllegalStateException(e);
73 }
74 }
75
76
77
78
79 public void start(WebAppContext context, Descriptor descriptor)
80 {
81
82 InjectionCollection injections = (InjectionCollection)context.getAttribute(InjectionCollection.INJECTION_COLLECTION);
83 if (injections == null)
84 {
85 injections = new InjectionCollection();
86 context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);
87 }
88
89 LifeCycleCallbackCollection callbacks = (LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
90 if (callbacks == null)
91 {
92 callbacks = new LifeCycleCallbackCollection();
93 context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, callbacks);
94 }
95
96 RunAsCollection runAsCollection = (RunAsCollection)context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
97 if (runAsCollection == null)
98 {
99 runAsCollection = new RunAsCollection();
100 context.setAttribute(RunAsCollection.RUNAS_COLLECTION, runAsCollection);
101 }
102 }
103
104
105
106
107
108 public void end(WebAppContext context,Descriptor descriptor)
109 {
110 }
111
112
113
114
115
116
117
118
119
120
121 public void visitEnvEntry (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
122 throws Exception
123 {
124 String name=node.getString("env-entry-name",false,true);
125 String type = node.getString("env-entry-type",false,true);
126 String valueStr = node.getString("env-entry-value",false,true);
127
128
129
130 if (valueStr==null || valueStr.equals(""))
131 {
132 LOG.warn("No value for env-entry-name "+name);
133 return;
134 }
135
136 Origin o = context.getMetaData().getOrigin("env-entry."+name);
137 switch (o)
138 {
139 case NotSet:
140 {
141
142 context.getMetaData().setOrigin("env-entry."+name, descriptor);
143
144
145
146
147
148 addInjections (context, descriptor, node, name, TypeUtil.fromName(type));
149 Object value = TypeUtil.valueOf(type,valueStr);
150 bindEnvEntry(name, value);
151 break;
152 }
153 case WebXml:
154 case WebDefaults:
155 case WebOverride:
156 {
157
158
159
160 if (!(descriptor instanceof FragmentDescriptor))
161 {
162
163
164 context.getMetaData().setOrigin("env-entry."+name, descriptor);
165 addInjections (context, descriptor, node, name, TypeUtil.fromName(type));
166 Object value = TypeUtil.valueOf(type,valueStr);
167 bindEnvEntry(name, value);
168 }
169 else
170 {
171
172
173
174 Descriptor d = context.getMetaData().getOriginDescriptor("env-entry."+name+".injection");
175 if (d==null || d instanceof FragmentDescriptor)
176 addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
177 }
178 break;
179 }
180 case WebFragment:
181 {
182
183 throw new IllegalStateException("Conflicting env-entry "+name+" in "+descriptor.getResource());
184 }
185 }
186 }
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231 public void visitResourceRef (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
232 throws Exception
233 {
234 String jndiName = node.getString("res-ref-name",false,true);
235 String type = node.getString("res-type", false, true);
236 String auth = node.getString("res-auth", false, true);
237 String shared = node.getString("res-sharing-scope", false, true);
238
239 Origin o = context.getMetaData().getOrigin("resource-ref."+jndiName);
240 switch (o)
241 {
242 case NotSet:
243 {
244
245 context.getMetaData().setOrigin("resource-ref."+jndiName, descriptor);
246
247
248 Class<?> typeClass = TypeUtil.fromName(type);
249 if (typeClass==null)
250 typeClass = context.loadClass(type);
251 addInjections(context, descriptor, node, jndiName, typeClass);
252 bindResourceRef(context,jndiName, typeClass);
253 break;
254 }
255 case WebXml:
256 case WebDefaults:
257 case WebOverride:
258 {
259
260 if (!(descriptor instanceof FragmentDescriptor))
261 {
262
263
264 context.getMetaData().setOrigin("resource-ref."+jndiName, descriptor);
265
266
267 Class<?> typeClass = TypeUtil.fromName(type);
268 if (typeClass==null)
269 typeClass = context.loadClass(type);
270
271 addInjections(context, descriptor, node, jndiName, typeClass);
272
273
274 bindResourceRef(context,jndiName, typeClass);
275 }
276 else
277 {
278
279
280
281
282 Descriptor d = context.getMetaData().getOriginDescriptor("resource-ref."+jndiName+".injection");
283 if (d==null || d instanceof FragmentDescriptor)
284 {
285 Class<?> typeClass = TypeUtil.fromName(type);
286 if (typeClass==null)
287 typeClass = context.loadClass(type);
288 addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
289 }
290 }
291 break;
292 }
293 case WebFragment:
294 {
295 Descriptor otherFragment = context.getMetaData().getOriginDescriptor("resource-ref."+jndiName);
296 XmlParser.Node otherFragmentRoot = otherFragment.getRoot();
297 Iterator<Object> iter = otherFragmentRoot.iterator();
298 XmlParser.Node otherNode = null;
299 while (iter.hasNext() && otherNode == null)
300 {
301 Object obj = iter.next();
302 if (!(obj instanceof XmlParser.Node)) continue;
303 XmlParser.Node n = (XmlParser.Node)obj;
304 if ("resource-ref".equals(n.getTag()) && jndiName.equals(n.getString("res-ref-name",false,true)))
305 otherNode = n;
306 }
307
308
309 if (otherNode != null)
310 {
311
312 String otherType = otherNode.getString("res-type", false, true);
313 String otherAuth = otherNode.getString("res-auth", false, true);
314 String otherShared = otherNode.getString("res-sharing-scope", false, true);
315
316
317 type = (type == null?"":type);
318 otherType = (otherType == null?"":otherType);
319 auth = (auth == null?"":auth);
320 otherAuth = (otherAuth == null?"":otherAuth);
321 shared = (shared == null?"":shared);
322 otherShared = (otherShared == null?"":otherShared);
323
324
325 if (!type.equals(otherType) || !auth.equals(otherAuth) || !shared.equals(otherShared))
326 throw new IllegalStateException("Conflicting resource-ref "+jndiName+" in "+descriptor.getResource());
327
328 addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
329 }
330 else
331 throw new IllegalStateException("resource-ref."+jndiName+" not found in declaring descriptor "+otherFragment);
332
333 }
334 }
335
336 }
337
338
339
340
341
342
343
344
345
346
347
348
349 public void visitResourceEnvRef (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
350 throws Exception
351 {
352 String jndiName = node.getString("resource-env-ref-name",false,true);
353 String type = node.getString("resource-env-ref-type", false, true);
354
355 Origin o = context.getMetaData().getOrigin("resource-env-ref."+jndiName);
356 switch (o)
357 {
358 case NotSet:
359 {
360
361
362
363 Class<?> typeClass = TypeUtil.fromName(type);
364 if (typeClass==null)
365 typeClass = context.loadClass(type);
366 addInjections (context, descriptor, node, jndiName, typeClass);
367 bindResourceEnvRef(context,jndiName, typeClass);
368 break;
369 }
370 case WebXml:
371 case WebDefaults:
372 case WebOverride:
373 {
374
375
376 if (!(descriptor instanceof FragmentDescriptor))
377 {
378
379
380 context.getMetaData().setOrigin("resource-env-ref."+jndiName, descriptor);
381 Class<?> typeClass = TypeUtil.fromName(type);
382 if (typeClass==null)
383 typeClass = context.loadClass(type);
384 addInjections (context, descriptor, node, jndiName, typeClass);
385 bindResourceEnvRef(context,jndiName, typeClass);
386 }
387 else
388 {
389
390
391 Descriptor d = context.getMetaData().getOriginDescriptor("resource-env-ref."+jndiName+".injection");
392 if (d == null || d instanceof FragmentDescriptor)
393 {
394 Class<?> typeClass = TypeUtil.fromName(type);
395 if (typeClass==null)
396 typeClass = context.loadClass(type);
397 addInjections (context, descriptor, node, jndiName, typeClass);
398 }
399 }
400 break;
401 }
402 case WebFragment:
403 {
404 Descriptor otherFragment = context.getMetaData().getOriginDescriptor("resource-env-ref."+jndiName);
405 XmlParser.Node otherFragmentRoot = otherFragment.getRoot();
406 Iterator<Object> iter = otherFragmentRoot.iterator();
407 XmlParser.Node otherNode = null;
408 while (iter.hasNext() && otherNode == null)
409 {
410 Object obj = iter.next();
411 if (!(obj instanceof XmlParser.Node)) continue;
412 XmlParser.Node n = (XmlParser.Node)obj;
413 if ("resource-env-ref".equals(n.getTag()) && jndiName.equals(n.getString("resource-env-ref-name",false,true)))
414 otherNode = n;
415 }
416 if (otherNode != null)
417 {
418
419 String otherType = otherNode.getString("resource-env-ref-type", false, true);
420
421
422 type = (type == null?"":type);
423 otherType = (otherType == null?"":otherType);
424
425
426 if (!type.equals(otherType))
427 throw new IllegalStateException("Conflicting resource-env-ref "+jndiName+" in "+descriptor.getResource());
428
429
430 addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
431 }
432 else
433 throw new IllegalStateException("resource-env-ref."+jndiName+" not found in declaring descriptor "+otherFragment);
434 }
435 }
436 }
437
438
439
440
441
442
443
444
445
446
447 public void visitMessageDestinationRef (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
448 throws Exception
449 {
450 String jndiName = node.getString("message-destination-ref-name",false,true);
451 String type = node.getString("message-destination-type",false,true);
452 String usage = node.getString("message-destination-usage",false,true);
453
454 Origin o = context.getMetaData().getOrigin("message-destination-ref."+jndiName);
455 switch (o)
456 {
457 case NotSet:
458 {
459
460 Class<?> typeClass = TypeUtil.fromName(type);
461 if (typeClass==null)
462 typeClass = context.loadClass(type);
463 addInjections(context, descriptor, node, jndiName, typeClass);
464 bindMessageDestinationRef(context,jndiName, typeClass);
465 context.getMetaData().setOrigin("message-destination-ref."+jndiName, descriptor);
466 break;
467 }
468 case WebXml:
469 case WebDefaults:
470 case WebOverride:
471 {
472
473
474 if (!(descriptor instanceof FragmentDescriptor))
475 {
476 Class<?> typeClass = TypeUtil.fromName(type);
477 if (typeClass==null)
478 typeClass = context.loadClass(type);
479 addInjections(context, descriptor, node, jndiName, typeClass);
480 bindMessageDestinationRef(context,jndiName, typeClass);
481 context.getMetaData().setOrigin("message-destination-ref."+jndiName, descriptor);
482 }
483 else
484 {
485
486
487 Descriptor d = context.getMetaData().getOriginDescriptor("message-destination-ref."+jndiName+".injection");
488 if (d == null || d instanceof FragmentDescriptor)
489 {
490 Class<?> typeClass = TypeUtil.fromName(type);
491 if (typeClass==null)
492 typeClass = context.loadClass(type);
493 addInjections(context, descriptor, node, jndiName, typeClass);
494 }
495 }
496 break;
497 }
498 case WebFragment:
499 {
500 Descriptor otherFragment = context.getMetaData().getOriginDescriptor("message-destination-ref."+jndiName);
501 XmlParser.Node otherFragmentRoot = otherFragment.getRoot();
502 Iterator<Object> iter = otherFragmentRoot.iterator();
503 XmlParser.Node otherNode = null;
504 while (iter.hasNext() && otherNode == null)
505 {
506 Object obj = iter.next();
507 if (!(obj instanceof XmlParser.Node)) continue;
508 XmlParser.Node n = (XmlParser.Node)obj;
509 if ("message-destination-ref".equals(n.getTag()) && jndiName.equals(n.getString("message-destination-ref-name",false,true)))
510 otherNode = n;
511 }
512 if (otherNode != null)
513 {
514 String otherType = node.getString("message-destination-type",false,true);
515 String otherUsage = node.getString("message-destination-usage",false,true);
516
517 type = (type==null?"":type);
518 usage = (usage==null?"":usage);
519 if (!type.equals(otherType) || !usage.equalsIgnoreCase(otherUsage))
520 throw new IllegalStateException("Conflicting message-destination-ref "+jndiName+" in "+descriptor.getResource());
521
522
523 addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
524 }
525 else
526 throw new IllegalStateException("message-destination-ref."+jndiName+" not found in declaring descriptor "+otherFragment);
527 }
528 }
529
530 }
531
532
533
534
535
536
537
538
539
540
541 public void visitPostConstruct(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
542 {
543 String className = node.getString("lifecycle-callback-class", false, true);
544 String methodName = node.getString("lifecycle-callback-method", false, true);
545
546 if (className==null || className.equals(""))
547 {
548 LOG.warn("No lifecycle-callback-class specified");
549 return;
550 }
551 if (methodName==null || methodName.equals(""))
552 {
553 LOG.warn("No lifecycle-callback-method specified for class "+className);
554 return;
555 }
556
557
558
559 Origin o = context.getMetaData().getOrigin("post-construct");
560 switch (o)
561 {
562 case NotSet:
563 {
564
565 context.getMetaData().setOrigin("post-construct", descriptor);
566
567 try
568 {
569 Class<?> clazz = context.loadClass(className);
570 LifeCycleCallback callback = new PostConstructCallback();
571 callback.setTarget(clazz, methodName);
572 ((LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)).add(callback);
573 }
574 catch (ClassNotFoundException e)
575 {
576 LOG.warn("Couldn't load post-construct target class "+className);
577 }
578 break;
579 }
580 case WebXml:
581 case WebDefaults:
582 case WebOverride:
583 {
584
585
586 if (!(descriptor instanceof FragmentDescriptor))
587 {
588 try
589 {
590 Class<?> clazz = context.loadClass(className);
591 LifeCycleCallback callback = new PostConstructCallback();
592 callback.setTarget(clazz, methodName);
593 ((LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)).add(callback);
594 }
595 catch (ClassNotFoundException e)
596 {
597 LOG.warn("Couldn't load post-construct target class "+className);
598 }
599 }
600 break;
601 }
602 case WebFragment:
603 {
604
605 try
606 {
607 Class<?> clazz = context.loadClass(className);
608 LifeCycleCallback callback = new PostConstructCallback();
609 callback.setTarget(clazz, methodName);
610 ((LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)).add(callback);
611 }
612 catch (ClassNotFoundException e)
613 {
614 LOG.warn("Couldn't load post-construct target class "+className);
615 }
616 break;
617 }
618 }
619
620 }
621
622
623
624
625
626
627
628
629 public void visitPreDestroy(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
630 {
631 String className = node.getString("lifecycle-callback-class", false, true);
632 String methodName = node.getString("lifecycle-callback-method", false, true);
633 if (className==null || className.equals(""))
634 {
635 LOG.warn("No lifecycle-callback-class specified for pre-destroy");
636 return;
637 }
638 if (methodName==null || methodName.equals(""))
639 {
640 LOG.warn("No lifecycle-callback-method specified for pre-destroy class "+className);
641 return;
642 }
643
644 Origin o = context.getMetaData().getOrigin("pre-destroy");
645 switch(o)
646 {
647 case NotSet:
648 {
649
650
651 context.getMetaData().setOrigin("pre-destroy", descriptor);
652 try
653 {
654 Class<?> clazz = context.loadClass(className);
655 LifeCycleCallback callback = new PreDestroyCallback();
656 callback.setTarget(clazz, methodName);
657 ((LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)).add(callback);
658 }
659 catch (ClassNotFoundException e)
660 {
661 LOG.warn("Couldn't load pre-destory target class "+className);
662 }
663 break;
664 }
665 case WebXml:
666 case WebDefaults:
667 case WebOverride:
668 {
669
670
671 if (!(descriptor instanceof FragmentDescriptor))
672 {
673 try
674 {
675 Class<?> clazz = context.loadClass(className);
676 LifeCycleCallback callback = new PreDestroyCallback();
677 callback.setTarget(clazz, methodName);
678 ((LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)).add(callback);
679 }
680 catch (ClassNotFoundException e)
681 {
682 LOG.warn("Couldn't load pre-destory target class "+className);
683 }
684 }
685 break;
686 }
687 case WebFragment:
688 {
689
690 try
691 {
692 Class<?> clazz = context.loadClass(className);
693 LifeCycleCallback callback = new PreDestroyCallback();
694 callback.setTarget(clazz, methodName);
695 ((LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)).add(callback);
696 }
697 catch (ClassNotFoundException e)
698 {
699 LOG.warn("Couldn't load pre-destory target class "+className);
700 }
701 break;
702 }
703 }
704 }
705
706
707
708
709
710
711
712
713
714
715 public void addInjections (WebAppContext context, Descriptor descriptor, XmlParser.Node node, String jndiName, Class<?> valueClass)
716 {
717 Iterator<XmlParser.Node> itor = node.iterator("injection-target");
718
719 while(itor.hasNext())
720 {
721 XmlParser.Node injectionNode = itor.next();
722 String targetClassName = injectionNode.getString("injection-target-class", false, true);
723 String targetName = injectionNode.getString("injection-target-name", false, true);
724 if ((targetClassName==null) || targetClassName.equals(""))
725 {
726 LOG.warn("No classname found in injection-target");
727 continue;
728 }
729 if ((targetName==null) || targetName.equals(""))
730 {
731 LOG.warn("No field or method name in injection-target");
732 continue;
733 }
734
735 InjectionCollection injections = (InjectionCollection)context.getAttribute(InjectionCollection.INJECTION_COLLECTION);
736 if (injections == null)
737 {
738 injections = new InjectionCollection();
739 context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);
740 }
741
742
743 try
744 {
745 Class<?> clazz = context.loadClass(targetClassName);
746 Injection injection = new Injection();
747 injection.setJndiName(jndiName);
748 injection.setTarget(clazz, targetName, valueClass);
749 injections.add(injection);
750
751
752 if (context.getMetaData().getOriginDescriptor(node.getTag()+"."+jndiName+".injection") == null)
753 context.getMetaData().setOrigin(node.getTag()+"."+jndiName+".injection", descriptor);
754 }
755 catch (ClassNotFoundException e)
756 {
757 LOG.warn("Couldn't load injection target class "+targetClassName);
758 }
759 }
760 }
761
762
763
764
765
766
767
768
769
770 public void bindEnvEntry(String name, Object value) throws Exception
771 {
772 InitialContext ic = null;
773 boolean bound = false;
774
775
776
777 ic = new InitialContext();
778 try
779 {
780 NamingEntry ne = (NamingEntry)ic.lookup("java:comp/env/"+NamingEntryUtil.makeNamingEntryName(ic.getNameParser(""), name));
781 if (ne!=null && ne instanceof EnvEntry)
782 {
783 EnvEntry ee = (EnvEntry)ne;
784 bound = ee.isOverrideWebXml();
785 }
786 }
787 catch (NameNotFoundException e)
788 {
789 bound = false;
790 }
791
792 if (!bound)
793 {
794
795 Context envCtx = (Context)ic.lookup("java:comp/env");
796 NamingUtil.bind(envCtx, name, value);
797 }
798 }
799
800
801
802
803
804
805
806
807
808
809 public void bindResourceRef(WebAppContext context, String name, Class<?> typeClass)
810 throws Exception
811 {
812 bindEntry(context, name, typeClass);
813 }
814
815
816
817
818
819 public void bindResourceEnvRef(WebAppContext context, String name, Class<?> typeClass)
820 throws Exception
821 {
822 bindEntry(context, name, typeClass);
823 }
824
825
826 public void bindMessageDestinationRef(WebAppContext context, String name, Class<?> typeClass)
827 throws Exception
828 {
829 bindEntry(context, name, typeClass);
830 }
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848 protected void bindEntry (WebAppContext context, String name, Class<?> typeClass)
849 throws Exception
850 {
851 String nameInEnvironment = name;
852 boolean bound = false;
853
854
855
856 Object scope = context;
857 NamingEntry ne = NamingEntryUtil.lookupNamingEntry(scope, name);
858
859 if (ne!=null && (ne instanceof Link))
860 {
861
862 nameInEnvironment = ((Link)ne).getLink();
863 }
864
865
866 scope = context;
867 bound = NamingEntryUtil.bindToENC(scope, name, nameInEnvironment);
868
869 if (bound)
870 return;
871
872
873 scope = context.getServer();
874 bound = NamingEntryUtil.bindToENC(scope, name, nameInEnvironment);
875 if (bound)
876 return;
877
878
879 bound = NamingEntryUtil.bindToENC(null, name, nameInEnvironment);
880 if (bound)
881 return;
882
883
884
885
886 nameInEnvironment = typeClass.getName()+"/default";
887
888 NamingEntry defaultNE = NamingEntryUtil.lookupNamingEntry(context.getServer(), nameInEnvironment);
889 if (defaultNE==null)
890 defaultNE = NamingEntryUtil.lookupNamingEntry(null, nameInEnvironment);
891
892 if (defaultNE!=null)
893 defaultNE.bindToENC(name);
894 else
895 throw new IllegalStateException("Nothing to bind for name "+nameInEnvironment);
896 }
897
898
899 }