001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.iiop.orb;
031:
032: import com.caucho.vfs.*;
033: import com.caucho.iiop.*;
034:
035: import java.util.logging.Logger;
036: import java.lang.reflect.Proxy;
037: import java.rmi.*;
038: import javax.rmi.PortableRemoteObject;
039: import javax.rmi.CORBA.PortableRemoteObjectDelegate;
040: import java.io.IOException;
041:
042: public class PortableRemoteObjectDelegateImpl implements
043: PortableRemoteObjectDelegate {
044: public void exportObject(Remote obj) throws RemoteException {
045: throw new UnsupportedOperationException();
046: }
047:
048: public Remote toStub(Remote obj) throws NoSuchObjectException {
049: throw new UnsupportedOperationException();
050: }
051:
052: public void unexportObject(Remote obj) throws NoSuchObjectException {
053: throw new UnsupportedOperationException();
054: }
055:
056: public Object narrow(Object narrowFrom, Class narrowTo)
057: throws ClassCastException {
058: try {
059: if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
060: return narrowFrom;
061:
062: if (narrowFrom instanceof StubImpl) {
063: StubImpl stub = (StubImpl) narrowFrom;
064:
065: if (!narrowTo.getName().startsWith("org.omg.")) {
066: org.omg.CORBA_2_3.portable.InputStream is = null;
067:
068: org.omg.CORBA_2_3.portable.OutputStream os = ((org.omg.CORBA_2_3.portable.OutputStream) stub
069: ._request("_is_a", true));
070:
071: os.write_string("RMI:" + narrowTo.getName() + ":0");
072:
073: is = ((org.omg.CORBA_2_3.portable.InputStream) stub
074: ._invoke(os));
075:
076: boolean isA = is.read_boolean();
077: is.close();
078:
079: if (!isA)
080: throw new ClassCastException(narrowFrom
081: .getClass().getName());
082: }
083:
084: StubMarshal stubMarshal = new StubMarshal(narrowTo);
085:
086: IiopProxyHandler handler = new IiopProxyHandler(stub
087: .getORBImpl(), stub, stubMarshal);
088:
089: return Proxy.newProxyInstance(
090: narrowTo.getClassLoader(), new Class[] {
091: narrowTo, IiopProxy.class }, handler);
092: }
093:
094: throw new ClassCastException(narrowFrom.getClass()
095: .getName());
096: } catch (ClassCastException e) {
097: throw e;
098: } catch (RuntimeException e) {
099: throw e;
100: } catch (Exception e) {
101: throw new RuntimeException(e);
102: }
103: }
104:
105: public void connect(Remote target, Remote source)
106: throws RemoteException {
107: throw new UnsupportedOperationException();
108: }
109: }
|