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 public class javaURLContextFactory implements ObjectFactory
38 {
39 private static final Logger LOG = Log.getLogger(javaURLContextFactory.class);
40
41
42
43
44
45
46
47
48
49
50
51 public Object getObjectInstance(Object url, Name name, Context ctx, Hashtable env)
52 throws Exception
53 {
54
55 if (url == null)
56 {
57 if(LOG.isDebugEnabled())LOG.debug(">>> new root context requested ");
58 return new javaRootURLContext(env);
59 }
60
61
62 if (url instanceof String)
63 {
64 if(LOG.isDebugEnabled())LOG.debug(">>> resolution of url "+url+" requested");
65 Context rootctx = new javaRootURLContext (env);
66 return rootctx.lookup ((String)url);
67 }
68
69
70 if (url instanceof String[])
71 {
72 if(LOG.isDebugEnabled())LOG.debug(">>> resolution of array of urls requested");
73 String[] urls = (String[])url;
74 Context rootctx = new javaRootURLContext (env);
75 Object object = null;
76 NamingException e = null;
77 for (int i=0;(i< urls.length) && (object == null); i++)
78 {
79 try
80 {
81 object = rootctx.lookup (urls[i]);
82 }
83 catch (NamingException x)
84 {
85 e = x;
86 }
87 }
88
89 if (object == null)
90 throw e;
91 else
92 return object;
93 }
94
95 if(LOG.isDebugEnabled())LOG.debug(">>> No idea what to do, so return a new root context anyway");
96 return new javaRootURLContext (env);
97 }
98 };