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