01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.core.ivm.naming.java;
17:
18: import java.util.Hashtable;
19:
20: import javax.naming.Context;
21: import javax.naming.Name;
22: import javax.naming.NamingException;
23: import javax.naming.spi.InitialContextFactory;
24: import javax.naming.spi.ObjectFactory;
25:
26: import org.apache.openejb.core.CoreDeploymentInfo;
27: import org.apache.openejb.core.ThreadContext;
28: import org.apache.openejb.spi.ContainerSystem;
29: import org.apache.openejb.loader.SystemInstance;
30:
31: public class javaURLContextFactory implements ObjectFactory,
32: InitialContextFactory {
33:
34: public Context getInitialContext(Hashtable env)
35: throws NamingException {
36: return getContext();
37: }
38:
39: public Object getObjectInstance(Object obj, Name name,
40: Context nameCtx, Hashtable env) throws NamingException {
41: if (obj == null) {
42: /*
43: A null obj ref means the NamingManager is requesting
44: a Context that can resolve the 'java:' schema
45: */
46: return getContext();
47: } else if (obj instanceof java.lang.String) {
48: String string = (String) obj;
49: if (string.startsWith("java:comp")
50: || string.startsWith("java:openejb")) {
51: /*
52: If the obj is a URL String with the 'java:' schema
53: resolve the URL in the context of this threads JNDI ENC
54: */
55: string = string.substring(string.indexOf(':'));
56: Context encRoot = getContext();
57: return encRoot.lookup(string);
58: }
59: }
60: return null;
61: }
62:
63: public Object getObjectInstance(Object obj, Hashtable env)
64: throws NamingException {
65: return getContext();
66: }
67:
68: public Context getContext() {
69: Context jndiCtx = null;
70:
71: ThreadContext callContext = ThreadContext.getThreadContext();
72: if (callContext == null) {
73: ContainerSystem containerSystem = SystemInstance.get()
74: .getComponent(ContainerSystem.class);
75: return containerSystem.getJNDIContext();
76: }
77:
78: CoreDeploymentInfo di = callContext.getDeploymentInfo();
79: if (di != null) {
80: return di.getJndiEnc();
81: } else {
82: ContainerSystem containerSystem = SystemInstance.get()
83: .getComponent(ContainerSystem.class);
84: return containerSystem.getJNDIContext();
85: }
86: }
87: }
|