bump product version to 6.4.0.3
[LibreOffice.git] / jurt / com / sun / star / comp / connections / Implementation.java
blob94cabe253a33c75f070f62e8f0409a7cd2ed7e09
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
26 /**
27 * Helper class for <code>Acceptor</code> and <code>Connector</code>.
29 final class Implementation {
30 /**
31 * Instantiate a service for a given connection type.
33 * @param factory the service factory used to instantiate the requested
34 * service.
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
39 * service factory as
40 * <code>com.sun.star.connection.<var>type</var>service<var></var><!--
41 * --></code>
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
46 * requested service.
47 * @param serviceType must be either <code>Acceptor</code> or
48 * <code>Connector</code>.
49 * @return an instance of the requested service. Never returns
50 * <code>null</code>.
51 * @throws ConnectionSetupException if the requested service can not be
52 * found, or cannot be instantiated.
54 public static Object getConnectionService(XMultiServiceFactory factory,
55 String description,
56 Class<?> serviceClass,
57 String serviceType)
58 throws ConnectionSetupException
60 int i = description.indexOf(',');
61 String type
62 = (i < 0 ? description : description.substring(0, i)).toLowerCase();
63 Object service = null;
64 try {
65 service = UnoRuntime.queryInterface(
66 serviceClass,
67 factory.createInstance("com.sun.star.connection." + type
68 + serviceType));
69 } catch (RuntimeException e) {
70 throw 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:
76 try {
77 service
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 "
87 + type);
89 return service;
92 private Implementation() {} // do not instantiate
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */