diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2007-11-23 12:11:51 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2007-11-23 12:11:51 +0000 |
commit | 536cb4f9a607a04fd9b008be19465747428915ba (patch) | |
tree | 9c81d57fe2095cb9348ae4ce0dce4249ccf7ff7b /jurt/com/sun/star/comp/bridgefactory | |
parent | INTEGRATION: CWS sb79 (1.7.136); FILE MERGED (diff) | |
download | core-536cb4f9a607a04fd9b008be19465747428915ba.tar.gz core-536cb4f9a607a04fd9b008be19465747428915ba.zip |
INTEGRATION: CWS sb79 (1.9.56); FILE MERGED
2007/09/27 11:59:04 sb 1.9.56.1: #i51323# Fixed createBridge with empty name.
Diffstat (limited to 'jurt/com/sun/star/comp/bridgefactory')
-rw-r--r-- | jurt/com/sun/star/comp/bridgefactory/BridgeFactory.java | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/jurt/com/sun/star/comp/bridgefactory/BridgeFactory.java b/jurt/com/sun/star/comp/bridgefactory/BridgeFactory.java index c294cd9f7885..5f7756cd619f 100644 --- a/jurt/com/sun/star/comp/bridgefactory/BridgeFactory.java +++ b/jurt/com/sun/star/comp/bridgefactory/BridgeFactory.java @@ -4,9 +4,9 @@ * * $RCSfile: BridgeFactory.java,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: rt $ $Date: 2005-09-07 18:48:56 $ + * last change: $Author: ihi $ $Date: 2007-11-23 13:11:51 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -35,7 +35,7 @@ package com.sun.star.comp.bridgefactory; - +import java.math.BigInteger; import java.util.Enumeration; import java.util.Vector; @@ -68,7 +68,7 @@ import com.sun.star.uno.UnoRuntime; * <p> * This component is only usable for remote bridges. * <p> - * @version $Revision: 1.9 $ $ $Date: 2005-09-07 18:48:56 $ + * @version $Revision: 1.10 $ $ $Date: 2007-11-23 13:11:51 $ * @author Kay Ramme * @see com.sun.star.uno.UnoRuntime * @since UDK1.0 @@ -131,24 +131,31 @@ public class BridgeFactory implements XBridgeFactory/*, XEventListener*/ { com.sun.star.lang.IllegalArgumentException, com.sun.star.uno.RuntimeException { - if(sName == null || sName.length() == 0) - sName = sProtocol + ":" + aConnection.getDescription(); + boolean hasName = sName.length() != 0; + Object context = hasName ? (Object) sName : (Object) new UniqueToken(); + // UnoRuntime.getBridgeByName internally uses context.toString() to + // distinguish bridges, so the result of + // new UniqueToken().toString() might clash with an explicit + // sName.toString(), but the UnoRuntime bridge management is + // obsolete anyway and should be removed // do not create a new bridge, if one already exists - IBridge iBridges[] = UnoRuntime.getBridges(); - for(int i = 0; i < iBridges.length; ++ i) { - XBridge xBridge = (XBridge)UnoRuntime.queryInterface(XBridge.class, iBridges[i]); - - if(xBridge != null) { - if(xBridge.getName().equals(sName)) - throw new BridgeExistsException(sName + " already exists"); + if (hasName) { + IBridge iBridges[] = UnoRuntime.getBridges(); + for(int i = 0; i < iBridges.length; ++ i) { + XBridge xBridge = (XBridge)UnoRuntime.queryInterface(XBridge.class, iBridges[i]); + + if(xBridge != null) { + if(xBridge.getName().equals(sName)) + throw new BridgeExistsException(sName + " already exists"); + } } } XBridge xBridge = null; try { - IBridge iBridge = UnoRuntime.getBridgeByName("java", sName, "remote", sName, new Object[]{sProtocol, aConnection, anInstanceProvider, sName}); + IBridge iBridge = UnoRuntime.getBridgeByName("java", context, "remote", context, hasName ? new Object[]{sProtocol, aConnection, anInstanceProvider, sName} : new Object[]{sProtocol, aConnection, anInstanceProvider}); xBridge = (XBridge)UnoRuntime.queryInterface(XBridge.class, iBridge); } @@ -213,5 +220,21 @@ public class BridgeFactory implements XBridgeFactory/*, XEventListener*/ { return xBridges; } + + private static final class UniqueToken { + public UniqueToken() { + synchronized (UniqueToken.class) { + token = counter.toString(); + counter = counter.add(BigInteger.ONE); + } + } + + public String toString() { + return token; + } + + private final String token; + private static BigInteger counter = BigInteger.ZERO; + } } |