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