bump product version to 6.4.0.3
[LibreOffice.git] / jurt / com / sun / star / comp / connections / Connector.java
blob6ffab9eea86b0353a679c8131d02b47afcf06c0c
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.comp.loader.FactoryHelper;
23 import com.sun.star.connection.ConnectionSetupException;
24 import com.sun.star.connection.NoConnectException;
25 import com.sun.star.connection.XConnection;
26 import com.sun.star.connection.XConnector;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.lang.XSingleServiceFactory;
29 import com.sun.star.registry.XRegistryKey;
31 /**
32 * A component that implements the <code>XConnector</code> interface.
34 * <p>The <code>Connector</code> is a general component, that uses less general
35 * components (like <code>com.sun.star.connection.socketConnector</code>) to
36 * implement its functionality.</p>
38 * @see com.sun.star.connection.XAcceptor
39 * @see com.sun.star.connection.XConnection
40 * @see com.sun.star.connection.XConnector
41 * @see com.sun.star.comp.loader.JavaLoader
43 * @since UDK 1.0
45 public class Connector implements XConnector {
46 /**
47 * The name of the service.
49 * <p>The <code>JavaLoader</code> accesses this through reflection.</p>
51 * @see com.sun.star.comp.loader.JavaLoader
53 public static final String __serviceName
54 = "com.sun.star.connection.Connector";
56 /**
57 * Returns a factory for creating the service.
59 * <p>This method is called by the <code>JavaLoader</code>.</p>
61 * @param implName the name of the implementation for which a service is
62 * requested.
63 * @param multiFactory the service manager to be used (if needed).
64 * @param regKey the registry key.
65 * @return an <code>XSingleServiceFactory</code> for creating the component.
67 * @see com.sun.star.comp.loader.JavaLoader
69 public static XSingleServiceFactory __getServiceFactory(
70 String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
72 return implName.equals(Connector.class.getName())
73 ? FactoryHelper.getServiceFactory(Connector.class, __serviceName,
74 multiFactory, regKey)
75 : null;
78 /**
79 * Constructs a new <code>Connector</code> that uses the given service
80 * factory to create a specific <code>XConnector</code>.
82 * @param serviceFactory the service factory to use.
84 public Connector(XMultiServiceFactory serviceFactory) {
85 this.serviceFactory = serviceFactory;
88 /**
89 * Connects via the given connection type to a waiting server.
91 * <p>The connection description has the following format:
92 * <code><var>type</var></code><!--
93 * -->*(<code><var>key</var>=<var>value</var></code>).
94 * The specific <code>XConnector</code> implementation is instantiated
95 * through the service factory as
96 * <code>com.sun.star.connection.<var>type</var>Connector</code> (with
97 * <code><var>type</var></code> in lower case).</p>
99 * @param connectionDescription the description of the connection.
100 * @return an <code>XConnection</code> to the server.
102 * @see com.sun.star.connection.XAcceptor
103 * @see com.sun.star.connection.XConnection
105 public synchronized XConnection connect(String connectionDescription)
106 throws NoConnectException, ConnectionSetupException
108 if (DEBUG) {
109 System.err.println("##### " + getClass().getName() + ".connect("
110 + connectionDescription + ")");
112 if (connected) {
113 throw new ConnectionSetupException("already connected");
115 XConnection con
116 = ((XConnector) Implementation.getConnectionService(
117 serviceFactory, connectionDescription, XConnector.class,
118 "Connector")).connect(connectionDescription);
119 connected = true;
120 return con;
123 private static final boolean DEBUG = false;
125 private final XMultiServiceFactory serviceFactory;
127 private boolean connected = false;
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */