2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com
.sun
.star
.comp
.connections
;
21 import com
.sun
.star
.connection
.ConnectionSetupException
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.uno
.UnoRuntime
;
26 * Helper class for <code>Acceptor</code> and <code>Connector</code>.
28 final class Implementation
{
30 * Instantiate a service for a given connection type.
32 * @param factory the service factory used to instantiate the requested
34 * @param description has the following format:
35 * <code><var>type</var></code><!--
36 * -->*(<code><var>key</var>=<var>value</var></code>).
37 * The specific service implementation is instantiated through the
39 * <code>com.sun.star.connection.<var>type</var>service<var></var><!--
41 * (with <code><var>type</var></code> in lower case, and
42 * <code><var>service</var></code> either <code>Acceptor</code> or
43 * <code>Connector</code>).</p>
44 * @param serviceClass the IDL interface type for which to query the
46 * @param serviceType must be either <code>Acceptor</code> or
47 * <code>Connector</code>.
48 * @return an instance of the requested service. Never returns
50 * @throws ConnectionSetupException if the requested service can not be
51 * found, or cannot be instantiated.
53 public static Object
getConnectionService(XMultiServiceFactory factory
,
55 Class
<?
> serviceClass
,
57 throws ConnectionSetupException
59 int i
= description
.indexOf(',');
61 = (i
< 0 ? description
: description
.substring(0, i
)).toLowerCase();
62 Object service
= null;
64 service
= UnoRuntime
.queryInterface(
66 factory
.createInstance("com.sun.star.connection." + type
68 } catch (RuntimeException e
) {
70 } catch (com
.sun
.star
.uno
.Exception e
) {
72 if (service
== null) {
73 // As a fallback, also try to instantiate the service from the
74 // com.sun.star.lib.connections package structure:
77 = Class
.forName("com.sun.star.lib.connections." + type
78 + "." + type
+ serviceType
).newInstance();
79 } catch (ClassNotFoundException e
) {
80 } catch (IllegalAccessException e
) {
81 } catch (InstantiationException e
) {
84 if (service
== null) {
85 throw new ConnectionSetupException("no " + serviceType
+ " for "
91 private Implementation() {} // do not instantiate