summaryrefslogtreecommitdiffstats
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/helper/Bootstrap.java429
-rw-r--r--ridljar/com/sun/star/comp/helper/BootstrapException.java82
-rw-r--r--ridljar/com/sun/star/comp/helper/ComponentContext.java308
-rw-r--r--ridljar/com/sun/star/comp/helper/ComponentContextEntry.java64
-rw-r--r--ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java175
-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
17 files changed, 3934 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 000000000..031e60d3f
--- /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 000000000..996eaeb85
--- /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 000000000..6ffab9eea
--- /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 000000000..6c2fcb2d8
--- /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 000000000..94cabe253
--- /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 000000000..631cfae40
--- /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/helper/Bootstrap.java b/ridljar/com/sun/star/comp/helper/Bootstrap.java
new file mode 100644
index 000000000..edf21d7d2
--- /dev/null
+++ b/ridljar/com/sun/star/comp/helper/Bootstrap.java
@@ -0,0 +1,429 @@
+// -*- 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.helper;
+
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.loader.JavaLoader;
+import com.sun.star.comp.servicemanager.ServiceManager;
+import com.sun.star.container.XSet;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lib.util.NativeLibraryLoader;
+import com.sun.star.loader.XImplementationLoader;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Random;
+
+/** Bootstrap offers functionality to obtain a context or simply
+ a service manager.
+ The service manager can create a few basic services, whose implementations are:
+ <ul>
+ <li>com.sun.star.comp.loader.JavaLoader</li>
+ <li>com.sun.star.comp.urlresolver.UrlResolver</li>
+ <li>com.sun.star.comp.bridgefactory.BridgeFactory</li>
+ <li>com.sun.star.comp.connections.Connector</li>
+ <li>com.sun.star.comp.connections.Acceptor</li>
+ <li>com.sun.star.comp.servicemanager.ServiceManager</li>
+ </ul>
+
+ Other services can be inserted into the service manager by
+ using its XSet interface:
+ <pre>
+ XSet xSet = UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
+ // insert the service manager
+ xSet.insert( aSingleComponentFactory );
+ </pre>
+*/
+public class Bootstrap {
+
+ private static void insertBasicFactories(
+ XSet xSet, XImplementationLoader xImpLoader )
+ throws Exception
+ {
+ // insert the factory of the loader
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.loader.JavaLoader", null, null, null ) );
+
+ // insert the factory of the URLResolver
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) );
+
+ // insert the bridgefactory
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null ) );
+
+ // insert the connector
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.connections.Connector", null, null, null ) );
+
+ // insert the acceptor
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.connections.Acceptor", null, null, null ) );
+ }
+
+ /**
+ * Returns an array of default commandline options to start bootstrapped
+ * instance of soffice with. You may use it in connection with bootstrap
+ * method for example like this:
+ * <pre>
+ * List list = Arrays.asList( Bootstrap.getDefaultOptions() );
+ * list.remove("--nologo");
+ * list.remove("--nodefault");
+ * list.add("--invisible");
+ *
+ * Bootstrap.bootstrap( list.toArray( new String[list.size()] );
+ * </pre>
+ *
+ * @return an array of default commandline options
+ * @see #bootstrap( String[] )
+ * @since LibreOffice 5.1
+ */
+ public static final String[] getDefaultOptions()
+ {
+ return new String[]
+ {
+ "--nologo",
+ "--nodefault",
+ "--norestore",
+ "--nolockcheck"
+ };
+ }
+
+ /**
+ backwards compatibility stub.
+ @param context_entries the hash table contains mappings of entry names (type string) to
+ context entries (type class ComponentContextEntry).
+ @throws Exception if things go awry.
+ @return a new context.
+ */
+ public static XComponentContext createInitialComponentContext( Hashtable<String, Object> context_entries )
+ throws Exception
+ {
+ return createInitialComponentContext((Map<String, Object>) context_entries);
+ }
+ /** Bootstraps an initial component context with service manager and basic
+ jurt components inserted.
+ @param context_entries the hash table contains mappings of entry names (type string) to
+ context entries (type class ComponentContextEntry).
+ @throws Exception if things go awry.
+ @return a new context.
+ */
+ public static XComponentContext createInitialComponentContext( Map<String, Object> context_entries )
+ throws Exception
+ {
+ ServiceManager xSMgr = new ServiceManager();
+
+ XImplementationLoader xImpLoader = UnoRuntime.queryInterface(
+ XImplementationLoader.class, new JavaLoader() );
+ XInitialization xInit = UnoRuntime.queryInterface(
+ XInitialization.class, xImpLoader );
+ Object[] args = new Object [] { xSMgr };
+ xInit.initialize( args );
+
+ // initial component context
+ if (context_entries == null)
+ context_entries = new HashMap<String,Object>( 1 );
+ // add smgr
+ context_entries.put(
+ "/singletons/com.sun.star.lang.theServiceManager",
+ new ComponentContextEntry( null, xSMgr ) );
+ // ... xxx todo: add standard entries
+ XComponentContext xContext = new ComponentContext( context_entries, null );
+
+ xSMgr.setDefaultContext(xContext);
+
+ XSet xSet = UnoRuntime.queryInterface( XSet.class, xSMgr );
+ // insert basic jurt factories
+ insertBasicFactories( xSet, xImpLoader );
+
+ return xContext;
+ }
+
+ /**
+ * Bootstraps a servicemanager with the jurt base components registered.
+ *
+ * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code>.
+ *
+ * @throws Exception if things go awry.
+ * @return a freshly bootstrapped service manager
+ */
+ public static XMultiServiceFactory createSimpleServiceManager() throws Exception
+ {
+ return UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, createInitialComponentContext( (Map<String, Object>) null ).getServiceManager() );
+ }
+
+
+ /** Bootstraps the initial component context from a native UNO installation.
+
+ @throws Exception if things go awry.
+ @return a freshly bootstrapped component context.
+
+ See also
+ <code>cppuhelper/defaultBootstrap_InitialComponentContext()</code>.
+ */
+ public static final XComponentContext defaultBootstrap_InitialComponentContext()
+ throws Exception
+ {
+ return defaultBootstrap_InitialComponentContext( (String) null, (Map<String,String>) null );
+ }
+ /**
+ * Backwards compatibility stub.
+ *
+ * @param ini_file
+ * ini_file (may be null: uno.rc besides cppuhelper lib)
+ * @param bootstrap_parameters
+ * bootstrap parameters (maybe null)
+ *
+ * @throws Exception if things go awry.
+ * @return a freshly bootstrapped component context.
+ */
+ public static final XComponentContext defaultBootstrap_InitialComponentContext(
+ String ini_file, Hashtable<String,String> bootstrap_parameters )
+ throws Exception
+ {
+ return defaultBootstrap_InitialComponentContext(ini_file, (Map<String,String>) bootstrap_parameters);
+
+ }
+ /** Bootstraps the initial component context from a native UNO installation.
+
+ See also
+ <code>cppuhelper/defaultBootstrap_InitialComponentContext()</code>.
+
+ @param ini_file
+ ini_file (may be null: uno.rc besides cppuhelper lib)
+ @param bootstrap_parameters
+ bootstrap parameters (maybe null)
+
+ @throws Exception if things go awry.
+ @return a freshly bootstrapped component context.
+ */
+ public static final XComponentContext defaultBootstrap_InitialComponentContext(
+ String ini_file, Map<String,String> bootstrap_parameters )
+ throws Exception
+ {
+ // jni convenience: easier to iterate over array than calling Hashtable
+ String pairs [] = null;
+ if (null != bootstrap_parameters)
+ {
+ pairs = new String [ 2 * bootstrap_parameters.size() ];
+ int n = 0;
+ for (Map.Entry<String, String> bootstrap_parameter : bootstrap_parameters.entrySet()) {
+ pairs[ n++ ] = bootstrap_parameter.getKey();
+ pairs[ n++ ] = bootstrap_parameter.getValue();
+ }
+ }
+
+ if (! m_loaded_juh)
+ {
+ if ("The Android Project".equals(System.getProperty("java.vendor")))
+ {
+ // Find out if we are configured with DISABLE_DYNLOADING or
+ // not. Try to load the lo-bootstrap shared library which
+ // won't exist in the DISABLE_DYNLOADING case. (And which will
+ // be already loaded otherwise, so nothing unexpected happens
+ // that case.) Yeah, this would be simpler if I just could be
+ // bothered to keep a separate branch for DISABLE_DYNLOADING
+ // on Android, merging in master periodically, until I know
+ // for sure whether it is what I want, or not.
+
+ boolean disable_dynloading = false;
+ try {
+ System.loadLibrary( "lo-bootstrap" );
+ } catch ( UnsatisfiedLinkError e ) {
+ disable_dynloading = true;
+ }
+
+ if (!disable_dynloading)
+ {
+ NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" );
+ }
+ }
+ else
+ {
+ NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" );
+ }
+ m_loaded_juh = true;
+ }
+ return UnoRuntime.queryInterface(
+ XComponentContext.class,
+ cppuhelper_bootstrap(
+ ini_file, pairs, Bootstrap.class.getClassLoader() ) );
+ }
+
+ private static boolean m_loaded_juh = false;
+ private static native Object cppuhelper_bootstrap(
+ String ini_file, String bootstrap_parameters [], ClassLoader loader )
+ throws Exception;
+
+ /**
+ * Bootstraps the component context from a UNO installation.
+ *
+ * @throws BootstrapException if things go awry.
+ *
+ * @return a bootstrapped component context.
+ *
+ * @since UDK 3.1.0
+ */
+ public static final XComponentContext bootstrap()
+ throws BootstrapException {
+
+ String[] defaultArgArray = getDefaultOptions();
+ return bootstrap( defaultArgArray );
+ }
+
+ /**
+ * Bootstraps the component context from a UNO installation.
+ *
+ * @param argArray
+ * an array of strings - commandline options to start instance of
+ * soffice with
+ * @see #getDefaultOptions()
+ *
+ * @throws BootstrapException if things go awry.
+ *
+ * @return a bootstrapped component context.
+ *
+ * @since LibreOffice 5.1
+ */
+ public static final XComponentContext bootstrap( String[] argArray )
+ throws BootstrapException {
+
+ XComponentContext xContext = null;
+
+ try {
+ // create default local component context
+ XComponentContext xLocalContext =
+ createInitialComponentContext( (Map<String, Object>) null );
+ if ( xLocalContext == null )
+ throw new BootstrapException( "no local component context!" );
+
+ // find office executable relative to this class's class loader
+ String sOffice =
+ System.getProperty( "os.name" ).startsWith( "Windows" ) ?
+ "soffice.exe" : "soffice";
+ File fOffice = NativeLibraryLoader.getResource(
+ Bootstrap.class.getClassLoader(), sOffice );
+ if ( fOffice == null )
+ throw new BootstrapException( "no office executable found!" );
+
+ // create random pipe name
+ String sPipeName = "uno" +
+ Long.toString(randomPipeName.nextLong() & 0x7fffffffffffffffL);
+
+ // create call with arguments
+ String[] cmdArray = new String[ argArray.length + 2 ];
+ cmdArray[0] = fOffice.getPath();
+ cmdArray[1] = ( "--accept=pipe,name=" + sPipeName + ";urp;" );
+
+ System.arraycopy( argArray, 0, cmdArray, 2, argArray.length );
+
+ // start office process
+ Process p = Runtime.getRuntime().exec( cmdArray );
+ pipe( p.getInputStream(), System.out, "CO> " );
+ pipe( p.getErrorStream(), System.err, "CE> " );
+
+ // initial service manager
+ XMultiComponentFactory xLocalServiceManager =
+ xLocalContext.getServiceManager();
+ if ( xLocalServiceManager == null )
+ throw new BootstrapException( "no initial service manager!" );
+
+ // create a URL resolver
+ XUnoUrlResolver xUrlResolver =
+ UnoUrlResolver.create( xLocalContext );
+
+ // connection string
+ String sConnect = "uno:pipe,name=" + sPipeName +
+ ";urp;StarOffice.ComponentContext";
+
+ // wait until office is started
+ for (int i = 0;; ++i) {
+ try {
+ // try to connect to office
+ Object context = xUrlResolver.resolve( sConnect );
+ xContext = UnoRuntime.queryInterface(
+ XComponentContext.class, context);
+ if ( xContext == null )
+ throw new BootstrapException( "no component context!" );
+ break;
+ } catch ( com.sun.star.connection.NoConnectException ex ) {
+ // Wait 500 ms, then try to connect again, but do not wait
+ // longer than 5 min (= 600 * 500 ms) total:
+ if (i == 600) {
+ throw new BootstrapException(ex);
+ }
+ Thread.sleep( 500 );
+ }
+ }
+ } catch ( BootstrapException e ) {
+ throw e;
+ } catch ( java.lang.RuntimeException e ) {
+ throw e;
+ } catch ( java.lang.Exception e ) {
+ throw new BootstrapException( e );
+ }
+
+ return xContext;
+ }
+
+ private static final Random randomPipeName = new Random();
+
+ private static void pipe(
+ final InputStream in, final PrintStream out, final String prefix ) {
+
+ new Thread( "Pipe: " + prefix) {
+ @Override
+ public void run() {
+ try {
+ BufferedReader r = new BufferedReader(
+ new InputStreamReader(in, "UTF-8") );
+
+ for ( ; ; ) {
+ String s = r.readLine();
+ if ( s == null ) {
+ break;
+ }
+ out.println( prefix + s );
+ }
+ } catch ( UnsupportedEncodingException e ) {
+ e.printStackTrace( System.err );
+ } catch ( java.io.IOException e ) {
+ e.printStackTrace( System.err );
+ }
+ }
+ }.start();
+ }
+}
+
+// vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/ridljar/com/sun/star/comp/helper/BootstrapException.java b/ridljar/com/sun/star/comp/helper/BootstrapException.java
new file mode 100644
index 000000000..11911bbc0
--- /dev/null
+++ b/ridljar/com/sun/star/comp/helper/BootstrapException.java
@@ -0,0 +1,82 @@
+/*
+ * 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.helper;
+
+/**
+ * BootstrapException is a checked exception that wraps an exception
+ * thrown by the original target.
+ *
+ * @since UDK 3.1.0
+ */
+public class BootstrapException extends java.lang.Exception {
+
+ /**
+ * This field holds the target exception.
+ */
+ private Exception m_target = null;
+
+ /**
+ * Constructs a <code>BootstrapException</code> with <code>null</code> as
+ * the target exception.
+ */
+ public BootstrapException() {
+ super();
+ }
+
+ /**
+ * Constructs a <code>BootstrapException</code> with the specified
+ * detail message.
+ *
+ * @param message the detail message
+ */
+ public BootstrapException( String message ) {
+ super( message );
+ }
+
+ /**
+ * Constructs a <code>BootstrapException</code> with the specified
+ * detail message and a target exception.
+ *
+ * @param message the detail message
+ * @param target the target exception
+ */
+ public BootstrapException( String message, Exception target ) {
+ super( message );
+ m_target = target;
+ }
+
+ /**
+ * Constructs a <code>BootstrapException</code> with a target exception.
+ *
+ * @param target the target exception
+ */
+ public BootstrapException( Exception target ) {
+ super();
+ m_target = target;
+ }
+
+ /**
+ * Get the thrown target exception.
+ *
+ * @return the target exception
+ */
+ public Exception getTargetException() {
+ return m_target;
+ }
+}
diff --git a/ridljar/com/sun/star/comp/helper/ComponentContext.java b/ridljar/com/sun/star/comp/helper/ComponentContext.java
new file mode 100644
index 000000000..34649d563
--- /dev/null
+++ b/ridljar/com/sun/star/comp/helper/ComponentContext.java
@@ -0,0 +1,308 @@
+/*
+ * 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.helper;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Any;
+
+import com.sun.star.uno.DeploymentException;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.EventObject;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Map;
+
+
+
+class Disposer implements XEventListener
+{
+ private final XComponent m_xComp;
+
+
+ Disposer( XComponent xComp )
+ {
+ m_xComp = xComp;
+ }
+
+ public void disposing( EventObject Source )
+ {
+ m_xComp.dispose();
+ }
+}
+
+/** Component context implementation.
+*/
+public class ComponentContext implements XComponentContext, XComponent
+{
+ private static final boolean DEBUG = false;
+ private static final String SMGR_NAME = "/singletons/com.sun.star.lang.theServiceManager";
+ private static final String TDMGR_NAME = "/singletons/com.sun.star.reflection.theTypeDescriptionManager";
+
+ private Map<String,Object> m_table;
+ private XComponentContext m_xDelegate;
+
+ private XMultiComponentFactory m_xSMgr;
+ private boolean m_bDisposeSMgr;
+
+ private ArrayList<XEventListener> m_eventListener;
+
+ public ComponentContext( Hashtable<String,Object> table, XComponentContext xDelegate )
+ {
+ this((Map<String,Object>) table, xDelegate);
+ }
+
+ /** Ctor to create a component context passing a hashtable for values and a delegator
+ reference. Entries of the passed hashtable are either direct values or
+ ComponentContextEntry objects.
+
+ @param table
+ entries
+ @param xDelegate
+ if values are not found, request is delegated to this object
+ */
+ public ComponentContext( Map<String,Object> table, XComponentContext xDelegate )
+ {
+ m_eventListener = new ArrayList<XEventListener>();
+ m_table = table;
+ m_xDelegate = xDelegate;
+ m_xSMgr = null;
+ m_bDisposeSMgr = false;
+
+ Object o = table.get( SMGR_NAME );
+ if (o != null)
+ {
+ if (o instanceof ComponentContextEntry)
+ {
+ o = ((ComponentContextEntry)o).m_value;
+ }
+ m_xSMgr = UnoRuntime.queryInterface(
+ XMultiComponentFactory.class, o );
+ }
+ if (m_xSMgr != null)
+ {
+ m_bDisposeSMgr = true;
+ }
+ else if (m_xDelegate != null)
+ {
+ m_xSMgr = m_xDelegate.getServiceManager();
+ }
+
+ // listen for delegate
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, m_xDelegate );
+ if (xComp != null)
+ {
+ xComp.addEventListener( new Disposer( this ) );
+ }
+ }
+
+ // XComponentContext impl
+
+ public Object getValueByName( String rName )
+ {
+ Object o = m_table.get( rName );
+ if (o == null)
+ {
+ if (m_xDelegate != null)
+ {
+ return m_xDelegate.getValueByName( rName );
+ }
+ else
+ {
+ return Any.VOID;
+ }
+ }
+
+ if (!(o instanceof ComponentContextEntry))
+ {
+ // direct value in map
+ return o;
+ }
+
+ ComponentContextEntry entry = (ComponentContextEntry)o;
+ if (entry.m_lateInit == null)
+ {
+ return entry.m_value;
+ }
+
+ Object xInstance = null;
+ try
+ {
+ String serviceName = (String)entry.m_lateInit;
+ if (serviceName != null)
+ {
+ if (m_xSMgr != null)
+ {
+ xInstance = m_xSMgr.createInstanceWithContext( serviceName, this );
+ }
+ else
+ {
+ if (DEBUG)
+ System.err.println( "### no service manager instance for late init of singleton instance \"" + rName + "\"!" );
+ }
+ }
+ else
+ {
+ XSingleComponentFactory xCompFac = UnoRuntime.queryInterface( XSingleComponentFactory.class, entry.m_lateInit );
+ if (xCompFac != null)
+ {
+ xInstance = xCompFac.createInstanceWithContext( this );
+ }
+ else
+ {
+ if (DEBUG)
+ System.err.println( "### neither service name nor service factory given for late init of singleton instance \"" + rName + "\"!" );
+ }
+ }
+ }
+ catch (com.sun.star.uno.Exception exc)
+ {
+ if (DEBUG)
+ System.err.println( "### exception occurred on late init of singleton instance \"" + rName + "\": " + exc.getMessage() );
+ }
+
+ if (xInstance != null)
+ {
+ synchronized (entry)
+ {
+ if (entry.m_lateInit != null)
+ {
+ entry.m_value = xInstance;
+ entry.m_lateInit = null;
+ }
+ else // inited in the meantime
+ {
+ // dispose fresh service instance
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, xInstance );
+ if (xComp != null)
+ {
+ xComp.dispose();
+ }
+ }
+ }
+ }
+ else
+ {
+ if (DEBUG)
+ System.err.println( "### failed late init of singleton instance \"" + rName + "\"!" );
+ }
+ return entry.m_value;
+ }
+
+ public XMultiComponentFactory getServiceManager()
+ {
+ if (m_xSMgr == null)
+ {
+ throw new DeploymentException(
+ "null component context service manager" );
+ }
+ return m_xSMgr;
+ }
+
+ // XComponent impl
+
+ public void dispose()
+ {
+ if (DEBUG)
+ System.err.print( "> disposing context " + this );
+
+ // fire events
+ EventObject evt = new EventObject( this );
+ for (XEventListener listener : m_eventListener)
+ {
+ listener.disposing( evt );
+ }
+ m_eventListener.clear();
+
+ XComponent tdmgr = null;
+ // dispose values, then service manager, then typedescription manager
+ for (Map.Entry<String, Object> entry : m_table.entrySet())
+ {
+ String name = entry.getKey();
+ if (! name.equals( SMGR_NAME ))
+ {
+ Object o = entry.getValue();
+ if (o instanceof ComponentContextEntry)
+ {
+ o = ((ComponentContextEntry)o).m_value;
+ }
+
+ XComponent xComp = UnoRuntime.queryInterface( XComponent.class, o );
+ if (xComp != null)
+ {
+ if (name.equals( TDMGR_NAME ))
+ {
+ tdmgr = xComp;
+ }
+ else
+ {
+ xComp.dispose();
+ }
+ }
+ }
+ }
+ m_table.clear();
+
+ // smgr
+ if (m_bDisposeSMgr)
+ {
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, m_xSMgr );
+ if (xComp != null)
+ {
+ xComp.dispose();
+ }
+ }
+ m_xSMgr = null;
+
+ // tdmgr
+ if (tdmgr != null)
+ {
+ tdmgr.dispose();
+ }
+
+ if (DEBUG)
+ System.err.println( "... finished" );
+ }
+
+ public void addEventListener( XEventListener xListener )
+ {
+ if (xListener == null)
+ throw new com.sun.star.uno.RuntimeException( "Listener must not be null" );
+ if (m_eventListener.contains( xListener ))
+ throw new com.sun.star.uno.RuntimeException( "Listener already registered." );
+
+ m_eventListener.add( xListener );
+ }
+
+ public void removeEventListener( XEventListener xListener )
+ {
+ if (xListener == null)
+ throw new com.sun.star.uno.RuntimeException( "Listener must not be null" );
+ if (! m_eventListener.contains( xListener ))
+ throw new com.sun.star.uno.RuntimeException( "Listener is not registered." );
+
+ m_eventListener.remove( xListener );
+ }
+}
diff --git a/ridljar/com/sun/star/comp/helper/ComponentContextEntry.java b/ridljar/com/sun/star/comp/helper/ComponentContextEntry.java
new file mode 100644
index 000000000..aa402d29c
--- /dev/null
+++ b/ridljar/com/sun/star/comp/helper/ComponentContextEntry.java
@@ -0,0 +1,64 @@
+/*
+ * 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.helper;
+
+/** Component context entry for constructing ComponentContext objects.
+ <p>
+ A ComponentContextEntry is separated into a late-init and direct-value
+ purpose.
+ The first one is commonly used for singleton objects of the component
+ context, that are raised on first-time retrieval of the key.
+ You have to pass a com.sun.star.lang.XSingleComponentFactory
+ or string (=&gt; service name) object for this.
+ </p>
+*/
+public class ComponentContextEntry
+{
+ /** if late init of service instance, set service name (String) or
+ component factory (XSingleComponentFactory), null otherwise
+ */
+ public Object m_lateInit;
+ /** set entry value
+ */
+ public Object m_value;
+
+ /** Creating a late-init singleton entry component context entry.
+ The second parameter will be ignored and overwritten during
+ instantiation of the singleton instance.
+
+ @param lateInit
+ object factory or service string
+ @param value
+ pass null (dummy separating from second constructor signature)
+ */
+ public ComponentContextEntry( Object lateInit, Object value )
+ {
+ this.m_lateInit = lateInit;
+ this.m_value = value;
+ }
+ /** Creating a direct value component context entry.
+
+ @param value
+ pass null
+ */
+ public ComponentContextEntry( Object value )
+ {
+ this.m_lateInit = null;
+ this.m_value = value;
+ }
+}
diff --git a/ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java b/ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java
new file mode 100644
index 000000000..035644efa
--- /dev/null
+++ b/ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java
@@ -0,0 +1,175 @@
+// -*- 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.helper;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.registry.XRegistryKey;
+
+/**
+ * @deprecated use class Bootstrap bootstrapping a native UNO installation
+ * and use the shared library loader service.
+ *
+ * The <code>SharedLibraryLoader</code> class provides the functionality of the <code>com.sun.star.loader.SharedLibrary</code>
+ * service.
+ *
+ * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code>.
+ *
+ * @see com.sun.star.loader.SharedLibrary
+ */
+@Deprecated
+public class SharedLibraryLoader {
+ /**
+ * The default library which contains the SharedLibraryLoader component
+ */
+ public static final String DEFAULT_LIBRARY = "shlibloader.uno";
+
+ /**
+ * The default implementation name
+ */
+ public static final String DEFAULT_IMPLEMENTATION = "com.sun.star.comp.stoc.DLLComponentLoader";
+
+ static {
+ if ("The Android Project".equals(System.getProperty("java.vendor"))) {
+ // See corresponding code in
+ // javaunohelper/com/sun/star/comp/helper/Bootstrap.java for more
+ // comments.
+
+ boolean disable_dynloading = false;
+ try {
+ System.loadLibrary("lo-bootstrap");
+ } catch (UnsatisfiedLinkError e) {
+ disable_dynloading = true;
+ }
+
+ if (!disable_dynloading)
+ System.loadLibrary("juh");
+ } else
+ System.loadLibrary("juh");
+ }
+
+ private static native boolean component_writeInfo(
+ String libName, XMultiServiceFactory smgr, XRegistryKey regKey,
+ ClassLoader loader );
+
+ private static native Object component_getFactory(
+ String libName, String implName, XMultiServiceFactory smgr,
+ XRegistryKey regKey, ClassLoader loader );
+
+ /**
+ * Supplies the ServiceFactory of the default SharedLibraryLoader.
+ * The defaults are "shlibloader.uno"
+ * for the library and "com.sun.star.comp.stoc.DLLComponentLoader"
+ * for the component name.
+ *
+ * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
+ * <code>com.sun.star.registry.RegistryKey</code>.
+ *
+ * @return the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component.
+ * @param smgr the ServiceManager
+ * @param regKey the root registry key
+ * @see com.sun.star.loader.SharedLibrary
+ */
+ public static XSingleServiceFactory getServiceFactory(
+ XMultiServiceFactory smgr,
+ XRegistryKey regKey )
+ {
+ return UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ component_getFactory(
+ DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey,
+ SharedLibraryLoader.class.getClassLoader() ) );
+ }
+
+ /**
+ * Loads and returns a specific factory for a given library and implementation name.
+ *
+ * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
+ * <code>com.sun.star.registry.RegistryKey</code>.
+ *
+ * @return the factory of the component
+ * @param libName the name of the shared library
+ * @param impName the implementation name of the component
+ * @param smgr the ServiceManager
+ * @param regKey the root registry key
+ * @see com.sun.star.loader.SharedLibrary
+ */
+ public static XSingleServiceFactory getServiceFactory(
+ String libName,
+ String impName,
+ XMultiServiceFactory smgr,
+ XRegistryKey regKey )
+ {
+ return UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ component_getFactory(
+ libName, impName, smgr, regKey,
+ SharedLibraryLoader.class.getClassLoader() ) );
+ }
+
+ /**
+ * Registers the SharedLibraryLoader under a RegistryKey.
+ *
+ * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
+ * <code>com.sun.star.registry.RegistryKey</code>.
+ *
+ * @return true if the registration was successful - otherwise false
+ * @param smgr the ServiceManager
+ * @param regKey the root key under that the component should be registered
+ * @see com.sun.star.loader.SharedLibrary
+ */
+ public static boolean writeRegistryServiceInfo(
+ com.sun.star.lang.XMultiServiceFactory smgr,
+ com.sun.star.registry.XRegistryKey regKey )
+ {
+ return component_writeInfo(
+ DEFAULT_LIBRARY, smgr, regKey,
+ SharedLibraryLoader.class.getClassLoader() );
+ }
+
+ /**
+ * Registers the SharedLibraryLoader under a RegistryKey.
+ *
+ * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
+ * <code>com.sun.star.registry.RegistryKey</code>.
+ *
+ * @return true if the registration was successful - otherwise false
+ * @param libName name of the shared library
+ * @param smgr the ServiceManager
+ * @param regKey the root key under that the component should be registered
+ * @throws com.sun.star.registry.InvalidRegistryException
+ * if the registry is not valid.
+ *
+ * @see com.sun.star.loader.SharedLibrary
+ */
+ public static boolean writeRegistryServiceInfo(
+ String libName,
+ com.sun.star.lang.XMultiServiceFactory smgr,
+ com.sun.star.registry.XRegistryKey regKey )
+
+ throws com.sun.star.registry.InvalidRegistryException,
+ com.sun.star.uno.RuntimeException
+ {
+ return component_writeInfo(
+ libName, smgr, regKey, SharedLibraryLoader.class.getClassLoader() );
+ }
+}
+
+// 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 000000000..fe56f594f
--- /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 000000000..42dee0da5
--- /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>ServiceManager</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 000000000..edf4f7a3a
--- /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 000000000..e7679da16
--- /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 000000000..574983f1e
--- /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 000000000..7585dabf6
--- /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: */