diff options
author | Kay Ramme <kr@openoffice.org> | 2001-01-16 17:01:32 +0000 |
---|---|---|
committer | Kay Ramme <kr@openoffice.org> | 2001-01-16 17:01:32 +0000 |
commit | 49b4d41601e387b89512f2422fc515e3f1506100 (patch) | |
tree | 426770ad5e7f0aefc8f7629165537225d8bd667f /jurt | |
parent | 8b739868ee0b344a5048816fef8ebf0b10f40c98 (diff) |
use Type and TypeDescription instead of Class
Diffstat (limited to 'jurt')
9 files changed, 369 insertions, 401 deletions
diff --git a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java index 2e34af011314..b03e8a3b7467 100644 --- a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java +++ b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java @@ -2,9 +2,9 @@ * * $RCSfile: java_remote_bridge.java,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: kr $ $Date: 2000-12-22 10:01:29 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -108,6 +108,8 @@ import com.sun.star.lib.uno.environments.remote.Job; import com.sun.star.lib.uno.environments.remote.ThreadID; import com.sun.star.lib.uno.environments.remote.ThreadPool; +import com.sun.star.lib.uno.typedesc.TypeDescription; + import com.sun.star.lib.util.IStableObject; import com.sun.star.lib.util.IStableListener; @@ -128,7 +130,7 @@ import com.sun.star.uno.IQueryInterface; * The protocol to used is passed by name, the bridge * then looks for it under <code>com.sun.star.lib.uno.protocols</code>. * <p> - * @version $Revision: 1.9 $ $ $Date: 2000-12-22 10:01:29 $ + * @version $Revision: 1.10 $ $ $Date: 2001-01-16 18:01:24 $ * @author Kay Ramme * @see com.sun.star.lib.uno.environments.remote.IProtocol * @since UDK1.0 @@ -139,7 +141,6 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid */ static private final boolean DEBUG = false; - /** * E.g. to get privleges for security managers, it is * possible to set a hook for the <code>MessageDispatcher</code> thread. @@ -203,7 +204,6 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid super("MessageDispatcher"); } - public void run() { if(__MessageDispatcher_run_hook != null) { try { @@ -227,21 +227,21 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid // Take care of special methods release and acquire if(iMessage.getOperation() != null && iMessage.getOperation().equals("release")) { - _java_environment.revokeInterface(iMessage.getOid(), iMessage.getInterface()); - remRefHolder(iMessage.getInterface(), iMessage.getOid()); + _java_environment.revokeInterface(iMessage.getOid(), new Type(iMessage.getInterface())); + remRefHolder(new Type(iMessage.getInterface()), iMessage.getOid()); } else if(iMessage.getOperation() != null && iMessage.getOperation().equals("acquire")) { String oid_o[] = new String[]{iMessage.getOid()}; - _java_environment.registerInterface(null, oid_o, iMessage.getInterface()); + _java_environment.registerInterface(null, oid_o, new Type(iMessage.getInterface())); - addRefHolder(iMessage.getInterface(), iMessage.getOid()); + addRefHolder(new Type(iMessage.getInterface()), iMessage.getOid()); } else { Object object = null; if(iMessage.getOperation() != null) { // is it a request - object = _java_environment.getRegisteredInterface(iMessage.getOid(), iMessage.getInterface()); + object = _java_environment.getRegisteredInterface(iMessage.getOid(), new Type(iMessage.getInterface())); Object xexception = null; @@ -297,6 +297,7 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid catch(Exception exception) { if(DEBUG) { System.err.println(getClass() + " - reading message - exception occurred: \"" + exception + "\""); + exception.printStackTrace(); System.err.println(getClass() + " - giving up"); } if(DEBUG) @@ -350,40 +351,40 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid // use a static class, it is smaller private static class RefHolder { - Class _zInterface; + Type _type; String _oid; int _mapCount; } - void addRefHolder(Class zInterface, String oid) { + void addRefHolder(Type type, String oid) { acquire(); - RefHolder refHolder = (RefHolder)_refHolders.get(oid + zInterface); + RefHolder refHolder = (RefHolder)_refHolders.get(oid + type); if(refHolder == null) { refHolder = new RefHolder(); - refHolder._zInterface = zInterface; + refHolder._type = type; refHolder._oid = oid; - _refHolders.put(oid + zInterface, refHolder); + _refHolders.put(oid + type, refHolder); } ++ refHolder._mapCount; } - void remRefHolder(Class zInterface, String oid) { - RefHolder refHolder = (RefHolder)_refHolders.get(oid + zInterface); + void remRefHolder(Type type, String oid) { + RefHolder refHolder = (RefHolder)_refHolders.get(oid + type); if(refHolder != null) { -- refHolder._mapCount; if(refHolder._mapCount <= 0) - _refHolders.remove(oid + zInterface); + _refHolders.remove(oid + type); release(); } else - System.err.println(getClass().getName() + ".remRefHolder - warning - unknown oid:" + oid + " " + zInterface); + System.err.println(getClass().getName() + ".remRefHolder - warning - unknown oid:" + oid + " " + type); } @@ -397,7 +398,7 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid while(refHolder._mapCount > 0) { -- refHolder._mapCount; - _java_environment.revokeInterface(refHolder._oid, refHolder._zInterface); + _java_environment.revokeInterface(refHolder._oid, refHolder._type); release(); } } @@ -569,10 +570,10 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid * <p> * @return the object in the destination environment * @param object the object to map - * @param zInterface the interface under which is to be mapped + * @param type the interface under which is to be mapped * @see com.sun.star.uno.IBridge#mapInterfaceTo */ - public Object mapInterfaceTo(Object object, Class zInterface) throws MappingException { + public Object mapInterfaceTo(Object object, Type type) throws MappingException { if(_disposed) throw new RuntimeException("java_remote_bridge(" + this + ").mapInterfaceTo - is disposed"); String oid[] = new String[1]; @@ -581,11 +582,11 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid if(object instanceof String) oid[0] = (String)object; else { - Object xobject = _java_environment.registerInterface(object, oid, zInterface); + Object xobject = _java_environment.registerInterface(object, oid, type); if(!(xobject instanceof com.sun.star.lib.uno.environments.java.java_environment.HolderProxy)) - addRefHolder(zInterface, oid[0]); + addRefHolder(type, oid[0]); } - if(DEBUG) System.err.println("##### " + getClass() + " - mapInterfaceTo:" + object + " interface:" + zInterface + " " + oid[0]); + if(DEBUG) System.err.println("##### " + getClass() + " - mapInterfaceTo:" + object + " interface:" + type + " " + oid[0]); return oid[0]; } @@ -595,14 +596,14 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid * <p> * @return the object in the source environment * @param object the object to map - * @param zInterface the interface under which is to be mapped + * @param type the interface under which is to be mapped * @see com.sun.star.uno.IBridge#mapInterfaceFrom */ - public Object mapInterfaceFrom(Object oId, Class zInterface) throws MappingException { + public Object mapInterfaceFrom(Object oId, Type type) throws MappingException { if(_disposed) throw new RuntimeException("java_remote_bridge(" + this + ").mapInterfaceFrom - is disposed"); // see if we already have object with zInterface of given oid - Object object = _java_environment.getRegisteredInterface((String)oId, zInterface); + Object object = _java_environment.getRegisteredInterface((String)oId, type); if(object != null) { if(object instanceof DispatcherAdapterBase) { DispatcherAdapterBase dispatcherAdapterBase = (DispatcherAdapterBase)object; @@ -612,7 +613,7 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid if(!(dispatcherAdapterBase.getObject() instanceof String)) { // is it not my object? try { - sendRequest(oId, new Type(zInterface), "release", null, null, null); + sendRequest(oId, type, "release", null, null, null); } catch(Exception exception) { throw new MappingException(exception.getMessage()); @@ -624,12 +625,12 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid else { String oid[] = new String[]{(String)oId}; - Object proxy = Proxy.create(this, oid[0], zInterface, false, _forceSynchronouse); // this proxy sends a release, when finalized - object = _java_environment.registerInterface(proxy, oid, zInterface); + Object proxy = Proxy.create(this, oid[0], type, false, _forceSynchronouse); // this proxy sends a release, when finalized + object = _java_environment.registerInterface(proxy, oid, type); acquire(); } - if(DEBUG) System.err.println("##### " + getClass() + " - mapInterfaceFrom:" + oId + " interface:" + zInterface + " " + object); + if(DEBUG) System.err.println("##### " + getClass() + " - mapInterfaceFrom:" + oId + " interface:" + type + " " + object); return object; } @@ -853,7 +854,7 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid // is this what we realy want to do, is the writing to the stream realy protected? Not that // an other thread flushes the output and an reply arrives before we have added the thread queue!!! synchronized(_xConnection) { - _iProtocol.writeRequest((String)object, type, operation, ThreadPool.getThreadId(), params, synchron, mustReply); + _iProtocol.writeRequest((String)object, (TypeDescription)type.getTypeDescription(), operation, ThreadPool.getThreadId(), params, synchron, mustReply); if(synchron[0].booleanValue()) // prepare a queue for this thread in the threadpool ThreadPool.addThread(this); diff --git a/jurt/com/sun/star/lib/uno/environments/java/java_environment.java b/jurt/com/sun/star/lib/uno/environments/java/java_environment.java index 477abbb38ed0..345fddd43c86 100644 --- a/jurt/com/sun/star/lib/uno/environments/java/java_environment.java +++ b/jurt/com/sun/star/lib/uno/environments/java/java_environment.java @@ -2,9 +2,9 @@ * * $RCSfile: java_environment.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: jbu $ $Date: 2001-01-09 13:43:15 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -76,6 +76,8 @@ import com.sun.star.lib.sandbox.generic.Dispatcher; import com.sun.star.lib.sandbox.generic.DispatcherAdapterBase; import com.sun.star.lib.sandbox.generic.DispatcherAdapterFactory; +import com.sun.star.lib.uno.typedesc.TypeDescription; + import com.sun.star.uno.IEnvironment; import com.sun.star.uno.IQueryInterface; import com.sun.star.uno.MappingException; @@ -90,7 +92,7 @@ import com.sun.star.uno.XInterface; * interface defined in the uno runtime. * <p> * <p> - * @version $Revision: 1.2 $ $ $Date: 2001-01-09 13:43:15 $ + * @version $Revision: 1.3 $ $ $Date: 2001-01-16 18:01:25 $ * @author Kay Ramme * @see com.sun.star.uno.UnoRuntime * @see com.sun.star.uno.IEnvironment @@ -138,7 +140,7 @@ public class java_environment implements IEnvironment, Disposable { } Holder _holder; - Class _zInterface; + Type _type; Hashtable _methods; @@ -171,18 +173,18 @@ public class java_environment implements IEnvironment, Disposable { super(); } - public void setInterface(Class zInterface) { - _zInterface = zInterface; + public void setInterface(Type type) { + _type = type; _methods = __getMethodsAsTable(object.getClass()); } - public Class getInterface() { - return _zInterface; + public Type getInterface() { + return _type; } // IQueryInterface - delegate calls through this proxy - public Object queryInterface(Class zInterface) throws MappingException { - return UnoRuntime.queryInterface(zInterface, object); + public Object queryInterface(Type type) throws MappingException { + return UnoRuntime.queryInterface(type, object); } public boolean isSame(Object object) throws MappingException { @@ -227,18 +229,19 @@ public class java_environment implements IEnvironment, Disposable { _objects.remove(_oId); } - Object xxgetObject(Class zInterface) { + Object xxgetObject(Type type) { Object result = _object; if(_object instanceof Proxy) { - if(DEBUG) System.err.println("###################### creating new Proxy Proxy"); - Class holderProxyClass = DispatcherAdapterFactory.createDispatcherAdapter(zInterface, HolderProxy.class.getName().replace('.', '/')); + if(DEBUG) System.err.println("##### " + getClass().getName() + " - creating new Proxy Proxy"); + Class holderProxyClass = DispatcherAdapterFactory.createDispatcherAdapter(((TypeDescription)type.getTypeDescription()).getZClass(), + HolderProxy.class.getName().replace('.', '/')); try { HolderProxy holderProxy = (HolderProxy)holderProxyClass.newInstance(); holderProxy.setObject(holderProxy, _object); holderProxy.setHolder(this); - holderProxy.setInterface(zInterface); + holderProxy.setInterface(type); result = holderProxy; } @@ -305,20 +308,20 @@ public class java_environment implements IEnvironment, Disposable { * @return a proxy to registered interface if necessare, otherwise the registered object itself * @param object the interface to register * @param oId[] inout parameter for the corresponding object id - * @param zInterface the type description of the given interface + * @param type the type description of the given interface * @see com.sun.star.uno.IEnvironment#registerInterface */ - public Object registerInterface(Object object, String oId[], Class zInterface) { + public Object registerInterface(Object object, String oId[], Type type) { if(oId[0] == null) oId[0] = UnoRuntime.generateOid(object); - String keyName = oId[0] + zInterface; + String keyName = oId[0] + type; // get the holder Holder holder = (Holder)_objects.get(keyName); if(DEBUG) - System.err.println("##### " + getClass().getName() + ".registerInterface:" + object + " " + oId[0] + " " + zInterface); + System.err.println("##### " + getClass().getName() + ".registerInterface:" + object + " " + oId[0] + " " + type); if(holder == null) { holder = new Holder(keyName, object); @@ -330,42 +333,42 @@ public class java_environment implements IEnvironment, Disposable { holder = (Holder)_objects.get(keyName); holder.incRefCount(); - return holder.xxgetObject(zInterface); + return holder.xxgetObject(type); } /** * You have to revoke ANY interface that has been registered via this method. * <p> * @param oId object id of interface to be revoked - * @param zInterface the type description of the interface + * @param type the type description of the interface * @see com.sun.star.uno.IEnvironment#revokeInterface */ - public void revokeInterface(String oId, Class zInterface) { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".revokeInterface:" + oId + " " + zInterface); - Holder holder = (Holder)_objects.get(oId + zInterface); + public void revokeInterface(String oId, Type type) { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".revokeInterface:" + oId + " " + type); + Holder holder = (Holder)_objects.get(oId + type); if(holder != null) holder.decRefCount(); else - System.err.println("java_environment.revokeInterface - unknown oid:" + oId + " " + zInterface); + System.err.println("java_environment.revokeInterface - unknown oid:" + oId + " " + type); } /** * Retrieves an interface identified by its object id and type from this environment. * <p> * @param oId object id of interface to be retrieved - * @param zInterface the type description of the interface to be retrieved + * @param type the type description of the interface to be retrieved * @see com.sun.star.uno.IEnvironment#getRegisteredInterface */ - public Object getRegisteredInterface(String oId, Class zInterface) { + public Object getRegisteredInterface(String oId, Type type) { Object result = null; - Holder holder = (Holder)_objects.get(oId + zInterface); + Holder holder = (Holder)_objects.get(oId + type); if(holder != null) { - result = holder.xxgetObject(zInterface); + result = holder.xxgetObject(type); } - if(DEBUG) System.err.println("##### " + getClass().getName() + ".getRegisteredInterface:>" + oId + "< " + zInterface +" " + result); + if(DEBUG) System.err.println("##### " + getClass().getName() + ".getRegisteredInterface:>" + oId + "< " + type +" " + result); return result; } diff --git a/jurt/com/sun/star/lib/uno/environments/remote/IProtocol.java b/jurt/com/sun/star/lib/uno/environments/remote/IProtocol.java index c90205cc053e..033f6d326238 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/IProtocol.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/IProtocol.java @@ -2,9 +2,9 @@ * * $RCSfile: IProtocol.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kr $ $Date: 2000-09-28 16:54:22 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:27 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,14 +70,14 @@ import com.sun.star.uno.IBridge; -import com.sun.star.uno.Type; +import com.sun.star.lib.uno.typedesc.TypeDescription; /** * This interface provides an abstraction for protocols * for remote bridges. * <p> - * @version $Revision: 1.2 $ $ $Date: 2000-09-28 16:54:22 $ + * @version $Revision: 1.3 $ $ $Date: 2001-01-16 18:01:27 $ * @author Kay Ramme * @see com.sun.star.lib.uno.environments.remote.IMessage * @see com.sun.star.lib.uno.environments.remote.Job @@ -117,7 +117,7 @@ public interface IProtocol { public void writeRequest(String oid, - Type zInterface, + TypeDescription zInterface, String operation, ThreadID threadId, Object params[], diff --git a/jurt/com/sun/star/lib/uno/environments/remote/Job.java b/jurt/com/sun/star/lib/uno/environments/remote/Job.java index 6915cf539d7e..360feef52fa8 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/Job.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/Job.java @@ -2,9 +2,9 @@ * * $RCSfile: Job.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kr $ $Date: 2000-11-17 10:45:40 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:27 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,16 +65,12 @@ package com.sun.star.lib.uno.environments.remote; import java.io.IOException; -import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import com.sun.star.corba.giop.ReplyStatusType_1_2; - -import com.sun.star.lib.uno.typeinfo.ParameterTypeInfo; +import com.sun.star.lib.uno.typedesc.TypeDescription; import com.sun.star.uno.Any; -import com.sun.star.uno.MappingException; import com.sun.star.uno.Type; import com.sun.star.uno.UnoRuntime; @@ -83,7 +79,7 @@ import com.sun.star.uno.UnoRuntime; * The Job is an abstraction for tasks which have to be done * remotely because of a method invocation. * <p> - * @version $Revision: 1.2 $ $ $Date: 2000-11-17 10:45:40 $ + * @version $Revision: 1.3 $ $ $Date: 2001-01-16 18:01:27 $ * @author Kay Ramme * @see com.sun.star.lib.uno.environments.remote.ThreadID * @see com.sun.star.lib.uno.environments.remote.IReceiver @@ -119,7 +115,7 @@ public class Job { * @param o_out_sig the out signature as an out parameter */ protected Object dispatch_MethodCall(Object params[]) throws Exception { - Method method = Protocol.__findMethod(_iMessage.getInterface(), _iMessage.getOperation()); + Method method = _iMessage.getInterface().getMethodDescription(_iMessage.getOperation()).getMethod(); if(DEBUG) System.err.println("##### " + getClass().getName() + ".dispatch_MethodCall:" + _object + " " + method.getName() + " " + params); @@ -137,14 +133,14 @@ public class Job { * @param o_out_sig the out signature as an out parameter */ protected Object dispatch_queryInterface(Type type) throws Exception { - Class zInterface = type.getDescription(); + Class zInterface = ((TypeDescription)type.getTypeDescription()).getZClass(); Object result = null; Object face = UnoRuntime.queryInterface(zInterface, _object); // the hell knows why, but empty interfaces a given back as void anys if(face != null) - result = new com.sun.star.uno.Any(type.getDescription(), face); + result = new Any(type, face); if(DEBUG) System.err.println("##### " + getClass().getName() + ".dispatch_queryInterface:" + _object + " " + zInterface + " result:" + result); @@ -190,17 +186,15 @@ public class Job { } while(theException instanceof InvocationTargetException); - // is this an exception we now? if(theException instanceof com.sun.star.uno.Exception || theException instanceof com.sun.star.uno.RuntimeException) { + if(_iMessage.isSynchron()) + _iReceiver.sendReply(true, _iMessage.getThreadID(), theException); if(DEBUG) System.err.println("#### RemoteStub.request - exception:" + theException); } - else // wrap it as uno exception - theException = new com.sun.star.uno.RuntimeException("java exception: " + theException.toString(), null); - - if(_iMessage.isSynchron()) - _iReceiver.sendReply(true, _iMessage.getThreadID(), theException); + else + throw (Exception)invocationTargetException.getTargetException(); } return result; @@ -256,7 +250,7 @@ public class Job { * <p> * @return returns the interface */ - public Class getInterface() { + public TypeDescription getInterface() { return _iMessage.getInterface(); } diff --git a/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java b/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java index 78a419d3041e..655c5c2922b3 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java @@ -2,9 +2,9 @@ * * $RCSfile: JobQueue.java,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: kr $ $Date: 2000-12-22 10:01:27 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:27 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,7 +81,7 @@ import com.sun.star.uno.UnoRuntime; * (put by <code>putjob</code>) into the async queue, which is only * known by the sync queue. * <p> - * @version $Revision: 1.6 $ $ $Date: 2000-12-22 10:01:27 $ + * @version $Revision: 1.7 $ $ $Date: 2001-01-16 18:01:27 $ * @author Kay Ramme * @see com.sun.star.lib.uno.environments.remote.ThreadPool * @see com.sun.star.lib.uno.environments.remote.Job @@ -94,7 +94,6 @@ public class JobQueue { */ public static final boolean DEBUG = false; - /** * E.g. to get privleges for security managers, it is * possible to set a hook for the <code>JobDispatcher</code> thread. @@ -318,10 +317,12 @@ public class JobQueue { // if there is an async queue, wait for jobs to be done if(_async_jobQueue != null) { synchronized(_async_jobQueue) { + // wait for async queue to be empty and last job to be done - while(_async_jobQueue._worker_thread != null && (_async_jobQueue._active || _async_jobQueue._head != null)) { + while(_async_jobQueue._active || _async_jobQueue._head != null) { if(DEBUG) System.err.println("waiting for async:" + _async_jobQueue._head + " " + _async_jobQueue._worker_thread); _async_jobQueue.wait(10); + if(DEBUG) System.err.println("waited for async"); } } } @@ -467,7 +468,7 @@ public class JobQueue { removeDisposeId(disposeId, disposeId_count); if(_sync_jobQueue != null) - notifyAll(); // notify waiters (e.g. this is an asyncQueue and there is a sync waiting) + notify(); // notify waiters (e.g. this is an asyncQueue and there is a sync waiting) } else quit = false; diff --git a/jurt/com/sun/star/lib/uno/environments/remote/remote_environment.java b/jurt/com/sun/star/lib/uno/environments/remote/remote_environment.java index d6069daa4080..589d2c57fc77 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/remote_environment.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/remote_environment.java @@ -2,9 +2,9 @@ * * $RCSfile: remote_environment.java,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 15:27:53 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:27 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,7 +67,10 @@ import java.util.Enumeration; import com.sun.star.lib.util.WeakTable; +import com.sun.star.lib.uno.typedesc.TypeDescription; + import com.sun.star.uno.IEnvironment; +import com.sun.star.uno.Type; import com.sun.star.uno.UnoRuntime; @@ -124,17 +127,17 @@ public class remote_environment implements IEnvironment { * @param oId[] inout parameter for the corresponding object id * @param xtypeDescr type description of interface */ - public Object registerInterface(Object object, String oId[], Class zInterface) { + public Object registerInterface(Object object, String oId[], Type type) { if(oId[0] == null) oId[0] = UnoRuntime.generateOid(object); - Object p_object = (Object)_objects.get(oId[0] + zInterface, zInterface); + Object p_object = (Object)_objects.get(oId[0] + type.getTypeDescription(), ((TypeDescription)type.getTypeDescription()).getZClass()); if(DEBUG) System.err.println("#### AbstractEnvironment.registerInterface:" + object + " " + UnoRuntime.generateOid(object) + " " + p_object); if(p_object == null) - object = _objects.put(oId[0] + zInterface, object, zInterface); + object = _objects.put(oId[0] + type.getTypeDescription(), object, ((TypeDescription)type.getTypeDescription()).getZClass()); else object = p_object; @@ -147,7 +150,7 @@ public class remote_environment implements IEnvironment { * @param oId object id of interface to be revoked * @param xtypeDescr type description of interface to be revoked */ - public void revokeInterface(String oId, Class zInterface) { + public void revokeInterface(String oId, Type type) { _objects.remove(oId); } @@ -157,10 +160,10 @@ public class remote_environment implements IEnvironment { * @param oId object id of interface to be retrieved * @param xtypeDescr description of interface to be retrieved */ - public Object getRegisteredInterface(String oId, Class zInterface) { - Object object = _objects.get(oId + zInterface, zInterface); + public Object getRegisteredInterface(String oId, Type type) { + Object object = _objects.get(oId + type.getTypeDescription(), ((TypeDescription)type.getTypeDescription()).getZClass()); - if(DEBUG) System.err.println("#### AbstractEnvironment(" + getName() + ").getRegisteredInterface:>" + oId + "< " + zInterface +" " + object); + if(DEBUG) System.err.println("#### AbstractEnvironment(" + getName() + ").getRegisteredInterface:>" + oId + "< " + type +" " + object); return object; } diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java b/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java index 9fb50ddb6391..7ba8e37fe2d7 100644 --- a/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java +++ b/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java @@ -2,9 +2,9 @@ * * $RCSfile: Marshal.java,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: kr $ $Date: 2000-12-13 16:32:20 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -91,6 +91,8 @@ import com.sun.star.lib.uno.environments.remote.IMarshal; import com.sun.star.lib.uno.environments.remote.Protocol; import com.sun.star.lib.uno.environments.remote.ThreadID; +import com.sun.star.lib.uno.typedesc.TypeDescription; + import com.sun.star.lib.uno.typeinfo.MemberTypeInfo; class Marshal implements IMarshal { @@ -99,6 +101,14 @@ class Marshal implements IMarshal { */ static public final boolean DEBUG = false; + static public final TypeDescription __xInterfaceTypeDescription = TypeDescription.getTypeDescription(XInterface.class); + static public final TypeDescription __M_InterfaceReferenceTypeDescription = TypeDescription.getTypeDescription(M_InterfaceReference.class); + static public final TypeDescription __M_ThreadIdTypeDescription = TypeDescription.getTypeDescription(M_ThreadId.class); + + static private final M_InterfaceReference __null_M_InterfaceReference = new M_InterfaceReference("", (short)0xffff); + + + static class M_ThreadId { public byte full[]; public short cache; @@ -146,25 +156,25 @@ class Marshal implements IMarshal { void writeAny(Object object) throws Exception { if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeAny:" + object); - Type type = null; + TypeDescription typeDescription = null; if(object == null) - type = new Type(Void.class); + typeDescription = TypeDescription.__void_TypeDescription; else if(object instanceof Any) { Any any = (Any)object; - type = new Type(any.getInterface()); + typeDescription = (TypeDescription)any.getType().getTypeDescription(); object = any.getObject(); } else if(object instanceof XInterface) - type = new Type(XInterface.class); + typeDescription = __xInterfaceTypeDescription; else - type = new Type(object.getClass()); + typeDescription = TypeDescription.getTypeDescription(object.getClass()); - writeType(type); - writeObject(type.getDescription(), object); + writeTypeDescrption(typeDescription); + writeObject(typeDescription, object); } void writeBoolean(Boolean zBoolean) throws Exception { @@ -184,9 +194,17 @@ class Marshal implements IMarshal { void writebyteSequence(byte bytes[]) throws Exception { if(DEBUG) System.err.println("##### " + getClass().getName() + ".writebyteSequence:" + bytes); - writeCompressedInt(bytes.length); + int size = 0; + if(bytes == null) + System.err.println("WARNING! writing null sequence as empty sequence"); - _dataOutput.write(bytes); + else + size = bytes.length; + + writeCompressedInt(size); + + if(size != 0) + _dataOutput.write(bytes); } void writeByte(Byte zByte) throws Exception { @@ -213,20 +231,13 @@ class Marshal implements IMarshal { writeint(enum.getValue()); } - void writeThrowable(Class zClass, Throwable throwable) throws Exception { + void writeThrowable(TypeDescription typeDescription, Throwable throwable) throws Exception { if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeThrowable:" + throwable); String message = throwable.getMessage(); writeString((message == null) ? "" : message); - if(java.lang.Exception.class.isAssignableFrom(zClass)) - writeStruct(zClass, throwable); - - else if(java.lang.RuntimeException.class.isAssignableFrom(zClass)) - writeStruct(zClass, throwable); - - else - throw new Exception("urp.Marshal.writeThrowable - unsupported throwable:" + zClass); + writeStruct(typeDescription, throwable); } void writeFloat(Float zFloat) throws Exception { @@ -253,81 +264,48 @@ class Marshal implements IMarshal { _dataOutput.writeLong(zLong.longValue()); } - // we may optimize this method with a hashtable in the future - public void writeObject(Class zClass, Object object) throws Exception { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeObject: <" + zClass + "> <" + object + ">"); - - if(zClass == Any.class || zClass == Object.class) // write an any ? - writeAny(object); - - else if(zClass.isArray() & zClass.getComponentType() == byte.class) // write a sequence ? - writebyteSequence((byte [])object); - - else if(zClass.isArray()) // write a sequence ? - writeSequence(zClass, object); - - else if(zClass == Void.class || zClass == void.class) // write nothing ? - ; // nop - - else if(Enum.class.isAssignableFrom(zClass)) // write an enum ? - writeEnum((Enum)object); - - else if(Union.class.isAssignableFrom(zClass)) // write a union ? - writeUnion((Union)object); - - else if(Type.class.isAssignableFrom(zClass)) // write a type ? - writeType((Type)object); - - else if(XInterface.class.isAssignableFrom(zClass)) // is it an interface ? - writeReference(zClass, object); - - else if(object instanceof ThreadID) // is it a thread id ? - writeThreadID((ThreadID)object); - - else if(zClass == boolean.class || zClass == Boolean.class) // is it a boolean - writeBoolean((Boolean)object); - - else if(zClass == char.class || zClass == Character.class) // is it a character ?) - writeCharacter((Character)object); - - else if(zClass == byte.class || zClass == Byte.class) // is it a byte ? - writeByte((Byte)object); - - else if(zClass == short.class || zClass == Short.class) // is it a short ? - writeShort((Short)object); - - else if(zClass == int.class || zClass == Integer.class) // is it an integer ? - writeInteger((Integer)object); - - else if(zClass == long.class || zClass == Long.class) // is it a long ? - writeLong((Long)object); - - else if(zClass == float.class || zClass == Float.class) // is it a float ? - writeFloat((Float)object); - - else if(zClass == double.class || zClass == Double.class) // is it a double ? - writeDouble((Double)object); - - else if(zClass == String.class) // is it a String ? - writeString((String)object); - - else if(Throwable.class.isAssignableFrom(zClass)) // is it an exception? - writeThrowable(zClass, (Throwable)object); - - else // otherwise it must be a struct - writeStruct(zClass, object); - + public void writeObject(TypeDescription typeDescription, Object object) throws Exception { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeObject: <" + typeDescription + "> <" + object + ">"); + + switch(typeDescription.getTypeClass().getValue()) { + case TypeClass.ANY_value: writeAny(object); break; // write an any ? + case TypeClass.SEQUENCE_value: + case TypeClass.ARRAY_value: writeSequence(typeDescription, object); break; // write a sequence ? + case TypeClass.VOID_value: break; // write nothing ? + case TypeClass.ENUM_value: writeEnum((Enum)object); break; // write an enum ? + case TypeClass.UNION_value: writeUnion((Union)object); break; // write a union ? + case TypeClass.TYPE_value: writeTypeDescrption((TypeDescription)((Type)object).getTypeDescription()); break; // write a type ? + case TypeClass.INTERFACE_value: writeReference(typeDescription, object); break; // is it an interface ? + case TypeClass.BOOLEAN_value: writeBoolean((Boolean)object); break; // is it a boolean + case TypeClass.CHAR_value: writeCharacter((Character)object); break; // is it a character ? + case TypeClass.BYTE_value: writeByte((Byte)object); break; // is it a byte ? + case TypeClass.SHORT_value: writeShort((Short)object); break; // is it a short ? + case TypeClass.LONG_value: writeInteger((Integer)object); break; // is it an integer ? + case TypeClass.HYPER_value: writeLong((Long)object); break; // is it a long ? + case TypeClass.FLOAT_value: writeFloat((Float)object); break; // is it a float ? + case TypeClass.DOUBLE_value: writeDouble((Double)object); break; // is it a double ? + case TypeClass.STRING_value: writeString((String)object); break; // is it a String ? + case TypeClass.STRUCT_value: + if(object instanceof ThreadID) // is it a thread id ? + writeThreadID((ThreadID)object); + else // is it a struct ? + writeStruct(typeDescription, object); + + break; + case TypeClass.EXCEPTION_value: writeThrowable(typeDescription, (Throwable)object); break; // is it an exception? + + default: + throw new com.sun.star.uno.RuntimeException(getClass().getName() + ".writeObject - unknown typeClass:" + typeDescription.getTypeClass().getValue()); + } } - static private final M_InterfaceReference null_M_InterfaceReference = new M_InterfaceReference("", (short)0xffff); - void writeOid(String oid) throws Exception { if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeOid:" + oid); M_InterfaceReference m_InterfaceReference = null; if(oid == null) - m_InterfaceReference = null_M_InterfaceReference; + m_InterfaceReference = __null_M_InterfaceReference; else { boolean found[] = new boolean[1]; short index; @@ -339,30 +317,35 @@ class Marshal implements IMarshal { m_InterfaceReference = new M_InterfaceReference(found[0] ? "" : oid, index); } - writeObject(M_InterfaceReference.class, m_InterfaceReference); + writeObject(__M_InterfaceReferenceTypeDescription, m_InterfaceReference); } - void writeReference(Class zInterface, Object object) throws Exception { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeReference:" + zInterface + " " + object); + void writeReference(TypeDescription typeDescription, Object object) throws Exception { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeReference:" + typeDescription + " " + object); // map the object to universe - writeOid(object != null ? (String)_iBridge.mapInterfaceTo(object, zInterface) : null); + writeOid(object != null ? (String)_iBridge.mapInterfaceTo(object, new Type(typeDescription)) : null); } - void writeSequence(Class zClass, Object object) throws Exception { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeSequence:" + zClass + " " + object); + void writeSequence(TypeDescription typeDescription, Object object) throws Exception { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeSequence:" + typeDescription + " " + object); - int size = 0; - if(object == null) - System.err.println("WARNING! writing null sequence as empty sequence"); - else - size = Array.getLength(object); + if(typeDescription.getTypeClass() == TypeClass.BYTE) // write a byte sequence ? + writebyteSequence((byte [])object); - writeCompressedInt(size); + else { + int size = 0; + if(object == null) + System.err.println("WARNING! writing null sequence as empty sequence"); + else + size = Array.getLength(object); + + writeCompressedInt(size); - zClass = zClass.getComponentType(); - for(int i = 0; i < size; ++ i) - writeObject(zClass, Array.get(object, i)); + typeDescription = typeDescription.getComponentType(); + for(int i = 0; i < size; ++ i) + writeObject(typeDescription, Array.get(object, i)); + } } void writeShort(Short zShort) throws Exception { @@ -397,13 +380,13 @@ class Marshal implements IMarshal { _dataOutput.write(bytes); } - void writeStruct(Class zClass, Object object) throws Exception { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeStruct:" + zClass + " " + object); + void writeStruct(TypeDescription typeDescription, Object object) throws Exception { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeStruct:" + typeDescription + " " + object); - Field fields[] = zClass.getFields(); + Field fields[] = typeDescription.getFields(); for(int i = 0; i < fields.length; ++ i) { if((fields[i].getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0) { // neither static nor transient ? - MemberTypeInfo memberTypeInfo = Protocol.__findMemberTypeInfo(zClass, fields[i].getName()); + MemberTypeInfo memberTypeInfo = typeDescription.getMemberTypeInfo(fields[i].getName()); // default the member type to the declared type Class zInterface = fields[i].getType(); @@ -430,7 +413,7 @@ class Marshal implements IMarshal { } } - writeObject(zInterface, fields[i].get(object)); + writeObject(TypeDescription.getTypeDescription(zInterface), fields[i].get(object)); } } } @@ -447,20 +430,20 @@ class Marshal implements IMarshal { M_ThreadId m_ThreadId = new M_ThreadId(found[0] ? null : threadID.getBytes(), index); - writeObject(M_ThreadId.class, m_ThreadId); + writeObject(__M_ThreadIdTypeDescription, m_ThreadId); } - void writeType(Type type) throws Exception { - TypeClass typeClass = type.getTypeClass(); + void writeTypeDescrption(TypeDescription typeDescription) throws Exception { + TypeClass typeClass = typeDescription.getTypeClass(); - if(Type.isTypeClassSimple(typeClass)) + if(TypeDescription.isTypeClassSimple(typeClass)) _dataOutput.writeByte((byte)typeClass.getValue()); // write the typeclass value else { boolean found[] = new boolean[1]; short index; if(_useCaches) - index = _typeCache.add(found, type.getTypeName()); + index = _typeCache.add(found, typeDescription.getTypeName()); else index = (short)0xffff; @@ -469,7 +452,7 @@ class Marshal implements IMarshal { _dataOutput.writeShort(index); // write the cache index if(!found[0]) // if not found in cache and the type is complex, write the type name - writeString(type.getTypeName()); + writeString(typeDescription.getTypeName()); } } diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/Unmarshal.java b/jurt/com/sun/star/lib/uno/protocols/urp/Unmarshal.java index 9067dd15ec17..3f56ddbb1266 100644 --- a/jurt/com/sun/star/lib/uno/protocols/urp/Unmarshal.java +++ b/jurt/com/sun/star/lib/uno/protocols/urp/Unmarshal.java @@ -2,9 +2,9 @@ * * $RCSfile: Unmarshal.java,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: kr $ $Date: 2000-09-28 16:53:16 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -88,8 +88,11 @@ import com.sun.star.lib.uno.environments.remote.IUnmarshal; import com.sun.star.lib.uno.environments.remote.Protocol; import com.sun.star.lib.uno.environments.remote.ThreadID; +import com.sun.star.lib.uno.typedesc.TypeDescription; + import com.sun.star.lib.uno.typeinfo.MemberTypeInfo; + class Unmarshal implements IUnmarshal { /** * When set to true, enables various debugging output. @@ -100,22 +103,22 @@ class Unmarshal implements IUnmarshal { private DataInput _dataInput; private IBridge _iBridge; private Object _objectCache[]; - private Type _typeCache[]; + private TypeDescription _typeDescriptionCache[]; private ThreadID _threadIdCache[]; Unmarshal(IBridge iBridge, short cacheSize) { _iBridge = iBridge; - _objectCache = new Object[cacheSize]; - _typeCache = new Type[cacheSize]; - _threadIdCache = new ThreadID[cacheSize]; - _inputStream = new ByteArrayInputStream(new byte[0]); - _dataInput = new DataInputStream(_inputStream); + _objectCache = new Object[cacheSize]; + _typeDescriptionCache = new TypeDescription[cacheSize]; + _threadIdCache = new ThreadID[cacheSize]; + _inputStream = new ByteArrayInputStream(new byte[0]); + _dataInput = new DataInputStream(_inputStream); } Object readAny() throws Exception { - Type type = readType(); - Object object = readObject(type.getDescription()); + TypeDescription typeDescription = readTypeDescription(); + Object object = readObject(typeDescription); if(DEBUG) System.err.println("##### " + getClass().getName() + ".readAny:" + object); @@ -173,10 +176,10 @@ class Unmarshal implements IUnmarshal { return result; } - Enum readEnum(Class zClass) throws Exception { + Enum readEnum(TypeDescription typeDescription) throws Exception { Integer index = readInteger(); - Method fromInt = zClass.getMethod("fromInt", new Class[] {int.class}); + Method fromInt = typeDescription.getZClass().getMethod("fromInt", new Class[] {int.class}); Enum result = (Enum)fromInt.invoke(null, new Object[]{index}); if(DEBUG) System.err.println("##### " + getClass().getName() + ".readEnum:" + result); @@ -184,20 +187,13 @@ class Unmarshal implements IUnmarshal { return result; } - Throwable readThrowable(Class zClass) throws Exception { + Throwable readThrowable(TypeDescription typeDescription) throws Exception { String message = readString(); - Constructor constructor = zClass.getConstructor(new Class[]{String.class}); + Constructor constructor = typeDescription.getZClass().getConstructor(new Class[]{String.class}); Throwable throwable = (Throwable)constructor.newInstance(new Object[]{message}); - if(java.lang.Exception.class.isAssignableFrom(zClass)) - readStruct(zClass, throwable); - - else if(java.lang.RuntimeException.class.isAssignableFrom(zClass)) - readStruct(zClass, throwable); - - else - throw new Exception("urp.Unmarshal.readThrowable - unsupported throwable:" + zClass); + readStruct(typeDescription, throwable); if(DEBUG) System.err.println("##### " + getClass().getName() + ".readThrowable:" + throwable); @@ -228,76 +224,50 @@ class Unmarshal implements IUnmarshal { return result; } - public Object readObject(Class zClass) throws Exception { + public Object readObject(TypeDescription typeDescription) throws Exception { Object result = null; - if(zClass == Any.class || zClass == Object.class) // read an any? - result = readAny(); - - else if(zClass.isArray() && zClass.getComponentType() == byte.class) // read a sequence ? - result = readbyteSequence(); - - else if(zClass.isArray()) // read a sequence ? - result = readSequence(zClass); - - else if(zClass == Void.class || zClass == void.class) // read nothing ? - ; // nop - - else if(Enum.class.isAssignableFrom(zClass)) // read an enum ? - result = readEnum(zClass); - - else if(Union.class.isAssignableFrom(zClass)) // read a union ? - result = readUnion(zClass); - - else if(zClass == Type.class) // read a type ? - result = readType(); - - else if(XInterface.class.isAssignableFrom(zClass)) // read an interface ? - result = readReference(zClass); - - else if(zClass == ThreadID.class) // read a thread id ? - result = readThreadID(); - - else if(zClass == boolean.class || zClass == Boolean.class) // is it a boolean - result = readBoolean(); - - else if(zClass == char.class || zClass == Character.class) // is it a character ?) - result = readCharacter(); - - else if(zClass == byte.class || zClass == Byte.class) // is it a byte ? - result = readByte(); - - else if(zClass == short.class || zClass == Short.class) // is it a short ? - result = readShort(); - - else if(zClass == int.class || zClass == Integer.class) // is it an integer ? - result = readInteger(); - - else if(zClass == long.class || zClass == Long.class) // is it a long ? - result = readLong(); - - else if(zClass == float.class || zClass == Float.class) // is it a float ? - result = readFloat(); - - else if(zClass == double.class || zClass == Double.class) // is it a double ? - result = readDouble(); - - else if(zClass == String.class) // is it a String ? - result = readString(); - - else if(Throwable.class.isAssignableFrom(zClass)) // is it an exception? - result = readThrowable(zClass); - - else // otherwise read a struct - result = readStruct(zClass); + switch(typeDescription.getTypeClass().getValue()) { + case TypeClass.ANY_value: result = readAny(); break; // read an any? + case TypeClass.SEQUENCE_value: + case TypeClass.ARRAY_value: result = readSequence(typeDescription); break; // read a sequence ? + case TypeClass.VOID_value: break; // nop // read nothing ? + case TypeClass.ENUM_value: result = readEnum(typeDescription); break; // read an enum ? + case TypeClass.UNION_value: result = readUnion(typeDescription); break; // read a union ? + case TypeClass.TYPE_value: result = new Type(readTypeDescription()); break; // read a type ? + case TypeClass.INTERFACE_value: result = readReference(typeDescription); break; // read an interface ? + case TypeClass.BOOLEAN_value: result = readBoolean(); break; // is it a boolean + case TypeClass.CHAR_value: result = readCharacter(); break; // is it a character ?) + case TypeClass.BYTE_value: result = readByte(); break; // is it a byte ? + case TypeClass.SHORT_value: + case TypeClass.UNSIGNED_SHORT_value: result = readShort(); break; // is it a short ? + case TypeClass.LONG_value: + case TypeClass.UNSIGNED_LONG_value: result = readInteger(); break; // is it an integer ? + case TypeClass.HYPER_value: + case TypeClass.UNSIGNED_HYPER_value: result = readLong(); break; // is it a long ? + case TypeClass.FLOAT_value: result = readFloat(); break; // is it a float ? + case TypeClass.DOUBLE_value: result = readDouble(); break; // is it a double ? + case TypeClass.STRING_value: result = readString(); break; // is it a String ? + case TypeClass.EXCEPTION_value: result = readThrowable(typeDescription); break; // is it an exception? + case TypeClass.STRUCT_value: + if(typeDescription.getZClass() == ThreadID.class) // read a thread id ? + result = readThreadID(); + else // otherwise read a struct + result = readStruct(typeDescription); + + break; + + default: + throw new com.sun.star.uno.RuntimeException("unknown typeClass:" + typeDescription.getTypeClass()); + } - if(DEBUG) System.err.println("##### " + getClass().getName() + ".readObject:" + zClass + " " + result); + if(DEBUG) System.err.println("##### " + getClass().getName() + ".readObject:" + typeDescription + " " + result); return result; } String readOid() throws Exception { - Marshal.M_InterfaceReference m_InterfaceReference = (Marshal.M_InterfaceReference)readObject(Marshal.M_InterfaceReference.class); + Marshal.M_InterfaceReference m_InterfaceReference = (Marshal.M_InterfaceReference)readObject(Marshal.__M_InterfaceReferenceTypeDescription); String oid = null; @@ -315,7 +285,7 @@ class Unmarshal implements IUnmarshal { return oid; } - Object readReference(Class zInterface) throws Exception { + Object readReference(TypeDescription typeDescription) throws Exception { Object oid = readOid();; // the result is a null ref, in case cache and oid are invalid @@ -323,26 +293,31 @@ class Unmarshal implements IUnmarshal { // map the object from universe if(oid != null) - result = _iBridge.mapInterfaceFrom(oid, zInterface); + result = _iBridge.mapInterfaceFrom(oid, new Type(typeDescription)); - if(DEBUG) System.err.println("##### " + getClass().getName() + ".readReference:" + zInterface + " " + result); + if(DEBUG) System.err.println("##### " + getClass().getName() + ".readReference:" + typeDescription + " " + result); return result; } - Object readSequence(Class zClass) throws Exception { - int size = readCompressedInt(); + Object readSequence(TypeDescription typeDescription) throws Exception { Object result = null; + if(typeDescription.getTypeClass() == TypeClass.BYTE) // read a byte sequence ? + result = readbyteSequence(); - zClass = zClass.getComponentType(); + else { + int size = readCompressedInt(); - if(zClass == Any.class) // take special care of any array (cause anys are mapped to objects) - result = Array.newInstance(Object.class, size); - else - result = Array.newInstance(zClass, size); + typeDescription = typeDescription.getComponentType(); - for(int i = 0; i < size; ++ i) - Array.set(result, i, readObject(zClass)); + if(typeDescription.getTypeClass() == TypeClass.ANY) // take special care of any array (cause anys are mapped to objects) + result = Array.newInstance(Object.class, size); + else + result = Array.newInstance(typeDescription.getZClass(), size); + + for(int i = 0; i < size; ++ i) + Array.set(result, i, readObject(typeDescription)); + } if(DEBUG) System.err.println("##### " + getClass().getName() + ".readSequence:" + result); @@ -385,12 +360,12 @@ class Unmarshal implements IUnmarshal { return new String(bytes, "UTF8"); } - void readStruct(Class zClass, Object object) throws Exception { - Field fields[] = zClass.getFields(); + void readStruct(TypeDescription typeDescription, Object object) throws Exception { + Field fields[] = typeDescription.getFields(); for(int i = 0; i < fields.length; ++ i) { if((fields[i].getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0) { // neither static nor transient ? - MemberTypeInfo memberTypeInfo = Protocol.__findMemberTypeInfo(zClass, fields[i].getName()); + MemberTypeInfo memberTypeInfo = typeDescription.getMemberTypeInfo(fields[i].getName()); // default the member type to the declared type Class zInterface = fields[i].getType(); @@ -415,23 +390,23 @@ class Unmarshal implements IUnmarshal { } } - fields[i].set(object, readObject(zInterface)); + fields[i].set(object, readObject(TypeDescription.getTypeDescription(zInterface))); } } if(DEBUG) System.err.println("##### " + getClass().getName() + ".readStruct:" + object); } - Object readStruct(Class zClass) throws Exception { - Object object = zClass.newInstance(); + Object readStruct(TypeDescription typeDescription) throws Exception { + Object object = typeDescription.getZClass().newInstance(); - readStruct(zClass, object); + readStruct(typeDescription, object); return object; } ThreadID readThreadID() throws Exception { - Marshal.M_ThreadId m_threadId = (Marshal.M_ThreadId)readObject(Marshal.M_ThreadId.class); + Marshal.M_ThreadId m_threadId = (Marshal.M_ThreadId)readObject(Marshal.__M_ThreadIdTypeDescription); ThreadID threadId = null; @@ -449,34 +424,36 @@ class Unmarshal implements IUnmarshal { return threadId; } - Type readType() throws Exception { + TypeDescription readTypeDescription() throws Exception { int typeClassValue = _dataInput.readUnsignedByte() & 0xff; TypeClass typeClass = TypeClass.fromInt(typeClassValue & 0x7f); - Type type = null; + TypeDescription typeDescription = null; - if(Type.isTypeClassSimple(typeClass)) // is it a simple type? - type = new Type(typeClass); + if(TypeDescription.isTypeClassSimple(typeClass)) // is it a simple type? + typeDescription = TypeDescription.getTypeDescription(typeClass); else { short index = _dataInput.readShort(); // the cache index if(index != (short)0xffff) { // shall we update the cache? if((typeClassValue & 0x80) != 0) // update the cache? - _typeCache[index] = new Type(typeClass, readString()); + _typeDescriptionCache[index] = TypeDescription.getTypeDescription(readString()); +// _typeDescriptionCache[index] = TypeDescription.getType(typeClass, readString()); - type = _typeCache[index]; + typeDescription = _typeDescriptionCache[index]; } else - type = new Type(typeClass, readString()); + typeDescription = TypeDescription.getTypeDescription(readString()); +// type = TypeDescription.getType(typeClass, readString()); } - if(DEBUG) System.err.println("##### " + getClass().getName() + ".readType:" + type); + if(DEBUG) System.err.println("##### " + getClass().getName() + ".readType:" + typeDescription); - return type; + return typeDescription; } - Union readUnion(Class zClass) throws Exception { + Union readUnion(TypeDescription typeDescription) throws Exception { throw new Exception("Unmarshal.readUnion - not implemented!!!"); } diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/urp.java b/jurt/com/sun/star/lib/uno/protocols/urp/urp.java index aabfdada9e0c..531095c921d2 100644 --- a/jurt/com/sun/star/lib/uno/protocols/urp/urp.java +++ b/jurt/com/sun/star/lib/uno/protocols/urp/urp.java @@ -2,9 +2,9 @@ * * $RCSfile: urp.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kr $ $Date: 2000-09-28 16:53:48 $ + * last change: $Author: kr $ $Date: 2001-01-16 18:01:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,8 +81,9 @@ import com.sun.star.lib.uno.environments.remote.Protocol; import com.sun.star.lib.uno.environments.remote.IUnmarshal; import com.sun.star.lib.uno.environments.remote.ThreadID; -import com.sun.star.lib.uno.typeinfo.MethodTypeInfo; -import com.sun.star.lib.uno.typeinfo.TypeInfo; +import com.sun.star.lib.uno.typedesc.MethodDescription; +import com.sun.star.lib.uno.typedesc.TypeDescription; +//import com.sun.star.lib.uno.typeinfo.TypeInfo; import com.sun.star.uno.Any; import com.sun.star.uno.UnoRuntime; @@ -94,7 +95,7 @@ import com.sun.star.uno.Type; * from uno. The functionality is reachable through * the <code>IProtocol</code> interface. * <p> - * @version $Revision: 1.2 $ $ $Date: 2000-09-28 16:53:48 $ + * @version $Revision: 1.3 $ $ $Date: 2001-01-16 18:01:32 $ * @author Kay Ramme * @see com.sun.star.lib.uno.environments.remote.IProtocol * @since UDK1.0 @@ -105,18 +106,19 @@ public class urp extends Protocol { */ static public final boolean DEBUG = false; - static private final short __cache_size = 256; + static private final TypeDescription __emptyTypeDescArray[] = new TypeDescription[0]; + static private final short __cache_size = 256; protected IBridge _iBridge; protected boolean _bIgnoreNextCloseConnection = false; private String _in_oid; - private Type _in_interface; + private TypeDescription _in_interface; private ThreadID _in_threadId; private String _out_oid; - private Type _out_interface; + private TypeDescription _out_interface; private ThreadID _out_threadId; private int _message_count; @@ -198,19 +200,19 @@ public class urp extends Protocol { // get the out signature and parameter array of the reply Object objects[] = (Object[])removePendingRequest(_in_threadId); Object param[] = (Object[])objects[0]; - Class signature[] = (Class[])objects[1]; - Class resultClass = (Class)objects[2]; + TypeDescription signature[] = (TypeDescription[])objects[1]; + TypeDescription resultType = (TypeDescription)objects[2]; exception[0] = (header & EXCEPTION) != 0; if(exception[0]) {// Exception? So the reply has an any as the result - signature = new Class[0]; - resultClass = com.sun.star.uno.Any.class; + signature = __emptyTypeDescArray; + resultType = TypeDescription.__any_TypeDescription; } // read the result object Object result = null; - if(resultClass != null) - result = _unmarshal.readObject(resultClass); + if(resultType != null) + result = _unmarshal.readObject(resultType); // read the out parameters for(int i = 0; i < signature.length; ++ i) { @@ -218,24 +220,29 @@ public class urp extends Protocol { Array.set(param[i], 0, _unmarshal.readObject(signature[i].getComponentType())); } + if(DEBUG) System.err.println("##### " + getClass().getName() + ".readReply:" + result); + return result; } - private Object []readParams(MMDesc mMDesc) throws Exception { - Object params[] = new Object[mMDesc._in_sig.length]; + private Object []readParams(MethodDescription methodDescription) throws Exception { + TypeDescription in_sig[] = methodDescription.getInSignature(); + TypeDescription out_sig[] = methodDescription.getOutSignature(); + + Object params[] = new Object[in_sig.length]; for(int i = 0; i < params.length; ++ i) { - if(mMDesc._in_sig[i] != null) // is it an in parameter? - if(mMDesc._out_sig[i] != null) {// is it also an out -> inout? - Object inout = Array.newInstance(mMDesc._out_sig[i].getComponentType(), 1); - Array.set(inout, 0, _unmarshal.readObject(mMDesc._out_sig[i].getComponentType())); + if(in_sig[i] != null) // is it an in parameter? + if(out_sig[i] != null) {// is it also an out -> inout? + Object inout = Array.newInstance(out_sig[i].getComponentType().getZClass(), 1); + Array.set(inout, 0, _unmarshal.readObject(out_sig[i].getComponentType())); params[i] = inout; } else // it is only an in parameter - params[i] = _unmarshal.readObject(mMDesc._in_sig[i]); + params[i] = _unmarshal.readObject(in_sig[i]); else // it is only an out parameter, so provide the holder - params[i] = Array.newInstance(mMDesc._out_sig[i].getComponentType(), 1); + params[i] = Array.newInstance(out_sig[i].getComponentType().getZClass(), 1); } return params; @@ -252,19 +259,18 @@ public class urp extends Protocol { else methodId = (header & 0x3f); - MMDesc mMDesc = getMMDesc(_in_interface.getDescription(), methodId); - operation[0] = mMDesc._name; + MethodDescription methodDescription = _in_interface.getMethodDescription(methodId); + operation[0] = methodDescription.getName(); - if(mMDesc._methodTypeInfo == null) // is there a method type info - synchron[0] = true; // if not, the default is synchron - else - synchron[0] = !mMDesc._methodTypeInfo.isOneway(); + synchron[0] = !methodDescription.isOneway(); - param[0] = readParams(mMDesc); + param[0] = readParams(methodDescription); if(synchron[0]) { // if the request is synchron, it is pending - putPendingReply(_in_threadId, new Object[]{param[0], mMDesc._out_sig, mMDesc._res/*, mMDesc*/}); + putPendingReply(_in_threadId, new Object[]{param[0], methodDescription.getOutSignature(), methodDescription.getReturnSig()/*, mMDesc*/}); } + + if(DEBUG) System.err.println("##### " + getClass().getName() + ".readShortRequest:" + _in_oid + " " + operation[0] + " " + synchron[0]); } private void readLongRequest(byte header, String operation[], Object param[][], boolean synchron[]) throws Exception { @@ -278,7 +284,7 @@ public class urp extends Protocol { methodId = _unmarshal.readbyte(); if((header & NEWTYPE) != 0) - _in_interface = _unmarshal.readType(); + _in_interface = _unmarshal.readTypeDescription(); if((header & NEWOID) != 0) // new oid? _in_oid = _unmarshal.readOid(); @@ -288,7 +294,7 @@ public class urp extends Protocol { _ignore_cache = ((header & IGNORECACHE) != 0); // do not use cache for this request? - MMDesc mMDesc = getMMDesc(_in_interface.getDescription(), methodId); + MethodDescription methodDescription = _in_interface.getMethodDescription(methodId); boolean mustReply; if((header & MOREFLAGS) != 0) {// is there an extended flags byte? @@ -299,16 +305,18 @@ public class urp extends Protocol { } else { // the typeinfo does not differentiate between MUSTREPLY and SYNCHRONOUSE - synchron[0] = mMDesc._methodTypeInfo != null ? !mMDesc._methodTypeInfo.isOneway() : true; + synchron[0] = !methodDescription.isOneway(); mustReply = synchron[0]; } - operation[0] = mMDesc._name; + operation[0] = methodDescription.getName(); - param[0] = readParams(mMDesc); + param[0] = readParams(methodDescription); if(synchron[0]) // if the request is synchron, the reply is pending - putPendingReply(_in_threadId, new Object[]{param[0], mMDesc._out_sig, mMDesc._res/*, mMDesc*/}); + putPendingReply(_in_threadId, new Object[]{param[0], methodDescription.getOutSignature(), methodDescription.getReturnSig()/*, mMDesc*/}); + + if(DEBUG) System.err.println("##### " + getClass().getName() + ".readLongRequest:" + _in_oid + " " + operation[0] + " " + synchron[0]); } private Object readMessage(String operation[], Object param[], boolean synchron[], boolean exception[]) throws Exception { @@ -334,7 +342,7 @@ public class urp extends Protocol { public void writeRequest(String oid, - Type zInterface, + TypeDescription zInterface, String operation, ThreadID threadId, Object params[], @@ -346,7 +354,7 @@ public class urp extends Protocol { ++ _requestsSend; ++ _message_count; synchronized(_marshal) { - MMDesc mMDesc = getMMDesc(zInterface.getDescription(), operation); + MethodDescription methodDescription = zInterface.getMethodDescription(operation); byte header = 0; boolean bigHeader = false; @@ -384,28 +392,24 @@ public class urp extends Protocol { // if the type of request is provided, test if it differs from declaration if(synchron[0] != null) { - if(mMDesc._methodTypeInfo != null && mMDesc._methodTypeInfo.isOneway() == synchron[0].booleanValue()) { + if(methodDescription.isOneway() == synchron[0].booleanValue()) { bigHeader = true; hasExFlags = true; } } - else if(mMDesc._methodTypeInfo != null) // if the request type is not provided, use the typeInfo if available - synchron[0] = new Boolean(!mMDesc._methodTypeInfo.isOneway()); - else // if no request type provided and no typeInfo available fall back to synchron - synchron[0] = new Boolean(true); + else + synchron[0] = new Boolean(!methodDescription.isOneway()); // if the type of request is provided, test if it differs from declaration if(mustReply[0] != null) { - if(mMDesc._methodTypeInfo != null && mMDesc._methodTypeInfo.isOneway() == mustReply[0].booleanValue()) { + if(methodDescription.isOneway() == mustReply[0].booleanValue()) { bigHeader = true; hasExFlags = true; } } - else if(mMDesc._methodTypeInfo != null) // if the request type is not provided, use the typeInfo if available - mustReply[0] = new Boolean(!mMDesc._methodTypeInfo.isOneway()); - else // if no request type provided and no typeInfo available fall back to synchron - mustReply[0] = new Boolean(true); + else + mustReply[0] = new Boolean(!methodDescription.isOneway()); if(bigHeader) { // something has changed, send big header @@ -413,7 +417,7 @@ public class urp extends Protocol { header |= REQUEST; header |= hasExFlags ? MOREFLAGS : 0; - if(mMDesc._index > 255) + if(methodDescription.getIndex() > 255) header |= LONGMETHODID; _marshal.writebyte(header); @@ -428,13 +432,13 @@ public class urp extends Protocol { } // write the method id - if(mMDesc._index > 255) - _marshal.writeshort((short)mMDesc._index); + if(methodDescription.getIndex() > 255) + _marshal.writeshort((short)methodDescription.getIndex()); else - _marshal.writebyte((byte)mMDesc._index); + _marshal.writebyte((byte)methodDescription.getIndex()); if(zInterface != null) // has the interface changed? -> write it - _marshal.writeType(zInterface); + _marshal.writeTypeDescrption(zInterface); if(oid != null) // has the oid changed? -> write it _marshal.writeOid(_out_oid); @@ -443,29 +447,31 @@ public class urp extends Protocol { _marshal.writeThreadID(threadId); } else { // simple request - if(mMDesc._index <= 0x2f) // does the method id fit in the header? - _marshal.writebyte((byte)mMDesc._index); + if(methodDescription.getIndex() <= 0x2f) // does the method id fit in the header? + _marshal.writebyte((byte)methodDescription.getIndex()); else { // no header |= DIR_MID; - header |= mMDesc._index >> 8; + header |= methodDescription.getIndex() >> 8; _marshal.writebyte(header); - _marshal.writebyte((byte)(mMDesc._index & 0xff)); + _marshal.writebyte((byte)(methodDescription.getIndex() & 0xff)); } } // write the in parameters - for(int i = 0; i < mMDesc._in_sig.length; ++ i) { - if(mMDesc._in_sig[i] != null) { // is it an in parameter? - if(mMDesc._out_sig[i] != null) // is it also an out parameter? - _marshal.writeObject(mMDesc._out_sig[i].getComponentType(), ((Object [])params[i])[0]); + TypeDescription in_sig[] = methodDescription.getInSignature(); + TypeDescription out_sig[] = methodDescription.getOutSignature(); + for(int i = 0; i < in_sig.length; ++ i) { + if(in_sig[i] != null) { // is it an in parameter? + if(out_sig[i] != null) // is it also an out parameter? + _marshal.writeObject(out_sig[i].getComponentType(), ((Object [])params[i])[0]); else // in only - _marshal.writeObject(mMDesc._in_sig[i], params[i]); + _marshal.writeObject(in_sig[i], params[i]); } } if(synchron[0].booleanValue()) // if we are waiting for a reply, the reply is pending - putPendingRequest(_out_threadId, new Object[]{params, mMDesc._out_sig, mMDesc._res}); + putPendingRequest(_out_threadId, new Object[]{params, out_sig, methodDescription.getReturnSig()}); } } @@ -475,16 +481,16 @@ public class urp extends Protocol { synchronized(_marshal) { Object objects[] = (Object[])removePendingReply(threadId); Object params[] = (Object[])objects[0]; - Class signature[] = (Class[])objects[1]; - Class resClass = (Class)objects[2]; + TypeDescription signature[] = (TypeDescription[])objects[1]; + TypeDescription resType = (TypeDescription)objects[2]; byte header = BIG_HEADER; // big header if(exception) { // has an exception occurred? header |= EXCEPTION; - signature = new Class[0]; - resClass = Any.class; + signature = __emptyTypeDescArray; + resType = TypeDescription.__any_TypeDescription; } if(_out_threadId == null || !_out_threadId.equals(threadId)) { // change thread id ? @@ -501,7 +507,7 @@ public class urp extends Protocol { _marshal.writeThreadID(threadId); // write the result - _marshal.writeObject(resClass, result); + _marshal.writeObject(resType, result); // write the out parameters for(int i = 0; i < signature.length; ++ i) @@ -536,7 +542,7 @@ public class urp extends Protocol { static class Message implements IMessage { String _oid; Object _result; - Class _interface; + TypeDescription _typeDescription; String _operation; ThreadID _threadId; boolean _synchron; @@ -545,7 +551,7 @@ public class urp extends Protocol { Message(String oid, Object result, - Class zInterface, + TypeDescription typeDescription, String operation, ThreadID threadId, boolean synchron, @@ -554,7 +560,7 @@ public class urp extends Protocol { { _oid = oid; _result = result; - _interface = zInterface; + _typeDescription = typeDescription; _operation = operation; _threadId = threadId; _synchron = synchron; @@ -570,8 +576,8 @@ public class urp extends Protocol { return _threadId; } - public Class getInterface() { - return _interface; + public TypeDescription getInterface() { + return _typeDescription; } public boolean isSynchron() { @@ -637,7 +643,7 @@ public class urp extends Protocol { else { // a request iMessage = new Message(_in_oid, null, - _in_interface.getDescription(), + _in_interface, operation[0], _in_threadId, synchron[0], |