01: package org.mockejb.jndi.java;
02:
03: import java.util.Hashtable;
04:
05: import javax.naming.Context;
06: import javax.naming.Name;
07: import javax.naming.spi.InitialContextFactory;
08: import javax.naming.spi.ObjectFactory;
09:
10: import org.mockejb.jndi.MockContextFactory;
11:
12: /**
13: * Handles the <code>java:</code> context. The class follows naming convention
14: * described in <code>javax.naming.spi.NamingManager.getURLContext()</code>.
15: * it delgates to the <code>MockContextFactory</code> to create the context.
16: *
17: * @author Alexander Ananiev
18: */
19: public class javaURLContextFactory implements ObjectFactory {
20:
21: private InitialContextFactory contextFactory = new MockContextFactory();
22:
23: public Object getObjectInstance(Object urlInfo, Name name,
24: Context nameCtx, Hashtable env) throws Exception {
25:
26: if (urlInfo == null) {
27: return contextFactory.getInitialContext(env);
28: }
29: if (urlInfo instanceof String)
30: throw new RuntimeException(
31: "Internal error in javaURLContextFactory.getObjectInstance: urlInfo="
32: + urlInfo);
33: if (urlInfo instanceof String[])
34: throw new RuntimeException(
35: "Internal error in javaURLContextFactory.getObjectInstance: urlInfo="
36: + urlInfo);
37: else
38: throw new IllegalArgumentException(
39: "javaURLContextFactory.getObjectInstance: argument must be an java URL String or array of URLs");
40: }
41:
42: }
|