bump product version to 6.4.0.3
[LibreOffice.git] / jurt / com / sun / star / comp / connections / Acceptor.java
blob44d8ef3e34f1471cb106fa1c082e9d1a168db0b3
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.AlreadyAcceptingException;
24 import com.sun.star.connection.ConnectionSetupException;
25 import com.sun.star.connection.XAcceptor;
26 import com.sun.star.connection.XConnection;
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>XAcceptor</code> interface.
34 * <p>The <code>Acceptor</code> is a general component, that uses less general
35 * components (like <code>com.sun.star.connection.socketAcceptor</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 final class Acceptor implements XAcceptor {
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.Acceptor";
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(Acceptor.class.getName())
73 ? FactoryHelper.getServiceFactory(Acceptor.class, __serviceName,
74 multiFactory, regKey)
75 : null;
78 /**
79 * Constructs a new <code>Acceptor</code> that uses the given service
80 * factory to create a specific <code>XAcceptor</code>.
82 * @param serviceFactory the service factory to use.
84 public Acceptor(XMultiServiceFactory serviceFactory) {
85 this.serviceFactory = serviceFactory;
88 /**
89 * Accepts a connection request via the given connection type.
91 * <p>This call blocks until a connection has been established.</p>
93 * <p>The connection description has the following format:
94 * <code><var>type</var></code><!--
95 * -->*(<code><var>key</var>=<var>value</var></code>).
96 * The specific <code>XAcceptor</code> implementation is instantiated
97 * through the service factory as
98 * <code>com.sun.star.connection.<var>type</var>Acceptor</code> (with
99 * <code><var>type</var></code> in lower case).</p>
101 * @param connectionDescription the description of the connection.
102 * @return an <code>XConnection</code> to the client.
104 * @see com.sun.star.connection.XConnection
105 * @see com.sun.star.connection.XConnector
107 public XConnection accept(String connectionDescription) throws
108 AlreadyAcceptingException, ConnectionSetupException,
109 com.sun.star.lang.IllegalArgumentException
111 if (DEBUG) {
112 System.err.println("##### " + getClass().getName() + ".accept("
113 + connectionDescription + ")");
115 XAcceptor acc;
116 synchronized (this) {
117 if (acceptor == null) {
118 acceptor = (XAcceptor) Implementation.getConnectionService(
119 serviceFactory, connectionDescription, XAcceptor.class,
120 "Acceptor");
121 acceptingDescription = connectionDescription;
122 } else if (!connectionDescription.equals(acceptingDescription)) {
123 throw new AlreadyAcceptingException(acceptingDescription
124 + " vs. "
125 + connectionDescription);
127 acc = acceptor;
129 return acc.accept(connectionDescription);
134 * @see com.sun.star.connection.XAcceptor#stopAccepting
136 public void stopAccepting() {
137 XAcceptor acc;
138 synchronized (this) {
139 acc = acceptor;
141 acc.stopAccepting();
144 private static final boolean DEBUG = false;
146 private final XMultiServiceFactory serviceFactory;
148 private XAcceptor acceptor = null;
149 private String acceptingDescription;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */