1*ae15d43aSAndrew Rist /************************************************************** 2*ae15d43aSAndrew Rist * 3*ae15d43aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ae15d43aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ae15d43aSAndrew Rist * distributed with this work for additional information 6*ae15d43aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ae15d43aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ae15d43aSAndrew Rist * "License"); you may not use this file except in compliance 9*ae15d43aSAndrew Rist * with the License. You may obtain a copy of the License at 10*ae15d43aSAndrew Rist * 11*ae15d43aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ae15d43aSAndrew Rist * 13*ae15d43aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ae15d43aSAndrew Rist * software distributed under the License is distributed on an 15*ae15d43aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ae15d43aSAndrew Rist * KIND, either express or implied. See the License for the 17*ae15d43aSAndrew Rist * specific language governing permissions and limitations 18*ae15d43aSAndrew Rist * under the License. 19*ae15d43aSAndrew Rist * 20*ae15d43aSAndrew Rist *************************************************************/ 21*ae15d43aSAndrew Rist 22cdf0e10cSrcweir import com.sun.star.comp.servicemanager.ServiceManager; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 25cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 26cdf0e10cSrcweir import com.sun.star.connection.XConnector; 27cdf0e10cSrcweir import com.sun.star.connection.XConnection; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31cdf0e10cSrcweir import com.sun.star.uno.XInterface; 32cdf0e10cSrcweir import com.sun.star.uno.XNamingService; 33cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 34cdf0e10cSrcweir 35cdf0e10cSrcweir import com.sun.star.container.*; 36cdf0e10cSrcweir import com.sun.star.beans.*; 37cdf0e10cSrcweir import com.sun.star.lang.*; 38cdf0e10cSrcweir 39cdf0e10cSrcweir import storagetesting.*; 40cdf0e10cSrcweir 41cdf0e10cSrcweir public class StorageFunctionality { 42cdf0e10cSrcweir main( String args[] )43cdf0e10cSrcweir public static void main( String args[] ) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir // connect to the office 46cdf0e10cSrcweir String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService"; 47cdf0e10cSrcweir 48cdf0e10cSrcweir // It is possible to use a different connection string, passed as argument 49cdf0e10cSrcweir if ( args.length == 1 ) { 50cdf0e10cSrcweir sConnectionString = args[0]; 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir XMultiServiceFactory xMSF = null; 54cdf0e10cSrcweir 55cdf0e10cSrcweir // create connection(s) and get multiservicefactory 56cdf0e10cSrcweir try { 57cdf0e10cSrcweir xMSF = connect( sConnectionString ); 58cdf0e10cSrcweir 59cdf0e10cSrcweir if ( xMSF == null ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir System.out.println( "Error: Couldn't get MSF!" ); 62cdf0e10cSrcweir return; 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } catch( Exception e ) { 65cdf0e10cSrcweir System.out.println( "Error: Couldn't get MSF, exception: " + e ); 66cdf0e10cSrcweir return; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = null; 70cdf0e10cSrcweir try 71cdf0e10cSrcweir { 72cdf0e10cSrcweir Object oStorageFactory = xMSF.createInstance( "com.sun.star.embed.StorageFactory" ); 73cdf0e10cSrcweir xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class, 74cdf0e10cSrcweir oStorageFactory ); 75cdf0e10cSrcweir 76cdf0e10cSrcweir if ( xStorageFactory == null ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir System.out.println( "Error: Can not get storage factory!" ); 79cdf0e10cSrcweir return; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir } 82cdf0e10cSrcweir catch ( Exception e ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir System.out.println( "Error: Can't get storage factory, exception: " + e + "!" ); 85cdf0e10cSrcweir return; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir boolean bTestsPassed = true; 89cdf0e10cSrcweir 90cdf0e10cSrcweir final int nNumTests = 9; 91cdf0e10cSrcweir StorageTest pTests[] = new StorageTest[nNumTests]; 92cdf0e10cSrcweir pTests[0] = (StorageTest) new Test01( xMSF, xStorageFactory ); 93cdf0e10cSrcweir pTests[1] = (StorageTest) new Test02( xMSF, xStorageFactory ); 94cdf0e10cSrcweir pTests[2] = (StorageTest) new Test03( xMSF, xStorageFactory ); 95cdf0e10cSrcweir pTests[3] = (StorageTest) new Test04( xMSF, xStorageFactory ); 96cdf0e10cSrcweir pTests[4] = (StorageTest) new Test05( xMSF, xStorageFactory ); 97cdf0e10cSrcweir pTests[5] = (StorageTest) new Test06( xMSF, xStorageFactory ); 98cdf0e10cSrcweir pTests[6] = (StorageTest) new Test07( xMSF, xStorageFactory ); 99cdf0e10cSrcweir pTests[7] = (StorageTest) new Test08( xMSF, xStorageFactory ); 100cdf0e10cSrcweir pTests[8] = (StorageTest) new Test09( xMSF, xStorageFactory ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir System.out.println( "\nstart testing\n" ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir for ( int nInd = 0; nInd < nNumTests; nInd++ ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir String sTestName = "Test" + ( ( nInd < 9 ) ? "0" : "" ) + ( nInd + 1 ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir System.out.println( "======= Storage test " + sTestName + " started!" ); 109cdf0e10cSrcweir if ( pTests[nInd].test() ) 110cdf0e10cSrcweir System.out.println( "======= Storage test " + sTestName + " passed!" ); 111cdf0e10cSrcweir else 112cdf0e10cSrcweir { 113cdf0e10cSrcweir System.out.println( "======= Storage test " + sTestName + " failed!" ); 114cdf0e10cSrcweir bTestsPassed = false; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir if ( bTestsPassed ) 119cdf0e10cSrcweir System.out.println( "\ntesting passed" ); 120cdf0e10cSrcweir else 121cdf0e10cSrcweir System.out.println( "\ntesting failed" ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir System.out.println( "done" ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir System.exit( 0 ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir connect( String sConnectStr )129cdf0e10cSrcweir public static XMultiServiceFactory connect( String sConnectStr ) 130cdf0e10cSrcweir throws com.sun.star.uno.Exception, 131cdf0e10cSrcweir com.sun.star.uno.RuntimeException, 132cdf0e10cSrcweir Exception 133cdf0e10cSrcweir { 134cdf0e10cSrcweir // Get component context 135cdf0e10cSrcweir XComponentContext xComponentContext = 136cdf0e10cSrcweir com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( 137cdf0e10cSrcweir null ); 138cdf0e10cSrcweir 139cdf0e10cSrcweir // initial serviceManager 140cdf0e10cSrcweir XMultiComponentFactory xLocalServiceManager = 141cdf0e10cSrcweir xComponentContext.getServiceManager(); 142cdf0e10cSrcweir 143cdf0e10cSrcweir // create a connector, so that it can contact the office 144cdf0e10cSrcweir Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( 145cdf0e10cSrcweir "com.sun.star.bridge.UnoUrlResolver", xComponentContext ); 146cdf0e10cSrcweir XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( 147cdf0e10cSrcweir XUnoUrlResolver.class, oUrlResolver ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir Object oInitialObject = xUrlResolver.resolve( sConnectStr ); 150cdf0e10cSrcweir XNamingService xName = (XNamingService)UnoRuntime.queryInterface( 151cdf0e10cSrcweir XNamingService.class, oInitialObject ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir XMultiServiceFactory xMSF = null; 154cdf0e10cSrcweir if( xName != null ) { 155cdf0e10cSrcweir System.err.println( "got the remote naming service !" ); 156cdf0e10cSrcweir Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager" ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir xMSF = (XMultiServiceFactory) 159cdf0e10cSrcweir UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir else 162cdf0e10cSrcweir System.out.println( "Error: Can't get XNamingService interface from url resolver!" ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir return xMSF; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169