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;
17:
18: import org.apache.openejb.core.CoreDeploymentInfo;
19: import org.apache.openejb.core.ThreadContext;
20:
21: /*
22: This class is used as a replacement when a IvmContext referenced by a stateful bean
23: is being serialized for passivation along with the bean. It ensures that the entire
24: JNDI ENC graph is not serialized with the bean and returns a reference to the correct
25: IvmContext when its deserialized.
26:
27: Stateful beans are activated by a thread with the relavent DeploymentInfo object in the
28: ThreadContext which makes it possible to lookup the correct IvmContext and swap in place of
29: this object.
30: */
31:
32: public class JndiEncArtifact implements java.io.Serializable {
33: String path = new String();
34:
35: public JndiEncArtifact(IvmContext context) {
36: NameNode node = context.mynode;
37: do {
38: path = node.getAtomicName() + "/" + path;
39: node = node.getParent();
40: } while (node != null);
41: }
42:
43: public Object readResolve() throws java.io.ObjectStreamException {
44: ThreadContext thrdCntx = ThreadContext.getThreadContext();
45: CoreDeploymentInfo deployment = thrdCntx.getDeploymentInfo();
46: javax.naming.Context cntx = deployment.getJndiEnc();
47: try {
48: Object obj = cntx.lookup(path);
49: if (obj == null)
50: throw new java.io.InvalidObjectException(
51: "JNDI ENC context reference could not be properly resolved when bean instance was activated");
52: return obj;
53: } catch (javax.naming.NamingException e) {
54: throw (java.io.InvalidObjectException) new java.io.InvalidObjectException(
55: "JNDI ENC context reference could not be properly resolved due to a JNDI exception, when bean instance was activated")
56: .initCause(e);
57: }
58: }
59:
60: }
|