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.geronimo.corba;
17:
18: import java.io.Serializable;
19: import java.io.ObjectStreamException;
20: import java.io.InvalidObjectException;
21: import javax.ejb.EJBObject;
22: import javax.ejb.EJBHome;
23: import javax.rmi.PortableRemoteObject;
24: import javax.naming.Context;
25: import javax.naming.InitialContext;
26:
27: import org.omg.CORBA.ORB;
28:
29: /**
30: * @version $Revision: 474745 $ $Date: 2006-11-14 03:30:38 -0800 (Tue, 14 Nov 2006) $
31: */
32: public class CORBAEJBMemento implements Serializable {
33: private final String ior;
34: private final boolean home;
35:
36: public CORBAEJBMemento(String ior, boolean home) {
37: this .ior = ior;
38: this .home = home;
39: }
40:
41: private Object readResolve() throws ObjectStreamException {
42: Class type;
43: if (home) {
44: type = EJBHome.class;
45: } else {
46: type = EJBObject.class;
47: }
48:
49: try {
50: return PortableRemoteObject.narrow(getOrb()
51: .string_to_object(ior), type);
52: } catch (Exception e) {
53: throw (InvalidObjectException) new InvalidObjectException(
54: "Unable to convert IOR into object").initCause(e);
55: }
56: }
57:
58: private static ORB getOrb() {
59: try {
60: Context context = new InitialContext();
61: ORB orb = (ORB) context.lookup("java:comp/ORB");
62: return orb;
63: } catch (Throwable e) {
64: throw (org.omg.CORBA.MARSHAL) new org.omg.CORBA.MARSHAL(
65: "Could not find ORB in jndi at java:comp/ORB", 0,
66: org.omg.CORBA.CompletionStatus.COMPLETED_YES)
67: .initCause(e);
68: }
69: }
70: }
|