01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.ejb3.naming.url;
08:
09: import java.util.Hashtable;
10: import javax.naming.Context;
11: import javax.naming.InitialContext;
12: import javax.naming.Name;
13: import javax.naming.spi.ObjectFactory;
14:
15: /**
16: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
17: */
18: public class javaURLContextFactory implements ObjectFactory {
19:
20: /**
21: * @param url String with a "java:" prefix or null.
22: * @param name Name of context, relative to ctx, or null.
23: * @param ctx Context relative to which 'name' is named.
24: * @param env Environment to use when creating the context *
25: * @return an instance of javaURLContext for a java URL. If url is null, the
26: * result is a context for resolving java URLs. If url is a URL, the
27: * result is a context named by the URL.
28: * @throws Exception if this object factory encountered an exception while
29: * attempting to create an object, and no other object factories are
30: * to be tried.
31: */
32: public Object getObjectInstance(Object url, Name name, Context ctx,
33: Hashtable env) throws Exception {
34:
35: if (url == null) {
36: // All naming operations with "java:..." comes here
37: // Users are encouraged to used intermediate contexts:
38: // ctx = ic.lookup("java:comp/env") called only once (perfs)
39: return new InitialContext(env);
40: }
41: if (url instanceof String) {
42: return null;
43: } else if (url instanceof String[]) {
44: // Don't know what to do here
45: return null;
46: } else {
47: // invalid argument
48: throw (new IllegalArgumentException("javaURLContextFactory"));
49: }
50: }
51: }
|