001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.corba; 018 019 import java.io.IOException; 020 import java.io.ObjectInputStream; 021 import java.io.ObjectOutputStream; 022 import javax.ejb.EJBHome; 023 import javax.ejb.EJBObject; 024 import javax.ejb.spi.HandleDelegate; 025 import javax.rmi.PortableRemoteObject; 026 027 028 /** 029 * See ejb spec 2.1, 19.5.5.1 030 * 031 * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $ 032 */ 033 public class CORBAHandleDelegate implements HandleDelegate { 034 035 /** 036 * Called by home handles to deserialize stubs in any app server, including ones by other vendors. 037 * The spec seems to imply that a simple cast of in.readObject() should work but in certain 038 * orbs this does not seem to work and in.readObject returns a generic remote stub that needs 039 * to be narrowed. Although we think this is likely an orb bug this code with narrow will 040 * work in both circumstances. 041 * @param in 042 * @return 043 * @throws ClassNotFoundException 044 * @throws IOException 045 */ 046 public EJBHome readEJBHome(ObjectInputStream in) throws ClassNotFoundException, IOException { 047 Object o = in.readObject(); 048 EJBHome home = (EJBHome) PortableRemoteObject.narrow(o, EJBHome.class); 049 return home; 050 } 051 052 /** 053 * Called by handles to deserialize stubs in any app server. See comment to readEJBHome. 054 * @param in 055 * @return 056 * @throws ClassNotFoundException 057 * @throws IOException 058 */ 059 public EJBObject readEJBObject(ObjectInputStream in) throws ClassNotFoundException, IOException { 060 Object o = in.readObject(); 061 EJBObject object = (EJBObject) PortableRemoteObject.narrow(o, EJBObject.class); 062 return object; 063 } 064 065 public void writeEJBHome(EJBHome ejbHome, ObjectOutputStream out) throws IOException { 066 out.writeObject(ejbHome); 067 } 068 069 public void writeEJBObject(EJBObject ejbObject, ObjectOutputStream out) throws IOException { 070 out.writeObject(ejbObject); 071 } 072 073 }