summaryrefslogtreecommitdiff
path: root/ridljar/com/sun/star/comp
diff options
context:
space:
mode:
Diffstat (limited to 'ridljar/com/sun/star/comp')
-rw-r--r--ridljar/com/sun/star/comp/bridgefactory/BridgeFactory.java212
-rw-r--r--ridljar/com/sun/star/comp/connections/Acceptor.java153
-rw-r--r--ridljar/com/sun/star/comp/connections/Connector.java130
-rw-r--r--ridljar/com/sun/star/comp/connections/ConstantInstanceProvider.java118
-rw-r--r--ridljar/com/sun/star/comp/connections/Implementation.java95
-rw-r--r--ridljar/com/sun/star/comp/connections/PipedConnection.java259
-rw-r--r--ridljar/com/sun/star/comp/loader/FactoryHelper.java502
-rw-r--r--ridljar/com/sun/star/comp/loader/JavaLoader.java439
-rw-r--r--ridljar/com/sun/star/comp/loader/JavaLoaderFactory.java90
-rw-r--r--ridljar/com/sun/star/comp/loader/RegistrationClassFinder.java69
-rw-r--r--ridljar/com/sun/star/comp/servicemanager/ServiceManager.java662
-rw-r--r--ridljar/com/sun/star/comp/urlresolver/UrlResolver.java147
12 files changed, 2876 insertions, 0 deletions
diff --git a/ridljar/com/sun/star/comp/bridgefactory/BridgeFactory.java b/ridljar/com/sun/star/comp/bridgefactory/BridgeFactory.java
new file mode 100644
index 000000000000..031e60d3f1dc
--- /dev/null
+++ b/ridljar/com/sun/star/comp/bridgefactory/BridgeFactory.java
@@ -0,0 +1,212 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.bridgefactory;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+
+import com.sun.star.bridge.BridgeExistsException;
+import com.sun.star.bridge.XBridge;
+import com.sun.star.bridge.XBridgeFactory;
+import com.sun.star.bridge.XInstanceProvider;
+import com.sun.star.comp.loader.FactoryHelper;
+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 com.sun.star.uno.IBridge;
+import com.sun.star.uno.UnoRuntime;
+
+
+/**
+ * The BridgeFactory class implements the <code>XBridgeFactory</code> Interface.
+ *
+ * <p>It wraps the <code>UnoRuntime#getBridgeByName</code>method and delivers a
+ * XBridge component.</p>
+ *
+ * <p>This component is only usable for remote bridges.</p>
+ *
+ * @see com.sun.star.uno.UnoRuntime
+ * @since UDK1.0
+ */
+public class BridgeFactory implements XBridgeFactory/*, XEventListener*/ {
+ private static final boolean DEBUG = false;
+
+ /**
+ * The name of the service, the <code>JavaLoader</code> accesses this through
+ * reflection.
+ */
+ public static final String __serviceName = "com.sun.star.bridge.BridgeFactory";
+
+ /**
+ * Gives 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 desired.
+ * @param multiFactory the service manager to be uses if needed.
+ * @param regKey the registryKey.
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component.
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals(BridgeFactory.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(BridgeFactory.class,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * Creates a remote bridge and memorizes it under <code>sName</code>.
+ *
+ * @param sName the name to memorize the bridge.
+ * @param sProtocol the protocol the bridge should use.
+ * @param anInstanceProvider the instance provider.
+ * @return the bridge.
+ *
+ * @see com.sun.star.bridge.XBridgeFactory
+ */
+ public XBridge createBridge(String sName, String sProtocol, XConnection aConnection, XInstanceProvider anInstanceProvider) throws
+ BridgeExistsException,
+ com.sun.star.lang.IllegalArgumentException,
+ com.sun.star.uno.RuntimeException
+ {
+ boolean hasName = sName.length() != 0;
+ Object context = hasName ? sName : 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
+ if (hasName) {
+ IBridge iBridges[] = UnoRuntime.getBridges();
+ for(int i = 0; i < iBridges.length; ++ i) {
+ XBridge xBridge = UnoRuntime.queryInterface(XBridge.class, iBridges[i]);
+
+ if(xBridge != null && xBridge.getName().equals(sName)) {
+ throw new BridgeExistsException(sName + " already exists");
+ }
+ }
+ }
+
+ XBridge xBridge;
+
+ try {
+ IBridge iBridge = UnoRuntime.getBridgeByName("java", context, "remote", context, hasName ? new Object[]{sProtocol, aConnection, anInstanceProvider, sName} : new Object[]{sProtocol, aConnection, anInstanceProvider});
+
+ xBridge = UnoRuntime.queryInterface(XBridge.class, iBridge);
+ }
+ catch (Exception e) {
+ throw new com.sun.star.lang.IllegalArgumentException(e, e.getMessage());
+ }
+
+ if(DEBUG) System.err.println("##### " + getClass().getName() + ".createBridge:" + sName + " " + sProtocol + " " + aConnection + " " + anInstanceProvider + " " + xBridge);
+
+ return xBridge;
+ }
+
+ /**
+ * Gets a remote bridge which must already exist.
+ *
+ * @param sName the name of the bridge.
+ * @return the bridge.
+ * @see com.sun.star.bridge.XBridgeFactory
+ */
+ public XBridge getBridge(String sName) throws com.sun.star.uno.RuntimeException {
+ XBridge xBridge = null;
+
+ IBridge iBridges[] = UnoRuntime.getBridges();
+ for(int i = 0; i < iBridges.length; ++ i) {
+ xBridge = UnoRuntime.queryInterface(XBridge.class, iBridges[i]);
+
+ if(xBridge != null) {
+ if(xBridge.getName().equals(sName))
+ break;
+
+ else
+ xBridge = null;
+ }
+ }
+
+
+ if(DEBUG) System.err.println("##### " + getClass().getName() + ".getBridge:" + sName + " " + xBridge);
+
+ return xBridge;
+ }
+
+ /**
+ * Gives all created bridges.
+ *
+ * @return the bridges.
+ * @see com.sun.star.bridge.XBridgeFactory
+ */
+ public synchronized XBridge[] getExistingBridges() throws com.sun.star.uno.RuntimeException {
+ ArrayList<XBridge> vector = new ArrayList<XBridge>();
+
+ IBridge iBridges[] = UnoRuntime.getBridges();
+ for(int i = 0; i < iBridges.length; ++ i) {
+ XBridge xBridge = UnoRuntime.queryInterface(XBridge.class, iBridges[i]);
+
+ if(xBridge != null)
+ vector.add(xBridge);
+ }
+
+ XBridge xBridges[]= new XBridge[vector.size()];
+ for(int i = 0; i < vector.size(); ++ i)
+ xBridges[i] = vector.get(i);
+
+ return xBridges;
+ }
+
+ private static final class UniqueToken {
+ public UniqueToken() {
+ synchronized (UniqueToken.class) {
+ token = counter.toString();
+ counter = counter.add(BigInteger.ONE);
+ }
+ }
+
+ /**
+ * Returns a string representation of the object.
+ *
+ * @return a string representation of the object.
+ * @see java.lang.Object#toString
+ */
+ @Override
+ public String toString() {
+ return token;
+ }
+
+ private final String token;
+ private static BigInteger counter = BigInteger.ZERO;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/connections/Acceptor.java b/ridljar/com/sun/star/comp/connections/Acceptor.java
new file mode 100644
index 000000000000..996eaeb858d7
--- /dev/null
+++ b/ridljar/com/sun/star/comp/connections/Acceptor.java
@@ -0,0 +1,153 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.connections;
+
+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;
+
+/**
+ * A component that implements the <code>XAcceptor</code> interface.
+ *
+ * <p>The <code>Acceptor</code> is a general component, that uses less general
+ * components (like <code>com.sun.star.connection.socketAcceptor</code>) to
+ * implement its functionality.</p>
+ *
+ * @see com.sun.star.connection.XAcceptor
+ * @see com.sun.star.connection.XConnection
+ * @see com.sun.star.connection.XConnector
+ * @see com.sun.star.comp.loader.JavaLoader
+ *
+ * @since UDK 1.0
+ */
+public final class Acceptor implements XAcceptor {
+ /**
+ * The name of the service.
+ *
+ * <p>The <code>JavaLoader</code> accesses this through reflection.</p>
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static final String __serviceName
+ = "com.sun.star.connection.Acceptor";
+
+ /**
+ * 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(Acceptor.class.getName())
+ ? FactoryHelper.getServiceFactory(Acceptor.class, __serviceName,
+ multiFactory, regKey)
+ : null;
+ }
+
+ /**
+ * Constructs a new <code>Acceptor</code> that uses the given service
+ * factory to create a specific <code>XAcceptor</code>.
+ *
+ * @param serviceFactory the service factory to use.
+ */
+ public Acceptor(XMultiServiceFactory serviceFactory) {
+ this.serviceFactory = serviceFactory;
+ }
+
+ /**
+ * Accepts a connection request via the given connection type.
+ *
+ * <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>).
+ * The specific <code>XAcceptor</code> implementation is instantiated
+ * through the service factory as
+ * <code>com.sun.star.connection.<var>type</var>Acceptor</code> (with
+ * <code><var>type</var></code> in lower case).</p>
+ *
+ * @param connectionDescription the description of the connection.
+ * @return an <code>XConnection</code> to the client.
+ *
+ * @see com.sun.star.connection.XConnection
+ * @see com.sun.star.connection.XConnector
+ */
+ public XConnection accept(String connectionDescription) throws
+ AlreadyAcceptingException, ConnectionSetupException,
+ com.sun.star.lang.IllegalArgumentException
+ {
+ if (DEBUG) {
+ System.err.println("##### " + getClass().getName() + ".accept("
+ + connectionDescription + ")");
+ }
+ XAcceptor acc;
+ synchronized (this) {
+ if (acceptor == null) {
+ acceptor = (XAcceptor) Implementation.getConnectionService(
+ serviceFactory, connectionDescription, XAcceptor.class,
+ "Acceptor");
+ acceptingDescription = connectionDescription;
+ } else if (!connectionDescription.equals(acceptingDescription)) {
+ throw new AlreadyAcceptingException(acceptingDescription
+ + " vs. "
+ + connectionDescription);
+ }
+ acc = acceptor;
+ }
+ return acc.accept(connectionDescription);
+ }
+
+ /**
+ *
+ * @see com.sun.star.connection.XAcceptor#stopAccepting
+ */
+ public void stopAccepting() {
+ XAcceptor acc;
+ synchronized (this) {
+ acc = acceptor;
+ }
+ acc.stopAccepting();
+ }
+
+ private static final boolean DEBUG = false;
+
+ private final XMultiServiceFactory serviceFactory;
+
+ private XAcceptor acceptor = null;
+ private String acceptingDescription;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
diff --git a/ridljar/com/sun/star/comp/connections/Connector.java b/ridljar/com/sun/star/comp/connections/Connector.java
new file mode 100644
index 000000000000..6ffab9eea86b
--- /dev/null
+++ b/ridljar/com/sun/star/comp/connections/Connector.java
@@ -0,0 +1,130 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.connections;
+
+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;
+
+/**
+ * A component that implements the <code>XConnector</code> interface.
+ *
+ * <p>The <code>Connector</code> is a general component, that uses less general
+ * components (like <code>com.sun.star.connection.socketConnector</code>) to
+ * implement its functionality.</p>
+ *
+ * @see com.sun.star.connection.XAcceptor
+ * @see com.sun.star.connection.XConnection
+ * @see com.sun.star.connection.XConnector
+ * @see com.sun.star.comp.loader.JavaLoader
+ *
+ * @since UDK 1.0
+ */
+public class Connector implements XConnector {
+ /**
+ * The name of the service.
+ *
+ * <p>The <code>JavaLoader</code> accesses this through reflection.</p>
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static final String __serviceName
+ = "com.sun.star.connection.Connector";
+
+ /**
+ * 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(Connector.class.getName())
+ ? FactoryHelper.getServiceFactory(Connector.class, __serviceName,
+ multiFactory, regKey)
+ : null;
+ }
+
+ /**
+ * Constructs a new <code>Connector</code> that uses the given service
+ * factory to create a specific <code>XConnector</code>.
+ *
+ * @param serviceFactory the service factory to use.
+ */
+ public Connector(XMultiServiceFactory serviceFactory) {
+ this.serviceFactory = serviceFactory;
+ }
+
+ /**
+ * Connects via the given connection type 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>).
+ * The specific <code>XConnector</code> implementation is instantiated
+ * through the service factory as
+ * <code>com.sun.star.connection.<var>type</var>Connector</code> (with
+ * <code><var>type</var></code> in lower case).</p>
+ *
+ * @param connectionDescription the description of the connection.
+ * @return an <code>XConnection</code> to the server.
+ *
+ * @see com.sun.star.connection.XAcceptor
+ * @see com.sun.star.connection.XConnection
+ */
+ public synchronized XConnection connect(String connectionDescription)
+ throws NoConnectException, ConnectionSetupException
+ {
+ if (DEBUG) {
+ System.err.println("##### " + getClass().getName() + ".connect("
+ + connectionDescription + ")");
+ }
+ if (connected) {
+ throw new ConnectionSetupException("already connected");
+ }
+ XConnection con
+ = ((XConnector) Implementation.getConnectionService(
+ serviceFactory, connectionDescription, XConnector.class,
+ "Connector")).connect(connectionDescription);
+ connected = true;
+ return con;
+ }
+
+ private static final boolean DEBUG = false;
+
+ private final XMultiServiceFactory serviceFactory;
+
+ private boolean connected = false;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/connections/ConstantInstanceProvider.java b/ridljar/com/sun/star/comp/connections/ConstantInstanceProvider.java
new file mode 100644
index 000000000000..6c2fcb2d85ee
--- /dev/null
+++ b/ridljar/com/sun/star/comp/connections/ConstantInstanceProvider.java
@@ -0,0 +1,118 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.connections;
+
+import com.sun.star.bridge.XInstanceProvider;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.registry.XRegistryKey;
+
+import com.sun.star.comp.loader.FactoryHelper;
+
+
+/**
+ * The <code>ConstantInstanceProvider</code> is a component
+ * that implements the <code>XInstanceProvider</code> Interface.
+ *
+ * @see com.sun.star.bridge.XBridge
+ * @see com.sun.star.bridge.XBridgeFactory
+ * @see com.sun.star.bridge.XInstanceProvider
+ * @see com.sun.star.comp.loader.JavaLoader
+ * @since UDK1.0
+ */
+public class ConstantInstanceProvider implements XInstanceProvider {
+ /**
+ * When set to true, enables various debugging output.
+ */
+ public static final boolean DEBUG = false;
+
+ /**
+ * The name of the service, the <code>JavaLoader</code> accesses this through
+ * reflection.
+ */
+ private static final String __serviceName = "com.sun.star.comp.connection.InstanceProvider";
+
+ /**
+ * Gives 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 desired.
+ * @param multiFactory the service manager to be uses if needed.
+ * @param regKey the registryKey.
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component.
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals(ConstantInstanceProvider.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(ConstantInstanceProvider.class,
+ __serviceName,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+
+ protected XMultiServiceFactory _serviceManager;
+ protected String _serviceName;
+ protected Object _instance;
+
+
+ public void setInstance(String serviceName) throws com.sun.star.uno.Exception {
+ _instance = _serviceManager.createInstance(serviceName);
+ _serviceName = serviceName;
+ }
+
+ /**
+ * Constructs a new <code>ConstantInstanceProvider</code>.
+ * <p>Uses the provided ServiceManager as the provided instance.</p>
+ *
+ * @param serviceManager the provided service manager
+ */
+ public ConstantInstanceProvider(XMultiServiceFactory serviceManager) {
+ _serviceManager = serviceManager;
+
+ _serviceName = "SERVICEMANAGER";
+ _instance = serviceManager;
+ }
+
+ /**
+ * Gives an object for the passed instance name.
+ *
+ * @return the desired instance
+ * @param sInstanceName the name of the desired instance
+ */
+ public Object getInstance(String sInstanceName) throws com.sun.star.container.NoSuchElementException, com.sun.star.uno.RuntimeException {
+ Object result = sInstanceName.equals(_serviceName) ? _instance : null;
+
+ if(DEBUG) System.err.println("##### " + getClass().getName() + ".getInstance(" + sInstanceName + "):" + result);
+
+ return result;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/connections/Implementation.java b/ridljar/com/sun/star/comp/connections/Implementation.java
new file mode 100644
index 000000000000..94cabe253a33
--- /dev/null
+++ b/ridljar/com/sun/star/comp/connections/Implementation.java
@@ -0,0 +1,95 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.connections;
+
+import com.sun.star.connection.ConnectionSetupException;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ * Helper class for <code>Acceptor</code> and <code>Connector</code>.
+ */
+final class Implementation {
+ /**
+ * Instantiate a service for a given connection type.
+ *
+ * @param factory the service factory used to instantiate the requested
+ * service.
+ * @param description has the following format:
+ * <code><var>type</var></code><!--
+ * -->*(<code><var>key</var>=<var>value</var></code>).
+ * The specific service implementation is instantiated through the
+ * service factory as
+ * <code>com.sun.star.connection.<var>type</var>service<var></var><!--
+ * --></code>
+ * (with <code><var>type</var></code> in lower case, and
+ * <code><var>service</var></code> either <code>Acceptor</code> or
+ * <code>Connector</code>).
+ * @param serviceClass the IDL interface type for which to query the
+ * requested service.
+ * @param serviceType must be either <code>Acceptor</code> or
+ * <code>Connector</code>.
+ * @return an instance of the requested service. Never returns
+ * <code>null</code>.
+ * @throws ConnectionSetupException if the requested service can not be
+ * found, or cannot be instantiated.
+ */
+ public static Object getConnectionService(XMultiServiceFactory factory,
+ String description,
+ Class<?> serviceClass,
+ String serviceType)
+ throws ConnectionSetupException
+ {
+ int i = description.indexOf(',');
+ String type
+ = (i < 0 ? description : description.substring(0, i)).toLowerCase();
+ Object service = null;
+ try {
+ service = UnoRuntime.queryInterface(
+ serviceClass,
+ factory.createInstance("com.sun.star.connection." + type
+ + serviceType));
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (com.sun.star.uno.Exception e) {
+ }
+ if (service == null) {
+ // As a fallback, also try to instantiate the service from the
+ // com.sun.star.lib.connections package structure:
+ try {
+ service
+ = Class.forName("com.sun.star.lib.connections." + type
+ + "." + type + serviceType).newInstance();
+ } catch (ClassNotFoundException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InstantiationException e) {
+ }
+ }
+ if (service == null) {
+ throw new ConnectionSetupException("no " + serviceType + " for "
+ + type);
+ }
+ return service;
+ }
+
+ private Implementation() {} // do not instantiate
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/connections/PipedConnection.java b/ridljar/com/sun/star/comp/connections/PipedConnection.java
new file mode 100644
index 000000000000..631cfae40ee0
--- /dev/null
+++ b/ridljar/com/sun/star/comp/connections/PipedConnection.java
@@ -0,0 +1,259 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.connections;
+
+
+import com.sun.star.comp.loader.FactoryHelper;
+import com.sun.star.connection.XConnection;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.registry.XRegistryKey;
+
+/**
+ * The <code>PipedConnection</code> is a component that implements the
+ * <code>XConnection</code> Interface.
+ * <p>It is useful for <code>Thread</code> communication in one Process.</p>
+ *
+ * @see com.sun.star.connection.XConnection
+ * @see com.sun.star.comp.loader.JavaLoader
+ * @since UDK1.0
+ */
+public class PipedConnection implements XConnection {
+ /**
+ * When set to true, enables various debugging output.
+ */
+ public static final boolean DEBUG = false;
+
+ /**
+ * The name of the service, the <code>JavaLoader</code> accesses this through
+ * reflection.
+ */
+ private static final String __serviceName = "com.sun.star.connection.PipedConnection";
+
+ /**
+ * Gives 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 desired.
+ * @param multiFactory the service manager to be uses if needed.
+ * @param regKey the registryKey.
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component.
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals(PipedConnection.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(PipedConnection.class,
+ __serviceName,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * The amount of time in milliseconds, to wait to see check the buffers.
+ */
+ protected static final int __waitTime = 10000;
+
+ protected byte _buffer[] = new byte[4096];
+ protected int _in,
+ _out;
+ protected boolean _closed;
+ protected PipedConnection _otherSide;
+
+ /**
+ * Constructs a new <code>PipedConnection</code>, sees if there is another
+ * side, which it should be connected to.
+ *
+ * @param args Another side could be in index 0.
+ */
+ public PipedConnection(Object args[]) throws com.sun.star.uno.RuntimeException {
+ if (DEBUG) System.err.println("##### " + getClass().getName() + " - instantiated");
+
+ _otherSide = (args.length == 1) ? (PipedConnection)args[0] : null;
+ if(_otherSide != null) {
+ if(_otherSide == this)
+ throw new RuntimeException("can not connect to myself");
+
+ _otherSide._otherSide = this;
+ }
+ }
+
+ /**
+ * This is a private method, used to communicate internal in the pipe.
+ */
+ private synchronized void receive(byte aData[]) throws com.sun.star.io.IOException {
+ int bytesWritten = 0;
+
+ if(DEBUG) System.err.println("##### PipedConnection.receive - bytes:" + aData.length + " at:" + _out);
+
+ while(bytesWritten < aData.length) {
+ // wait until it is not full anymore
+ while(_out == (_in - 1) || (_in == 0 && _out == _buffer.length - 1)) {
+ try {
+ notify(); // the buffer is full, signal it
+
+ wait(__waitTime);
+ }
+ catch(InterruptedException interruptedException) {
+ throw new com.sun.star.io.IOException(interruptedException);
+ }
+ }
+
+ if(_closed) throw new com.sun.star.io.IOException("connection has been closed");
+
+ int bytes ;
+
+ if(_out < _in) {
+ bytes = Math.min(aData.length - bytesWritten, _in - _out - 1);
+
+ System.arraycopy(aData, bytesWritten, _buffer, _out, bytes);
+ }
+ else {
+ if(_in > 0){
+ bytes = Math.min(aData.length - bytesWritten, _buffer.length - _out);
+ }
+ else {
+ bytes = Math.min(aData.length - bytesWritten, _buffer.length - _out - 1);
+ }
+
+ System.arraycopy(aData, bytesWritten, _buffer, _out, bytes);
+ }
+
+ bytesWritten += bytes;
+ _out += bytes;
+ if(_out >= _buffer.length)
+ _out = 0;
+ }
+ }
+
+ /**
+ * Read the required number of bytes.
+ *
+ * @param aReadBytes the out parameter, where the bytes have to be placed.
+ * @param nBytesToRead the number of bytes to read.
+ * @return the number of bytes read.
+ *
+ * @see com.sun.star.connection.XConnection#read
+ */
+ public synchronized int read(/*OUT*/byte[][] aReadBytes, int nBytesToRead) throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException {
+ aReadBytes[0] = new byte[nBytesToRead];
+
+ if(DEBUG) System.err.println("##### PipedConnection.read - bytes:" + nBytesToRead + " at:" + _in);
+
+ // loop while not all bytes read or when closed but there is still data
+ while(nBytesToRead > 0 && (_in != _out || !_closed)) {
+ while(_in == _out && !_closed) {
+ try {
+ notify(); // the buffer is empty, signal it
+
+ wait(__waitTime); // we wait for data or for the pipe to be closed
+ }
+ catch(InterruptedException interruptedException) {
+ throw new com.sun.star.io.IOException(interruptedException);
+ }
+ }
+
+ if(_in < _out) {
+ int bytes = Math.min(nBytesToRead, _out - _in);
+
+ System.arraycopy(_buffer, _in, aReadBytes[0], aReadBytes[0].length - nBytesToRead, bytes);
+
+ nBytesToRead -= bytes;
+ _in += bytes;
+ }
+ else if(_in > _out) {
+ int bytes = Math.min(nBytesToRead, _buffer.length - _in);
+
+ System.arraycopy(_buffer, _in, aReadBytes[0], aReadBytes[0].length - nBytesToRead, bytes);
+
+ nBytesToRead -= bytes;
+ _in += bytes;
+ if(_in >= _buffer.length)
+ _in = 0;
+ }
+ }
+
+ if(nBytesToRead > 0) { // not all bytes read
+ byte tmp[] = new byte[aReadBytes[0].length - nBytesToRead];
+ System.arraycopy(aReadBytes[0], 0, tmp, 0, tmp.length);
+
+ aReadBytes[0] = tmp;
+ }
+
+ return aReadBytes[0].length;
+ }
+
+ /**
+ * Write bytes.
+ *
+ * @param aData the bytes to write.
+ * @see com.sun.star.connection.XConnection#write
+ */
+ public void write(byte aData[]) throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException {
+ _otherSide.receive(aData);
+ }
+
+ /**
+ * Flushes the buffer, notifies if necessary the other side that new data has
+ * arrived.
+ *
+ * @see com.sun.star.connection.XConnection#flush
+ */
+ public void flush() throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException {
+ synchronized(_otherSide) {
+ _otherSide.notify();
+ }
+ }
+
+ /**
+ * Closes the pipe.
+ *
+ * @see com.sun.star.connection.XConnection#close()
+ */
+ public synchronized void close() throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException {
+ if(!_closed) {
+ _closed = true;
+
+ _otherSide.close();
+
+ notify();
+ }
+ }
+
+ /**
+ * Gives a description of this pipe.
+ *
+ * @return the description.
+ * @see com.sun.star.connection.XConnection#getDescription
+ */
+ public String getDescription() throws com.sun.star.uno.RuntimeException {
+ return getClass().getName();
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/loader/FactoryHelper.java b/ridljar/com/sun/star/comp/loader/FactoryHelper.java
new file mode 100644
index 000000000000..fe56f594f2bd
--- /dev/null
+++ b/ridljar/com/sun/star/comp/loader/FactoryHelper.java
@@ -0,0 +1,502 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.loader;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Type;
+
+
+/**
+ * The purpose of this class to help component implementation.
+ *
+ * <p>This class has default implementations for <code>getServiceFactory</code>
+ * and <code>writeRegistryServiceInfo</code>.</p>
+ *
+ * @see com.sun.star.lang.XMultiServiceFactory
+ * @see com.sun.star.lang.XServiceInfo
+ * @see com.sun.star.lang.XSingleServiceFactory
+ * @see com.sun.star.registry.XRegistryKey
+ * @since UDK1.0
+ */
+public class FactoryHelper {
+
+ private static final boolean DEBUG = false;
+ // the factory
+ protected static class Factory
+ implements XSingleServiceFactory, XSingleComponentFactory, XServiceInfo,
+ XTypeProvider {
+
+ protected XMultiServiceFactory _xMultiServiceFactory;
+ protected XRegistryKey _xRegistryKey;
+ protected int _nCode;
+ protected Constructor<?> _constructor;
+ protected String _implName;
+ protected String _serviceName;
+
+ protected Factory(Class<?> implClass,
+ String serviceName,
+ XMultiServiceFactory xMultiServiceFactory,
+ XRegistryKey xRegistryKey)
+ {
+ _xMultiServiceFactory = xMultiServiceFactory;
+ _xRegistryKey = xRegistryKey;
+ _implName = implClass.getName();
+ _serviceName = serviceName;
+
+ Constructor<?> constructors[] = implClass.getConstructors();
+ for(int i = 0; i < constructors.length && _constructor == null; ++i) {
+ Class<?> parameters[] = constructors[i].getParameterTypes();
+
+ if(parameters.length == 3
+ && parameters[0].equals(XComponentContext.class)
+ && parameters[1].equals(XRegistryKey.class)
+ && parameters[2].equals(Object[].class)) {
+ _nCode = 0;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 2
+ && parameters[0].equals(XComponentContext.class)
+ && parameters[1].equals(XRegistryKey.class)) {
+ _nCode = 1;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 2
+ && parameters[0].equals(XComponentContext.class)
+ && parameters[1].equals(Object[].class)) {
+ _nCode = 2;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 1
+ && parameters[0].equals(XComponentContext.class)) {
+ _nCode = 3;
+ _constructor = constructors[i];
+ }
+ // depr
+ else if(parameters.length == 3
+ && parameters[0].equals(XMultiServiceFactory.class)
+ && parameters[1].equals(XRegistryKey.class)
+ && parameters[2].equals(Object[].class)) {
+ _nCode = 4;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 2
+ && parameters[0].equals(XMultiServiceFactory.class)
+ && parameters[1].equals(XRegistryKey.class)) {
+ _nCode = 5;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 2
+ && parameters[0].equals(XMultiServiceFactory.class)
+ && parameters[1].equals(Object[].class)) {
+ _nCode = 6;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 1
+ && parameters[0].equals(XMultiServiceFactory.class)) {
+ _nCode = 7;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 1
+ && parameters[0].equals(Object[].class)) {
+ _nCode = 8;
+ _constructor = constructors[i];
+ }
+ else if(parameters.length == 0) {
+ _nCode = 9;
+ _constructor = constructors[i];
+ }
+ }
+
+ if(_constructor == null) // have not found a usable constructor
+ throw new com.sun.star.uno.RuntimeException(getClass().getName() + " can not find a usable constructor");
+ }
+
+ private final XMultiServiceFactory getSMgr( XComponentContext xContext )
+ {
+ if (xContext != null)
+ {
+ return UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, xContext.getServiceManager() );
+ }
+ else
+ {
+ return _xMultiServiceFactory;
+ }
+ }
+
+ // XComponentContext impl
+
+ public Object createInstanceWithContext(
+ XComponentContext xContext )
+ throws com.sun.star.uno.Exception
+ {
+ Object args[];
+ switch (_nCode)
+ {
+ case 0:
+ args = new Object [] { xContext, _xRegistryKey, new Object[ 0 ] };
+ break;
+ case 1:
+ args = new Object [] { xContext, _xRegistryKey };
+ break;
+ case 2:
+ args = new Object [] { xContext, new Object[ 0 ] };
+ break;
+ case 3:
+ args = new Object [] { xContext };
+ break;
+ case 4:
+ args = new Object [] { getSMgr( xContext ), _xRegistryKey, new Object[ 0 ] };
+ break;
+ case 5:
+ args = new Object [] { getSMgr( xContext ), _xRegistryKey };
+ break;
+ case 6:
+ args = new Object [] { getSMgr( xContext ), new Object[ 0 ] };
+ break;
+ case 7:
+ args = new Object [] { getSMgr( xContext ) };
+ break;
+ case 8:
+ args = new Object [] { new Object[ 0 ] };
+ break;
+ default:
+ args = new Object [ 0 ];
+ break;
+ }
+
+ try {
+ return _constructor.newInstance( args );
+ } catch (InvocationTargetException invocationTargetException) {
+ Throwable targetException = invocationTargetException.getCause();
+
+ if (targetException instanceof java.lang.RuntimeException)
+ throw (java.lang.RuntimeException)targetException;
+ else if (targetException instanceof com.sun.star.uno.Exception)
+ throw (com.sun.star.uno.Exception)targetException;
+ else if (targetException instanceof com.sun.star.uno.RuntimeException)
+ throw (com.sun.star.uno.RuntimeException)targetException;
+ else
+ throw new com.sun.star.uno.Exception( targetException );
+ } catch (IllegalAccessException illegalAccessException) {
+ throw new com.sun.star.uno.Exception( illegalAccessException );
+ } catch (InstantiationException instantiationException) {
+ throw new com.sun.star.uno.Exception( instantiationException );
+ }
+ }
+
+ public Object createInstanceWithArgumentsAndContext(
+ Object rArguments[], XComponentContext xContext )
+ throws com.sun.star.uno.Exception
+ {
+ Object args[];
+
+ boolean bInitCall = true;
+ switch (_nCode)
+ {
+ case 0:
+ args = new Object [] { xContext, _xRegistryKey, rArguments };
+ bInitCall = false;
+ break;
+ case 1:
+ args = new Object [] { xContext, _xRegistryKey };
+ break;
+ case 2:
+ args = new Object [] { xContext, rArguments };
+ bInitCall = false;
+ break;
+ case 3:
+ args = new Object [] { xContext };
+ break;
+ case 4:
+ args = new Object [] { getSMgr( xContext ), _xRegistryKey, rArguments };
+ bInitCall = false;
+ break;
+ case 5:
+ args = new Object [] { getSMgr( xContext ), _xRegistryKey };
+ break;
+ case 6:
+ args = new Object [] { getSMgr( xContext ), rArguments };
+ bInitCall = false;
+ break;
+ case 7:
+ args = new Object [] { getSMgr( xContext ) };
+ break;
+ case 8:
+ args = new Object [] { rArguments };
+ bInitCall = false;
+ break;
+ default:
+ args = new Object [ 0 ];
+ break;
+ }
+
+ try {
+ Object instance = _constructor.newInstance( args );
+ if (bInitCall)
+ {
+ XInitialization xInitialization = UnoRuntime.queryInterface(
+ XInitialization.class, instance );
+ if (xInitialization != null)
+ {
+ xInitialization.initialize( rArguments );
+ }
+ }
+ return instance;
+ } catch (InvocationTargetException invocationTargetException) {
+ Throwable targetException = invocationTargetException.getCause();
+
+ if (targetException instanceof java.lang.RuntimeException)
+ throw (java.lang.RuntimeException)targetException;
+ else if (targetException instanceof com.sun.star.uno.Exception)
+ throw (com.sun.star.uno.Exception)targetException;
+ else if (targetException instanceof com.sun.star.uno.RuntimeException)
+ throw (com.sun.star.uno.RuntimeException)targetException;
+ else
+ throw new com.sun.star.uno.Exception( targetException );
+ } catch (IllegalAccessException illegalAccessException) {
+ throw new com.sun.star.uno.Exception( illegalAccessException );
+ } catch (InstantiationException instantiationException) {
+ throw new com.sun.star.uno.Exception( instantiationException );
+ }
+ }
+
+ /**
+ * Creates an instance of the desired service.
+ *
+ * @return returns an instance of the desired service.
+ * @see com.sun.star.lang.XSingleServiceFactory
+ */
+ public Object createInstance()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ return createInstanceWithContext( null );
+ }
+
+ /**
+ * Creates an instance of the desired service.
+ *
+ * @param args the args given to the constructor of the service.
+ * @return returns an instance of the desired service.
+ *
+ * @see com.sun.star.lang.XSingleServiceFactory
+ */
+ public Object createInstanceWithArguments(Object[] args)
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ return createInstanceWithArgumentsAndContext( args, null );
+ }
+
+ /**
+ * Gives the supported services.
+ *
+ * @return returns an array of supported services.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public String[] getSupportedServiceNames() throws com.sun.star.uno.RuntimeException {
+ return new String[]{_serviceName};
+ }
+
+ /**
+ * Gives the implementation name.
+ *
+ * @return returns the implementation name.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public String getImplementationName() throws com.sun.star.uno.RuntimeException {
+ return _implName;
+ }
+
+ /**
+ * Indicates if the given service is supported.
+ *
+ * @return returns true if the given service is supported.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public boolean supportsService(String serviceName) throws com.sun.star.uno.RuntimeException {
+ String services[] = getSupportedServiceNames();
+
+ boolean found = false;
+
+ for(int i = 0; i < services.length && !found; ++i)
+ found = services[i].equals(serviceName);
+
+ return found;
+ }
+
+ //XTypeProvider
+ public byte[] getImplementationId()
+ {
+ return new byte[0];
+ }
+ //XTypeProvider
+ public com.sun.star.uno.Type[] getTypes()
+ {
+ Type[] t = new Type[] {
+ new Type(XSingleServiceFactory.class),
+ new Type(XSingleComponentFactory.class),
+ new Type(XServiceInfo.class),
+ new Type(XTypeProvider.class)
+ };
+ return t;
+ }
+
+ }
+
+ /**
+ * Creates a factory for the given class.
+ *
+ * @param implClass the implementing class.
+ * @param multiFactory the given multi service factory (service manager).
+ * @param regKey the given registry key.
+ * @return returns a factory.
+ *
+ * @see com.sun.star.lang.XServiceInfo
+ * @deprecated as of UDK 1.0
+ */
+ @Deprecated
+ public static XSingleServiceFactory getServiceFactory(Class<?> implClass,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ try {
+ Field serviceName ;
+
+ try {
+ serviceName = implClass.getField("__serviceName");
+ } catch(NoSuchFieldException noSuchFieldExceptio) {
+ serviceName = implClass.getField("serviceName"); // old style
+ }
+
+ xSingleServiceFactory = new Factory(implClass, (String)serviceName.get(null), multiFactory, regKey);
+ } catch(NoSuchFieldException noSuchFieldException) {
+ System.err.println("##### FactoryHelper.getServiceFactory - exception:" + noSuchFieldException);
+ } catch(IllegalAccessException illegalAccessException) {
+ System.err.println("##### FactoryHelper.getServiceFactory - exception:" + illegalAccessException);
+ }
+
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * Creates a factory for the given class.
+ *
+ * @param implClass the implementing class.
+ * @param serviceName the service name of the implementing class.
+ * @param multiFactory the given multi service factory (service manager).
+ * @param regKey the given registry key.
+ *
+ * @return returns a factory.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public static XSingleServiceFactory getServiceFactory(Class<?> implClass,
+ String serviceName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ return new Factory(implClass, serviceName, multiFactory, regKey);
+ }
+
+ /**
+ * Creates a factory for the given class.
+ *
+ * @param implClass the implementing class.
+ * @return returns a factory object.
+ */
+ public static Object createComponentFactory( Class<?> implClass, String serviceName )
+ {
+ return new Factory( implClass, serviceName, null, null );
+ }
+
+ /**
+ * Writes the registration data into the registry key.
+ *
+ * @param implName the name of the implementing class.
+ * @param serviceName the service name.
+ * @param regKey the given registry key.
+ * @return success.
+ *
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public static boolean writeRegistryServiceInfo(String implName, String serviceName, XRegistryKey regKey) {
+ boolean result = false;
+
+ try {
+ XRegistryKey newKey = regKey.createKey("/" + implName + "/UNO/SERVICES");
+
+ newKey.createKey(serviceName);
+
+ result = true;
+ }
+ catch (Exception ex) {
+ System.err.println(">>>Connection_Impl.writeRegistryServiceInfo " + ex);
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes the registration data into the registry key.
+ *
+ * <p>Several services are supported.</p>
+ *
+ * @param impl_name name of implementation.
+ * @param supported_services supported services of implementation.
+ * @param xKey registry key to write to.
+ * @return success.
+ */
+ public static boolean writeRegistryServiceInfo(
+ String impl_name, String supported_services [], XRegistryKey xKey )
+ {
+ try {
+ XRegistryKey xNewKey = xKey.createKey( "/" + impl_name + "/UNO/SERVICES" );
+ for ( int nPos = 0; nPos < supported_services.length; ++nPos ) {
+ xNewKey.createKey( supported_services[ nPos ] );
+ }
+ return true;
+ } catch (com.sun.star.registry.InvalidRegistryException exc) {
+ if (DEBUG) {
+ System.err.println(
+ "##### " + Factory.class.getName() + ".writeRegistryServiceInfo -- exc: " +
+ exc.toString() );
+ }
+ }
+ return false;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/loader/JavaLoader.java b/ridljar/com/sun/star/comp/loader/JavaLoader.java
new file mode 100644
index 000000000000..8bc0ae228593
--- /dev/null
+++ b/ridljar/com/sun/star/comp/loader/JavaLoader.java
@@ -0,0 +1,439 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.loader;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URLDecoder;
+
+import com.sun.star.loader.CannotActivateFactoryException;
+import com.sun.star.loader.XImplementationLoader;
+
+import com.sun.star.registry.CannotRegisterImplementationException;
+import com.sun.star.registry.XRegistryKey;
+
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XInitialization;
+
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.util.XMacroExpander;
+
+import com.sun.star.uno.Type;
+import com.sun.star.uno.UnoRuntime;
+
+import com.sun.star.lib.util.StringHelper;
+
+import com.sun.star.uno.AnyConverter;
+
+
+/**
+ * The <code>JavaLoader</code> class provides the functionality of the
+ * <code>com.sun.star.loader.Java</code> service.
+ *
+ * <p>Therefore the <code>JavaLoader</code> activates external UNO components
+ * which are implemented in Java.</p>
+ *
+ * <p>The loader is used by the <code>ServiceManger</code>.</p>
+ *
+ * @see com.sun.star.loader.XImplementationLoader
+ * @see com.sun.star.loader.Java
+ * @see com.sun.star.comp.servicemanager.ServiceManager
+ * @since UDK1.0
+ */
+public class JavaLoader implements XImplementationLoader,
+ XServiceInfo,
+ XInitialization
+{
+ private static final boolean DEBUG = false;
+
+ private static final void DEBUG(String dbg) {
+ if (DEBUG) System.err.println( dbg );
+ }
+
+ private static String[] supportedServices = {
+ "com.sun.star.loader.Java"
+ };
+
+ protected XMultiServiceFactory multiServiceFactory = null;
+
+ private XMacroExpander m_xMacroExpander = null;
+ private static final String EXPAND_PROTOCOL_PREFIX = "vnd.sun.star.expand:";
+
+ /**
+ * Expands macrofied url using the macro expander singleton.
+ */
+ private String expand_url( String url ) throws RuntimeException
+ {
+ if (url == null || !url.startsWith( EXPAND_PROTOCOL_PREFIX )) {
+ return url;
+ }
+ try {
+ if (m_xMacroExpander == null) {
+ XPropertySet xProps =
+ UnoRuntime.queryInterface(
+ XPropertySet.class, multiServiceFactory );
+ if (xProps == null) {
+ throw new com.sun.star.uno.RuntimeException(
+ "service manager does not support XPropertySet!",
+ this );
+ }
+ XComponentContext xContext = (XComponentContext)
+ AnyConverter.toObject(
+ new Type( XComponentContext.class ),
+ xProps.getPropertyValue( "DefaultContext" ) );
+ m_xMacroExpander = (XMacroExpander)AnyConverter.toObject(
+ new Type( XMacroExpander.class ),
+ xContext.getValueByName(
+ "/singletons/com.sun.star.util.theMacroExpander" )
+ );
+ }
+ // decode uric class chars
+ String macro = URLDecoder.decode(
+ StringHelper.replace(
+ url.substring( EXPAND_PROTOCOL_PREFIX.length() ),
+ '+', "%2B" ), "UTF-8" );
+ // expand macro string
+ String ret = m_xMacroExpander.expandMacros( macro );
+ if (DEBUG) {
+ System.err.println(
+ "JavaLoader.expand_url(): " + url + " => " +
+ macro + " => " + ret );
+ }
+ return ret;
+ } catch (com.sun.star.uno.Exception exc) {
+ throw new com.sun.star.uno.RuntimeException(exc,
+ exc.getMessage(), this );
+ } catch (java.lang.Exception exc) {
+ throw new com.sun.star.uno.RuntimeException(exc,
+ exc.getMessage(), this );
+ }
+ }
+
+ /**
+ * Default constructor.
+ *
+ * <p>Creates a new instance of the <code>JavaLoader</code> class.</p>
+ */
+ public JavaLoader() {}
+
+ /**
+ * Creates a new <code>JavaLoader</code> object.
+ *
+ * <p>The specified <code>com.sun.star.lang.XMultiServiceFactory</code> is
+ * the <code>ServiceManager</code> service which can be delivered to all
+ * components the <code>JavaLoader</code> is loading.</p>
+ *
+ * <p>To set the <code>MultiServiceFactory</code> you can use the
+ * <code>com.sun.star.lang.XInitialization</code> interface, either.</p>
+ *
+ * @param factory the <code>ServiceManager</code>.
+ * @see com.sun.star.comp.servicemanager.ServiceManager
+ * @see com.sun.star.lang.XInitialization
+ */
+ public JavaLoader(XMultiServiceFactory factory) {
+ multiServiceFactory = factory;
+ }
+
+ /**
+ * Unlike the original intention, the method could be called every time a
+ * new <code>com.sun.star.lang.XMultiServiceFactory</code> should be set at
+ * the loader.
+ *
+ * @param args - the first parameter (args[0]) specifies the <code>ServiceManager</code>.
+ * @see com.sun.star.lang.XInitialization
+ * @see com.sun.star.comp.servicemanager.ServiceManager
+ */
+ public void initialize( java.lang.Object[] args )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (args.length == 0)
+ throw new com.sun.star.lang.IllegalArgumentException("No arguments specified");
+
+ try {
+ multiServiceFactory = (XMultiServiceFactory) AnyConverter.toObject(
+ new Type(XMultiServiceFactory.class), args[0]);
+ } catch (ClassCastException castEx) {
+ throw new com.sun.star.lang.IllegalArgumentException(castEx,
+ "The argument must be an instance of XMultiServiceFactory");
+ }
+ }
+
+ /**
+ * Supplies the implementation name of the component.
+ *
+ * @return the implementation name - here the class name.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return getClass().getName();
+ }
+
+ /**
+ * Verifies if a given service is supported by the component.
+ *
+ * @param serviceName the name of the service that should be checked.
+ * @return true,if service is supported - otherwise false.
+ *
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public boolean supportsService(String serviceName)
+ throws com.sun.star.uno.RuntimeException
+ {
+ for (String supportedService : supportedServices) {
+ if (supportedService.equals(serviceName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Supplies a list of all service names supported by the component.
+ *
+ * @return a String array with all supported services.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return supportedServices;
+ }
+
+ /**
+ * Provides a components factory.
+ *
+ * <p>The <code>JavaLoader</code> tries to load the class first. If a
+ * location URL is given the RegistrationClassFinder is used to load the
+ * class. Otherwise the class is loaded through the Class.forName method.</p>
+ *
+ * <p>To get the factory the inspects the class for the optional static member
+ * functions __getServiceFactory resp. getServiceFactory (DEPRECATED).</p>
+ *
+ * @param implementationName the implementation (class) name of the component.
+ * @param implementationLoaderUrl the URL of the implementation loader. Not used.
+ * @param locationUrl points to an archive (JAR file) which contains a component.
+ * @param xKey registry key.
+ * @return the factory for the component (@see com.sun.star.lang.XSingleServiceFactory)
+ *
+ * @see com.sun.star.loader.XImplementationLoader
+ * @see com.sun.star.comp.loader.RegistrationClassFinder
+ */
+ public java.lang.Object activate( String implementationName,
+ String implementationLoaderUrl,
+ String locationUrl,
+ XRegistryKey xKey )
+ throws CannotActivateFactoryException,
+ com.sun.star.uno.RuntimeException
+ {
+ locationUrl = expand_url( locationUrl );
+
+ Object returnObject = null;
+ Class<?> clazz ;
+
+ DEBUG("try to get factory for " + implementationName);
+
+ // First we must get the class of the implementation
+ // 1. If a location URL is given it is assumed that this points to a JAR file.
+ // The components class name is stored in the manifest file.
+ // 2. If only the implementation name is given, the class is loaded with the
+ // Class.forName() method. This is a hack to load bootstrap components.
+ // Normally a string must no be null.
+ try {
+ if ( locationUrl != null ) {
+ clazz = RegistrationClassFinder.find( locationUrl );
+ if (clazz == null) {
+ throw new CannotActivateFactoryException(
+ "Cannot activate jar " + locationUrl);
+ }
+ } else {
+ clazz = Class.forName( implementationName );
+ if (clazz == null) {
+ throw new CannotActivateFactoryException(
+ "Cannot find class " + implementationName);
+ }
+ }
+ } catch (java.net.MalformedURLException e) {
+ throw new CannotActivateFactoryException(e, "Can not activate factory because " + e);
+ } catch (java.io.IOException e) {
+ throw new CannotActivateFactoryException(e, "Can not activate factory because " + e);
+ } catch (java.lang.ClassNotFoundException e) {
+ throw new CannotActivateFactoryException(e, "Can not activate factory because " + e);
+ }
+
+ Class<?>[] paramTypes = {String.class, XMultiServiceFactory.class, XRegistryKey.class};
+ Object[] params = { implementationName, multiServiceFactory, xKey };
+
+ // try to get factory from implementation class
+ // latest style: use the public static method __getComponentFactory
+ // - new style: use the public static method __getServiceFactory
+ // - old style: use the public static method getServiceFactory ( DEPRECATED )
+
+ Method compfac_method = null;
+ try {
+ compfac_method = clazz.getMethod(
+ "__getComponentFactory", new Class [] { String.class } );
+ } catch ( NoSuchMethodException noSuchMethodEx) {
+ } catch ( SecurityException secEx) {
+ }
+
+ Method method = null;
+ if (null == compfac_method) {
+ try {
+ method = clazz.getMethod("__getServiceFactory", paramTypes);
+ } catch ( NoSuchMethodException noSuchMethodEx) {
+ } catch ( SecurityException secEx) {
+ }
+ }
+
+ try {
+ if (null != compfac_method) {
+ Object ret = compfac_method.invoke( clazz, new Object [] { implementationName } );
+ if (!(ret instanceof XSingleComponentFactory))
+ throw new CannotActivateFactoryException(
+ "No factory object for " + implementationName );
+
+ return ret;
+ }
+ else {
+ if ( method == null )
+ method = clazz.getMethod("getServiceFactory", paramTypes);
+
+ Object oRet = method.invoke(clazz, params);
+
+ if ( (oRet != null) && (oRet instanceof XSingleServiceFactory) )
+ returnObject = oRet;
+ }
+ } catch ( NoSuchMethodException e) {
+ throw new CannotActivateFactoryException(e, "Can not activate the factory for "
+ + implementationName);
+ } catch ( SecurityException e) {
+ throw new CannotActivateFactoryException(e, "Can not activate the factory for "
+ + implementationName);
+ } catch ( IllegalAccessException e ) {
+ throw new CannotActivateFactoryException(e, "Can not activate the factory for "
+ + implementationName);
+ }
+ catch ( IllegalArgumentException e ) {
+ throw new CannotActivateFactoryException(e, "Can not activate the factory for "
+ + implementationName);
+ } catch ( InvocationTargetException e ) {
+ throw new CannotActivateFactoryException(e, "Can not activate the factory for "
+ + implementationName);
+ }
+
+ return returnObject;
+ }
+
+ /**
+ * Registers the component in a registry under a given root key.
+ *
+ * <p>If the component supports the optional
+ * methods __writeRegistryServiceInfo, writeRegistryServiceInfo (DEPRECATED),
+ * the call is delegated to that method. Otherwise a default registration
+ * will be accomplished.</p>
+ *
+ * @param regKey the root key under that the component should be registered.
+ * @param implementationLoaderUrl specifies the loader, the component is loaded by.
+ * @param locationUrl points to an archive (JAR file) which contains a component.
+ * @return true if registration is successfully - otherwise false.
+ */
+ public boolean writeRegistryInfo( XRegistryKey regKey,
+ String implementationLoaderUrl,
+ String locationUrl )
+ throws CannotRegisterImplementationException,
+ com.sun.star.uno.RuntimeException
+ {
+ locationUrl = expand_url( locationUrl );
+
+ boolean success = false;
+
+ try {
+
+ Class<?> clazz = RegistrationClassFinder.find(locationUrl);
+ if (null == clazz)
+ throw new CannotRegisterImplementationException(
+ "Cannot determine registration class!" );
+
+ Class<?>[] paramTypes = { XRegistryKey.class };
+ Object[] params = { regKey };
+
+ Method method = clazz.getMethod("__writeRegistryServiceInfo", paramTypes);
+ Object oRet = method.invoke(clazz, params);
+
+ if ( (oRet != null) && (oRet instanceof Boolean) )
+ success = ((Boolean) oRet).booleanValue();
+ } catch (Exception e) {
+ throw new CannotRegisterImplementationException(e, e.toString());
+ }
+
+ return success;
+ }
+
+ /**
+ * Supplies the factory for the <code>JavaLoader</code>.
+ *
+ * @param implName the name of the desired component.
+ * @param multiFactory the <code>ServiceManager</code> is delivered to the factory.
+ * @param regKey not used - can be null.
+ * @return the factory for the <code>JavaLoader</code>.
+ */
+ public static XSingleServiceFactory getServiceFactory( String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ if ( implName.equals(JavaLoader.class.getName()) )
+ return new JavaLoaderFactory( multiFactory );
+
+ return null;
+ }
+
+ /**
+ * Registers the <code>JavaLoader</code> at the registry.
+ *
+ * @param regKey root key under which the <code>JavaLoader</code> should be registered.
+ * @return true if registration succeeded - otherwise false.
+ */
+ public static boolean writeRegistryServiceInfo(XRegistryKey regKey) {
+ boolean result = false;
+
+ try {
+ XRegistryKey newKey = regKey.createKey("/" + JavaLoader.class.getName() + "/UNO/SERVICE");
+
+ for (String supportedService : supportedServices) {
+ newKey.createKey(supportedService);
+ }
+
+ result = true;
+ } catch (Exception ex) {
+ if (DEBUG) System.err.println(">>>JavaLoader.writeRegistryServiceInfo " + ex);
+ }
+
+ return result;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/loader/JavaLoaderFactory.java b/ridljar/com/sun/star/comp/loader/JavaLoaderFactory.java
new file mode 100644
index 000000000000..edf4f7a3a4c7
--- /dev/null
+++ b/ridljar/com/sun/star/comp/loader/JavaLoaderFactory.java
@@ -0,0 +1,90 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.loader;
+
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+
+
+public class JavaLoaderFactory implements XSingleServiceFactory, XServiceInfo {
+
+ private static String[] supportedServices = {
+ "com.sun.star.loader.Java",
+ "com.sun.star.loader.Java2"
+ };
+
+ protected XMultiServiceFactory multiServiceFactory = null;
+
+ public JavaLoaderFactory(XMultiServiceFactory factory) {
+ multiServiceFactory = factory;
+ }
+
+ public java.lang.Object createInstance()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ return new JavaLoader(multiServiceFactory);
+ }
+
+ public java.lang.Object createInstanceWithArguments( java.lang.Object[] args )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ JavaLoader loader = new JavaLoader();
+ loader.initialize(args);
+
+ return loader;
+ }
+
+ /**
+ * Implements the XServiceInfo interface.
+ */
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return JavaLoader.class.getName();
+ }
+
+ /**
+ * Implements the XServiceInfo interface.
+ */
+ public boolean supportsService(String serviceName)
+ throws com.sun.star.uno.RuntimeException
+ {
+ for (String supportedService : supportedServices) {
+ if (supportedService.equals(serviceName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Implements the XServiceInfo interface.
+ */
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return supportedServices;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/loader/RegistrationClassFinder.java b/ridljar/com/sun/star/comp/loader/RegistrationClassFinder.java
new file mode 100644
index 000000000000..e7679da1670a
--- /dev/null
+++ b/ridljar/com/sun/star/comp/loader/RegistrationClassFinder.java
@@ -0,0 +1,69 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.loader;
+
+import com.sun.star.lib.unoloader.UnoClassLoader;
+import com.sun.star.lib.util.WeakMap;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.jar.Attributes;
+
+final class RegistrationClassFinder {
+ public static Class<?> find(String locationUrl)
+ throws ClassNotFoundException, IOException
+ {
+ synchronized (map) {
+ Class<?> c = (Class<?>) WeakMap.getValue(map.get(locationUrl));
+ if (c != null) {
+ return c;
+ }
+ }
+ URL url = new URL(locationUrl);
+ Attributes attr = UnoClassLoader.getJarMainAttributes(url);
+ String name = attr == null
+ ? null : attr.getValue("RegistrationClassName");
+ if (name == null) {
+ return null;
+ }
+ ClassLoader cl1 = RegistrationClassFinder.class.getClassLoader();
+ ClassLoader cl2;
+ if (cl1 instanceof UnoClassLoader) {
+ cl2 = ((UnoClassLoader) cl1).getClassLoader(url, attr);
+ } else {
+ cl2 = URLClassLoader.newInstance(new URL[] { url }, cl1);
+ }
+ Class<?> c = cl2.loadClass(name);
+ synchronized (map) {
+ Class<?> c2 = (Class<?>) WeakMap.getValue(map.get(locationUrl));
+ if (c2 != null) {
+ return c2;
+ }
+ map.put(locationUrl, c);
+ }
+ return c;
+ }
+
+ private RegistrationClassFinder() {} // do not instantiate
+
+ private static final WeakMap map = new WeakMap();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/servicemanager/ServiceManager.java b/ridljar/com/sun/star/comp/servicemanager/ServiceManager.java
new file mode 100644
index 000000000000..574983f1e238
--- /dev/null
+++ b/ridljar/com/sun/star/comp/servicemanager/ServiceManager.java
@@ -0,0 +1,662 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.servicemanager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import com.sun.star.container.XContentEnumerationAccess;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XSet;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+/**
+ * The <code>ServiceManager</code> class is an implementation of the
+ * <code>ServiceManager</code>the central class needed for implementing or using
+ * UNO components in Java.
+ *
+ * <p>The Methods <code>queryInterface</code> and <code>isSame</code> delegate
+ * calls to the implementing objects and are used instead of casts and identity
+ * comparisons.</p>
+ *
+ * @see com.sun.star.lang.XMultiServiceFactory
+ * @see com.sun.star.container.XSet
+ * @see com.sun.star.container.XContentEnumerationAccess
+ * @see com.sun.star.lang.XComponent
+ * @see com.sun.star.lang.XServiceInfo
+ * @since UDK1.0
+ */
+public class ServiceManager implements XMultiServiceFactory,
+ XMultiComponentFactory,
+ XSet,
+ XContentEnumerationAccess,
+ XComponent,
+ XServiceInfo
+{
+ private static final boolean DEBUG = false;
+
+ private static final void DEBUG (String dbg) {
+ if (DEBUG) System.err.println( dbg );
+ }
+
+ private static com.sun.star.uno.Type UNO_TYPE = null;
+
+ static String[] supportedServiceNames = {
+ "com.sun.star.lang.MultiServiceFactory",
+ "com.sun.star.lang.ServiceManager"
+ };
+
+ ArrayList<XEventListener> eventListener;
+ java.util.HashMap<String, Object> factoriesByImplNames;
+ java.util.HashMap<String, ArrayList<Object>> factoriesByServiceNames; // keys:
+
+ private com.sun.star.uno.XComponentContext m_xDefaultContext;
+
+ /**
+ * Creates a new instance of the <code>ServiceManager</code>.
+ */
+ public ServiceManager() {
+ eventListener = new ArrayList<XEventListener>();
+ factoriesByImplNames = new java.util.HashMap<String, Object>();
+ factoriesByServiceNames = new java.util.HashMap<String, ArrayList<Object>>();
+ m_xDefaultContext = null;
+ }
+
+ public void setDefaultContext(XComponentContext context) {
+ m_xDefaultContext = context;
+ }
+
+ /**
+ * Creates a new instance of a specified service.
+ *
+ * <p>Therefore the associated factory of the service is looked up and used
+ * to instantiate a new component. </p>
+ *
+ * @param serviceSpecifier indicates the service or component name.
+ * @return newly created component.
+ *
+ * @see com.sun.star.lang.XMultiServiceFactory
+ */
+ public java.lang.Object createInstance( String serviceSpecifier )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ return createInstanceWithContext( serviceSpecifier, m_xDefaultContext );
+ }
+
+ /**
+ * Creates a new instance of a specified service with the given parameters.
+ *
+ * <p>Therefore the associated factory of the service is looked up and used
+ * to instantiate a new component.</p>
+ *
+ * @return newly created component.
+ * @param serviceSpecifier indicates the service or component name.
+ * @see com.sun.star.lang.XMultiServiceFactory
+ */
+ public java.lang.Object createInstanceWithArguments(
+ String serviceSpecifier, Object[] args )
+ throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException
+ {
+ if (DEBUG) {
+ System.err.println("createInstanceWithArguments:" );
+
+ for (Object arg : args) {
+ System.err.print(" " + arg);
+ }
+
+ System.err.println();
+ }
+
+ return createInstanceWithArgumentsAndContext( serviceSpecifier, args, m_xDefaultContext );
+ }
+
+ /**
+ * Look up the factory for a given service or implementation name.
+ *
+ * <p>First the requested service name is search in the list of available
+ * services. If it can not be found the name is looked up in the implementation
+ * list.</p>
+ *
+ * @param serviceName indicates the service or implementation name.
+ * @return the factory of the service / implementation.
+ *
+ * @see com.sun.star.lang.XMultiServiceFactory
+ */
+ private Object queryServiceFactory(String serviceName)
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ DEBUG("queryServiceFactory for name " + serviceName );
+ Object factory = null;
+
+ if ( factoriesByServiceNames.containsKey( serviceName ) ) {
+ ArrayList<Object> availableFact = factoriesByServiceNames.get( serviceName );
+
+ DEBUG("");
+ DEBUG("available factories for " + serviceName +" "+ availableFact);
+ DEBUG("");
+
+ if ( !availableFact.isEmpty() )
+ factory = availableFact.get(availableFact.size()-1);
+
+ } else // not found in list of services - now try the implementations
+ factory = factoriesByImplNames.get( serviceName ); // return null if none is available
+
+ if (DEBUG) {
+ if (factory == null) System.err.println("service not registered");
+ else
+ System.err.println("service found:" + factory + " " + UnoRuntime.queryInterface(XSingleServiceFactory.class, factory));
+ }
+
+ if (factory == null)
+ throw new com.sun.star.uno.Exception("Query for service factory for " + serviceName + " failed.");
+
+ return factory;
+ }
+
+ /**
+ * Supplies a list of all available services names.
+ *
+ * @return list of Strings of all service names.
+ * @see com.sun.star.container.XContentEnumerationAccess
+ */
+ public String[] getAvailableServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ try{
+ return factoriesByServiceNames.keySet().toArray(
+ new String[ factoriesByServiceNames.size() ] );
+ } catch(Exception ex) {
+ throw new com.sun.star.uno.RuntimeException(ex);
+ }
+ }
+
+ // XMultiComponentFactory implementation
+
+ /** Create a service instance with given context.
+ *
+ * @param rServiceSpecifier service name.
+ * @param xContext context.
+ * @return service instance.
+ */
+ public java.lang.Object createInstanceWithContext(
+ String rServiceSpecifier,
+ com.sun.star.uno.XComponentContext xContext )
+ throws com.sun.star.uno.Exception
+ {
+ Object fac = queryServiceFactory( rServiceSpecifier );
+ if (fac != null)
+ {
+ XSingleComponentFactory xCompFac = UnoRuntime.queryInterface(
+ XSingleComponentFactory.class, fac );
+ if (xCompFac != null)
+ {
+ return xCompFac.createInstanceWithContext( xContext );
+ }
+ else
+ {
+ XSingleServiceFactory xServiceFac = UnoRuntime.queryInterface(
+ XSingleServiceFactory.class, fac );
+ if (xServiceFac != null)
+ {
+ if (DEBUG)
+ System.err.println( "### ignoring context raising service \"" + rServiceSpecifier + "\"!" );
+ return xServiceFac.createInstance();
+ }
+ else
+ {
+ throw new com.sun.star.uno.Exception(
+ "retrieved service factory object for \"" + rServiceSpecifier +
+ "\" does not export XSingleComponentFactory nor XSingleServiceFactory!" );
+ }
+ }
+ }
+ return null;
+ }
+ /**
+ * Create a service instance with given context and arguments.
+ *
+ * @param rServiceSpecifier service name.
+ * @param rArguments arguments.
+ * @param xContext context.
+ * @return service instance.
+ */
+ public java.lang.Object createInstanceWithArgumentsAndContext(
+ String rServiceSpecifier,
+ java.lang.Object[] rArguments,
+ com.sun.star.uno.XComponentContext xContext )
+ throws com.sun.star.uno.Exception
+ {
+ Object fac = queryServiceFactory( rServiceSpecifier );
+ if (fac != null)
+ {
+ XSingleComponentFactory xCompFac = UnoRuntime.queryInterface(
+ XSingleComponentFactory.class, fac );
+ if (xCompFac != null)
+ {
+ return xCompFac.createInstanceWithArgumentsAndContext( rArguments, xContext );
+ }
+ else
+ {
+ XSingleServiceFactory xServiceFac = UnoRuntime.queryInterface(
+ XSingleServiceFactory.class, fac );
+ if (xServiceFac != null)
+ {
+ if (DEBUG)
+ System.err.println( "### ignoring context raising service \"" + rServiceSpecifier + "\"!" );
+ return xServiceFac.createInstanceWithArguments( rArguments );
+ }
+ else
+ {
+ throw new com.sun.star.uno.Exception(
+ "retrieved service factory object for \"" + rServiceSpecifier +
+ "\" does not export XSingleComponentFactory nor XSingleServiceFactory!" );
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Removes all listeners from the <code>ServiceManager</code> and clears the
+ * list of the services.
+ *
+ * @see com.sun.star.lang.XComponent
+ */
+ public void dispose()
+ throws com.sun.star.uno.RuntimeException
+ {
+ if (eventListener != null) {
+ for (XEventListener listener : eventListener) {
+ listener.disposing(new com.sun.star.lang.EventObject(this));
+ }
+ eventListener.clear();
+ }
+
+ factoriesByServiceNames.clear();
+ factoriesByImplNames.clear();
+ }
+
+ /**
+ * Adds a new <code>EventListener</code>.
+ *
+ * <p>The listener is notified when a service is added (removed) to (from)
+ * the <code>ServiceManager</code>.</p>
+ *
+ * <p>If the listener is already registered a
+ * <code>com.sun.star.uno.RuntimeException</code> will be thrown.</p>
+ *
+ * @param xListener the new listener which should been added.
+ * @see com.sun.star.lang.XComponent
+ */
+ public void addEventListener( XEventListener xListener )
+ throws com.sun.star.uno.RuntimeException
+ {
+ if (xListener == null)
+ throw new com.sun.star.uno.RuntimeException("Listener must not be null");
+
+ if ( eventListener.contains(xListener) )
+ throw new com.sun.star.uno.RuntimeException("Listener already registered.");
+
+ eventListener.add(xListener);
+ }
+
+ /**
+ * Removes a <code>EventListener</code> from the <code>ServiceManager</code>.
+ *
+ * <p>If the listener is not registered a <code>com.sun.star.uno.RuntimeException</code>
+ * will be thrown.</p>
+ *
+ * @param xListener the new listener which should been removed.
+ * @see com.sun.star.lang.XComponent
+ */
+ public void removeEventListener( XEventListener xListener )
+ throws com.sun.star.uno.RuntimeException
+ {
+ if (xListener == null)
+ throw new com.sun.star.uno.RuntimeException("Listener must not be null");
+
+ if ( !eventListener.contains(xListener) )
+ throw new com.sun.star.uno.RuntimeException("Listener is not registered.");
+
+ eventListener.remove(xListener);
+ }
+
+ /**
+ * Checks if a component is registered at the <code>ServiceManager</code>.
+ *
+ * <p>The given object argument must provide a <code>XServiceInfo</code>
+ * interface.</p>
+ *
+ * @param object object which provides a <code>XServiceInfo</code> interface.
+ * @return true if the component is registered otherwise false.
+ *
+ * @see com.sun.star.container.XSet
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public boolean has( Object object )
+ throws com.sun.star.uno.RuntimeException
+ {
+ if (object == null)
+ throw new com.sun.star.uno.RuntimeException("The parameter must not been null");
+
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, object);
+
+ return xServiceInfo != null && UnoRuntime.areSame(factoriesByImplNames.get(xServiceInfo.getImplementationName()), object);
+ }
+
+ /**
+ * Adds a <code>SingleServiceFactory</code> to the <code>ServiceManager</code>.
+ *
+ * @param object factory which should be added.
+ * @see com.sun.star.container.XSet
+ * @see com.sun.star.lang.XSingleServiceFactory
+ */
+ public void insert( Object object )
+ throws com.sun.star.lang.IllegalArgumentException,
+ com.sun.star.container.ElementExistException,
+ com.sun.star.uno.RuntimeException
+ {
+ if (object == null) throw new com.sun.star.lang.IllegalArgumentException();
+
+ XServiceInfo xServiceInfo =
+ UnoRuntime.queryInterface(XServiceInfo.class, object);
+
+ if (xServiceInfo == null)
+ throw new com.sun.star.lang.IllegalArgumentException(
+ "The given object does not implement the XServiceInfo interface."
+ );
+
+ if ( factoriesByImplNames.containsKey( xServiceInfo.getImplementationName() ) ) {
+ throw new com.sun.star.container.ElementExistException(
+ xServiceInfo.getImplementationName() + " already registered"
+ );
+ }
+
+ DEBUG("add factory " + object.toString() + " for " + xServiceInfo.getImplementationName());
+ factoriesByImplNames.put( xServiceInfo.getImplementationName(), object );
+
+
+ String[] serviceNames = xServiceInfo.getSupportedServiceNames();
+ ArrayList<Object> vec ;
+
+ for (String serviceName : serviceNames) {
+ if (!factoriesByServiceNames.containsKey(serviceName)) {
+ DEBUG("> no registered services found under " + serviceName + ": adding...");
+ factoriesByServiceNames.put(serviceName, new ArrayList<Object>());
+ }
+ vec = factoriesByServiceNames.get(serviceName);
+ if (vec.contains( object )) {
+ System.err.println("The implementation " + xServiceInfo.getImplementationName() +
+ " already registered for the service " + serviceName + " - ignoring!");
+ } else {
+ vec.add(object);
+ }
+ }
+ }
+
+ /**
+ * Removes a <code>SingleServiceFactory</code> from the <code>ServiceManager</code>.
+ *
+ * @param object factory which should be removed.
+ * @see com.sun.star.container.XSet
+ * @see com.sun.star.lang.XSingleServiceFactory
+ */
+ public void remove( Object object )
+ throws com.sun.star.lang.IllegalArgumentException,
+ com.sun.star.container.NoSuchElementException,
+ com.sun.star.uno.RuntimeException
+ {
+ if (object == null)
+ throw new com.sun.star.lang.IllegalArgumentException(
+ "The given object must not be null."
+ );
+
+ XServiceInfo xServiceInfo =
+ UnoRuntime.queryInterface(XServiceInfo.class, object);
+
+ if (xServiceInfo == null)
+ throw new com.sun.star.lang.IllegalArgumentException(
+ "The given object does not implement the XServiceInfo interface."
+ );
+
+ XSingleServiceFactory xSingleServiceFactory =
+ UnoRuntime.queryInterface(XSingleServiceFactory.class, object);
+
+ if (xSingleServiceFactory == null)
+ throw new com.sun.star.lang.IllegalArgumentException(
+ "The given object does not implement the XSingleServiceFactory interface."
+ );
+
+ if ( factoriesByImplNames.remove( xServiceInfo.getImplementationName() ) == null )
+ throw new com.sun.star.container.NoSuchElementException(
+ xServiceInfo.getImplementationName() +
+ " is not registered as an implementation."
+ );
+
+ String[] serviceNames = xServiceInfo.getSupportedServiceNames();
+
+ for (String serviceName : serviceNames) {
+ if (factoriesByServiceNames.containsKey(serviceName)) {
+ ArrayList<Object> vec = factoriesByServiceNames.get(serviceName);
+ if (!vec.remove(object)) {
+ System.err.println("The implementation " + xServiceInfo.getImplementationName() +
+ " is not registered for the service " + serviceName + " - ignoring!");
+ }
+ // remove the vector if no implementations available for the service
+ if (vec.isEmpty()) {
+ factoriesByServiceNames.remove(serviceName);
+ }
+ }
+ }
+ }
+
+ /**
+ * Provides an enumeration of all registered services.
+ *
+ * @return an enumeration of all available services.
+ * @see com.sun.star.container.XEnumerationAccess
+ */
+ public XEnumeration createEnumeration()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return new ServiceEnumerationImpl( factoriesByImplNames.values().iterator() );
+ }
+
+ /**
+ * Provides the UNO type of the <code>ServiceManager</code>
+ *
+ * @return the UNO type of the <code>ServiceManager</code>.
+ * @see com.sun.star.container.XElementAccess
+ * @see com.sun.star.uno.TypeClass
+ */
+ public com.sun.star.uno.Type getElementType()
+ throws com.sun.star.uno.RuntimeException
+ {
+ if ( UNO_TYPE == null )
+ UNO_TYPE = new com.sun.star.uno.Type(ServiceManager.class);
+
+ return UNO_TYPE;
+ }
+
+ /**
+ * Checks if the any components are registered.
+ *
+ * @return true - if the list of the registered components is not empty - otherwise false.
+ * @see com.sun.star.container.XElementAccess
+ */
+ public boolean hasElements() {
+ return ! factoriesByImplNames.isEmpty();
+ }
+
+ /**
+ * Provides an enumeration of all factories for a specified service.
+ *
+ * @param serviceName name of the requested service.
+ * @return an enumeration for service name.
+ * @see com.sun.star.container.XContentEnumerationAccess
+ */
+ public XEnumeration createContentEnumeration( String serviceName )
+ throws com.sun.star.uno.RuntimeException
+ {
+ XEnumeration enumer ;
+
+ ArrayList<Object> serviceList = factoriesByServiceNames.get(serviceName);
+
+ if (serviceList != null)
+ enumer = new ServiceEnumerationImpl( serviceList.iterator() );
+ else
+ enumer = new ServiceEnumerationImpl();
+
+ return enumer;
+ }
+
+ /**
+ * Returns the implementation name of the <code>ServiceManager</code> component.
+ *
+ * @return the class name of the <code>ServiceManager</code>.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return getClass().getName();
+ }
+
+ /**
+ * Checks if the <code>ServiceManager</code> supports a service.
+ *
+ * @param serviceName service name which should be checked.
+ * @return true if the service is supported - otherwise false.
+ *
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public boolean supportsService( String serviceName )
+ throws com.sun.star.uno.RuntimeException
+ {
+ for (String supportedServiceName : supportedServiceNames) {
+ if (supportedServiceName.equals(serviceName)) {
+ return true;
+ }
+ }
+
+ return getImplementationName().equals(serviceName);
+ }
+
+ /**
+ * Supplies list of all supported services.
+ *
+ * @return a list of all supported service names.
+ * @see com.sun.star.lang.XServiceInfo
+ */
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return supportedServiceNames;
+ }
+
+ /**
+ * The <code>ServiceEnumerationImpl</code> class provides an
+ * implementation of the @see com.sun.star.container.XEnumeration interface.
+ *
+ * <p>It is an inner wrapper for a java.util.Enumeration object.</p>
+ *
+ * @see com.sun.star.lang.XSingleServiceFactory
+ * @see com.sun.star.lang.XServiceInfo
+ * @since UDK1.0
+ */
+ static class ServiceEnumerationImpl implements XEnumeration {
+ java.util.Iterator<Object> enumeration = null;
+
+ /**
+ * Constructs a new empty instance.
+ */
+ public ServiceEnumerationImpl() {
+ }
+
+ /**
+ * Constructs a new instance with a given enumeration.
+ *
+ * @param enumer is the enumeration which should been wrapped.
+ * @see com.sun.star.container.XEnumeration
+ */
+ public ServiceEnumerationImpl(java.util.Enumeration<Object> enumer) {
+ enumeration = Collections.list(enumer).iterator();
+ }
+
+ /**
+ * Constructs a new instance with a given enumeration.
+ *
+ * @param enumer is the enumeration which should been wrapped.
+ * @see com.sun.star.container.XEnumeration
+ */
+ public ServiceEnumerationImpl(java.util.Iterator<Object> enumer) {
+ enumeration = enumer;
+ }
+
+ /**
+ * Checks if the enumeration contains more elements.
+ *
+ * @return true if more elements are available - otherwise false.
+ * @see com.sun.star.container.XEnumeration
+ */
+ public boolean hasMoreElements()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return enumeration != null && enumeration.hasNext();
+
+ }
+
+ /**
+ * Returns the next element of the enumeration.
+ *
+ * <p>If no further elements available a com.sun.star.container.NoSuchElementException
+ * exception will be thrown.</p>
+ *
+ * @return the next element.
+ * @see com.sun.star.container.XEnumeration
+ */
+ public Object nextElement()
+ throws com.sun.star.container.NoSuchElementException,
+ com.sun.star.lang.WrappedTargetException,
+ com.sun.star.uno.RuntimeException
+ {
+ if (enumeration == null)
+ throw new com.sun.star.container.NoSuchElementException();
+
+ try {
+ return enumeration.next();
+ } catch (java.util.NoSuchElementException e) {
+ throw new com.sun.star.container.NoSuchElementException(e, e.toString());
+ }
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ridljar/com/sun/star/comp/urlresolver/UrlResolver.java b/ridljar/com/sun/star/comp/urlresolver/UrlResolver.java
new file mode 100644
index 000000000000..7585dabf6d2f
--- /dev/null
+++ b/ridljar/com/sun/star/comp/urlresolver/UrlResolver.java
@@ -0,0 +1,147 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.urlresolver;
+
+
+import com.sun.star.bridge.XBridge;
+import com.sun.star.bridge.XBridgeFactory;
+import com.sun.star.bridge.XUnoUrlResolver;
+
+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.IllegalArgumentException;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.registry.XRegistryKey;
+
+import com.sun.star.uno.UnoRuntime;
+
+
+/**
+ * This component gives a factory for an <code>UnoUrlResolver</code> service.
+ *
+ * @see com.sun.star.bridge.XBridgeFactory
+ * @see com.sun.star.connection.Connector
+ * @since UDK1.0
+ */
+public class UrlResolver {
+ public static class _UrlResolver implements XUnoUrlResolver {
+ private static final String __serviceName = "com.sun.star.bridge.UnoUrlResolver";
+
+ private final XMultiServiceFactory _xMultiServiceFactory;
+
+ public _UrlResolver(XMultiServiceFactory xMultiServiceFactory) {
+ _xMultiServiceFactory = xMultiServiceFactory;
+ }
+
+ public Object resolve(/*IN*/String dcp) throws NoConnectException, ConnectionSetupException, IllegalArgumentException, com.sun.star.uno.RuntimeException {
+ String conDcp ;
+ String protDcp ;
+ String rootOid ;
+
+ if(dcp.indexOf(';') == -1) {// use old style
+ conDcp = dcp;
+ protDcp = "iiop";
+ rootOid = "classic_uno";
+ }
+ else { // new style
+ int index = dcp.indexOf(':');
+ dcp = dcp.substring(index + 1).trim();
+
+ index = dcp.indexOf(';');
+ conDcp = dcp.substring(0, index).trim();
+ dcp = dcp.substring(index + 1).trim();
+
+ index = dcp.indexOf(';');
+ protDcp = dcp.substring(0, index).trim();
+ dcp = dcp.substring(index + 1).trim();
+
+ rootOid = dcp.trim().trim();
+ }
+
+ Object rootObject ;
+ XBridgeFactory xBridgeFactory ;
+ try {
+ xBridgeFactory = UnoRuntime.queryInterface(XBridgeFactory.class,
+ _xMultiServiceFactory.createInstance("com.sun.star.bridge.BridgeFactory"));
+ } catch (com.sun.star.uno.Exception e) {
+ throw new com.sun.star.uno.RuntimeException(e);
+ }
+ XBridge xBridge = xBridgeFactory.getBridge(conDcp + ";" + protDcp);
+
+ if(xBridge == null) {
+ Object connector ;
+ try {
+ connector = _xMultiServiceFactory.createInstance("com.sun.star.connection.Connector");
+ } catch (com.sun.star.uno.Exception e) {
+ throw new com.sun.star.uno.RuntimeException(e);
+ }
+
+ XConnector connector_xConnector = UnoRuntime.queryInterface(XConnector.class, connector);
+
+ // connect to the server
+ XConnection xConnection = connector_xConnector.connect(conDcp);
+ try {
+ xBridge = xBridgeFactory.createBridge(conDcp + ";" + protDcp, protDcp, xConnection, null);
+ } catch (com.sun.star.bridge.BridgeExistsException e) {
+ throw new com.sun.star.uno.RuntimeException(e);
+ }
+ }
+ rootObject = xBridge.getInstance(rootOid);
+ return rootObject;
+ }
+ }
+
+
+ /**
+ * Gives 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 desired.
+ * @param multiFactory the service manager to be uses if needed.
+ * @param regKey the registryKey.
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component.
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals(UrlResolver.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(_UrlResolver.class,
+ _UrlResolver.__serviceName,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */