xref: /AOO41X/main/jurt/com/sun/star/lib/connections/pipe/pipeConnector.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package com.sun.star.lib.connections.pipe;
29 
30 import com.sun.star.comp.loader.FactoryHelper;
31 import com.sun.star.connection.ConnectionSetupException;
32 import com.sun.star.connection.NoConnectException;
33 import com.sun.star.connection.XConnection;
34 import com.sun.star.connection.XConnector;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.lang.XSingleServiceFactory;
37 import com.sun.star.registry.XRegistryKey;
38 
39 /**
40  * A component that implements the <code>XConnector</code> interface.
41  *
42  * <p>The <code>pipeConnector</code> is a specialized component that uses TCP
43  * pipes for communication.  The <code>pipeConnector</code> is generally
44  * used by the <code>com.sun.star.connection.Connector</code> service.</p>
45  *
46  * @see com.sun.star.connections.XAcceptor
47  * @see com.sun.star.connections.XConnection
48  * @see com.sun.star.connections.XConnector
49  * @see com.sun.star.loader.JavaLoader
50  *
51  * @since UDK 1.0
52  */
53 public final class pipeConnector implements XConnector {
54     /**
55      * The name of the service.
56      *
57      * <p>The <code>JavaLoader</code> acceses this through reflection.</p>
58      *
59      * @see com.sun.star.comp.loader.JavaLoader
60      */
61     public static final String __serviceName = "com.sun.star.connection.pipeConnector";
62 
63     /**
64      * Returns a factory for creating the service.
65      *
66      * <p>This method is called by the <code>JavaLoader</code>.</p>
67      *
68      * @param implName the name of the implementation for which a service is
69      *     requested.
70      * @param multiFactory the service manager to be used (if needed).
71      * @param regKey the registry key.
72      * @return an <code>XSingleServiceFactory</code> for creating the component.
73      *
74      * @see com.sun.star.comp.loader.JavaLoader
75      */
76     public static XSingleServiceFactory __getServiceFactory(
77         String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
78     {
79         return implName.equals(pipeConnector.class.getName())
80             ? FactoryHelper.getServiceFactory(pipeConnector.class,
81                                               __serviceName, multiFactory,
82                                               regKey)
83             : null;
84     }
85 
86     /**
87      * Connects via the described pipe to a waiting server.
88      *
89      * <p>The connection description has the following format:
90      * <code><var>type</var></code><!--
91      *     -->*(<code><var>key</var>=<var>value</var></code>),
92      * where <code><var>type</var></code> should be <code>pipe</code>
93      * (ignoring case).  Supported keys (ignoring case) currently are
94      * <dl>
95      * <dt><code>host</code>
96      * <dd>The name or address of the server.  Must be present.
97      * <dt><code>port</code>
98      * <dd>The TCP port number of the server (defaults to <code>6001</code>).
99      * <dt><code>tcpnodelay</code>
100      * <dd>A flag (<code>0</code>/<code>1</code>) enabling or disabling Nagle's
101      *     algorithm on the resulting connection.
102      * </dl></p>
103      *
104      * @param connectionDescription the description of the connection.
105      * @return an <code>XConnection</code> to the server.
106      *
107      * @see com.sun.star.connections.XAcceptor
108      * @see com.sun.star.connections.XConnection
109      */
110     public synchronized XConnection connect(String connectionDescription)
111         throws NoConnectException, ConnectionSetupException
112     {
113         if (bConnected) {
114             throw new ConnectionSetupException("alread connected");
115         }
116 
117 	try
118 	{
119 		XConnection xConn = new PipeConnection( connectionDescription );
120 		bConnected = true;
121 		return xConn;
122 	}
123 	catch ( java.io.IOException e ) { throw new NoConnectException(); }
124     }
125 
126     private boolean bConnected = false;
127 }
128