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