fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / jurt / com / sun / star / comp / connections / Implementation.java
blob49aba665d6faf1f3f67f64ff8843f37ca8d6286c
1 /*
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;
25 /**
26 * Helper class for <code>Acceptor</code> and <code>Connector</code>.
28 final class Implementation {
29 /**
30 * Instantiate a service for a given connection type.
32 * @param factory the service factory used to instantiate the requested
33 * service.
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
38 * service factory as
39 * <code>com.sun.star.connection.<var>type</var>service<var></var><!--
40 * --></code>
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
45 * requested service.
46 * @param serviceType must be either <code>Acceptor</code> or
47 * <code>Connector</code>.
48 * @return an instance of the requested service. Never returns
49 * <code>null</code>.
50 * @throws ConnectionSetupException if the requested service can not be
51 * found, or cannot be instantiated.
53 public static Object getConnectionService(XMultiServiceFactory factory,
54 String description,
55 Class<?> serviceClass,
56 String serviceType)
57 throws ConnectionSetupException
59 int i = description.indexOf(',');
60 String type
61 = (i < 0 ? description : description.substring(0, i)).toLowerCase();
62 Object service = null;
63 try {
64 service = UnoRuntime.queryInterface(
65 serviceClass,
66 factory.createInstance("com.sun.star.connection." + type
67 + serviceType));
68 } catch (RuntimeException e) {
69 throw 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:
75 try {
76 service
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 "
86 + type);
88 return service;
91 private Implementation() {} // do not instantiate