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 package com.sun.star.demo;
24 
25 import com.sun.star.bridge.XBridge;
26 import com.sun.star.bridge.XBridgeFactory;
27 import com.sun.star.bridge.XInstanceProvider;
28 
29 import com.sun.star.comp.servicemanager.ServiceManager;
30 
31 import com.sun.star.connection.XAcceptor;
32 import com.sun.star.connection.XConnection;
33 
34 import com.sun.star.uno.UnoRuntime;
35 
36 public class DemoServer {
37 	static String neededServices[] = new String[] {
38 		"com.sun.star.comp.servicemanager.ServiceManager",
39 		"com.sun.star.comp.loader.JavaLoader",
40 		"com.sun.star.comp.connections.Acceptor",
41 		"com.sun.star.comp.bridgefactory.BridgeFactory"
42 	};
43 
44 	static class InstanceProvider implements XInstanceProvider {
getInstance( String sInstanceName )45 		public Object getInstance( /*IN*/String sInstanceName ) throws com.sun.star.container.NoSuchElementException, com.sun.star.uno.RuntimeException {
46 			System.err.println("##### " + getClass().getName() + ".getInstance:" + sInstanceName);
47 
48 			return null;
49 		}
50 	}
51 
main(String args[])52 	static public void main(String args[]) throws Exception {
53 		if(args.length != 1)	{
54 			System.err.println("usage : SCalc uno:connection;protocol;objectName");
55 			System.exit(-1);
56 		}
57 
58 		String conDcp = null;
59 		String protDcp = null;
60 		String rootOid = null;
61 
62 		String dcp = args[0];
63 
64 		if(dcp.indexOf(';') == -1) {// use old style
65 			conDcp = dcp;
66 			protDcp = "iiop";
67 			rootOid = "classic_uno";
68 		}
69 		else { // new style
70 			int index = dcp.indexOf(':');
71 			String url = dcp.substring(0, index).trim();
72 			dcp = dcp.substring(index + 1).trim();
73 
74 			index = dcp.indexOf(';');
75 			conDcp = dcp.substring(0, index).trim();
76 			dcp = dcp.substring(index + 1).trim();
77 
78 			index = dcp.indexOf(';');
79 			protDcp = dcp.substring(0, index).trim();
80 			dcp = dcp.substring(index + 1).trim();
81 
82 			rootOid = dcp.trim().trim();
83 		}
84 
85 		ServiceManager serviceManager = new ServiceManager();
86 		serviceManager.addFactories(neededServices);
87 
88 		XAcceptor xAcceptor = UnoRuntime.queryInterface(XAcceptor.class, serviceManager.createInstance("com.sun.star.connection.Acceptor"));
89 
90 		System.err.println("waiting for connect...");
91 		XConnection xConnection = xAcceptor.accept(conDcp);
92 
93 		XBridgeFactory xBridgeFactory = UnoRuntime.queryInterface(XBridgeFactory.class, serviceManager.createInstance("com.sun.star.bridge.BridgeFactory"));
94 		XBridge xBridge = xBridgeFactory.createBridge(conDcp + ";" + protDcp, protDcp, xConnection, new InstanceProvider());
95 
96 	}
97 }
98