Update ooo320-m1
[ooovba.git] / jurt / com / sun / star / comp / connections / Acceptor.java
blobd76119c4c2af51595cdce648c49ee71da84b705e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Acceptor.java,v $
10 * $Revision: 1.5 $
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.comp.loader.FactoryHelper;
34 import com.sun.star.connection.AlreadyAcceptingException;
35 import com.sun.star.connection.ConnectionSetupException;
36 import com.sun.star.connection.XAcceptor;
37 import com.sun.star.connection.XConnection;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.lang.XSingleServiceFactory;
40 import com.sun.star.registry.XRegistryKey;
42 /**
43 * A component that implements the <code>XAcceptor</code> interface.
45 * <p>The <code>Acceptor</code> is a general component, that uses less general
46 * components (like <code>com.sun.star.connection.socketAcceptor</code>) to
47 * implement its functionality.</p>
49 * @see com.sun.star.connections.XAcceptor
50 * @see com.sun.star.connections.XConnection
51 * @see com.sun.star.connections.XConnector
52 * @see com.sun.star.loader.JavaLoader
54 * @since UDK 1.0
56 public final class Acceptor implements XAcceptor {
57 /**
58 * The name of the service.
60 * <p>The <code>JavaLoader</code> acceses this through reflection.</p>
62 * @see com.sun.star.comp.loader.JavaLoader
64 public static final String __serviceName
65 = "com.sun.star.connection.Acceptor";
67 /**
68 * Returns a factory for creating the service.
70 * <p>This method is called by the <code>JavaLoader</code>.</p>
72 * @param implName the name of the implementation for which a service is
73 * requested.
74 * @param multiFactory the service manager to be used (if needed).
75 * @param regKey the registry key.
76 * @return an <code>XSingleServiceFactory</code> for creating the component.
78 * @see com.sun.star.comp.loader.JavaLoader
80 public static XSingleServiceFactory __getServiceFactory(
81 String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
83 return implName.equals(Acceptor.class.getName())
84 ? FactoryHelper.getServiceFactory(Acceptor.class, __serviceName,
85 multiFactory, regKey)
86 : null;
89 /**
90 * Writes the service information into the given registry key.
92 * <p>This method is called by the <code>JavaLoader</code>.</p>
94 * @param regKey the registry key.
95 * @return <code>true</code> if the operation succeeded.
97 * @see com.sun.star.comp.loader.JavaLoader
99 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
100 return FactoryHelper.writeRegistryServiceInfo(Acceptor.class.getName(),
101 __serviceName, regKey);
105 * Constructs a new <code>Acceptor</code> that uses the given service
106 * factory to create a specific <code>XAcceptor</code>.
108 * @param serviceFactory the service factory to use.
110 public Acceptor(XMultiServiceFactory serviceFactory) {
111 this.serviceFactory = serviceFactory;
115 * Accepts a connection request via the given connection type.
117 * <p>This call blocks until a connection has been established.</p>
119 * <p>The connection description has the following format:
120 * <code><var>type</var></code><!--
121 * -->*(<code><var>key</var>=<var>value</var></code>).
122 * The specific <code>XAcceptor</code> implementation is instantiated
123 * through the service factory as
124 * <code>com.sun.star.connection.<var>type</var>Acceptor</code> (with
125 * <code><var>type</var></code> in lower case).</p>
127 * @param connectionDescription the description of the connection.
128 * @return an <code>XConnection</code> to the client.
130 * @see com.sun.star.connections.XConnection
131 * @see com.sun.star.connections.XConnector
133 public XConnection accept(String connectionDescription) throws
134 AlreadyAcceptingException, ConnectionSetupException,
135 com.sun.star.lang.IllegalArgumentException
137 if (DEBUG) {
138 System.err.println("##### " + getClass().getName() + ".accept("
139 + connectionDescription + ")");
141 XAcceptor acc;
142 synchronized (this) {
143 if (acceptor == null) {
144 acceptor = (XAcceptor) Implementation.getConnectionService(
145 serviceFactory, connectionDescription, XAcceptor.class,
146 "Acceptor");
147 acceptingDescription = connectionDescription;
148 } else if (!connectionDescription.equals(acceptingDescription)) {
149 throw new AlreadyAcceptingException(acceptingDescription
150 + " vs. "
151 + connectionDescription);
153 acc = acceptor;
155 return acc.accept(connectionDescription);
158 // see com.sun.star.connection.XAcceptor#stopAccepting
159 public void stopAccepting() {
160 XAcceptor acc;
161 synchronized (this) {
162 acc = acceptor;
164 acc.stopAccepting();
167 private static final boolean DEBUG = false;
169 private final XMultiServiceFactory serviceFactory;
171 private XAcceptor acceptor = null;
172 private String acceptingDescription;