1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.lib.connections.pipe;
25 
26 import com.sun.star.comp.loader.FactoryHelper;
27 import com.sun.star.connection.ConnectionSetupException;
28 import com.sun.star.connection.NoConnectException;
29 import com.sun.star.connection.XConnection;
30 import com.sun.star.connection.XConnector;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.lang.XSingleServiceFactory;
33 import com.sun.star.registry.XRegistryKey;
34 
35 /**
36  * A component that implements the <code>XConnector</code> interface.
37  *
38  * <p>The <code>pipeConnector</code> is a specialized component that uses TCP
39  * pipes for communication.  The <code>pipeConnector</code> is generally
40  * used by the <code>com.sun.star.connection.Connector</code> service.</p>
41  *
42  * @see com.sun.star.connections.XAcceptor
43  * @see com.sun.star.connections.XConnection
44  * @see com.sun.star.connections.XConnector
45  * @see com.sun.star.loader.JavaLoader
46  *
47  * @since UDK 1.0
48  */
49 public final class pipeConnector implements XConnector {
50     /**
51      * The name of the service.
52      *
53      * <p>The <code>JavaLoader</code> acceses this through reflection.</p>
54      *
55      * @see com.sun.star.comp.loader.JavaLoader
56      */
57     public static final String __serviceName = "com.sun.star.connection.pipeConnector";
58 
59     /**
60      * Returns a factory for creating the service.
61      *
62      * <p>This method is called by the <code>JavaLoader</code>.</p>
63      *
64      * @param implName the name of the implementation for which a service is
65      *     requested.
66      * @param multiFactory the service manager to be used (if needed).
67      * @param regKey the registry key.
68      * @return an <code>XSingleServiceFactory</code> for creating the component.
69      *
70      * @see com.sun.star.comp.loader.JavaLoader
71      */
__getServiceFactory( String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)72     public static XSingleServiceFactory __getServiceFactory(
73         String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
74     {
75         return implName.equals(pipeConnector.class.getName())
76             ? FactoryHelper.getServiceFactory(pipeConnector.class,
77                                               __serviceName, multiFactory,
78                                               regKey)
79             : null;
80     }
81 
82     /**
83      * Connects via the described pipe to a waiting server.
84      *
85      * <p>The connection description has the following format:
86      * <code><var>type</var></code><!--
87      *     -->*(<code><var>key</var>=<var>value</var></code>),
88      * where <code><var>type</var></code> should be <code>pipe</code>
89      * (ignoring case).  Supported keys (ignoring case) currently are
90      * <dl>
91      * <dt><code>host</code>
92      * <dd>The name or address of the server.  Must be present.
93      * <dt><code>port</code>
94      * <dd>The TCP port number of the server (defaults to <code>6001</code>).
95      * <dt><code>tcpnodelay</code>
96      * <dd>A flag (<code>0</code>/<code>1</code>) enabling or disabling Nagle's
97      *     algorithm on the resulting connection.
98      * </dl></p>
99      *
100      * @param connectionDescription the description of the connection.
101      * @return an <code>XConnection</code> to the server.
102      *
103      * @see com.sun.star.connections.XAcceptor
104      * @see com.sun.star.connections.XConnection
105      */
connect(String connectionDescription)106     public synchronized XConnection connect(String connectionDescription)
107         throws NoConnectException, ConnectionSetupException
108     {
109         if (bConnected) {
110             throw new ConnectionSetupException("alread connected");
111         }
112 
113 	try
114 	{
115 		XConnection xConn = new PipeConnection( connectionDescription );
116 		bConnected = true;
117 		return xConn;
118 	}
119 	catch ( java.io.IOException e ) { throw new NoConnectException(); }
120     }
121 
122     private boolean bConnected = false;
123 }
124