diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2003-03-26 11:41:32 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2003-03-26 11:41:32 +0000 |
commit | 44bf5dacd75eec3d27acf9590a29ce49a3b585cf (patch) | |
tree | d4bf189a381cfc27c683a3f105927c66a63fa0e9 /jurt | |
parent | b7ea5b0ca567c0ce8272148244e4579dcec548a7 (diff) |
MWS_SRX644: migrate branch mws_srx644 -> HEAD
Diffstat (limited to 'jurt')
22 files changed, 1997 insertions, 504 deletions
diff --git a/jurt/com/sun/star/comp/loader/JavaLoader.java b/jurt/com/sun/star/comp/loader/JavaLoader.java index 1a23463c2cf7..18b7fed4db85 100644 --- a/jurt/com/sun/star/comp/loader/JavaLoader.java +++ b/jurt/com/sun/star/comp/loader/JavaLoader.java @@ -2,9 +2,9 @@ * * $RCSfile: JavaLoader.java,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: jl $ $Date: 2002-10-22 15:46:43 $ + * last change: $Author: hr $ $Date: 2003-03-26 12:32:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -106,7 +106,7 @@ import java.net.MalformedURLException; * service. Therefor the <code>JavaLoader</code> activates external UNO components which are implemented in Java. * The loader is used by the <code>ServiceManger</code>. * <p> - * @version $Revision: 1.10 $ $ $Date: 2002-10-22 15:46:43 $ + * @version $Revision: 1.11 $ $ $Date: 2003-03-26 12:32:54 $ * @author Markus Herzog * @see com.sun.star.loader.XImplementationLoader * @see com.sun.star.loader.Java @@ -222,7 +222,8 @@ public class JavaLoader implements XImplementationLoader, if (args.length == 0) throw new com.sun.star.lang.IllegalArgumentException("No arguments specified"); try { - multiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, args[0]); + multiServiceFactory = (XMultiServiceFactory) AnyConverter.toObject( + new Type(XMultiServiceFactory.class), args[0]); } catch (ClassCastException castEx) { throw new com.sun.star.lang.IllegalArgumentException( diff --git a/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java b/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java new file mode 100644 index 000000000000..d13d361a7e0c --- /dev/null +++ b/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java @@ -0,0 +1,300 @@ +/************************************************************************* + * + * $RCSfile: PipeConnection.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-26 12:32:55 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +package com.sun.star.lib.connections.pipe; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; + +import java.util.StringTokenizer; +import java.util.Enumeration; +import java.util.Vector; + + +import com.sun.star.io.XStreamListener; + +import com.sun.star.connection.XConnection; +import com.sun.star.connection.XConnectionBroadcaster; + +/** + * The PipeConnection implements the <code>XConnection</code> interface + * and is uses by the <code>PipeConnector</code> and the <code>PipeAcceptor</code>. + * This class is not part of the provided <code>api</code>. + * <p> + * @version $Revision: 1.2 $ $ $Date: 2003-03-26 12:32:55 $ + * @author Kay Ramme + * @see com.sun.star.comp.connections.PipeAcceptor + * @see com.sun.star.comp.connections.PipeConnector + * @see com.sun.star.connections.XConnection + * @since UDK1.0 + */ +public class PipeConnection implements XConnection, XConnectionBroadcaster { + /** + * When set to true, enables various debugging output. + */ + static public final boolean DEBUG = false; + static private final String PIPE_LIB_NAME = "jpipe"; + + static + { + + // determine name of executable soffice + String aExec = "soffice"; // default for UNIX + String aOS = System.getProperty("os.name"); + + // running on Windows? + if (aOS.startsWith("Windows")) + aExec = "soffice.exe"; + + // add other non-UNIX operating systems here + + // find soffice executable via CLASSPATH: + // <INSTDIR>/program/classes/*.jar => <INSTDIR>/program/soffice + String mProgramPath = null; + String aClassPath = System.getProperty("java.class.path" ); + java.util.StringTokenizer aTokenizer = new java.util.StringTokenizer( + aClassPath, java.io.File.pathSeparator ); + while ( mProgramPath == null && aTokenizer.hasMoreTokens() ) + { + java.io.File aJAR = new java.io.File( aTokenizer.nextToken() ).getAbsoluteFile(); + String aPath = aJAR.getParentFile().getParent(); + java.io.File aProgFile = new java.io.File( + aPath + java.io.File.separator + aExec ); + if ( aProgFile.exists() ) + mProgramPath = aProgFile.getParent(); + + } + + // load libofficebean.so/officebean.dll + System.load( mProgramPath + java.io.File.separator + + System.mapLibraryName(PIPE_LIB_NAME) ); + } + + protected String _aDescription; + protected long _nPipeHandle; + protected Vector _aListeners; + protected boolean _bFirstRead; + + /** + * Constructs a new <code>PipeConnection</code>. + * <p> + * @param description the description of the connection + * @param pipe the pipe of the connection + */ + public PipeConnection(String description) + throws IOException + { + if (DEBUG) System.err.println("##### " + getClass().getName() + " - instantiated " + description ); + + _aListeners = new Vector(); + _bFirstRead = true; + + // get pipe name from pipe descriptor + String aPipeName = null; + StringTokenizer aTokenizer = new StringTokenizer( description, "," ); + if ( aTokenizer.hasMoreTokens() ) + { + String aConnType = aTokenizer.nextToken(); + if ( !aConnType.equals( "pipe" ) ) + throw new RuntimeException( "invalid pipe descriptor: does not start with 'pipe,'" ); + + String aPipeNameParam = aTokenizer.nextToken(); + if ( !aPipeNameParam.substring( 0, 5 ).equals( "name=" ) ) + throw new RuntimeException( "invalid pipe descriptor: no 'name=' parameter found" ); + aPipeName = aPipeNameParam.substring( 5 ); + } + else + throw new RuntimeException( "invalid or empty pipe descriptor" ); + + // create the pipe + try + { createJNI( aPipeName ); } + catch ( java.lang.NullPointerException aNPE ) + { throw new IOException( aNPE.getMessage() ); } + catch ( com.sun.star.io.IOException aIOE ) + { throw new IOException( aIOE.getMessage() ); } + catch ( java.lang.Exception aE ) + { throw new IOException( aE.getMessage() ); } + } + + public void addStreamListener(XStreamListener aListener ) throws com.sun.star.uno.RuntimeException { + _aListeners.addElement(aListener); + } + + public void removeStreamListener(XStreamListener aListener ) throws com.sun.star.uno.RuntimeException { + _aListeners.removeElement(aListener); + } + + private void notifyListeners_open() { + Enumeration elements = _aListeners.elements(); + while(elements.hasMoreElements()) { + XStreamListener xStreamListener = (XStreamListener)elements.nextElement(); + xStreamListener.started(); + } + } + + private void notifyListeners_close() { + Enumeration elements = _aListeners.elements(); + while(elements.hasMoreElements()) { + XStreamListener xStreamListener = (XStreamListener)elements.nextElement(); + xStreamListener.closed(); + } + } + + private void notifyListeners_error(com.sun.star.uno.Exception exception) { + Enumeration elements = _aListeners.elements(); + while(elements.hasMoreElements()) { + XStreamListener xStreamListener = (XStreamListener)elements.nextElement(); + xStreamListener.error(exception); + } + } + + // JNI implementation to create the pipe + private native int createJNI( String name ) + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException; + + // JNI implementation to read from the pipe + private native int readJNI(/*OUT*/byte[][] bytes, int nBytesToRead) + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException; + + // JNI implementation to write to the pipe + private native void writeJNI(byte aData[]) + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException; + + // JNI implementation to flush the pipe + private native void flushJNI() + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException; + + // JNI implementation to close the pipe + private native void closeJNI() + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException; + + /** + * Read the required number of bytes. + * <p> + * @return the number of bytes read + * @param aReadBytes the outparameter, where the bytes have to be placed + * @param nBytesToRead the number of bytes to read + * @see com.sun.star.connections.XConnection#read + */ + public int read(/*OUT*/byte[][] bytes, int nBytesToRead) + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException + { + if(_bFirstRead) { + _bFirstRead = false; + + notifyListeners_open(); + } + + return readJNI( bytes, nBytesToRead ); + } + + /** + * Write bytes. + * <p> + * @param aData the bytes to write + * @see com.sun.star.connections.XConnection#write + */ + public void write(byte aData[]) + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException + { + writeJNI( aData ); + } + + /** + * Flushes the buffer. + * <p> + * @see com.sun.star.connections.XConnection#flush + */ + public void flush() + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException + { + flushJNI(); + } + + /** + * Closes the connection. + * <p> + * @see com.sun.star.connections.XConnection#close + */ + public void close() + throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException + { + if (DEBUG) System.out.print( "PipeConnection::close() " ); + closeJNI(); + notifyListeners_close(); + if (DEBUG) System.out.println( "done" ); + } + + /** + * Gives a description of the connection. + * <p> + * @return the description + * @see com.sun.star.connections.XConnection#getDescription + */ + public String getDescription() throws com.sun.star.uno.RuntimeException { + return _aDescription; + } + +} + diff --git a/jurt/com/sun/star/lib/connections/pipe/makefile.mk b/jurt/com/sun/star/lib/connections/pipe/makefile.mk new file mode 100644 index 000000000000..b11ef455a83e --- /dev/null +++ b/jurt/com/sun/star/lib/connections/pipe/makefile.mk @@ -0,0 +1,77 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: hr $ $Date: 2003-03-26 12:32:55 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +#************************************************************************* + +PRJ = ..$/..$/..$/..$/..$/.. +PRJNAME = jurt +TARGET = com_sun_star_connections_pipe + +PACKAGE = com$/sun$/star$/lib$/connections$/pipe + +.INCLUDE: $(PRJ)$/util$/makefile.pmk + +JAVAFILES = $(subst,$(CLASSDIR)$/$(PACKAGE)$/, $(subst,.class,.java $(JAVACLASSFILES))) + +JAVACLASSFILES = \ + $(CLASSDIR)$/$(PACKAGE)$/PipeConnection.class \ + $(CLASSDIR)$/$(PACKAGE)$/pipeAcceptor.class \ + $(CLASSDIR)$/$(PACKAGE)$/pipeConnector.class + +.INCLUDE: target.mk diff --git a/jurt/com/sun/star/lib/connections/pipe/pipeAcceptor.java b/jurt/com/sun/star/lib/connections/pipe/pipeAcceptor.java new file mode 100644 index 000000000000..d99f5a1852b8 --- /dev/null +++ b/jurt/com/sun/star/lib/connections/pipe/pipeAcceptor.java @@ -0,0 +1,182 @@ +/************************************************************************* + * + * $RCSfile: pipeAcceptor.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-26 12:32:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.connections.pipe; + +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.connection.AlreadyAcceptingException; +import com.sun.star.connection.ConnectionSetupException; +import com.sun.star.connection.XAcceptor; +import com.sun.star.connection.XConnection; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.registry.XRegistryKey; +import java.io.IOException; +import java.net.InetAddress; + +/** + * A component that implements the <code>XAcceptor</code> interface. + * + * <p>The <code>pipeAcceptor</code> is a specialized component that uses TCP + * pipes for communication. The <code>pipeAcceptor</code> is generally used + * by the <code>com.sun.star.connection.Acceptor</code> service.</p> + * + * @see com.sun.star.connections.XAcceptor + * @see com.sun.star.connections.XConnection + * @see com.sun.star.connections.XConnector + * @see com.sun.star.loader.JavaLoader + * + * @since UDK 1.0 + */ +public final class pipeAcceptor implements XAcceptor { + /** + * The name of the service. + * + * <p>The <code>JavaLoader</code> acceses this through reflection.</p> + * + * @see com.sun.star.comp.loader.JavaLoader + */ + public static final String __serviceName + = "com.sun.star.connection.pipeAcceptor"; + + /** + * Returns a factory for creating the service. + * + * <p>This method is called by the <code>JavaLoader</code>.</p> + * + * @param implName the name of the implementation for which a service is + * requested. + * @param multiFactory the service manager to be used (if needed). + * @param regKey the registry key. + * @return an <code>XSingleServiceFactory</code> for creating the component. + * + * @see com.sun.star.comp.loader.JavaLoader + */ + public static XSingleServiceFactory __getServiceFactory( + String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey) + { + return implName.equals(pipeAcceptor.class.getName()) + ? FactoryHelper.getServiceFactory( + pipeAcceptor.class, __serviceName, multiFactory, regKey) + : null; + } + + /** + * Writes the service information into the given registry key. + * + * <p>This method is called by the <code>JavaLoader</code>.</p> + * + * @param regKey the registry key. + * @return <code>true</code> if the operation succeeded. + * + * @see com.sun.star.comp.loader.JavaLoader + */ + public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { + return FactoryHelper.writeRegistryServiceInfo( + pipeAcceptor.class.getName(), __serviceName, regKey); + } + + /** + * Accepts a connection request via the described pipe. + * + * <p>This call blocks until a connection has been established.</p> + * + * <p>The connection description has the following format: + * <code><var>type</var></code><!-- + * -->*(<code><var>key</var>=<var>value</var></code>), + * where <code><var>type</var></code> should be <code>pipe</code> + * (ignoring case). Supported keys (ignoring case) currently are + * <dl> + * <dt><code>host</code> + * <dd>The name or address of the accepting interface (defaults to + * <code>0</code>, meaning any interface). + * <dt><code>port</code> + * <dd>The TCP port number to accept on (defaults to <code>6001</code>). + * <dt><code>backlog</code> + * <dd>The maximum length of the acceptor's queue (defaults to + * <code>50</code>). + * <dt><code>tcpnodelay</code> + * <dd>A flag (<code>0</code>/<code>1</code>) enabling or disabling Nagle's + * algorithm on the resulting connection. + * </dl></p> + * + * @param connectionDescription the description of the connection. + * @return an <code>XConnection</code> to the client. + * + * @see com.sun.star.connections.XConnection + * @see com.sun.star.connections.XConnector + */ + public XConnection accept(String connectionDescription) throws + AlreadyAcceptingException, ConnectionSetupException, + com.sun.star.lang.IllegalArgumentException + { + throw new java.lang.NoSuchMethodError( "pipeAcceptor not fully implemented yet" ); + + //try { return new PipeConnection( connectionDescription ); } + //catch ( java.io.IOException e ) { return null; } + } + + // see com.sun.star.connection.XAcceptor#stopAccepting + public void stopAccepting() { + } + + private static final boolean DEBUG = false; +} diff --git a/jurt/com/sun/star/lib/connections/pipe/pipeConnector.java b/jurt/com/sun/star/lib/connections/pipe/pipeConnector.java new file mode 100644 index 000000000000..8fc988f10acb --- /dev/null +++ b/jurt/com/sun/star/lib/connections/pipe/pipeConnector.java @@ -0,0 +1,179 @@ +/************************************************************************* + * + * $RCSfile: pipeConnector.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-26 12:32:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.connections.pipe; + +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.connection.ConnectionSetupException; +import com.sun.star.connection.NoConnectException; +import com.sun.star.connection.XConnection; +import com.sun.star.connection.XConnector; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.registry.XRegistryKey; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * A component that implements the <code>XConnector</code> interface. + * + * <p>The <code>pipeConnector</code> is a specialized component that uses TCP + * pipes for communication. The <code>pipeConnector</code> is generally + * used by the <code>com.sun.star.connection.Connector</code> service.</p> + * + * @see com.sun.star.connections.XAcceptor + * @see com.sun.star.connections.XConnection + * @see com.sun.star.connections.XConnector + * @see com.sun.star.loader.JavaLoader + * + * @since UDK 1.0 + */ +public final class pipeConnector implements XConnector { + /** + * The name of the service. + * + * <p>The <code>JavaLoader</code> acceses this through reflection.</p> + * + * @see com.sun.star.comp.loader.JavaLoader + */ + public static final String __serviceName = "com.sun.star.connection.pipeConnector"; + + /** + * Returns a factory for creating the service. + * + * <p>This method is called by the <code>JavaLoader</code>.</p> + * + * @param implName the name of the implementation for which a service is + * requested. + * @param multiFactory the service manager to be used (if needed). + * @param regKey the registry key. + * @return an <code>XSingleServiceFactory</code> for creating the component. + * + * @see com.sun.star.comp.loader.JavaLoader + */ + public static XSingleServiceFactory __getServiceFactory( + String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey) + { + return implName.equals(pipeConnector.class.getName()) + ? FactoryHelper.getServiceFactory(pipeConnector.class, + __serviceName, multiFactory, + regKey) + : null; + } + + /** + * Writes the service information into the given registry key. + * + * <p>This method is called by the <code>JavaLoader</code>.</p> + * + * @param regKey the registry key. + * @return <code>true</code> if the operation succeeded. + * + * @see com.sun.star.comp.loader.JavaLoader + */ + public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { + return FactoryHelper.writeRegistryServiceInfo( + pipeConnector.class.getName(), __serviceName, regKey); + } + + /** + * Connects via the described pipe to a waiting server. + * + * <p>The connection description has the following format: + * <code><var>type</var></code><!-- + * -->*(<code><var>key</var>=<var>value</var></code>), + * where <code><var>type</var></code> should be <code>pipe</code> + * (ignoring case). Supported keys (ignoring case) currently are + * <dl> + * <dt><code>host</code> + * <dd>The name or address of the server. Must be present. + * <dt><code>port</code> + * <dd>The TCP port number of the server (defaults to <code>6001</code>). + * <dt><code>tcpnodelay</code> + * <dd>A flag (<code>0</code>/<code>1</code>) enabling or disabling Nagle's + * algorithm on the resulting connection. + * </dl></p> + * + * @param connectionDescription the description of the connection. + * @return an <code>XConnection</code> to the server. + * + * @see com.sun.star.connections.XAcceptor + * @see com.sun.star.connections.XConnection + */ + public synchronized XConnection connect(String connectionDescription) + throws NoConnectException, ConnectionSetupException + { + if (bConnected) { + throw new ConnectionSetupException("alread connected"); + } + + try + { + XConnection xConn = new PipeConnection( connectionDescription ); + bConnected = true; + return xConn; + } + catch ( java.io.IOException e ) { throw new NoConnectException(); } + } + + private boolean bConnected = false; +} diff --git a/jurt/com/sun/star/lib/uno/Proxy.java b/jurt/com/sun/star/lib/uno/Proxy.java new file mode 100644 index 000000000000..99cb12a87681 --- /dev/null +++ b/jurt/com/sun/star/lib/uno/Proxy.java @@ -0,0 +1,74 @@ +/************************************************************************* + * + * $RCSfile: Proxy.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-26 12:32:57 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.uno; + +/** + * Marker interface implemented by proxies for UNO objects. + * + * <p>Currently, this interface is used internally by + * <code>com.sun.star.lib.uno.environments.java.java_environment</code> to + * distinguish between proxies and local objects. Any proxy object that shall + * be registered at the <code>java_environment</code> must implement this marker + * interface.</p> + */ +public interface Proxy { +} 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 70290c95bf2a..37c0de4b7d1a 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.27 $ + * $Revision: 1.28 $ * - * last change: $Author: sb $ $Date: 2002-10-30 15:29:36 $ + * last change: $Author: hr $ $Date: 2003-03-26 12:32:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -123,6 +123,8 @@ import com.sun.star.uno.IEnvironment; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.uno.Type; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.Any; /** * This class implements a remote bridge. Therefor @@ -131,7 +133,7 @@ import com.sun.star.uno.Type; * 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.27 $ $ $Date: 2002-10-30 15:29:36 $ + * @version $Revision: 1.28 $ $ $Date: 2003-03-26 12:32:59 $ * @author Kay Ramme * @see com.sun.star.lib.uno.environments.remote.IProtocol * @since UDK1.0 @@ -571,9 +573,8 @@ 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, type); - if(!(xobject instanceof com.sun.star.lib.uno.environments.java.java_environment.HolderProxy)) - addRefHolder(type, oid[0]); + _java_environment.registerInterface(object, oid, type); + addRefHolder(type, oid[0]); } if(DEBUG) System.err.println("##### " + getClass() + " - mapInterfaceTo:" + object + " interface:" + type + " " + oid[0]); @@ -853,6 +854,9 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid dispose(e); throw new DisposedException(getClass().getName() + ".sendReply - unexpected: " + e); + } catch (Error e) { + dispose(e); + throw e; } } @@ -910,6 +914,19 @@ public class java_remote_bridge implements IBridge, IReceiver, IRequester, XBrid if(DEBUG) System.err.println("##### " + getClass().getName() + ".sendRequest left:" + result); + // On the wire (at least in URP), the result of queryInterface is + // transported as an ANY, but in Java it shall be transported as a + // direct reference to the UNO object (represented as a Java Object), + // never boxed in a com.sun.star.uno.Any: + if (operation.equals("queryInterface") && result instanceof Any) { + Any a = (Any) result; + if (a.getType().getTypeClass() == TypeClass.INTERFACE) { + result = a.getObject(); + } else { + result = null; // should never happen + } + } + return result; } 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 45eb9aed7dac..2a9f46665860 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.10 $ + * $Revision: 1.11 $ * - * last change: $Author: sb $ $Date: 2002-10-30 15:32:05 $ + * last change: $Author: hr $ $Date: 2003-03-26 12:33:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,390 +61,239 @@ package com.sun.star.lib.uno.environments.java; - -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import java.util.Hashtable; -import java.util.Enumeration; - - import com.sun.star.lib.sandbox.Disposable; - -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.TypedProxy; -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.Type; import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XInterface; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; +import java.util.HashMap; /** * The java_environment is the environment where objects and * interfaces are registered, which are mapped out of java or - * into java. The java_environment implements the <code>IEnvironment</code> - * interface defined in the uno runtime. - * <p> - * <p> - * @version $Revision: 1.10 $ $ $Date: 2002-10-30 15:32:05 $ - * @author Kay Ramme - * @see com.sun.star.uno.UnoRuntime - * @see com.sun.star.uno.IEnvironment - * @since UDK1.0 + * into java. + * + * <p>The java_environment implements the <code>IEnvironment</code> interface + * defined in the uno runtime.</p> + * + * @see com.sun.star.uno.UnoRuntime + * @see com.sun.star.uno.IEnvironment + * @since UDK1.0 */ -public class java_environment implements IEnvironment, Disposable { - /** - * When set to true, enables various debugging output. - */ - static public final boolean DEBUG = false; - final static String _holderProxyClassName = HolderProxy.class.getName().replace('.', '/'); - - /* - ** This is the holder proxy, which one gets while trying to get a registered object - */ - static public class HolderProxy extends DispatcherAdapterBase - implements Dispatcher, XInterface, IQueryInterface, TypedProxy - { - static private Hashtable __methodss = new Hashtable(); - - /** - * Gets the methods of a class as a hashtable. - * Uses reflection for first time and stores the methods - * array in hashtable for later use. - * <p> - * This method does not belong to the provided <code>api</code> - * <p> - * @return the methods - * @param zClass the class - * @see java.lang.Class#getMethods - */ - static public Hashtable __getMethodsAsTable(Class zClass) { - Hashtable methods_tab = (Hashtable)__methodss.get(zClass); - - if(methods_tab == null) { - methods_tab = new Hashtable(); - - Class [] interfaces = zClass.getInterfaces(); - for( int j = 0 ; j < interfaces.length ; j ++ ) - { - Method methods [] = interfaces[j].getMethods(); - for(int i = 0; i < methods.length; ++ i) { - methods_tab.put(methods[i].getName(), methods[i]); - } - } - - __methodss.put(zClass, methods_tab); - } - - return methods_tab; - } - - Holder _holder; - Type _type; - - Hashtable _methods; - - void setHolder(Holder holder) { - _holder = holder; - } - - public Object invoke(Object object, String name, Object params[]) throws Exception { - Method method = (Method)_methods.get(name); - - Object result = null; - - if(method == null) { - System.err.println(getClass().getName() + ".invoke - method not found:" + object + " " + name + " " + params); - } - else { - try { - result = method.invoke(object, params); - } - // don't hide exceptions - catch(InvocationTargetException invocationTargetException) { - throw (Exception)invocationTargetException.getTargetException(); - } - } - - return result; - } - - public HolderProxy() { - super(); - } - - public void setInterface(Type type) { - _type = type; - _methods = __getMethodsAsTable(object.getClass()); - } - - public Type getInterface() { - return _type; - } +public final class java_environment implements IEnvironment, Disposable { + public java_environment(Object context) { + this.context = context; + } - // IQueryInterface - delegate calls through this proxy - public Object queryInterface(Type type) { - return UnoRuntime.queryInterface(type, object); - } + // @see com.sun.star.uno.IEnvironment#getContext + public Object getContext() { + return context; + } - public boolean isSame(Object object) { - if (object instanceof HolderProxy) - object=((HolderProxy) object).object; + // @see com.sun.star.uno.IEnvironment#getName + public String getName() { + return "java"; + } - return UnoRuntime.areSame(this.object, object); + // @see com.sun.star.uno.IEnvironment#registerInterface + public Object registerInterface(Object object, String[] oid, Type type) { + if (oid[0] == null) { + oid[0] = UnoRuntime.generateOid(object); } + return (isProxy(object) ? proxies : localObjects).register( + object, createKey(oid[0], type)); + } - public String getOid() { - return UnoRuntime.generateOid(object); + /** + * You have to revoke ANY interface that has been registered via this + * method. + * + * @param oid object id of interface to be revoked + * @param type the type description of the interface + * @see com.sun.star.uno.IEnvironment#revokeInterface + */ + public void revokeInterface(String oid, Type type) { + String key = createKey(oid, type); + if (!proxies.revoke(key)) { + localObjects.revoke(key); } + } - // @see com.sun.star.lib.uno.TypedProxy#getType - public Type getType() { - return _type; + /** + * Retrieves an interface identified by its object id and type from this + * environment. + * + * @param oid object id of 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, Type type) { + String key = createKey(oid, type); + Object o = proxies.get(key); + if (o == null) { + o = localObjects.get(key); } + return o; + } - public void finalize() { - if(java_environment.DEBUG) System.err.println("###################### Proxy Proxy is dying"); - _holder.decRefCount(); - } + /** + * Retrieves the object identifier for a registered interface from this + * environment. + * + * @param object a registered interface + * @see com.sun.star.uno.IEnvironment#getRegisteredObjectIdentifier + */ + public String getRegisteredObjectIdentifier(Object object) { + return UnoRuntime.generateOid(object); } - /* - ** This is the holder class, whichs instances are put into the hashtable - */ - class Holder { + // @see com.sun.star.uno.IEnvironment#list + public void list() { +// TODO??? +// synchronized (proxies) { +// System.err.println("##### " + getClass().getName() + ".list: " +// + getName() + ", " + getContext()); +// for (Iterator it = proxies.values().iterator(); it.hasNext();) { +// System.err.println("#### entry: " + it.next()); +// } +// } + } - int _refCount; - String _oId; - Object _object; - Class _class; - boolean _instanceOfProxy; + // @see com.sun.star.uno.IEnvironment#dispose + public void dispose() { +// TODO??? +// synchronized (proxies) { +// if (!proxies.isEmpty()) { +// list(); +// } +// proxies.clear(); +// } + } - Holder(String oId, Object object , Type type) { - _oId = oId; - _object = object; - _refCount = 1; + // TODO What's this??? java.lang.Object#equals requires reflexivity... + // + // Maybe this was hacked in so that different bridges use different + // instances of java_environment. That is desirable for the following + // reason: An OID is bridged in over bridge A, a proxy is created on the + // Java side, and recorded in the java_environment. The same OID is then + // bridged in over another bridge B. If there were only one + // java_environment shared by both bridges, the proxy from bridge A would be + // reused. If now bridge A is taken down programatically (e.g., because + // some controlling code somehow deduced that no objects are mapped over + // that bridge any longer), but the proxy is still used by bridge B, using + // the proxy would now result in errors. The explicit API to control + // bridges forbids to transparently share proxies between bridges, and using + // different java_environment instances for different bridges is the way to + // enforce this. + public boolean equals(Object obj) { + return false; + } - com.sun.star.uno.ITypeDescription typedescr = type.getTypeDescription(); - // [HACK] workaround uninitialized Type object: - if (null == typedescr) - { - try - { - _class = Class.forName( type.getTypeName() ); - } - catch (ClassNotFoundException exc) - { + private static final class Registry { + public Object register(Object object, String key) { + synchronized (map) { + cleanUp(); + Entry e = (Entry) map.get(key); + if (e != null) { + Object o = e.get(); + if (o != null) { + e.acquire(); + return o; + } } + // TODO If a holder references an unreachable object, but still + // has a positive count, it is replaced with a new holder + // (referencing a reachable object, and with a count of 1). Any + // later calls to revoke that should decrement the count of the + // previous holder would now decrement the count of the new + // holder, removing it prematurely. This is a design flaw that + // will be fixed when IEnvironment.revokeInterface is changed to + // no longer use counting. (And this problem is harmless, as + // currently a holder either references a strongly held object + // and uses register/revoke to control it, or references a + // weakly held proxy and never revokes it.) + map.put(key, new Entry(key, object, queue)); } - else - { - _class = ((TypeDescription)type.getTypeDescription()).getZClass(); - } - _instanceOfProxy = (object instanceof Proxy); + return object; } - synchronized void incRefCount() { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".incRefCount:" + _refCount); - - ++ _refCount; + public boolean revoke(String key) { + synchronized (map) { + Entry e = (Entry) map.get(key); + if (e != null && e.release()) { + map.remove(key); + } + cleanUp(); + return e != null; + } } - synchronized void decRefCount() { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".decRefCount:" + _refCount); - - -- _refCount; - - if(_refCount == 0) - _objects.remove(_oId); + public Object get(String key) { + Entry e; + synchronized (map) { + e = (Entry) map.get(key); + } + return e == null ? null : e.get(); } - Object xxgetObject(Type type) - { - Object result = _object; - if( _instanceOfProxy ) { - if(DEBUG) System.err.println("##### " + getClass().getName() + " - creating new Proxy Proxy"); - Class holderProxyClass = - DispatcherAdapterFactory.createDispatcherAdapter( - _class, - _holderProxyClassName); - try { - HolderProxy holderProxy = (HolderProxy)holderProxyClass.newInstance(); - holderProxy.setObject(holderProxy, _object); - holderProxy.setHolder(this); - holderProxy.setInterface(type); - result = holderProxy; + // must only be called while synchronized on map: + private void cleanUp() { + for (;;) { + Entry e = (Entry) queue.poll(); + if (e == null) { + break; } - catch(Exception exception) { - System.err.println("##### " + getClass().getName() + ".xxgetObject - exception occurred:" + exception); - exception.printStackTrace(); - result = null; + // It is possible that an Entry e1 for key k becomes weakly + // reachable, then another Entry e2 is registered for the same + // key k (a new Entry is created since now e1.get() == null), + // and only then e1 is enqueued. To not erroneously remove the + // new e2 in that case, check whether the map still contains e1: + String key = e.getKey(); + if (map.get(key) == e) { + map.remove(key); } } - return result; } - public String toString() { - return "holder:" + _refCount + " " + _oId + " " + _object; - } - } - - protected Hashtable _objects; - protected String _name; - // free context pointer, that can be used for specific classes of environments, - protected Object _context; - - public java_environment(Object context) { - _name = "java"; - _context = context; - _objects = new Hashtable(); - - if(DEBUG) System.err.println("##### " + getClass().getName() + " - instantiated "); - } - - /** - * the context - */ - public Object getContext() { - return _context; - } - - /** - * a name for this environment - */ - public String getName() { - return _name; - } - - /** - * Tests if two environments are equal. - *<BR> - * @param environment one environment - */ - public boolean equals(Object object) { - return false; - } - - /** - * You register internal and external interfaces via this method. Internal interfaces are - * proxies that are used in an environment. External interfaces are interfaces that are - * exported to another environment, thus providing an object identifier for this task. - * This can be called an external reference. - * Interfaces are held weakly at an environment; they demand a final revokeInterface() - * call for each interface that has been registered. - * <p> - * @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 type the type description of the given interface - * @see com.sun.star.uno.IEnvironment#registerInterface - */ - public Object registerInterface(Object object, String oId[], Type type) { - if(oId[0] == null) - oId[0] = UnoRuntime.generateOid(object); - - String keyName = oId[0].concat( type.getTypeName()); + private static final class Entry extends WeakReference { + public Entry(String key, Object object, ReferenceQueue queue) { + super(object, queue); + this.key = key; + } - synchronized(_objects) { - // get the holder - Holder holder = (Holder)_objects.get(keyName); + // must only be called while synchronized on map: + public void acquire() { + ++count; + } - if(DEBUG) - System.err.println("##### " + getClass().getName() + ".registerInterface:" + object + " " + oId[0] + " " + type); + // must only be called while synchronized on map: + public boolean release() { + return --count == 0; + } - if(holder == null) { - holder = new Holder(keyName, object , type ); - _objects.put(keyName, holder); + public String getKey() { + return key; } - else - holder.incRefCount(); - object = holder.xxgetObject(type); + private final String key; + private int count = 1; } - return object; + private final HashMap map = new HashMap(); // from key (String) to Entry + private final ReferenceQueue queue = new ReferenceQueue(); } - /** - * You have to revoke ANY interface that has been registered via this method. - * <p> - * @param oId object id of interface to be revoked - * @param type the type description of the interface - * @see com.sun.star.uno.IEnvironment#revokeInterface - */ - public void revokeInterface(String oId, Type type) { - if(DEBUG) System.err.println("##### " + getClass().getName() + ".revokeInterface:" + oId + " " + type); - synchronized(_objects) { - Holder holder = (Holder)_objects.get(oId.concat( type.getTypeName())); - if(holder != null) - holder.decRefCount(); - else - System.err.println("java_environment.revokeInterface - unknown oid:" + oId + " " + type); - } + private String createKey(String oid, Type type) { + return oid.concat(type.getTypeName()); } - /** - * Retrieves an interface identified by its object id and type from this environment. - * <p> - * @param oId object id of 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, Type type) { - Object result = null; - - Holder holder = (Holder)_objects.get(oId.concat( type.getTypeName())); - - if(holder != null) { - result = holder.xxgetObject(type); - } - - if(DEBUG) System.err.println("##### " + getClass().getName() + ".getRegisteredInterface:>" + oId + "< " + type +" " + result); - - return result; + private boolean isProxy(Object object) { + return object instanceof com.sun.star.lib.uno.Proxy; } - /** - * Retrieves the object identifier for a registered interface from this environment. - * <p> - * @param object a registered interface - * @see com.sun.star.uno.IEnvironment#getRegisteredObjectIdentifier - */ - public String getRegisteredObjectIdentifier(Object object) { - return UnoRuntime.generateOid(object); - } - - /** - * List the registered interfaces. - * <p> - * @see com.sun.star.uno.IEnvironment#list - */ - public void list() { - System.err.println("##### " + getClass().getName() + ".list(" + getName() + " " + getContext() + "):"); - - Enumeration elements = _objects.elements(); - while(elements.hasMoreElements()) { - System.err.println("#### key:" + elements.nextElement()); - } - } - - /** - * Dispose this environment - * <p> - * @see com.sun.star.uno.IEnvironment#dispose - */ - public void dispose() { - if(_objects.size() > 0) - list(); - - _objects = new Hashtable(); - } + private static final Registry localObjects = new Registry(); + private final Object context; + private final Registry proxies = new Registry(); } - diff --git a/jurt/com/sun/star/lib/uno/makefile.mk b/jurt/com/sun/star/lib/uno/makefile.mk index 212921cdaeda..b1638bf7f21b 100644 --- a/jurt/com/sun/star/lib/uno/makefile.mk +++ b/jurt/com/sun/star/lib/uno/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: sb $ $Date: 2002-10-30 15:27:51 $ +# last change: $Author: hr $ $Date: 2003-03-26 12:32:58 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -67,6 +67,6 @@ PACKAGE = com$/sun$/star$/lib$/uno .INCLUDE: $(PRJ)$/util$/makefile.pmk JAVACLASSFILES = \ - $(CLASSDIR)$/$(PACKAGE)$/TypedProxy.class + $(CLASSDIR)$/$(PACKAGE)$/Proxy.class .INCLUDE: target.mk 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 75581f6b233a..d768b505d8d8 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.12 $ + * $Revision: 1.13 $ * - * last change: $Author: sb $ $Date: 2002-10-30 15:32:52 $ + * last change: $Author: hr $ $Date: 2003-03-26 12:33:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -382,9 +382,18 @@ class Marshal implements IMarshal { 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.SHORT_value: + case TypeClass.UNSIGNED_SHORT_value: + writeShort((Short) object); + break; + case TypeClass.LONG_value: + case TypeClass.UNSIGNED_LONG_value: + writeInteger((Integer) object); + break; + case TypeClass.HYPER_value: + case TypeClass.UNSIGNED_HYPER_value: + writeLong((Long) object); + break; 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 ? 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 f5d044af1e4b..044a3b5acbf1 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.10 $ + * $Revision: 1.11 $ * - * last change: $Author: sb $ $Date: 2002-10-30 15:32:52 $ + * last change: $Author: hr $ $Date: 2003-03-26 12:33:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -119,17 +119,64 @@ class Unmarshal implements IUnmarshal { } Object readAny() { - ITypeDescription iTypeDescription = readTypeDescription(); - Object object = readObject(iTypeDescription); - - // the object can only be null, if the return is an void-any or null interface - // cause java does not know a "void value", we create a special any - if(object == null && iTypeDescription.getZClass() == void.class) - object = new Any(new Type(iTypeDescription), null); - - if(DEBUG) System.err.println("##### " + getClass().getName() + ".readAny:" + object); - - return object; + ITypeDescription t = readTypeDescription(); + switch (t.getTypeClass().getValue()) { + case TypeClass.VOID_value: + return Any.VOID; + case TypeClass.CHAR_value: + return readCharacter(); + case TypeClass.BOOLEAN_value: + return readBoolean(); + case TypeClass.BYTE_value: + return readByte(); + case TypeClass.SHORT_value: + return readShort(); + case TypeClass.UNSIGNED_SHORT_value: + return new Any(Type.UNSIGNED_SHORT, readShort()); + case TypeClass.LONG_value: + return readInteger(); + case TypeClass.UNSIGNED_LONG_value: + return new Any(Type.UNSIGNED_LONG, readInteger()); + case TypeClass.HYPER_value: + return readLong(); + case TypeClass.UNSIGNED_HYPER_value: + return new Any(Type.UNSIGNED_HYPER, readLong()); + case TypeClass.FLOAT_value: + return readFloat(); + case TypeClass.DOUBLE_value: + return readDouble(); + case TypeClass.STRING_value: + return readString(); + case TypeClass.TYPE_value: + return new Type(readTypeDescription()); + case TypeClass.ENUM_value: + return readEnum(t); + case TypeClass.STRUCT_value: + return readStruct(t); + case TypeClass.EXCEPTION_value: + return readThrowable(t); + case TypeClass.SEQUENCE_value: + Object os = readSequence(t); + ITypeDescription tc = t.getComponentType(); + while (tc.getTypeClass() == TypeClass.SEQUENCE) { + tc = tc.getComponentType(); + } + switch (tc.getTypeClass().getValue()) { + case TypeClass.UNSIGNED_SHORT_value: + case TypeClass.UNSIGNED_LONG_value: + case TypeClass.UNSIGNED_HYPER_value: + return new Any(new Type(t), os); + default: + return os; + } + case TypeClass.INTERFACE_value: + Object oi = readReference(t); + return t.getZClass() == XInterface.class ? oi + : new Any(new Type(t), oi); + default: + throw new com.sun.star.uno.RuntimeException( + "Reading Any with bad type " + t.getTypeClass()); + } } boolean readboolean() { diff --git a/jurt/com/sun/star/uno/AnyConverter.java b/jurt/com/sun/star/uno/AnyConverter.java index 51af79904a72..1628d4b43c0d 100644 --- a/jurt/com/sun/star/uno/AnyConverter.java +++ b/jurt/com/sun/star/uno/AnyConverter.java @@ -9,12 +9,38 @@ import com.sun.star.lang.IllegalArgumentException; */ public class AnyConverter { + /** Determines the type of an any object. + + @param object any object + @return type object + */ + static public Type getType( Object object ) + { + Type t; + if (null == object) + { + t = m_XInterface_type; + } + else if (object instanceof Any) + { + t = ((Any)object).getType(); + // nested any + if (TypeClass.ANY_value == t.getTypeClass().getValue()) + return getType( ((Any)object).getObject() ); + } + else + { + t = new Type( object.getClass() ); + } + return t; + } + /** checks if the any contains the idl type <code>void</code>. @param object the object to check @return true when the any is void, false otherwise */ - static public boolean isVoid( Object object){ - return containsType( TypeClass.VOID, object); + static public boolean isVoid(Object object){ + return containsType(TypeClass.VOID, object); } /** checks if the any contains a value of the idl type <code>char</code>. @@ -22,7 +48,7 @@ public class AnyConverter @return true when the any contains a char, false otherwise. */ static public boolean isChar(Object object){ - return containsType( TypeClass.CHAR, object); + return containsType(TypeClass.CHAR, object); } /** checks if the any contains a value of the idl type <code>boolean</code>. @@ -30,7 +56,7 @@ public class AnyConverter @return true when the any contains a boolean, false otherwise. */ static public boolean isBoolean(Object object){ - return containsType( TypeClass.BOOLEAN, object); + return containsType(TypeClass.BOOLEAN, object); } /** checks if the any contains a value of the idl type <code>byte</code>. @@ -38,7 +64,7 @@ public class AnyConverter @return true when the any contains a byte, false otherwise. */ static public boolean isByte(Object object){ - return containsType( TypeClass.BYTE, object); + return containsType(TypeClass.BYTE, object); } /** checks if the any contains a value of the idl type <code>short</code>. @@ -46,7 +72,7 @@ public class AnyConverter @return true when the any contains a short, false otherwise. */ static public boolean isShort(Object object){ - return containsType( TypeClass.SHORT, object); + return containsType(TypeClass.SHORT, object); } /** checks if the any contains a value of the idl type <code>long</code> (which maps to a java-int). @@ -54,7 +80,7 @@ public class AnyConverter @return true when the any contains a int, false otherwise. */ static public boolean isInt(Object object){ - return containsType( TypeClass.LONG, object); + return containsType(TypeClass.LONG, object); } /** checks if the any contains a value of the idl type <code>hyper</code> (which maps to a java-long). @@ -62,7 +88,7 @@ public class AnyConverter @return true when the any contains a long, false otherwise. */ static public boolean isLong(Object object){ - return containsType( TypeClass.HYPER, object); + return containsType(TypeClass.HYPER, object); } /** checks if the any contains a value of the idl type <code>float</code>. @@ -70,7 +96,7 @@ public class AnyConverter @return true when the any contains a float, false otherwise. */ static public boolean isFloat(Object object){ - return containsType( TypeClass.FLOAT, object); + return containsType(TypeClass.FLOAT, object); } /** checks if the any contains a value of the idl type <code>double</code>. @@ -78,7 +104,7 @@ public class AnyConverter @return true when the any contains a double, false otherwise. */ static public boolean isDouble(Object object){ - return containsType( TypeClass.DOUBLE, object); + return containsType(TypeClass.DOUBLE, object); } /** checks if the any contains a value of the idl type <code>string</code>. @@ -86,50 +112,50 @@ public class AnyConverter @return true when the any contains a string, false otherwise. */ static public boolean isString(Object object){ - return containsType( TypeClass.STRING, object); + return containsType(TypeClass.STRING, object); } + /** checks if the any contains a value of the idl type <code>enum</code>. + @param object the object to check + @return true if the any contains an enum, false otherwise + */ + static public boolean isEnum(Object object) + { + return containsType(TypeClass.ENUM, object); + } /** checks if the any contains a value of the idl type <code>type</code>. @param object the object to check @return true when the any contains a type, false otherwise. */ static public boolean isType(Object object){ - return containsType( TypeClass.TYPE, object); + return containsType(TypeClass.TYPE, object); } - /** checks if the any contains a value which implements interfaces. - If <em>object</em> is an any with an interface type, then true is also returned if the any contains - a null reference. This is because interfacec are allowed to have a null value contrary - to other UNO types. + /** checks if the any contains an interface, struct, exception, sequence or enum. + If <em>object</em> is an any with an interface type, then true is also returned if + the any contains a null reference. This is because interfaces are allowed to have + a null value contrary to other UNO types. @param object the object to check - @return true when the any contains an object which implements interfaces, false otherwise. + @return true if the any contains an object */ - static public boolean isObject(Object object){ - boolean retVal= false; - if (object instanceof Any) - { - if( ((Any) object).getObject() == null ) - { - Type _t= ((Any) object).getType(); - if (_t.getTypeClass() == TypeClass.INTERFACE) - return true; - } - object= ((Any) object).getObject(); - - } - if (object != null && object.getClass().getInterfaces().length > 0) - retVal= true; - return retVal; + static public boolean isObject(Object object) + { + int tc = getType(object).getTypeClass().getValue(); + return (TypeClass.INTERFACE_value == tc || + TypeClass.STRUCT_value == tc || + TypeClass.EXCEPTION_value == tc || + TypeClass.SEQUENCE_value == tc || + TypeClass.ENUM_value == tc); } - /** checks if the any contains UNO idl sequence value ( meaning a java array + /** checks if the any contains UNO idl sequence value (meaning a java array containing elements which are values of UNO idl types). @param object the object to check @return true when the any contains an object which implements interfaces, false otherwise. */ - static public boolean isArray( Object object){ - return containsType( TypeClass.SEQUENCE, object); + static public boolean isArray(Object object){ + return containsType(TypeClass.SEQUENCE, object); } /** converts an Char object or an Any object containing a Char object into a simple char. @@ -138,8 +164,8 @@ public class AnyConverter @throws com.sun.star.lang.IllegalArgumentException in case no char is contained within object @see #isChar */ - static public char toChar(Object object) throws com.sun.star.lang.IllegalArgumentException{ - Character ret=(Character) convertSimple( TypeClass.CHAR, null, object); + static public char toChar(Object object) throws com.sun.star.lang.IllegalArgumentException{ + Character ret= (Character)convertSimple(TypeClass.CHAR, null, object); return ret.charValue(); } @@ -150,7 +176,7 @@ public class AnyConverter @see #isBoolean */ static public boolean toBoolean(Object object) throws com.sun.star.lang.IllegalArgumentException{ - Boolean ret= (Boolean) convertSimple( TypeClass.BOOLEAN, null, object); + Boolean ret= (Boolean)convertSimple(TypeClass.BOOLEAN, null, object); return ret.booleanValue(); } @@ -161,7 +187,7 @@ public class AnyConverter @see #isBoolean */ static public byte toByte(Object object) throws com.sun.star.lang.IllegalArgumentException{ - Byte ret= (Byte) convertSimple( TypeClass.BYTE, null, object); + Byte ret= (Byte)convertSimple(TypeClass.BYTE, null, object); return ret.byteValue(); } @@ -172,7 +198,20 @@ public class AnyConverter @return the short contained within the object */ static public short toShort(Object object) throws com.sun.star.lang.IllegalArgumentException{ - Short ret= (Short) convertSimple( TypeClass.SHORT, null, object); + Short ret= (Short)convertSimple(TypeClass.SHORT, null, object); + return ret.shortValue(); + } + /** converts a number object into an idl unsigned short and allows widening conversions. + Allowed argument types are Anies containing idl unsigned short values. + @param object the object to convert + @throws com.sun.star.lang.IllegalArgumentException + in case no idl unsigned short is contained within Any + @return an (unsigned) short + */ + static public short toUnsignedShort(Object object) + throws com.sun.star.lang.IllegalArgumentException + { + Short ret= (Short)convertSimple(TypeClass.UNSIGNED_SHORT, null, object); return ret.shortValue(); } @@ -186,6 +225,19 @@ public class AnyConverter Integer ret= (Integer) convertSimple( TypeClass.LONG, null, object); return ret.intValue(); } + /** converts a number object into an idl unsigned long and allows widening conversions. + Allowed argument types are Anies containing idl unsigned short or unsigned long values. + @param object the object to convert + @throws com.sun.star.lang.IllegalArgumentException + in case no idl unsigned short nor unsigned long is contained within Any + @return an (unsigned) int + */ + static public int toUnsignedInt(Object object) + throws com.sun.star.lang.IllegalArgumentException + { + Integer ret = (Integer)convertSimple(TypeClass.UNSIGNED_LONG, null, object); + return ret.intValue(); + } /** converts a number object into a simple long and allows widening conversions. Allowed argument types are Byte, Short, Integer, Long or Any containing these types. @@ -198,6 +250,21 @@ public class AnyConverter Long ret= (Long) convertSimple( TypeClass.HYPER, null, object); return ret.longValue(); } + /** converts a number object into an idl unsigned hyper and allows widening conversions. + Allowed argument types are Anies containing idl unsigned short, unsigned long or + unsigned hyper values. + @param object the object to convert + @throws com.sun.star.lang.IllegalArgumentException + in case no idl unsigned short, nor unsigned long nor unsigned hyper + is contained within object. + @return an (unsigned) long + */ + static public long toUnsignedLong(Object object) + throws com.sun.star.lang.IllegalArgumentException + { + Long ret = (Long)convertSimple(TypeClass.UNSIGNED_HYPER, null, object); + return ret.longValue(); + } /** converts a number object into a simple float and allows widening conversions. Allowed argument types are Byte, Short, Float or Any containing these types. @@ -241,21 +308,39 @@ public class AnyConverter return (Type) convertSimple( TypeClass.TYPE, null, object); } - /** converts a UNO object or an Any containing a UNO object into an UNO object of a specified type. - * The argument <em>object</em> is examined for implemented interfaces. If it has implemented interfaces - * then the method attempts to query for the interface specified by the <em>type</em> argument. That query - * (UnoRuntime.queryInterface) might return null, if the interface is not implemented. - * If <em>object</em> is an Any which contains an interface type and a null reference, - * then null is returned. + /** converts a UNO object (struct, exception, sequence, enum or interface) or an Any containing + * these types into an UNO object of a specified destination type. + * For interfaces, the argument <em>object</em> is queried for the interface specified + * by the <em>type</em> argument. That query (UnoRuntime.queryInterface) might return null, + * if the interface is not implemented or a null-ref or a VOID any is given. * - * @param type the Type of the returned value + * @param type type of the returned value * @param object the object that is to be converted - * @return the object contained within the object - * @throws com.sun.star.lang.IllegalArgumentException in case no UNO object is contained within object. + * @return destination object + * @throws com.sun.star.lang.IllegalArgumentException + * in case conversion is not possible */ static public Object toObject(Type type, Object object) - throws com.sun.star.lang.IllegalArgumentException{ - return convertSimple( TypeClass.INTERFACE, type, object); + throws com.sun.star.lang.IllegalArgumentException + { + return convertSimple( type.getTypeClass(), type, object ); + } + /** converts a UNO object (struct, exception, sequence, enum or interface) or an Any containing + * these types into an UNO object of a specified destination type. + * For interfaces, the argument <em>object</em> is queried for the interface specified + * by the <em>type</em> argument. That query (UnoRuntime.queryInterface) might return null, + * if the interface is not implemented or a null-ref or a VOID any is given. + * + * @param clazz class of the returned value + * @param object the object that is to be converted + * @return destination object + * @throws com.sun.star.lang.IllegalArgumentException + * in case conversion is not possible + */ + static public Object toObject(Class clazz, Object object) + throws com.sun.star.lang.IllegalArgumentException + { + return toObject( new Type( clazz ), object ); } /** converts an array or an any containing an array into an array. @@ -273,139 +358,196 @@ public class AnyConverter contained object is matched against the type. */ static private boolean containsType( TypeClass what, Object object){ - boolean retVal= false; - if (object instanceof Any) - object= ((Any) object).getObject(); - - Type _t= object == null ? new Type(void.class) : new Type( object.getClass()); - if (_t.getTypeClass().getValue() == what.getValue()) - retVal= true; - - return retVal; + return (getType(object).getTypeClass().getValue() == what.getValue()); } - static private Object convertSimple( TypeClass destTClass, Type destType, Object src) - throws com.sun.star.lang.IllegalArgumentException { - - Object _src= src; - int srcTypeValue=0; + static private final Type m_XInterface_type = new Type( XInterface.class ); - if (src instanceof Any) + static private Object convertSimple( TypeClass destTClass, Type destType, Object object_ ) + throws com.sun.star.lang.IllegalArgumentException + { + Object object; + Type type; + if (object_ instanceof Any) { - Any _a= (Any) src; - // If the any contains an Interface with a null reference then it is valid and - // null is returned - if ( _a.getObject() == null && _a.getType().getTypeClass() == TypeClass.INTERFACE) - return null; - _src= _a.getObject(); + // unbox + Any a = (Any)object_; + object = a.getObject(); + type = a.getType(); + // nested any + if (TypeClass.ANY_value == type.getTypeClass().getValue()) + return convertSimple( destTClass, destType, object ); } - - if (_src != null) + else { - Type srcType= new Type(_src.getClass()); + object = object_; + type = (null == object ? m_XInterface_type : new Type( object.getClass() )); + } - if( destTClass == TypeClass.INTERFACE) - { - if( _src.getClass().getInterfaces().length == 0) - throw new com.sun.star.lang.IllegalArgumentException( - "The argument does not implement interfaces"); - else - srcTypeValue= TypeClass.INTERFACE.getValue(); - } - else - srcTypeValue= new Type(_src.getClass()).getTypeClass().getValue(); + int tc = type.getTypeClass().getValue(); + int dest_tc = destTClass.getValue(); - switch( destTClass.getValue()) + if (null == object) + { + // special for interfaces + if (TypeClass.INTERFACE_value == tc && dest_tc == tc) + return null; + } + else + { + switch (dest_tc) { case TypeClass.CHAR_value: - if( srcTypeValue == TypeClass.CHAR_value) - return _src; + if (tc == TypeClass.CHAR_value) + return object; break; case TypeClass.BOOLEAN_value: - if( srcTypeValue == TypeClass.BOOLEAN_value) - return _src; + if (tc == TypeClass.BOOLEAN_value) + return object; break; case TypeClass.BYTE_value: - if( srcTypeValue == TypeClass.BYTE_value) - return _src; + if (tc == TypeClass.BYTE_value) + return object; break; case TypeClass.SHORT_value: - switch( srcTypeValue) + switch (tc) { case TypeClass.BYTE_value: - return new Short( ((Byte)_src).byteValue()); + return new Short( ((Byte)object).byteValue() ); case TypeClass.SHORT_value: - return _src; + return object; + } + break; + case TypeClass.UNSIGNED_SHORT_value: + switch (tc) + { + case TypeClass.UNSIGNED_SHORT_value: + return object; } break; case TypeClass.LONG_value: - switch( srcTypeValue) + switch (tc) { case TypeClass.BYTE_value: - return new Integer( ((Byte)_src).byteValue()); + return new Integer( ((Byte)object).byteValue() ); case TypeClass.SHORT_value: - return new Integer( ((Short)_src).shortValue()); + case TypeClass.UNSIGNED_SHORT_value: + return new Integer( ((Short)object).shortValue() ); case TypeClass.LONG_value: - return _src; + return object; + } + break; + case TypeClass.UNSIGNED_LONG_value: + switch (tc) + { + case TypeClass.UNSIGNED_SHORT_value: + return new Integer( ((Short)object).shortValue() ); + case TypeClass.UNSIGNED_LONG_value: + return object; } break; case TypeClass.HYPER_value: - switch( srcTypeValue) + switch (tc) { case TypeClass.BYTE_value: - return new Long( ((Byte)_src).byteValue()); + return new Long( ((Byte)object).byteValue() ); case TypeClass.SHORT_value: - return new Long( ((Short)_src).shortValue()); + case TypeClass.UNSIGNED_SHORT_value: + return new Long( ((Short)object).shortValue() ); case TypeClass.LONG_value: - return new Long( ((Integer)_src).intValue()); + case TypeClass.UNSIGNED_LONG_value: + return new Long( ((Integer)object).intValue() ); case TypeClass.HYPER_value: - return _src; + return object; + } + break; + case TypeClass.UNSIGNED_HYPER_value: + switch (tc) + { + case TypeClass.UNSIGNED_SHORT_value: + return new Long( ((Short)object).shortValue() ); + case TypeClass.UNSIGNED_LONG_value: + return new Long( ((Integer)object).intValue() ); + case TypeClass.UNSIGNED_HYPER_value: + return object; } break; case TypeClass.FLOAT_value: - switch( srcTypeValue) + switch (tc) { case TypeClass.BYTE_value: - return new Float( ((Byte)_src).byteValue()); + return new Float( ((Byte)object).byteValue() ); case TypeClass.SHORT_value: - return new Float( ((Short)_src).shortValue()); + return new Float( ((Short)object).shortValue() ); case TypeClass.FLOAT_value: - return _src; + return object; } break; case TypeClass.DOUBLE_value: - switch( srcTypeValue) + switch (tc) { case TypeClass.BYTE_value: - return new Double( ((Byte)_src).byteValue()); + return new Double( ((Byte)object).byteValue() ); case TypeClass.SHORT_value: - return new Double( ((Short)_src).shortValue()); + return new Double( ((Short)object).shortValue() ); case TypeClass.LONG_value: - return new Double( ((Integer)_src).intValue()); + return new Double( ((Integer)object).intValue() ); case TypeClass.FLOAT_value: - return new Double( ((Float)_src).floatValue()); + return new Double( ((Float)object).floatValue() ); case TypeClass.DOUBLE_value: - return _src; + return object; + } + break; + case TypeClass.ENUM_value: + if (tc == TypeClass.ENUM_value && + (null == destTClass || destType.equals( type ) /* optional destType */)) + { + return object; } break; case TypeClass.STRING_value: - if( srcTypeValue == TypeClass.STRING_value) - return _src; + if (tc == TypeClass.STRING_value) + return object; break; - case TypeClass.TYPE_value: - if( srcTypeValue == TypeClass.TYPE_value) - return _src; + if (tc == TypeClass.TYPE_value) + return object; break; case TypeClass.INTERFACE_value: - if( srcTypeValue == TypeClass.INTERFACE_value) - return UnoRuntime.queryInterface( destType, _src); + if (tc == TypeClass.INTERFACE_value) + return UnoRuntime.queryInterface( destType, object ); + break; + case TypeClass.STRUCT_value: + case TypeClass.EXCEPTION_value: + if (dest_tc == tc) + { + Class source_class = type.getZClass(); + if (null == source_class) + source_class = object.getClass(); + Class dest_class = destType.getZClass(); + if (null == dest_class) + { + try + { + dest_class = Class.forName( destType.getTypeName() ); + } + catch (ClassNotFoundException exc) + { + throw new com.sun.star.lang.IllegalArgumentException( + "The destination type (STRUCT, EXCEPTION) cannot be resolved!" ); + } + } + if (dest_class.isAssignableFrom( source_class )) + return object; + } break; case TypeClass.SEQUENCE_value: - if( srcTypeValue == TypeClass.SEQUENCE_value) - return _src; + if (tc == TypeClass.SEQUENCE_value && + (null == destType || destType.equals( type ) /* optional destType */)) + { + return object; + } break; - } } throw new com.sun.star.lang.IllegalArgumentException( diff --git a/jurt/prj/build.lst b/jurt/prj/build.lst index 7c0a2740917a..0d8e4a89b2af 100644 --- a/jurt/prj/build.lst +++ b/jurt/prj/build.lst @@ -10,9 +10,11 @@ ju jurt\com\sun\star\lib\uno\environments\remote nmake - all ju_env_remote ju_e ju jurt\com\sun\star\lib\uno\protocols\urp nmake - all ju_prot_urp ju_env_remote NULL ju jurt\com\sun\star\lib\uno\bridges\java_remote nmake - all ju_brid_jrm ju_co_loader ju_env_remote NULL ju jurt\com\sun\star\lib\connections\socket nmake - all ju_con_sock ju_co_loader NULL +ju jurt\com\sun\star\lib\connections\pipe nmake - all ju_con_pipe ju_co_loader NULL ju jurt\com\sun\star\comp\connections nmake - all ju_con ju_co_loader NULL ju jurt\com\sun\star\comp\servicemanager nmake - all ju_servman ju_co_loader NULL ju jurt\com\sun\star\comp\typedescriptionmanager nmake - all ju_typdesman ju_uno NULL ju jurt\com\sun\star\comp\urlresolver nmake - all ju_urlres ju_uno ju_co_loader NULL -ju jurt\util nmake - all ju_ut ju_brid_jrm ju_co_bfactr ju_con ju_con_sock ju_cssl_uno ju_env_java ju_prot_urp ju_servman ju_typdesman ju_urlres NULL +ju jurt\source\pipe nmake - all ju_src_pipe NULL +ju jurt\util nmake - all ju_ut ju_brid_jrm ju_co_bfactr ju_con ju_con_sock ju_con_pipe ju_cssl_uno ju_env_java ju_prot_urp ju_servman ju_typdesman ju_urlres ju_src_pipe NULL diff --git a/jurt/prj/d.lst b/jurt/prj/d.lst index 6658abcf919a..7c903e679eb7 100644 --- a/jurt/prj/d.lst +++ b/jurt/prj/d.lst @@ -1,4 +1,9 @@ ..\%__SRC%\class\jurt.jar %_DEST%\bin%_EXT%\jurt.jar +..\%__SRC%\bin\jpipe*.dll %_DEST%\bin%_EXT%\jpipe*.dll +..\%__SRC%\lib\libjpipe*.so %_DEST%\lib%_EXT%\libjpipe*.so +..\%__SRC%\lib\libjpipe*.dylib %_DEST%\lib%_EXT%\libjpipe*.dylib + +..\%__SRC%\bin\jurt_src.zip %COMMON_DEST%\bin%_EXT%\jurt_src.zip ..\%__SRC%\lib\lib*static*.dylib %_DEST%\lib%_EXT%\lib*static*.dylib ..\%__SRC%\misc\*staticdatamembers.cxx %_DEST%\inc%_EXT%\*staticdatamembers.cxx diff --git a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c new file mode 100644 index 000000000000..5b67da3b19da --- /dev/null +++ b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c @@ -0,0 +1,432 @@ +/************************************************************************* + * + * $RCSfile: com_sun_star_lib_connections_pipe_PipeConnection.c,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-26 12:33:03 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#include <osl/pipe.h> + +#include "com_sun_star_lib_connections_pipe_PipeConnection.h" + +/*****************************************************************************/ +/* exception macros */ + +#define Throw_IfException(env) { \ + if ((*env)->ExceptionOccurred(env) != NULL) break; } + +#define ThrowException(env, type, msg) { \ + (*env)->ThrowNew(env, (*env)->FindClass(env, type), msg); } + +#define ThrowIO_If(cond, env, msg) { if (cond) \ + { ThrowException(env, "com/sun/star/io/IOException", msg); break; } } + +#define ThrowRT_If(cond, env, msg) { if (cond) \ + { ThrowException(env, "java/lang/RuntimeException", msg); break; } } + +/*****************************************************************************/ +/* helper functions prototypes */ + +static oslPipe getPipe(JNIEnv * env, jobject obj_this); +static rtl_uString * jstring2ustring(JNIEnv * env, jstring jstr); + +/*****************************************************************************/ +/* get pipe */ + +static oslPipe getPipe(JNIEnv * env, jobject obj_this) +{ + jclass tclass; + jfieldID fid; + while (1) + { + tclass = (*env)->GetObjectClass(env, obj_this); + ThrowRT_If((tclass == NULL), + env, "native pipe cannot find class"); + fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); + ThrowRT_If((fid == NULL), + env, "native pipe cannot find field"); + return ((oslPipe)((*env)->GetLongField(env, obj_this, fid))); + } + return NULL; +} + +/*****************************************************************************/ +/* convert jstring to rtl_uString */ + +static rtl_uString * jstring2ustring(JNIEnv * env, jstring jstr) +{ + const char * cstr; + rtl_uString * ustr = NULL; + cstr = (*env)->GetStringUTFChars(env, jstr, NULL); + rtl_uString_newFromAscii(&ustr, cstr); + (*env)->ReleaseStringUTFChars(env, jstr, cstr); + return ustr; +} + +/*****************************************************************************/ +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: connect + * Signature: (Lcom/sun/star/beans/NativeService;)V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI + (JNIEnv * env, jobject obj_this, jstring name) +{ + enum { + START = 0, + INMONITOR, + GOTNAME, + CREATED + }; + + short state = START; + + jclass tclass; + jfieldID fid; + + oslPipe npipe = NULL; + rtl_uString * pname = NULL; + while (1) + { + ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0), + env, "native pipe cannot synchronize on the object"); + state = INMONITOR; + + /* check connection state */ + npipe = getPipe(env, obj_this); + Throw_IfException(env); + ThrowIO_If((npipe != NULL), + env, "native pipe is already connected"); + + /* save the pipe name */ + tclass = (*env)->GetObjectClass(env, obj_this); + ThrowRT_If((tclass == NULL), + env, "native pipe cannot find class"); + fid = (*env)->GetFieldID(env, tclass, + "_aDescription", "Ljava/lang/String;"); + ThrowRT_If((fid == NULL), + env, "native pipe cannot find field"); + (*env)->SetObjectField(env, obj_this, fid, (jobject)name); + + /* convert pipe name to rtl_uString */ + pname = jstring2ustring(env, name); + ThrowRT_If((pname == NULL), + env, "native pipe cannot convert name"); + state = GOTNAME; + + /* try to connect */ + npipe = osl_createPipe(pname, osl_Pipe_OPEN, NULL); + ThrowRT_If((npipe == NULL), + env, "cannot create native pipe"); + state = CREATED; + + /* save the pipe */ + tclass = (*env)->GetObjectClass(env, obj_this); + ThrowRT_If((tclass == NULL), + env, "native pipe cannot find class"); + fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); + ThrowRT_If((fid == NULL), + env, "native pipe cannot find field"); + (*env)->SetLongField(env, obj_this, fid, (jlong)npipe); + + /* done */ + rtl_uString_release(pname); + (*env)->MonitorExit(env, obj_this); + return; + } + switch (state) + { + case CREATED: + osl_closePipe(npipe); + osl_releasePipe(npipe); + case GOTNAME: + rtl_uString_release(pname); + case INMONITOR: + (*env)->MonitorExit(env, obj_this); + case START: + default: + break; + } + return; +} + +/*****************************************************************************/ +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: closeJNI + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI + (JNIEnv * env, jobject obj_this) +{ + enum { + START = 0, + INMONITOR + }; + + short state = START; + oslPipe npipe; /* native pipe */ + jclass tclass; /* this class */ + jfieldID fid; /* a field identifier */ + + while (1) + { + ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0), + env, "native pipe cannot synchronize on the object"); + state = INMONITOR; + + /* check connection state */ + npipe = getPipe(env, obj_this); + Throw_IfException(env); + ThrowIO_If((npipe == NULL), + env, "native pipe is not connected"); + + /* remove the reference to the pipe */ + tclass = (*env)->GetObjectClass(env, obj_this); + ThrowRT_If((tclass == NULL), + env, "native pipe cannot find class"); + fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); + ThrowRT_If((fid == NULL), + env, "native pipe cannot find field"); + (*env)->SetLongField(env, obj_this, fid, (jlong)0); + + /* release the pipe */ + osl_closePipe(npipe); + osl_releasePipe(npipe); + + /* done */ + (*env)->MonitorExit(env, obj_this); + return; + } + switch (state) + { + case INMONITOR: + (*env)->MonitorExit(env, obj_this); + case START: + default: + break; + } + return; +} + +/*****************************************************************************/ +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: readJNI + * Signature: ([[BI)I + */ +JNIEXPORT jint JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI + (JNIEnv * env, jobject obj_this, jobjectArray buffer, jint len) +{ + enum { + START = 0, + INMONITOR, + AQUIRED, + GOTBUFFER + }; + + short state = START; + oslPipe npipe; /* native pipe */ + void * nbuff; /* native read buffer */ + jbyteArray bytes; /* java read buffer */ + jint nread; /* number of bytes has been read */ + + while (1) + { + /* enter monitor */ + ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0), + env, "native pipe cannot synchronize on the object"); + state = INMONITOR; + + /* check connection state */ + npipe = getPipe(env, obj_this); + Throw_IfException(env); + ThrowIO_If((npipe == NULL), + env, "native pipe is not connected"); + + /* aquire pipe */ + osl_acquirePipe( npipe ); + state = AQUIRED; + + /* allocate a buffer */ + ThrowRT_If(((nbuff = malloc(len)) == NULL), + env, "native pipe out of memory"); + state = GOTBUFFER; + + /* exit monitor */ + (*env)->MonitorExit(env, obj_this); + + /* reading */ + nread = osl_readPipe(npipe, nbuff, len); + + /* enter monitor again */ + ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0), + env, "native pipe cannot synchronize on the object"); + + /* copy buffer */ + if (nread >= 0) + { + bytes = (*env)->NewByteArray(env, len); + ThrowRT_If((bytes == NULL), + env, "native pipe out of memory"); + /* save the data */ + (*env)->SetByteArrayRegion(env, bytes, 0, len, nbuff); + (*env)->SetObjectArrayElement(env, buffer, 0, bytes); + (*env)->DeleteLocalRef(env, bytes); + } + + /* done */ + free(nbuff); + if ( state >= AQUIRED ) + osl_releasePipe( npipe ); + + /* exit monitor */ + (*env)->MonitorExit(env, obj_this); + return nread; + } + switch (state) + { + case GOTBUFFER: + free(nbuff); + case INMONITOR: + (*env)->MonitorExit(env, obj_this); + case START: + default: + break; + } + return -1; +} + +/*****************************************************************************/ +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: writeJNI + * Signature: ([B)V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI + (JNIEnv * env, jobject obj_this, jbyteArray buffer) +{ + enum { + START = 0, + INMONITOR, + GOTBUFFER + }; + + short state = START; + oslPipe npipe; /* native pipe */ + long count; /* number of bytes has been written */ + jsize nwrite; /* number of bytes to write */ + jbyte * nbuff; /* native buffer */ + + while (1) + { + ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0), + env, "native pipe cannot synchronize on the object"); + state = INMONITOR; + /* check connection state */ + npipe = getPipe(env, obj_this); + Throw_IfException(env); + ThrowIO_If((npipe == NULL), + env, "native pipe is not connected"); + nwrite = (*env)->GetArrayLength(env, buffer); + if (nwrite > 0) + { + nbuff = (*env)->GetByteArrayElements(env, buffer, NULL); + ThrowRT_If((nbuff == NULL), + env, "native pipe out of memory"); + state = GOTBUFFER; + (*env)->MonitorExit(env, obj_this); + /* writing */ + count = osl_writePipe(npipe, nbuff, nwrite); + ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0), + env, "native pipe cannot synchronize on the object"); + ThrowIO_If((count != nwrite), + env, "native pipe is failed to write"); + } + /* done */ + (*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT); + (*env)->MonitorExit(env, obj_this); + return; + } + switch (state) + { + case GOTBUFFER: + (*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT); + case INMONITOR: + (*env)->MonitorExit(env, obj_this); + case START: + default: + break; + } + return; +} + +/*****************************************************************************/ +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: flushJNI + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI + (JNIEnv * env, jobject obj_this) +{ + return; +} diff --git a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.h b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.h new file mode 100644 index 000000000000..a21e8f979348 --- /dev/null +++ b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.h @@ -0,0 +1,53 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class com_sun_star_connections_pipe_PipeConnection */ + +#ifndef _Included_com_sun_star_lib_connections_pipe_PipeConnection_h +#define _Included_com_sun_star_lib_connections_pipe_PipeConnection_h +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: connect + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI + (JNIEnv *, jobject, jstring); + +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: readJNI + * Signature: ([[BI)I + */ +JNIEXPORT jint JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI + (JNIEnv *, jobject, jobjectArray, jint); + +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: writeJNI + * Signature: ([B)V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI + (JNIEnv *, jobject, jbyteArray); + +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: flushJNI + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI + (JNIEnv *, jobject); + +/* + * Class: com_sun_star_lib_connections_pipe_PipeConnection + * Method: closeJNI + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/jurt/source/pipe/jpipe.dxp b/jurt/source/pipe/jpipe.dxp new file mode 100644 index 000000000000..e07ea907470f --- /dev/null +++ b/jurt/source/pipe/jpipe.dxp @@ -0,0 +1,5 @@ +Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI +Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI +Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI +Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI +Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI diff --git a/jurt/source/pipe/makefile.mk b/jurt/source/pipe/makefile.mk new file mode 100644 index 000000000000..b0f0b9588e8c --- /dev/null +++ b/jurt/source/pipe/makefile.mk @@ -0,0 +1,35 @@ +PRJ=..$/.. + +PRJNAME=jurt +TARGET=jpipe +ENABLE_EXCEPTIONS=TRUE + +#? +NO_DEFAULT_STL=TRUE +NO_BSYMBOLIC=TRUE +USE_DEFFILE=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/com_sun_star_lib_connections_pipe_PipeConnection.obj + +SHL1TARGET=$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1STDLIBS=$(SALLIB) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=$(TARGET).dxp +DEF1DES=jurtpipe + +NO_SHL1DESCRIPTION=TRUE + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/jurt/test/com/sun/star/uno/AnyConverter_Test.java b/jurt/test/com/sun/star/uno/AnyConverter_Test.java index 9577f55409ce..1d7af642b5cb 100644 --- a/jurt/test/com/sun/star/uno/AnyConverter_Test.java +++ b/jurt/test/com/sun/star/uno/AnyConverter_Test.java @@ -43,7 +43,7 @@ public class AnyConverter_Test anyLong= new Any(new Type(Long.TYPE), aLong); anyFloat= new Any(new Type(Float.TYPE), aFloat); anyDouble= new Any(new Type(Double.TYPE), aDouble); - anyObj= new Any(new Type(Object.class), aObj); + anyObj= new Any(new Type(Object.class) /* any */, aObj); anyStr= new Any(new Type(String.class), aStr); anyType= new Any(new Type(Type.class), aType); anyArByte= new Any(new Type(byte[].class), arByte); @@ -236,6 +236,12 @@ public class AnyConverter_Test r[i++]= sh == ((Byte)anyByte.getObject()).byteValue() ? true : false; sh= AnyConverter.toShort(anyShort); r[i++]= sh == ((Short) anyShort.getObject()).shortValue() ? true : false; + + Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) ); + r[i++]= (5 == AnyConverter.toUnsignedShort( a )); + try { AnyConverter.toShort(a); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + try { AnyConverter.toUnsignedShort(anyShort); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + // must fail with a com.sun.star.lang.IllegalArgumentException try { AnyConverter.toChar(aBool); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} try { AnyConverter.toChar(anyBool); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} @@ -301,6 +307,16 @@ public class AnyConverter_Test r[i++]= val == ((Short) anyShort.getObject()).shortValue() ? true : false; val= AnyConverter.toInt(anyInt); r[i++]= val == ((Integer) anyInt.getObject()).intValue() ? true : false; + + Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) ); + r[i++]= (5 == AnyConverter.toInt(a)); + r[i++]= (5 == AnyConverter.toUnsignedInt(a)); + try { AnyConverter.toUnsignedInt(anyInt); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + a = new Any( Type.UNSIGNED_LONG, new Integer(5) ); + r[i++]= (5 == AnyConverter.toUnsignedInt(a)); + try { AnyConverter.toInt(a); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + try { AnyConverter.toUnsignedInt(anyShort); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + // must fail with a com.sun.star.lang.IllegalArgumentException try { AnyConverter.toInt(aChar); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} try { AnyConverter.toInt(anyChar); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} @@ -366,6 +382,20 @@ public class AnyConverter_Test r[i++]= val == ((Integer) anyInt.getObject()).intValue() ? true : false; val= AnyConverter.toLong(anyLong); r[i++]= val == ((Long) anyLong.getObject()).longValue() ? true : false; + + Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) ); + r[i++]= (5 == AnyConverter.toLong(a)); + r[i++]= (5 == AnyConverter.toUnsignedLong(a)); + try { AnyConverter.toUnsignedLong(anyShort); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + a = new Any( Type.UNSIGNED_LONG, new Integer(5) ); + r[i++]= (5 == AnyConverter.toUnsignedLong(a)); + r[i++]= (5 == AnyConverter.toLong(a)); + try { AnyConverter.toUnsignedLong(anyInt); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + a = new Any( Type.UNSIGNED_HYPER, new Long(5) ); + r[i++]= (5 == AnyConverter.toUnsignedLong(a)); + try { AnyConverter.toLong(a); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + try { AnyConverter.toUnsignedLong(anyLong); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + // must fail with a com.sun.star.lang.IllegalArgumentException try { AnyConverter.toLong(aChar); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} try { AnyConverter.toLong(anyChar); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} @@ -390,6 +420,7 @@ public class AnyConverter_Test boolean bError= false; for (int c= 0; c < i; c++) { if (r[c] == false) { + System.err.println( "[toLong()] r[" + c + "] == false : failed!" ); bError= true; break; } @@ -549,11 +580,31 @@ public class AnyConverter_Test r[i++]= UnoRuntime.areSame(val, anyObj.getObject()); val= AnyConverter.toObject(_type, new Any( new Type(XTypeProvider.class), null)); r[i++]= val == null; + + // structs, exceptions + com.sun.star.lang.IllegalArgumentException exc = + new com.sun.star.lang.IllegalArgumentException(); + Any any_exc = new Any( + new Type( "com.sun.star.lang.IllegalArgumentException", TypeClass.EXCEPTION ), exc ); + r[i++] = AnyConverter.toObject( new Type( com.sun.star.lang.IllegalArgumentException.class ), any_exc ).equals( exc ); + r[i++] = AnyConverter.toObject( new Type( com.sun.star.uno.Exception.class ), any_exc ).equals( exc ); + try { AnyConverter.toObject( new Type( com.sun.star.uno.RuntimeException.class ), any_exc ); } catch (com.sun.star.lang.IllegalArgumentException ie) {r[i]=true;}; + ++i; + any_exc = new Any( com.sun.star.lang.IllegalArgumentException.class, exc ); + r[i++] = AnyConverter.toObject( new Type( com.sun.star.lang.IllegalArgumentException.class ), any_exc ).equals( exc ); + r[i++] = AnyConverter.toObject( new Type( com.sun.star.uno.Exception.class ), any_exc ).equals( exc ); + try { AnyConverter.toObject( new Type( com.sun.star.uno.RuntimeException.class ), any_exc ); } catch (com.sun.star.lang.IllegalArgumentException ie) {r[i]=true;}; + ++i; + // must fail - try { AnyConverter.toObject(_type, aType); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} - try { AnyConverter.toObject(_type, anyType); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} - try { AnyConverter.toObject(_type, anyVoid); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} - try { AnyConverter.toObject(_type, new Object()); i++;} catch (com.sun.star.lang.IllegalArgumentException ie) {r[i++]=true;} + try { AnyConverter.toObject(_type, aType); } catch (com.sun.star.lang.IllegalArgumentException ie) {r[i]=true;} + ++i; + try { AnyConverter.toObject(_type, anyType); } catch (com.sun.star.lang.IllegalArgumentException ie) {r[i]=true;} + ++i; + try { AnyConverter.toObject(_type, anyVoid); } catch (com.sun.star.lang.IllegalArgumentException ie) {r[i]=true;} + ++i; + try { AnyConverter.toObject(_type, new Object()); } catch (com.sun.star.lang.IllegalArgumentException ie) {r[i]=true;} + ++i; } catch (java.lang.Exception e) { i++; @@ -561,6 +612,7 @@ public class AnyConverter_Test boolean bError= false; for (int c= 0; c < i; c++) { if (r[c] == false) { + System.err.println( "[toObject()] r[" + c + "] == false : failed!" ); bError= true; break; } @@ -850,7 +902,14 @@ public class AnyConverter_Test // must work r[i++]= AnyConverter.isShort(aShort); r[i++]= AnyConverter.isShort(anyShort); + r[i++]= Type.SHORT.equals( AnyConverter.getType(anyShort) ); + + Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) ); + r[i++]= Type.UNSIGNED_SHORT.equals( AnyConverter.getType(a) ); + // must fail + r[i++]= AnyConverter.isShort(a) ? false : true; + r[i++]= ! Type.SHORT.equals( AnyConverter.getType(a) ); r[i++]= AnyConverter.isShort(aBool) ? false : true; } catch (java.lang.Exception e) { i++; @@ -882,7 +941,14 @@ public class AnyConverter_Test // must work r[i++]= AnyConverter.isInt(aInt); r[i++]= AnyConverter.isInt(anyInt); + r[i++]= Type.LONG.equals( AnyConverter.getType(anyInt) ); + + Any a = new Any( Type.UNSIGNED_LONG, new Integer(5) ); + r[i++]= Type.UNSIGNED_LONG.equals( AnyConverter.getType(a) ); + // must fail + r[i++]= AnyConverter.isInt(a) ? false : true; + r[i++]= ! Type.LONG.equals( AnyConverter.getType(a) ); r[i++]= AnyConverter.isInt(aBool) ? false : true; } catch (java.lang.Exception e) { i++; @@ -914,7 +980,14 @@ public class AnyConverter_Test // must work r[i++]= AnyConverter.isLong(aLong); r[i++]= AnyConverter.isLong(anyLong); + r[i++]= Type.HYPER.equals( AnyConverter.getType(anyLong) ); + + Any a = new Any( Type.UNSIGNED_HYPER, new Long(5) ); + r[i++]= Type.UNSIGNED_HYPER.equals( AnyConverter.getType(a) ); + // must fail + r[i++]= AnyConverter.isLong(a) ? false : true; + r[i++]= ! Type.HYPER.equals( AnyConverter.getType(a) ); r[i++]= AnyConverter.isLong(aBool) ? false : true; } catch (java.lang.Exception e) { i++; @@ -1018,6 +1091,7 @@ public class AnyConverter_Test boolean bError= false; for (int c= 0; c < i; c++) { if (r[c] == false) { + System.err.println( "[isObject()] r[" + c + "] == false : failed!" ); bError= true; break; } diff --git a/jurt/test/makefile.mk b/jurt/test/makefile.mk index 1a9af3e423d4..b1773ff58866 100644 --- a/jurt/test/makefile.mk +++ b/jurt/test/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.5 $ +# $Revision: 1.6 $ # -# last change: $Author: dbo $ $Date: 2001-11-26 17:45:10 $ +# last change: $Author: hr $ $Date: 2003-03-26 12:33:05 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -65,6 +65,8 @@ test: # cd ./com/sun/star/comp/bootstrap; make debug # cd ./com/sun/star/comp/implementationregistration/makefile.mk # cd ./com/sun/star/comp/loader; dmake debug=t +# cd ./com/sun/star/comp/rmclient/makefile.mk +# cd ./com/sun/star/comp/rmserver/makefile.mk # cd ./com/sun/star/comp/typedescriptionmanager/makefile.mk # cd ./com/sun/star/comp/testcomp/makefile.mk cd ./com/sun/star/comp/connections; dmake debug=t product=full diff --git a/jurt/util/delzip b/jurt/util/delzip new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/jurt/util/delzip diff --git a/jurt/util/makefile.mk b/jurt/util/makefile.mk index 45c7ff151e04..c463b6a56256 100644 --- a/jurt/util/makefile.mk +++ b/jurt/util/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.3 $ # -# last change: $Author: jl $ $Date: 2002-10-25 06:45:15 $ +# last change: $Author: hr $ $Date: 2003-03-26 12:33:13 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -74,6 +74,14 @@ JARCLASSDIRS = com JARTARGET = $(TARGET).jar JARCOMPRESS = TRUE +# Special work necessary for building java reference with javadoc. +# The source of puplic APIs must be delivered and used later in the +# odk module. +ZIP1TARGET=$(TARGET)_src +ZIP1FLAGS=-u -r +ZIP1DIR=$(PRJ) +ZIP1LIST=com -x "*makefile.mk" + # --- Targets ------------------------------------------------------ .INCLUDE : target.mk |