1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.jndi.java;
20
21 import java.util.Hashtable;
22
23 import javax.naming.Context;
24 import javax.naming.Name;
25 import javax.naming.NamingException;
26 import javax.naming.spi.ObjectFactory;
27
28 import org.eclipse.jetty.util.log.Log;
29 import org.eclipse.jetty.util.log.Logger;
30
31
32
33
34
35
36
37
38
39
40
41 public class javaURLContextFactory implements ObjectFactory
42 {
43 private static final Logger LOG = Log.getLogger(javaURLContextFactory.class);
44
45
46
47
48
49
50
51
52
53
54
55 public Object getObjectInstance(Object url, Name name, Context ctx, Hashtable env)
56 throws Exception
57 {
58
59 if (url == null)
60 {
61 if(LOG.isDebugEnabled())LOG.debug(">>> new root context requested ");
62 return new javaRootURLContext(env);
63 }
64
65
66 if (url instanceof String)
67 {
68 if(LOG.isDebugEnabled())LOG.debug(">>> resolution of url "+url+" requested");
69 Context rootctx = new javaRootURLContext (env);
70 return rootctx.lookup ((String)url);
71 }
72
73
74 if (url instanceof String[])
75 {
76 if(LOG.isDebugEnabled())LOG.debug(">>> resolution of array of urls requested");
77 String[] urls = (String[])url;
78 Context rootctx = new javaRootURLContext (env);
79 Object object = null;
80 NamingException e = null;
81 for (int i=0;(i< urls.length) && (object == null); i++)
82 {
83 try
84 {
85 object = rootctx.lookup (urls[i]);
86 }
87 catch (NamingException x)
88 {
89 e = x;
90 }
91 }
92
93 if (object == null)
94 throw e;
95 else
96 return object;
97 }
98
99 if(LOG.isDebugEnabled())LOG.debug(">>> No idea what to do, so return a new root context anyway");
100 return new javaRootURLContext (env);
101 }
102 };