1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Implementation.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.comp
.connections
;
33 import com
.sun
.star
.connection
.ConnectionSetupException
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
38 * Helper class for <code>Acceptor</code> and <code>Connector</code>.
40 final class Implementation
{
42 * Instantiate a service for a given connection type.
44 * @param factory the service factory used to instantiate the requested
46 * @param description has the following format:
47 * <code><var>type</var></code><!--
48 * -->*(<code><var>key</var>=<var>value</var></code>).
49 * The specific service implementation is instantiated through the
51 * <code>com.sun.star.connection.<var>type</var>service<var></var><!--
53 * (with <code><var>type</var></code> in lower case, and
54 * <code><var>service</var></code> either <code>Acceptor</code> or
55 * <code>Connector</code>).</p>
56 * @param serviceClass the IDL interface type for which to query the
58 * @param serviceType must be either <code>Acceptor</code> or
59 * <code>Connector</code>.
60 * @return an instance of the requested service. Never returns
62 * @throws ConnectionSetupException if the requested service can not be
63 * found, or cannot be instantiated.
65 public static Object
getConnectionService(XMultiServiceFactory factory
,
69 throws ConnectionSetupException
71 int i
= description
.indexOf(',');
73 = (i
< 0 ? description
: description
.substring(0, i
)).toLowerCase();
74 Object service
= null;
76 service
= UnoRuntime
.queryInterface(
78 factory
.createInstance("com.sun.star.connection." + type
80 } catch (RuntimeException e
) {
82 } catch (com
.sun
.star
.uno
.Exception e
) {
84 if (service
== null) {
85 // As a fallback, also try to instantiate the service from the
86 // com.sun.star.lib.connections package structure:
89 = Class
.forName("com.sun.star.lib.connections." + type
90 + "." + type
+ serviceType
).newInstance();
91 } catch (ClassNotFoundException e
) {
92 } catch (IllegalAccessException e
) {
93 } catch (InstantiationException e
) {
96 if (service
== null) {
97 throw new ConnectionSetupException("no " + serviceType
+ " for "
103 private Implementation() {} // do not instantiate