01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jndi.url.java;
09:
10: import java.util.Hashtable; //import java.net.URI;
11: import java.net.URL;
12:
13: import javax.naming.Context;
14: import javax.naming.Name;
15: import javax.naming.spi.ObjectFactory;
16:
17: import org.huihoo.jfox.jndi.ContextSupport; //import org.huihoo.jfox.jndi.URLUtil;
18: import org.huihoo.jfox.jndi.JNDIProperties;
19: import org.huihoo.jfox.jndi.url.JndiURL;
20:
21: /**
22: * performed when use Reference with it's RefAddr is StringRefAddr,type is URL, content is "java://.."
23: *
24: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
25: */
26:
27: public class javaURLContextFactory implements ObjectFactory {
28: public Object getObjectInstance(Object obj, Name name,
29: Context nameCtx, Hashtable environment) throws Exception {
30: if (obj == null)
31: obj = JNDIProperties.PROVIDER_URL;
32: if (obj instanceof String) {
33: String url = (String) obj;
34: // URI uri = new URI(url);
35: URL _url = JndiURL.getURL(nameCtx, url);
36: Hashtable env = (Hashtable) environment.clone();
37: // env.put(Context.PROVIDER_URL, URLUtil.getProviderURL(uri));
38: env.put(Context.PROVIDER_URL, _url.getProtocol() + "://"
39: + _url.getHost() + ":" + _url.getPort());
40: ContextSupport context = new ContextSupport("/", env);
41: return context;
42: } else {
43: return null;
44: }
45: }
46:
47: }
|