incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r420804 [4/8] - in /incubator/yoko/trunk/rmi: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/yoko/ src/main/java/org/apache/yoko/rmi/ src/main/java/org/apache/yoko/rmi/api/ src/main/ja...
Date Tue, 11 Jul 2006 11:35:35 GMT
Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIServant.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIServant.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIServant.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIServant.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,196 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import java.lang.reflect.Method;
+import java.util.logging.Logger;
+
+import org.omg.CORBA.OBJECT_NOT_EXIST;
+import org.omg.CORBA.portable.Delegate;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.POAHelper;
+
+public class RMIServant extends org.omg.PortableServer.Servant implements
+         javax.rmi.CORBA.Tie {
+
+    static final Logger logger = Logger.getLogger(RMIServant.class.getName());
+
+    RMIState _state;
+
+    RemoteDescriptor _descriptor;
+
+    byte[] _id;
+
+    Class getJavaClass() {
+        return _descriptor.getJavaClass();
+    }
+
+    RMIState getRMIState() {
+        return _state;
+    }
+
+    public RMIServant(RMIState state) {
+        _state = state;
+    }
+
+    private java.rmi.Remote _target = null;
+
+    /** this implements the sole missing method in javax.rmi.CORBA.Tie */
+    public String[] _all_interfaces(final org.omg.PortableServer.POA poa,
+            final byte[] objectId) {
+        return _descriptor.all_interfaces();
+    }
+
+    static String debug_name(Method m) {
+        return m.getDeclaringClass().getName() + "." + m.getName();
+    }
+
+    /**
+         * this implements the sole missing method in
+         * org.omg.CORBA.portable.InvokeHandler
+         */
+    public org.omg.CORBA.portable.OutputStream _invoke(java.lang.String opName,
+            org.omg.CORBA.portable.InputStream _input,
+            org.omg.CORBA.portable.ResponseHandler response)
+            throws org.omg.CORBA.SystemException {
+
+        MethodDescriptor method = _descriptor.getMethod(opName);
+
+        if (method == null) {
+            _descriptor.debugMethodMap();
+            throw new org.omg.CORBA.BAD_OPERATION(opName);
+        }
+
+        java.lang.reflect.Method m = method.getReflectedMethod();
+
+        logger.finer(debug_name(m) + ": invoking on " + _id);
+
+        try {
+            Object[] args = method.readArguments(_input);
+
+            Object result = invoke_method(m, args);
+
+            org.omg.CORBA.portable.OutputStream _out = response.createReply();
+
+            method.writeResult(_out, result);
+            logger.finer(debug_name(m) + ": returning normally");
+
+            return _out;
+        } catch (org.omg.CORBA.SystemException ex) {
+            logger.throwing(RMIServant.class.getName(), "_invoke", ex);
+            logger.warning(ex.toString());
+            throw ex;
+
+        } catch (java.lang.reflect.UndeclaredThrowableException ex) {
+            logger.throwing(RMIServant.class.getName(), "_invoke", ex
+                    .getUndeclaredThrowable());
+            throw new org.omg.CORBA.portable.UnknownException(ex
+                    .getUndeclaredThrowable());
+        } catch (RuntimeException ex) {
+            logger.finer(debug_name(m) + ": RuntimeException " + ex);
+            return method.writeException(response, ex);
+        } catch (java.rmi.RemoteException ex) {
+            logger.finer(debug_name(m) + ": RemoteException " + ex);
+            // return method.writeException (response, ex);
+            throw UtilImpl.mapRemoteException(ex);
+        } catch (Throwable ex) {
+            logger.finer(debug_name(m) + ": Throwable " + ex);
+            return method.writeException(response, ex);
+        } finally {
+            // PortableRemoteObjectExt.popState();
+
+        }
+    }
+
+    /* package */
+    Object invoke_method(java.lang.reflect.Method m, Object[] args)
+	    throws java.rmi.RemoteException, Throwable {
+
+	if(_target != null) {
+	    try {
+		return m.invoke(_target, args);
+	    } catch (java.lang.reflect.InvocationTargetException ex) {
+		throw ex.getTargetException();
+	    }
+	}
+	else {
+	    throw new OBJECT_NOT_EXIST();
+	}
+    }
+
+    public org.omg.CORBA.ORB orb() {
+	return _orb();
+    }
+
+    public void orb(org.omg.CORBA.ORB orb) {
+        try {
+            POA _poa = POAHelper.narrow(orb
+                    .resolve_initial_references("RootPOA"));
+
+            _poa.activate_object(this);
+        } catch (org.omg.CORBA.ORBPackage.InvalidName ex) {
+            throw new RuntimeException("ORB must have POA support");
+        } catch (org.omg.PortableServer.POAPackage.WrongPolicy ex) {
+            throw new RuntimeException("wrong policy: " + ex);
+        } catch (org.omg.PortableServer.POAPackage.ServantAlreadyActive ex) {
+            throw new RuntimeException("already active: " + ex);
+        }
+    }
+
+    public void deactivate() {
+        if (_get_delegate() == null)
+            throw new RuntimeException("object not active");
+
+        try {
+            org.omg.PortableServer.POA poa = _state.getPOA();
+            byte[] id = poa.servant_to_id(this);
+            poa.deactivate_object(id);
+            _set_delegate(null);
+        } catch (Throwable ex) {
+            logger.throwing("", "deactivate", ex);
+            throw new RuntimeException("cannot deactivate: " + ex);
+        }
+    }
+
+    public java.rmi.Remote getTarget() {
+        return _target;
+    }
+
+    public synchronized void setTarget(java.rmi.Remote target) {
+        if (target == null) {
+            throw new IllegalArgumentException();
+        }
+
+        _descriptor = ((RemoteDescriptor) _state.getTypeRepository()
+                .getDescriptor(target.getClass())).getRemoteInterface();
+
+        if (_descriptor == null) {
+            throw new RuntimeException("remote classes not supported");
+        }
+
+        _target = target;
+    }
+
+    Delegate getDelegate() {
+        return _state.createDelegate(this);
+    }
+
+    public org.omg.CORBA.Object thisObject() {
+            return _this_object();
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIServant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIServant.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIState.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIState.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIState.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIState.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,352 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.logging.Logger;
+
+import javax.rmi.CORBA.Stub;
+import javax.rmi.CORBA.ValueHandler;
+
+import org.apache.yoko.rmi.api.PortableRemoteObjectExt;
+import org.apache.yoko.rmi.api.PortableRemoteObjectState;
+import org.apache.yoko.rmi.util.NodeleteSynchronizedMap;
+import org.omg.CORBA.BAD_INV_ORDER;
+import org.omg.CORBA.Policy;
+import org.omg.CORBA.ORBPackage.InvalidName;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
+import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
+import org.omg.PortableServer.POAPackage.InvalidPolicy;
+
+
+public class RMIState implements PortableRemoteObjectState {
+    static final Logger logger = Logger.getLogger(RMIState.class.getName());
+
+    private boolean isShutdown;
+
+    final private org.omg.CORBA.ORB _orb;
+
+    private String _name;
+
+    private TypeRepository _typerepository;
+    
+    private POA poa;
+    
+    POA getPOA() {
+	return poa;
+    }
+
+    TypeRepository getTypeRepository() {
+        if (_typerepository == null)
+            _typerepository = new TypeRepository(_orb);
+
+        return _typerepository;
+    }
+
+    RMIState(org.omg.CORBA.ORB orb, String name) {
+        if (orb == null) {
+            throw new NullPointerException("ORB is null");
+        }
+        
+        try {
+            POA rootPoa = (POA) orb.resolve_initial_references("RootPOA");
+	    poa = rootPoa.create_POA(name, null, new Policy[0]);
+	    poa.the_POAManager().activate();
+	} catch (AdapterAlreadyExists e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	} catch (InvalidPolicy e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	} catch (InvalidName e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	} catch (AdapterInactive e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+
+        _orb = orb;
+        _name = name;
+    }
+
+    void checkShutDown() {
+        if (isShutdown) {
+            BAD_INV_ORDER ex = new BAD_INV_ORDER(
+                    "RMIState has already been shut down");
+            logger.fine("RMIState has already been shut down " + ex);
+            throw ex;
+        }
+    }
+
+    public void shutdown() {
+        logger.finer("RMIState shutdown requested; name = " + _name);
+
+        checkShutDown();
+
+        isShutdown = true;
+    }
+
+    public org.omg.CORBA.ORB getORB() {
+        return _orb;
+    }
+
+
+    org.omg.CORBA.portable.Delegate createDelegate(RMIServant servant) {
+        checkShutDown();
+
+        System.out.println("createDelegate");
+        byte[] id = servant._id;
+        RemoteDescriptor desc = servant._descriptor;
+
+        String repid = desc.getRepositoryID();
+
+        org.omg.CORBA.portable.ObjectImpl ref;
+        org.omg.PortableServer.POA poa;
+
+        try {
+            poa = getPOA();
+            ref = (org.omg.CORBA.portable.ObjectImpl) poa
+                    .create_reference_with_id(id, repid);
+        } catch (org.omg.CORBA.BAD_PARAM ex) {
+            throw new InternalError("wrong policy: " + ex);
+        }
+
+        return ref._get_delegate();
+    }
+
+    ValueHandler valueHandler;
+
+    public ValueHandler createValueHandler() {
+        checkShutDown();
+
+        if (valueHandler == null) {
+            valueHandler = new ValueHandlerImpl(getTypeRepository());
+        }
+
+        return valueHandler;
+    }
+
+    static RMIState current() {
+	return (RMIState) PortableRemoteObjectExt.getState();
+    }
+
+    public ClassLoader getClassLoader() {
+        ClassLoader loader  = Thread.currentThread().getContextClassLoader();
+        return loader;
+    }
+
+    //
+    // data for use in PortableRemoteObjectImpl
+    //
+
+    java.util.Map stub_map = new NodeleteSynchronizedMap() {
+        public java.util.Map initialValue() {
+            return new HashMap();
+        }
+    };
+
+    //
+    // data for use in UtilImpl
+    //
+    java.util.Map tie_map = java.util.Collections
+            .synchronizedMap(new IdentityHashMap());
+
+    private java.util.Map static_stub_map = new NodeleteSynchronizedMap() {
+        public java.util.Map initialValue() {
+            return new HashMap();
+        }
+    };
+
+    private URL _codebase;
+
+    //
+    //
+    //
+    public void setCodeBase(URL codebase) {
+        _codebase = codebase;
+    }
+
+    public URL getCodeBase() {
+        return _codebase;
+    }
+
+    void clearState() {
+        _typerepository = null;
+        valueHandler = null;
+        stub_map = null;
+        tie_map = null;
+
+        static_stub_map = null;
+    }
+
+    static class StaticStubEntry {
+        java.lang.reflect.Constructor stub_constructor;
+    }
+
+    /**
+     * Method getStaticStub.
+     * 
+     * @param codebase
+     * @param type
+     * @return Stub
+     */
+    public Stub getStaticStub1(String codebase, Class type) {
+        return null;
+    }
+
+    public Stub getStaticStub(String codebase, Class type) {
+
+        StaticStubEntry ent = (StaticStubEntry) static_stub_map.get(type);
+        if (ent == null) {
+            ent = new StaticStubEntry();
+
+            java.lang.reflect.Constructor cons = findConstructor(codebase,
+                    getNewStubClassName(type));
+
+            if (cons != null
+                    && !javax.rmi.CORBA.Stub.class.isAssignableFrom(cons
+                            .getDeclaringClass())) {
+                logger.fine("class " + cons.getDeclaringClass()
+                        + " is not a javax.rmi.CORBA.Stub");
+                cons = null;
+            }
+
+            if (cons == null) {
+                cons = findConstructor(codebase, getOldStubClassName(type));
+            }
+
+            if (cons != null
+                    && !javax.rmi.CORBA.Stub.class.isAssignableFrom(cons
+                            .getDeclaringClass())) {
+                logger.fine("class " + cons.getDeclaringClass()
+                        + " is not a javax.rmi.CORBA.Stub");
+                cons = null;
+            }
+
+            ent.stub_constructor = cons;
+
+            static_stub_map.put(type, ent);
+        }
+
+        if (ent.stub_constructor == null) {
+            return null;
+        }
+
+        try {
+            return (Stub) ent.stub_constructor
+                    .newInstance(PortableRemoteObjectImpl.NO_ARG);
+        } catch (ClassCastException ex) {
+            logger.fine("loaded class "
+                    + ent.stub_constructor.getDeclaringClass()
+                    + " is not a proper stub");
+        } catch (IllegalAccessException ex) {
+            logger.fine("cannot instantiate stub class for " + type + " :: "
+                    + ex);
+        } catch (InstantiationException ex) {
+            logger.fine("cannot instantiate stub class for " + type + " :: "
+                    + ex);
+        } catch (InvocationTargetException ex) {
+            logger.fine("cannot instantiate stub class for " + type + " :: "
+                    + ex);
+        }
+
+        return null;
+    }
+
+    private java.lang.reflect.Constructor findConstructor(String codebase,
+            String stubName) {
+        try {
+            Class stubClass = javax.rmi.CORBA.Util.loadClass(stubName,
+                    codebase, getClassLoader());
+            return stubClass.getConstructor(new Class[0]);
+
+        } catch (NoSuchMethodException ex) {
+            logger.warning("stub class " + stubName
+                    + " has no default constructor");
+
+        } catch (ClassNotFoundException ex) {
+            logger.fine("failed to load remote class " + stubName + " from "
+                    + codebase);
+            // ignore //
+        }
+
+        return null;
+    }
+
+    String getNewStubClassName(Class c) {
+
+        String cname = c.getName();
+
+        String pkgname = null;
+        int idx = cname.lastIndexOf('.');
+
+        if (idx == -1) {
+            pkgname = "org.omg.stub";
+        } else {
+            pkgname = "org.omg.stub." + cname.substring(0, idx);
+        }
+
+        String cplain = cname.substring(idx + 1);
+
+        return pkgname + "." + "_" + cplain + "_Stub";
+    }
+
+    String getOldStubClassName(Class c) {
+
+        String cname = c.getName();
+
+        //String pkgname = null;
+        int idx = cname.lastIndexOf('.');
+
+        if (idx == -1) {
+            return "_" + cname + "_Stub";
+        } else {
+            return cname.substring(0, idx + 1) + "_" + cname.substring(idx + 1)
+                    + "_Stub";
+        }
+    }
+
+    public void exportObject(Remote remote) throws RemoteException {
+        //PortableRemoteObjectExt.pushState(this);
+        try {
+            javax.rmi.PortableRemoteObject.exportObject(remote);
+        } finally {
+            //PortableRemoteObjectExt.popState();
+        }
+    }
+
+    public void unexportObject(Remote remote) throws RemoteException {
+        //PortableRemoteObjectExt.pushState(this);
+        try {
+            javax.rmi.PortableRemoteObject.unexportObject(remote);
+        } finally {
+            //PortableRemoteObjectExt.popState();
+        }
+    }
+
+    public String getName() {
+        return _name;
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIState.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStub.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStub.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStub.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStub.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,122 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import org.apache.yoko.rmi.api.PortableRemoteObjectExt;
+import org.omg.CORBA.portable.Delegate;
+import org.omg.CORBA.portable.ServantObject;
+
+
+public abstract class RMIStub extends javax.rmi.CORBA.Stub {
+    protected final transient RemoteDescriptor _descriptor;
+
+    protected RMIServant _servant;
+
+    protected ServantObject _so;
+
+    protected Delegate _delegate;
+
+    public RMIStub() {
+        super();
+
+        Class remote_interface = getClass().getInterfaces()[0];
+
+        RMIState state = (RMIState) PortableRemoteObjectExt.getState();
+        Object o = state.getTypeRepository().getRemoteDescriptor(
+                remote_interface);
+
+        _descriptor = (RemoteDescriptor) o;
+    }
+
+    public String[] _ids() {
+        return _descriptor.all_interfaces();
+    }
+
+    // replace stub with RMIPersistentStub
+    protected abstract Object writeReplace();
+
+    private void writeObject(java.io.ObjectOutputStream oo)
+            throws java.io.IOException {
+        //
+        // This should never happen, because writeReplace ought to
+        // have been called.
+        //
+        throw new java.io.IOException("should not happen");
+    }
+
+    // apparently this implementation is expected!
+    public String toString() {
+        return _orb().object_to_string(this);
+    }
+
+    /**
+     * @see org.omg.CORBA.portable.ObjectImpl#_get_delegate()
+     */
+    public Delegate _get_delegate() {
+        if (_delegate != null) {
+            return _delegate;
+        } else if (_servant != null) {
+            return (_delegate = _servant.getDelegate());
+        } else {
+            return super._get_delegate();
+        }
+    }
+
+    public void _set_delegate(Delegate del) {
+        _delegate = del;
+    }
+
+    /**
+     * @see org.omg.CORBA.portable.ObjectImpl#_is_local()
+     */
+    public boolean _is_local() {
+        if (_servant != null) {
+            return true;
+        } else {
+            return super._is_local();
+        }
+    }
+
+    /**
+     * @see org.omg.CORBA.portable.ObjectImpl#_servant_postinvoke(ServantObject)
+     */
+    public void _servant_postinvoke(ServantObject servant) {
+        if (_servant == null) {
+            super._servant_postinvoke(servant);
+        } else {
+            // do nothing //
+        }
+    }
+
+    /**
+     * @see org.omg.CORBA.portable.ObjectImpl#_servant_preinvoke(String, Class)
+     */
+    public ServantObject _servant_preinvoke(String operation, Class expectedType) {
+        if (_servant == null) {
+            return super._servant_preinvoke(operation, expectedType);
+        } else {
+            if (_so == null) {
+                ServantObject so = new ServantObject();
+                so.servant = _servant;
+                _so = so;
+            }
+            return _so;
+        }
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStub.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,73 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+public class RMIStubDescriptor extends ValueDescriptor {
+    RMIStubDescriptor(Class type, TypeRepository repository) {
+        super(type, repository);
+    }
+
+    String stub_repid = null;
+
+    public String getRepositoryID() {
+        if (stub_repid == null) {
+            init_repid();
+        }
+
+        return stub_repid;
+    }
+
+    void init_repid() {
+        Class type = getJavaClass();
+
+        Class[] ifaces = type.getInterfaces();
+
+        if (ifaces.length != 2 || ifaces[1] != org.apache.yoko.rmi.util.stub.Stub.class) {
+            throw new RuntimeException("Unexpected RMIStub structure");
+        }
+
+        String ifname = ifaces[0].getName();
+        String stubClassName = null;
+
+        int idx = ifname.lastIndexOf('.');
+        if (idx == -1) {
+            stubClassName = "_" + ifname + "_Stub";
+        } else {
+            stubClassName = ifname.substring(0, idx + 1) + "_"
+                    + ifname.substring(idx + 1) + "_Stub";
+        }
+
+        stub_repid = "RMI:" + stubClassName + ":0";
+    }
+
+    //
+    // Override writeValue/readvalue, such that only the superclass'
+    // state is written. This ensures that fields in the proxy are
+    // not included on the wire.
+    //
+    protected void writeValue(ObjectWriter writer, java.io.Serializable val)
+            throws java.io.IOException {
+        _super_descriptor.writeValue(writer, val);
+    }
+
+    protected void readValue(ObjectReader reader, java.io.Serializable value)
+            throws java.io.IOException {
+        _super_descriptor.readValue(reader, value);
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,254 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Logger;
+
+import org.omg.CORBA.ORB;
+
+/**
+ * This class is the InvocationHandler for instances of POAStub. When a client
+ * calls a remote method, this is translated to a call to the invoke() method in
+ * this class.
+ */
+public final class RMIStubHandler implements java.io.Serializable {
+    static final Logger logger = Logger.getLogger(RMIStubHandler.class
+	    .getName());
+
+    private RMIStubHandler() {
+
+    }
+
+    static final RMIStubHandler instance = new RMIStubHandler();
+
+    public Object stubWriteReplace(RMIStub stub) {
+	Class type = stub._descriptor.getJavaClass();
+	return new org.apache.yoko.rmi.impl.RMIPersistentStub(stub, type);
+    }
+
+    public Object invoke(RMIStub stub, MethodDescriptor method, Object[] args)
+	    throws Throwable {
+
+	// special-case for writeReplace
+	if (method == null) {
+	    return stubWriteReplace(stub);
+	}
+
+	final String method_name = method.getIDLName();
+	boolean stream_arguments = false;
+
+	logger.finer("invoking " + method_name);
+
+	while (true) {
+	    boolean is_local = stub._is_local();
+
+	    if (!is_local || stream_arguments) {
+
+		org.omg.CORBA.portable.OutputStream out = null;
+		org.omg.CORBA.portable.InputStream in = null;
+
+		try {
+		    out = stub._request(method_name, method.responseExpected());
+
+		    // write arguments
+		    method.writeArguments(out, args);
+
+		    // invoke method
+		    in = stub._invoke(out);
+
+		    Object result = method.readResult(in);
+
+		    return result;
+
+		} catch (org.omg.CORBA.portable.ApplicationException ex) {
+		    try {
+			method.readException(ex.getInputStream());
+
+		    } catch (Throwable exx) {
+			logger.fine("rmi1::" + method_name + " " + exx);
+
+			addLocalTrace(method, exx);
+
+			throw exx;
+		    }
+
+		} catch (org.omg.CORBA.portable.UnknownException ex) {
+		    logger.finer("rmi2::" + method_name + " " + ex);
+		    logger.finer("rmi2::" + method_name + " " + ex.originalEx);
+
+		    addLocalTrace(method, ex.originalEx);
+
+		    throw ex.originalEx;
+
+		} catch (org.omg.CORBA.portable.RemarshalException _exception) {
+		    continue;
+
+		} catch (org.omg.CORBA.SystemException ex) {
+		    java.rmi.RemoteException exx = javax.rmi.CORBA.Util
+			    .mapSystemException(ex);
+
+		    logger.finer("rmi3::" + method_name + " " + exx);
+
+		    throw exx;
+
+		} catch (Throwable ex) {
+		    logger.finer("rmi4::" + method_name + " " + ex);
+
+		    throw ex;
+
+		} finally {
+		    stub._releaseReply(in);
+		}
+
+	    } else {
+		org.omg.CORBA.portable.ServantObject so;
+
+		so = stub._servant_preinvoke(method_name, RMIServant.class);
+
+		RMIServant servant;
+
+		try {
+		    servant = (RMIServant) so.servant;
+		} catch (ClassCastException ex) {
+		    stream_arguments = true;
+		    continue;
+		} catch (NullPointerException ex) {
+		    stream_arguments = true;
+		    continue;
+		}
+
+		final RMIState target_state = servant.getRMIState();
+		final ORB orb = target_state.getORB();
+
+		Object return_value = null;
+		boolean same_state;
+
+		RMIState currentState = RMIState.current();
+		same_state = (currentState == target_state);
+
+		Object[] copied_args = method.copyArguments(args,
+			same_state, orb);
+
+		try {
+		    java.lang.reflect.Method m = method
+		    .getReflectedMethod();
+
+		    return_value = servant
+		    .invoke_method(m, copied_args);
+		} catch (org.omg.CORBA.SystemException ex) {
+		    throw javax.rmi.CORBA.Util.mapSystemException(ex);
+
+		} finally {
+		    stub._servant_postinvoke(so);
+		}
+
+		return method.copyResult(return_value, same_state, orb);
+	    }
+	}
+    }
+
+    private static Throwable addLocalTrace(MethodDescriptor desc, Throwable ex) {
+	try {
+	    throw new Throwable("Client-Side RMI Trace");
+
+	} catch (Throwable lex) {
+
+	    StackTraceElement[] remoteTrace = ex.getStackTrace();
+	    StackTraceElement[] localTrace = lex.getStackTrace();
+
+	    StackTraceElement[] fullTrace = new StackTraceElement[localTrace.length
+		    + remoteTrace.length];
+
+	    for (int i = 0; i < remoteTrace.length; i++) {
+		fullTrace[i] = remoteTrace[i];
+	    }
+
+	    java.lang.reflect.Method m = desc.getReflectedMethod();
+	    resetTraceInfo(m.getDeclaringClass().getName(), m.getName(),
+		    localTrace[0]);
+
+	    for (int i = 0; i < localTrace.length; i++) {
+		fullTrace[remoteTrace.length + i] = localTrace[i];
+	    }
+
+	    ex.setStackTrace(fullTrace);
+	    return ex;
+	}
+    }
+
+    static Field classNameField;
+
+    static Field methodNameField;
+
+    static Field fileNameField;
+
+    static Field lineNumberField;
+
+    static {
+	AccessController.doPrivileged(new PrivilegedAction() {
+	    /**
+                 * @see java.security.PrivilegedAction#run()
+                 */
+	    public Object run() {
+		try {
+		    classNameField = StackTraceElement.class
+			    .getDeclaredField("declaringClass");
+		    classNameField.setAccessible(true);
+
+		    methodNameField = StackTraceElement.class
+			    .getDeclaredField("methodName");
+		    methodNameField.setAccessible(true);
+
+		    fileNameField = StackTraceElement.class
+			    .getDeclaredField("fileName");
+		    fileNameField.setAccessible(true);
+
+		    lineNumberField = StackTraceElement.class
+			    .getDeclaredField("lineNumber");
+		    lineNumberField.setAccessible(true);
+
+		} catch (Exception ex) {
+		    // ignore
+		}
+		return null;
+	    }
+
+	});
+    }
+
+    /**
+         * Method resetTraceInfo.
+         * 
+         * @param stackTraceElement
+         */
+    private static void resetTraceInfo(String className, String methodName,
+	    StackTraceElement ste) {
+	try {
+	    classNameField.set(ste, className);
+	    methodNameField.set(ste, methodName);
+	    fileNameField.set(ste, "--- RMI/IIOP INVOCATION ---");
+	    lineNumberField.set(ste, new Integer(-2000));
+	} catch (IllegalAccessException e) {
+	} catch (NullPointerException e) {
+	}
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,30 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+class RMIStubInitializer implements org.apache.yoko.rmi.util.stub.StubInitializer {
+    private RMIStubInitializer() {
+
+    }
+
+    static RMIStubInitializer instance = new RMIStubInitializer();
+
+    public Object getStubHandler() {
+        return RMIStubHandler.instance;
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteClassDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteClassDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteClassDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteClassDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,33 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+public class RemoteClassDescriptor extends RemoteDescriptor {
+
+    public String getRepositoryID() {
+        return "IDL:" + getJavaClass().getName().replace('.', '/') + ":1.0";
+    }
+
+    RemoteClassDescriptor(Class type, TypeRepository repository) {
+        super(type, repository);
+    }
+
+    public void init() {
+        super.init();
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteClassDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteClassDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,570 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.logging.Level;
+
+import javax.rmi.PortableRemoteObject;
+
+public abstract class RemoteDescriptor extends TypeDescriptor {
+    private java.util.Map method_map;
+
+    private java.util.Map refl_method_map;
+
+    private MethodDescriptor[] operations;
+
+    private Class[] remote_interfaces;
+
+    protected List super_descriptors;
+
+    public RemoteInterfaceDescriptor getRemoteInterface() {
+        RemoteInterfaceDescriptor result = super.getRemoteInterface();
+        if (result != null)
+            return result;
+
+        if (this instanceof RemoteInterfaceDescriptor) {
+            result = (RemoteInterfaceDescriptor) this;
+        } else {
+            Class[] remotes = collect_remote_interfaces(getJavaClass());
+            if (remotes.length == 0) {
+                throw new RuntimeException("" + getJavaClass()
+                        + " has no remote interfaces");
+            }
+            Class most_specific_interface = remotes[0];
+
+            result = (RemoteInterfaceDescriptor) repository
+                    .getDescriptor(most_specific_interface);
+        }
+
+        setRemoteInterface(result);
+
+        return result;
+    }
+
+    static final Class REMOTE_CLASS = java.rmi.Remote.class;
+
+    static final Class OBJECT_CLASS = java.lang.Object.class;
+
+    static final java.lang.Class REMOTE_EXCEPTION = java.rmi.RemoteException.class;
+
+    String[] _ids;
+
+    public String[] all_interfaces() {
+        if (_ids == null) {
+            Class[] ifaces = collect_remote_interfaces(getJavaClass());
+            int len = ifaces.length;
+            String[] ids = new String[len];
+            for (int i = 0; i < len; i++) {
+                TypeDescriptor desc = repository.getDescriptor(ifaces[i]);
+                ids[i] = desc.getRepositoryID();
+            }
+
+            _ids = ids;
+        }
+
+        return _ids;
+    }
+
+    public MethodDescriptor getMethod(String idl_name) {
+        if (operations == null) {
+            init_methods();
+        }
+
+        if (method_map == null) {
+            method_map = new java.util.HashMap();
+            for (int i = 0; i < operations.length; i++)
+                method_map.put(operations[i].getIDLName(), operations[i]);
+        }
+
+        return (MethodDescriptor) method_map.get(idl_name);
+    }
+
+    void debugMethodMap() {
+        if (logger.isLoggable(Level.FINER)) {
+            logger.finer("METHOD MAP FOR " + getJavaClass());
+
+            Iterator it = method_map.keySet().iterator();
+            while (it.hasNext()) {
+                String idl_name = (String) it.next();
+                MethodDescriptor desc = (MethodDescriptor) method_map
+                        .get(idl_name);
+
+                logger
+                        .finer("IDL " + idl_name + " -> "
+                                + desc.reflected_method);
+            }
+        }
+    }
+
+    public MethodDescriptor getMethod(Method refl_method) {
+        if (operations == null) {
+            init_methods();
+        }
+
+        if (refl_method_map == null) {
+            refl_method_map = new java.util.HashMap();
+            for (int i = 0; i < operations.length; i++)
+                refl_method_map.put(operations[i].getReflectedMethod(),
+                        operations[i]);
+        }
+
+        return (MethodDescriptor) refl_method_map.get(refl_method);
+    }
+
+    RemoteDescriptor(Class type, TypeRepository repository) {
+        super(type, repository);
+    }
+
+    public void init() {
+    }
+
+    public MethodDescriptor[] getMethods() {
+        if (operations == null)
+            init_methods();
+
+        return operations;
+    }
+
+    public synchronized void init_methods() {
+        if (operations != null)
+            return;
+
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                init_methods0();
+                return null;
+            }
+        });
+    }
+
+    private void init_methods0() {
+
+        ArrayList method_list = new ArrayList();
+
+        // first step is to build the helpers for any super classes
+        Class[] supers = getJavaClass().getInterfaces();
+        super_descriptors = new ArrayList();
+
+        Map all_methods = new HashMap();
+        Map lower_case_names = new HashMap();
+        for (int i = 0; i < supers.length; i++) {
+            Class iface = supers[i];
+
+            if (!REMOTE_CLASS.equals(iface) && !OBJECT_CLASS.equals(iface)
+                    && REMOTE_CLASS.isAssignableFrom(iface)
+                    && iface.isInterface()) {
+                RemoteDescriptor superHelper = (RemoteDescriptor) repository
+                        .getDescriptor(iface);
+
+                super_descriptors.add(superHelper);
+
+                MethodDescriptor[] superOps = superHelper.getMethods();
+                for (int j = 0; j < superOps.length; j++) {
+                    MethodDescriptor op = superOps[j];
+
+                    method_list.add(op);
+                    addMethodOverloading(all_methods, op.getReflectedMethod());
+                    addMethodCaseSensitive(lower_case_names, op
+                            .getReflectedMethod());
+                }
+            }
+        }
+
+        // next, build the method helpers for this class
+        Method[] methods = getLocalMethods();
+
+        // register methods
+        for (int i = 0; i < methods.length; i++) {
+            addMethodOverloading(all_methods, methods[i]);
+            addMethodCaseSensitive(lower_case_names, methods[i]);
+        }
+
+        Set overloaded_names = new HashSet();
+        Iterator it = all_methods.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry entry = (Map.Entry) it.next();
+            String mname = (String) entry.getKey();
+            Set s = (Set) entry.getValue();
+            if (s.size() > 1) {
+                overloaded_names.add(mname);
+            }
+        }
+
+        for (int i = 0; i < methods.length; i++) {
+            MethodDescriptor op = new MethodDescriptor(methods[i], repository);
+
+            String mname = op.getJavaName();
+
+            // is there another method that differs only in case?
+            Set same_case_names = (Set) lower_case_names.get(mname
+                    .toLowerCase());
+            if (same_case_names.size() > 1) {
+                op.setCaseSensitive(true);
+            }
+
+            // is this method overloaded?
+            Set overload_names = (Set) all_methods.get(mname);
+            if (overload_names.size() > 1) {
+                op.setOverloaded(true);
+            }
+
+            op.init();
+
+            method_list.add(op);
+        }
+
+        // init method map...
+        method_map = new java.util.HashMap();
+        for (int i = 0; i < method_list.size(); i++) {
+            MethodDescriptor desc = (MethodDescriptor) method_list.get(i);
+            method_map.put(desc.getIDLName(), desc);
+        }
+
+        //
+        // initialize "operations" from the values of the map, such
+        // that repeat methods are eliminated.
+        //
+        operations = (MethodDescriptor[]) method_map.values().toArray(
+                new MethodDescriptor[0]);
+
+        debugMethodMap();
+    }
+
+    private void addMethodOverloading(Map map, Method m) {
+        String mname = m.getName();
+        Set entry = (Set) map.get(mname);
+
+        if (entry == null) {
+            entry = new HashSet();
+            map.put(mname, entry);
+        }
+
+        entry.add(createMethodSelector(m));
+    }
+
+    Method[] getLocalMethods() {
+        ArrayList result = new ArrayList();
+
+        addNonRemoteInterfaceMethods(getJavaClass(), result);
+
+        Method[] out = new Method[result.size()];
+        result.toArray(out);
+        return out;
+    }
+
+    void addNonRemoteInterfaceMethods(Class clz, ArrayList result) {
+        Method[] methods;
+        try {
+            methods = clz.getDeclaredMethods();
+        } catch (NoClassDefFoundError e) {
+            ClassLoader clzClassLoader = clz.getClassLoader();
+            logger.finer("cannot find class " + e.getMessage() + " from "
+                    + clz.getName() + " (classloader " + clzClassLoader + "): "
+                    + e);
+            throw e;
+        }
+        for (int j = 0; j < methods.length; j++) {
+            if (isRemoteMethod(methods[j]))
+                result.add(methods[j]);
+        }
+
+        Class[] ifaces = clz.getInterfaces();
+        for (int i = 0; i < ifaces.length; i++) {
+            if (!REMOTE_CLASS.isAssignableFrom(ifaces[i])) {
+                addNonRemoteInterfaceMethods(ifaces[i], result);
+            }
+        }
+    }
+
+    boolean isRemoteMethod(Method m) {
+        Class[] ex = m.getExceptionTypes();
+
+        for (int i = 0; i < ex.length; i++) {
+            if (REMOTE_EXCEPTION.isAssignableFrom(ex[i]))
+                return true;
+        }
+
+        return false;
+    }
+
+    private static String createMethodSelector(java.lang.reflect.Method m) {
+        StringBuffer sb = new StringBuffer(m.getName());
+        sb.append('(');
+        Class[] parameterTypes = m.getParameterTypes();
+        for (int n = 0; n < parameterTypes.length; n++) {
+            sb.append(parameterTypes[n].getName());
+            if (n < parameterTypes.length - 1) {
+                sb.append(", ");
+            }
+        }
+        sb.append(')');
+        return sb.toString().intern();
+    }
+
+    private void addMethodCaseSensitive(Map map, Method m) {
+        String mname = m.getName();
+        String lowname = mname.toLowerCase();
+        Set entry = (Set) map.get(lowname);
+
+        if (entry == null) {
+            entry = new HashSet();
+            map.put(lowname, entry);
+        }
+
+        entry.add(mname);
+    }
+
+    private void collect_interfaces(Set s, Class c) {
+        if (c.isInterface() && !REMOTE_CLASS.equals(c))
+            s.add(c);
+
+        Class sup = c.getSuperclass();
+        if (sup != null && !OBJECT_CLASS.equals(sup)) {
+            collect_interfaces(s, sup);
+        }
+
+        Class[] supers = c.getInterfaces();
+
+        for (int i = 0; i < supers.length; i++) {
+            Class iface = supers[i];
+
+            if (!REMOTE_CLASS.equals(iface)
+                    && REMOTE_CLASS.isAssignableFrom(iface)) {
+                collect_interfaces(s, iface);
+            }
+        }
+    }
+
+    protected Class[] collect_remote_interfaces(Class c) {
+        if (remote_interfaces != null)
+            return remote_interfaces;
+
+        Set s = new TreeSet(new Comparator() {
+            public int compare(Object o1, Object o2) {
+                Class c1 = (Class) o1;
+                Class c2 = (Class) o2;
+
+                if (c1.equals(c2))
+                    return 0;
+
+                if (c1.isAssignableFrom(c2)) {
+                    // c2 is more specific (so it should come first)
+
+                    return 1;
+                } else if (c2.isAssignableFrom(c1)) {
+                    // c1 is more specific (so it should come first)
+
+                    return -1;
+                } else // they are unrelated
+                {
+                    // just define some consistent order...
+                    return c1.getName().compareTo(c2.getName());
+                }
+            }
+        });
+
+        collect_interfaces(s, c);
+        remote_interfaces = new Class[s.size()];
+        s.toArray(remote_interfaces);
+        return remote_interfaces;
+    }
+
+    /** Read an instance of this value from a CDR stream */
+    public Object read(org.omg.CORBA.portable.InputStream in) {
+        return javax.rmi.PortableRemoteObject.narrow(in.read_Object(),
+                getJavaClass());
+    }
+
+    /** Write an instance of this value to a CDR stream */
+    public void write(org.omg.CORBA.portable.OutputStream out, Object val) {
+        javax.rmi.CORBA.Util.writeRemoteObject(out, val);
+    }
+
+    org.omg.CORBA.TypeCode getTypeCode() {
+        if (_type_code == null) {
+            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
+            return orb.create_interface_tc(getRepositoryID(), getJavaClass()
+                    .getName());
+        }
+
+        return _type_code;
+    }
+
+    void writeMarshalValue(java.io.PrintWriter pw, String outName,
+            String paramName) {
+        pw.print("javax.rmi.CORBA.Util.writeRemoteObject(");
+        pw.print(outName);
+        pw.print(',');
+        pw.print(paramName);
+        pw.print(')');
+    }
+
+    void writeUnmarshalValue(java.io.PrintWriter pw, String inName) {
+        pw.print('(');
+        pw.print(getJavaClass().getName());
+        pw.print(')');
+        pw.print(PortableRemoteObject.class.getName());
+        pw.print(".narrow(");
+        pw.print(inName);
+        pw.print('.');
+        pw.print("read_Object(),");
+        pw.print(getJavaClass().getName());
+        pw.print(".class)");
+    }
+
+    static String classNameFromStub(String name) {
+        if (name.startsWith("org.omg.stub."))
+            name = name.substring("org.omg.stub.".length());
+
+        // strip xx._X_Stub -> xx.X
+        int idx = name.lastIndexOf('.');
+        if (name.charAt(idx + 1) == '_' && name.endsWith("_Stub")) {
+            if (idx == -1) {
+                return name.substring(1, name.length() - 5);
+            } else {
+                return name.substring(0, idx + 1) /* package. */
+                        + name.substring(idx + 2, name.length() - 5);
+            }
+        }
+
+        return null;
+    }
+
+    static String stubClassName(Class c) {
+
+        String cname = c.getName();
+
+        String pkgname = null;
+        int idx = cname.lastIndexOf('.');
+        if (idx == -1) {
+            pkgname = "org.omg.stub";
+        } else {
+            pkgname = "org.omg.stub." + cname.substring(0, idx);
+        }
+
+        String cplain = cname.substring(idx + 1);
+
+        return pkgname + "._" + cplain + "_Stub";
+    }
+
+    void writeStubClass(java.io.PrintWriter pw) {
+
+        Class c = getJavaClass();
+        String cname = c.getName();
+        String fullname = stubClassName(c);
+        //String stubname = fullname.substring(fullname.lastIndexOf('.') + 1);
+        String pkgname = fullname.substring(0, fullname.lastIndexOf('.'));
+        String cplain = cname.substring(cname.lastIndexOf('.') + 1);
+
+        pw.println("/** ");
+        pw.println(" *  RMI/IIOP stub for " + cname);
+        pw.println(" *  Generated using Trifork stub generator.");
+        pw.println(" *  Copyright (c) 2001 by Trifork Technologies");
+        pw.println(" */");
+
+        pw.println("package " + pkgname + ";\n");
+
+        pw.println("public class _" + cplain + "_Stub");
+        pw.println("\textends javax.rmi.CORBA.Stub");
+        pw.println("\timplements " + cname);
+        pw.println("{");
+
+        //
+        // construct String[] _ids;
+        //
+        String[] all_interfaces = all_interfaces();
+        pw.println("\tprivate static final String[] _ids = {");
+        for (int i = 0; i < all_interfaces.length; i++) {
+            pw.println("\t\t\"" + all_interfaces[i] + "\",");
+        }
+        pw.println("\t};\n");
+
+        pw.println("\tpublic String[] _ids() {");
+        pw.println("\t\treturn _ids;");
+        pw.println("\t}");
+
+        //
+        // now, construct stub methods
+        //
+        MethodDescriptor[] meths = getMethods();
+        for (int i = 0; i < meths.length; i++) {
+            meths[i].writeStubMethod(pw);
+        }
+
+        pw.println("}");
+    }
+
+    String getStubClassName() {
+        Class c = getJavaClass();
+        String cname = c.getName();
+
+        String pkgname = null;
+        int idx = cname.lastIndexOf('.');
+        if (idx == -1) {
+            pkgname = "org.omg.stub";
+        } else {
+            pkgname = "org.omg.stub." + cname.substring(0, idx);
+        }
+
+        String cplain = cname.substring(idx + 1);
+
+        return pkgname + "." + "_" + cplain + "_Stub";
+    }
+
+    void addDependencies(Set classes) {
+        Class c = getJavaClass();
+
+        if (c == java.rmi.Remote.class || classes.contains(c))
+            return;
+
+        classes.add(c);
+
+        if (c.getSuperclass() != null) {
+            TypeDescriptor desc = getTypeRepository().getDescriptor(
+                    c.getSuperclass());
+            desc.addDependencies(classes);
+        }
+
+        Class[] ifaces = c.getInterfaces();
+        for (int i = 0; i < ifaces.length; i++) {
+            TypeDescriptor desc = getTypeRepository().getDescriptor(ifaces[i]);
+            desc.addDependencies(classes);
+        }
+
+        MethodDescriptor[] mths = getMethods();
+        for (int i = 0; i < mths.length; i++) {
+            mths[i].addDependencies(classes);
+        }
+    }
+
+    boolean copyInStub() {
+        return false;
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteInterfaceDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteInterfaceDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteInterfaceDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteInterfaceDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,29 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+public class RemoteInterfaceDescriptor extends RemoteDescriptor {
+    RemoteInterfaceDescriptor(Class type, TypeRepository repository) {
+        super(type, repository);
+    }
+
+    public void init() {
+        super.init();
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteInterfaceDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RemoteInterfaceDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RunTimeCodeBaseImpl.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RunTimeCodeBaseImpl.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RunTimeCodeBaseImpl.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RunTimeCodeBaseImpl.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,70 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import org.omg.CORBA.ValueDefPackage.FullValueDescription;
+
+class RunTimeCodeBaseImpl extends org.omg.SendingContext.CodeBasePOA {
+    ValueHandlerImpl valueHandler;
+
+    RunTimeCodeBaseImpl(ValueHandlerImpl handler) {
+        valueHandler = handler;
+    }
+
+    public String implementation(String id) {
+        return valueHandler.getImplementation(id);
+    }
+
+    public String[] implementations(String[] ids) {
+        return valueHandler.getImplementations(ids);
+    }
+
+    public String[] bases(String id) {
+        return valueHandler.getBases(id);
+    }
+
+    public org.omg.CORBA.Repository get_ir() {
+        throw new org.omg.CORBA.NO_IMPLEMENT();
+    }
+
+    public org.omg.CORBA.ValueDefPackage.FullValueDescription meta(String id) {
+        return valueHandler.meta(id);
+    }
+
+    public org.omg.CORBA.ValueDefPackage.FullValueDescription[] metas(String id) {
+        String[] bases = bases(id);
+        org.omg.CORBA.ValueDefPackage.FullValueDescription[] descriptors = new org.omg.CORBA.ValueDefPackage.FullValueDescription[bases.length];
+
+        for (int i = bases.length - 1; i >= 0; i--) {
+            descriptors[i] = meta(bases[i]);
+        }
+
+        return descriptors;
+    }
+
+    public String implementationx(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public FullValueDescription[] metas(String[] arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RunTimeCodeBaseImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/RunTimeCodeBaseImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/ShortDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/ShortDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/ShortDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/ShortDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,33 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+class ShortDescriptor extends SimpleDescriptor {
+    ShortDescriptor(TypeRepository repository) {
+        super(Short.TYPE, repository, "short", org.omg.CORBA.TCKind.tk_short);
+    }
+
+    public Object read(org.omg.CORBA.portable.InputStream in) {
+        return new Short(in.read_short());
+    }
+
+    public void write(org.omg.CORBA.portable.OutputStream out, Object val) {
+        out.write_short(((Short) val).shortValue());
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/ShortDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/ShortDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/SimpleDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/SimpleDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/SimpleDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/SimpleDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,47 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+public abstract class SimpleDescriptor extends TypeDescriptor {
+    SimpleDescriptor(Class type, TypeRepository repository, String idl_name,
+            org.omg.CORBA.TCKind tc) {
+        super(type, repository);
+        setJavaName(type.getName());
+        setIDLName(idl_name);
+
+        org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
+        _type_code = orb.get_primitive_tc(tc);
+    }
+
+    org.omg.CORBA.TypeCode getTypeCode() {
+        return _type_code;
+    }
+
+    boolean copyInStub() {
+        return false;
+    }
+
+    public boolean copyBetweenStates() {
+        return false;
+    }
+
+    public boolean copyWithinState() {
+        return false;
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/SimpleDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/SimpleDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StringDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StringDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StringDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StringDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,61 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+public class StringDescriptor extends ValueDescriptor {
+    public String getIDLName() {
+        return "CORBA_WStringValue";
+    }
+
+    StringDescriptor(TypeRepository repository) {
+        super(String.class, repository);
+    }
+
+    public void init() {
+        super.init();
+    }
+
+    /** Read an instance of this value from a CDR stream */
+    public Object read(org.omg.CORBA.portable.InputStream in) {
+        return org.omg.CORBA.WStringValueHelper.read(in);
+    }
+
+    /** Write an instance of this value to a CDR stream */
+    public void write(org.omg.CORBA.portable.OutputStream out, Object value) {
+        org.omg.CORBA.WStringValueHelper.write(out, (String) value);
+    }
+
+    public void writeValue(org.omg.CORBA.portable.OutputStream out,
+            java.io.Serializable value) {
+        throw new org.omg.CORBA.MARSHAL("internal error");
+    }
+
+    public java.io.Serializable readValue(
+            org.omg.CORBA.portable.InputStream in, java.io.Serializable value,
+            java.util.Map offsetMap) {
+        throw new org.omg.CORBA.MARSHAL("internal error");
+    }
+
+    org.omg.CORBA.TypeCode getTypeCode() {
+        return org.omg.CORBA.WStringValueHelper.type();
+    }
+
+    Object copyObject(Object value, CopyState state) {
+        return value;
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StringDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StringDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubBuilder.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubBuilder.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubBuilder.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubBuilder.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,96 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class StubBuilder {
+    public StubBuilder() {
+    }
+
+    /**
+     * Generate stubs for the list of Classes (java.lang.Class objects)
+     * specified in INTERFACES; into the directory specified by DIR. The
+     * resulting set of generated classes may well include more classes than
+     * specified in INTERFACES.
+     * 
+     * @return list of File objects for generated files.
+     */
+    static public Collection generateStubs(File dir, Collection interfaces)
+            throws IOException {
+        Set pending = new HashSet();
+        ArrayList result = new ArrayList();
+
+        TypeRepository rep = new TypeRepository(null);
+        Iterator it = interfaces.iterator();
+        while (it.hasNext()) {
+            Class cl = (Class) it.next();
+            RemoteDescriptor desc = (RemoteDescriptor) rep.getDescriptor(cl);
+
+            desc.addDependencies(pending);
+        }
+
+        Class[] classes = new Class[pending.size()];
+        pending.toArray(classes);
+
+        for (int i = 0; i < classes.length; i++) {
+
+            if (!java.rmi.Remote.class.isAssignableFrom(classes[i])) {
+                continue;
+            }
+
+            RemoteDescriptor desc = (RemoteDescriptor) rep
+                    .getDescriptor(classes[i]);
+
+            String name = desc.getStubClassName();
+            String file = name.replace('.', File.separatorChar) + ".java";
+
+            File stubfile = new File(dir, file);
+            File gendir = stubfile.getParentFile();
+
+            gendir.mkdirs();
+
+            PrintWriter pw = new PrintWriter(new FileWriter(stubfile));
+
+            desc.writeStubClass(pw);
+
+            pw.close();
+
+            result.add(file);
+        }
+
+        return result;
+    }
+
+    public static void main(String[] args) throws Exception {
+        ArrayList al = new ArrayList();
+        for (int i = 0; i < args.length; i++) {
+            al.add(Class.forName(args[i]));
+        }
+
+        StubBuilder.generateStubs(new File("."), al);
+    }
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubImpl.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubImpl.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubImpl.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubImpl.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,114 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+public class StubImpl implements javax.rmi.CORBA.StubDelegate {
+    public StubImpl() {
+    }
+
+    public int hashCode(javax.rmi.CORBA.Stub stub) {
+        return stub._get_delegate().hashCode(stub);
+    }
+
+    public boolean equals(javax.rmi.CORBA.Stub stub, java.lang.Object obj) {
+        if (obj instanceof org.omg.CORBA.Object) {
+            return stub._is_equivalent((org.omg.CORBA.Object) obj);
+        } else {
+            return false;
+        }
+    }
+
+    public java.lang.String toString(javax.rmi.CORBA.Stub stub) {
+        return stub._get_delegate().toString(stub);
+    }
+
+    public void connect(javax.rmi.CORBA.Stub stub, org.omg.CORBA.ORB orb)
+            throws java.rmi.RemoteException {
+        try {
+            org.omg.CORBA.portable.Delegate delegate;
+
+            try {
+                delegate = stub._get_delegate();
+            } catch (org.omg.CORBA.BAD_OPERATION ex) {
+                throw new java.rmi.RemoteException("stub has no identity");
+            }
+
+            if (delegate.orb(stub) != orb) {
+                org.omg.CORBA.portable.OutputStream out = orb
+                        .create_output_stream();
+
+                out.write_Object(stub);
+
+                org.omg.CORBA.portable.InputStream in = out
+                        .create_input_stream();
+
+                org.omg.CORBA.portable.ObjectImpl impl = (org.omg.CORBA.portable.ObjectImpl) in
+                        .read_Object();
+
+                stub._set_delegate(impl._get_delegate());
+            }
+
+        } catch (org.omg.CORBA.SystemException ex) {
+            throw javax.rmi.CORBA.Util.mapSystemException(ex);
+        }
+    }
+
+    public void readObject(javax.rmi.CORBA.Stub stub,
+            java.io.ObjectInputStream ois) throws java.io.IOException,
+            java.lang.ClassNotFoundException {
+        org.omg.CORBA.portable.InputStream in = null;
+
+        if (ois instanceof CorbaObjectReader) {
+            in = ((CorbaObjectReader) ois).in;
+        } else {
+            IOR ior = new IOR();
+            ior.read(ois);
+
+            org.omg.CORBA.portable.OutputStream out = RMIState.current()
+                    .getORB().create_output_stream();
+
+            ior.write(out);
+
+            in = out.create_input_stream();
+        }
+
+        org.omg.CORBA.portable.ObjectImpl impl = (org.omg.CORBA.portable.ObjectImpl) in
+                .read_Object();
+
+        stub._set_delegate(impl._get_delegate());
+    }
+
+    public void writeObject(javax.rmi.CORBA.Stub stub,
+            java.io.ObjectOutputStream oos) throws java.io.IOException {
+        if (oos instanceof CorbaObjectWriter) {
+            ((CorbaObjectWriter) oos).out.write_Object(stub);
+        } else {
+            org.omg.CORBA.portable.OutputStream out = RMIState.current()
+                    .getORB().create_output_stream();
+
+            out.write_Object(stub);
+
+            org.omg.CORBA.portable.InputStream in = out.create_input_stream();
+
+            IOR ior = new IOR();
+            ior.read(in);
+            ior.write(oos);
+        }
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/StubImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/TypeDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/TypeDescriptor.java?rev=420804&view=auto
==============================================================================
--- incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/TypeDescriptor.java (added)
+++ incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/TypeDescriptor.java Tue Jul 11 04:35:32 2006
@@ -0,0 +1,227 @@
+/**
+*
+* Copyright 2006 The Apache Software Foundation
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/ 
+
+package org.apache.yoko.rmi.impl;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.omg.CORBA.portable.InputStream;
+
+public abstract class TypeDescriptor extends ModelElement {
+    static Logger logger = Logger.getLogger(TypeDescriptor.class.getName());
+
+    protected Class _java_class;
+
+    protected String _repid;
+
+    protected RemoteInterfaceDescriptor remoteDescriptor;
+
+    public Class getJavaClass() {
+        return _java_class;
+    }
+
+    protected TypeDescriptor(Class type, TypeRepository repository) {
+        _java_class = type;
+        setTypeRepository(repository);
+        setIDLName(type.getName().replace('.', '_'));
+    }
+
+    public String getRepositoryIDForArray() {
+        return getRepositoryID();
+    }
+
+    public String getRepositoryID() {
+        if (_repid == null)
+            _repid = "RMI:" + getJavaClass().getName() + ":0000000000000000";
+
+        return _repid;
+    }
+
+    RemoteInterfaceDescriptor getRemoteInterface() {
+        return remoteDescriptor;
+    }
+
+    void setRemoteInterface(RemoteInterfaceDescriptor desc) {
+        remoteDescriptor = desc;
+    }
+
+    /** Read an instance of this value from a CDR stream */
+    public abstract Object read(org.omg.CORBA.portable.InputStream in);
+
+    /** Write an instance of this value to a CDR stream */
+    public abstract void write(org.omg.CORBA.portable.OutputStream out,
+            Object val);
+
+    public void init() {
+    }
+
+    public boolean isCustomMarshalled() {
+        return false;
+    }
+
+    static class WrappedIOException extends RuntimeException {
+        IOException wrapped;
+
+        WrappedIOException(IOException ex) {
+            super("wrapped IO exception");
+            this.wrapped = ex;
+        }
+    }
+
+    CorbaObjectReader makeCorbaObjectReader(final InputStream in,
+            final Map offsetMap, final java.io.Serializable obj)
+            throws IOException {
+        try {
+            return (CorbaObjectReader) AccessController
+                    .doPrivileged(new PrivilegedAction() {
+                        public Object run() {
+                            try {
+                                return new CorbaObjectReader(in, offsetMap, obj);
+                            } catch (IOException ex) {
+                                throw new WrappedIOException(ex);
+                            }
+                        }
+                    });
+        } catch (WrappedIOException ex) {
+            throw ex.wrapped;
+        }
+    }
+
+    String makeSignature(Class type) {
+        if (type.isPrimitive()) {
+
+            if (type == Boolean.TYPE) {
+                return "Z";
+            } else if (type == Byte.TYPE) {
+                return "B";
+            } else if (type == Short.TYPE) {
+                return "S";
+            } else if (type == Character.TYPE) {
+                return "C";
+            } else if (type == Integer.TYPE) {
+                return "I";
+            } else if (type == Long.TYPE) {
+                return "J";
+            } else if (type == Float.TYPE) {
+                return "F";
+            } else if (type == Double.TYPE) {
+                return "D";
+            } else if (type == Void.TYPE) {
+                return "V";
+            } else
+                throw new RuntimeException("unknown primitive class" + type);
+
+        } else if (type.isArray()) {
+            int i = 0;
+            Class elem = type;
+            for (; elem.isArray(); elem = elem.getComponentType())
+                i += 1;
+
+            StringBuffer sb = new StringBuffer();
+            for (int j = 0; j < i; j++)
+                sb.append('[');
+
+            sb.append(makeSignature(elem));
+
+            return sb.toString();
+        } else {
+            return "L" + (type.getName()).replace('.', '/') + ";";
+        }
+    }
+
+    long getHashCode() {
+        return 0L;
+    }
+
+    protected org.omg.CORBA.TypeCode _type_code = null;
+
+    abstract org.omg.CORBA.TypeCode getTypeCode();
+
+    Object copyObject(Object value, CopyState state) {
+        throw new InternalError("cannot copy " + value.getClass().getName());
+    }
+
+    void writeMarshalValue(java.io.PrintWriter pw, String outName,
+            String paramName) {
+        pw.print(outName);
+        pw.print('.');
+        pw.print("write_");
+        pw.print(getIDLName());
+        pw.print('(');
+        pw.print(paramName);
+        pw.print(')');
+    }
+
+    void writeUnmarshalValue(java.io.PrintWriter pw, String inName) {
+        pw.print(inName);
+        pw.print('.');
+        pw.print("read_");
+        pw.print(getIDLName());
+        pw.print('(');
+        pw.print(')');
+    }
+
+    void addDependencies(java.util.Set classes) {
+        return;
+    }
+
+    boolean copyInStub() {
+        return true;
+    }
+
+    void print(java.io.PrintWriter pw, java.util.Map recurse, Object val) {
+        if (val == null) {
+            pw.print("null");
+        }
+
+        Integer old = (Integer) recurse.get(val);
+        if (old != null) {
+            pw.print("^" + old);
+        } else {
+            Integer key = new Integer(System.identityHashCode(val));
+            pw.println(getJavaClass().getName() + "@"
+                    + Integer.toHexString(key.intValue()));
+        }
+    }
+
+    synchronized TypeDescriptor getSelf() {
+        return this;
+    }
+
+    /**
+     * Method copyBetweenStates.
+     * 
+     * @return boolean
+     */
+    public boolean copyBetweenStates() {
+        return true;
+    }
+
+    /**
+     * Method copyWithinState.
+     * 
+     * @return boolean
+     */
+    public boolean copyWithinState() {
+        return true;
+    }
+
+}

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/TypeDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi/src/main/java/org/apache/yoko/rmi/impl/TypeDescriptor.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message