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