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