1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 package com
.sun
.star
.comp
.connections
;
22 import com
.sun
.star
.connection
.ConnectionSetupException
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
27 * Helper class for <code>Acceptor</code> and <code>Connector</code>.
29 final class Implementation
{
31 * Instantiate a service for a given connection type.
33 * @param factory the service factory used to instantiate the requested
35 * @param description has the following format:
36 * <code><var>type</var></code><!--
37 * -->*(<code><var>key</var>=<var>value</var></code>).
38 * The specific service implementation is instantiated through the
40 * <code>com.sun.star.connection.<var>type</var>service<var></var><!--
42 * (with <code><var>type</var></code> in lower case, and
43 * <code><var>service</var></code> either <code>Acceptor</code> or
44 * <code>Connector</code>).
45 * @param serviceClass the IDL interface type for which to query the
47 * @param serviceType must be either <code>Acceptor</code> or
48 * <code>Connector</code>.
49 * @return an instance of the requested service. Never returns
51 * @throws ConnectionSetupException if the requested service can not be
52 * found, or cannot be instantiated.
54 public static Object
getConnectionService(XMultiServiceFactory factory
,
56 Class
<?
> serviceClass
,
58 throws ConnectionSetupException
60 int i
= description
.indexOf(',');
62 = (i
< 0 ? description
: description
.substring(0, i
)).toLowerCase();
63 Object service
= null;
65 service
= UnoRuntime
.queryInterface(
67 factory
.createInstance("com.sun.star.connection." + type
69 } catch (RuntimeException e
) {
71 } catch (com
.sun
.star
.uno
.Exception e
) {
73 if (service
== null) {
74 // As a fallback, also try to instantiate the service from the
75 // com.sun.star.lib.connections package structure:
78 = Class
.forName("com.sun.star.lib.connections." + type
79 + "." + type
+ serviceType
).newInstance();
80 } catch (ClassNotFoundException e
) {
81 } catch (IllegalAccessException e
) {
82 } catch (InstantiationException e
) {
85 if (service
== null) {
86 throw new ConnectionSetupException("no " + serviceType
+ " for "
92 private Implementation() {} // do not instantiate
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */