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