1*cdf0e10cSrcweir import com.sun.star.comp.servicemanager.ServiceManager; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 4*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 5*cdf0e10cSrcweir import com.sun.star.connection.XConnector; 6*cdf0e10cSrcweir import com.sun.star.connection.XConnection; 7*cdf0e10cSrcweir 8*cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 9*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 10*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 11*cdf0e10cSrcweir import com.sun.star.uno.XNamingService; 12*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir import com.sun.star.container.*; 15*cdf0e10cSrcweir import com.sun.star.beans.*; 16*cdf0e10cSrcweir import com.sun.star.lang.*; 17*cdf0e10cSrcweir 18*cdf0e10cSrcweir import storagetesting.*; 19*cdf0e10cSrcweir 20*cdf0e10cSrcweir public class StorageFunctionality { 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir public static void main( String args[] ) 23*cdf0e10cSrcweir { 24*cdf0e10cSrcweir // connect to the office 25*cdf0e10cSrcweir String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService"; 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir // It is possible to use a different connection string, passed as argument 28*cdf0e10cSrcweir if ( args.length == 1 ) { 29*cdf0e10cSrcweir sConnectionString = args[0]; 30*cdf0e10cSrcweir } 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir XMultiServiceFactory xMSF = null; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir // create connection(s) and get multiservicefactory 35*cdf0e10cSrcweir try { 36*cdf0e10cSrcweir xMSF = connect( sConnectionString ); 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir if ( xMSF == null ) 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir System.out.println( "Error: Couldn't get MSF!" ); 41*cdf0e10cSrcweir return; 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir } catch( Exception e ) { 44*cdf0e10cSrcweir System.out.println( "Error: Couldn't get MSF, exception: " + e ); 45*cdf0e10cSrcweir return; 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = null; 49*cdf0e10cSrcweir try 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir Object oStorageFactory = xMSF.createInstance( "com.sun.star.embed.StorageFactory" ); 52*cdf0e10cSrcweir xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class, 53*cdf0e10cSrcweir oStorageFactory ); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir if ( xStorageFactory == null ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir System.out.println( "Error: Can not get storage factory!" ); 58*cdf0e10cSrcweir return; 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir catch ( Exception e ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir System.out.println( "Error: Can't get storage factory, exception: " + e + "!" ); 64*cdf0e10cSrcweir return; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir boolean bTestsPassed = true; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir final int nNumTests = 9; 70*cdf0e10cSrcweir StorageTest pTests[] = new StorageTest[nNumTests]; 71*cdf0e10cSrcweir pTests[0] = (StorageTest) new Test01( xMSF, xStorageFactory ); 72*cdf0e10cSrcweir pTests[1] = (StorageTest) new Test02( xMSF, xStorageFactory ); 73*cdf0e10cSrcweir pTests[2] = (StorageTest) new Test03( xMSF, xStorageFactory ); 74*cdf0e10cSrcweir pTests[3] = (StorageTest) new Test04( xMSF, xStorageFactory ); 75*cdf0e10cSrcweir pTests[4] = (StorageTest) new Test05( xMSF, xStorageFactory ); 76*cdf0e10cSrcweir pTests[5] = (StorageTest) new Test06( xMSF, xStorageFactory ); 77*cdf0e10cSrcweir pTests[6] = (StorageTest) new Test07( xMSF, xStorageFactory ); 78*cdf0e10cSrcweir pTests[7] = (StorageTest) new Test08( xMSF, xStorageFactory ); 79*cdf0e10cSrcweir pTests[8] = (StorageTest) new Test09( xMSF, xStorageFactory ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir System.out.println( "\nstart testing\n" ); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir for ( int nInd = 0; nInd < nNumTests; nInd++ ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir String sTestName = "Test" + ( ( nInd < 9 ) ? "0" : "" ) + ( nInd + 1 ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir System.out.println( "======= Storage test " + sTestName + " started!" ); 88*cdf0e10cSrcweir if ( pTests[nInd].test() ) 89*cdf0e10cSrcweir System.out.println( "======= Storage test " + sTestName + " passed!" ); 90*cdf0e10cSrcweir else 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir System.out.println( "======= Storage test " + sTestName + " failed!" ); 93*cdf0e10cSrcweir bTestsPassed = false; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir if ( bTestsPassed ) 98*cdf0e10cSrcweir System.out.println( "\ntesting passed" ); 99*cdf0e10cSrcweir else 100*cdf0e10cSrcweir System.out.println( "\ntesting failed" ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir System.out.println( "done" ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir System.exit( 0 ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir public static XMultiServiceFactory connect( String sConnectStr ) 109*cdf0e10cSrcweir throws com.sun.star.uno.Exception, 110*cdf0e10cSrcweir com.sun.star.uno.RuntimeException, 111*cdf0e10cSrcweir Exception 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir // Get component context 114*cdf0e10cSrcweir XComponentContext xComponentContext = 115*cdf0e10cSrcweir com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( 116*cdf0e10cSrcweir null ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // initial serviceManager 119*cdf0e10cSrcweir XMultiComponentFactory xLocalServiceManager = 120*cdf0e10cSrcweir xComponentContext.getServiceManager(); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // create a connector, so that it can contact the office 123*cdf0e10cSrcweir Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( 124*cdf0e10cSrcweir "com.sun.star.bridge.UnoUrlResolver", xComponentContext ); 125*cdf0e10cSrcweir XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( 126*cdf0e10cSrcweir XUnoUrlResolver.class, oUrlResolver ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir Object oInitialObject = xUrlResolver.resolve( sConnectStr ); 129*cdf0e10cSrcweir XNamingService xName = (XNamingService)UnoRuntime.queryInterface( 130*cdf0e10cSrcweir XNamingService.class, oInitialObject ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir XMultiServiceFactory xMSF = null; 133*cdf0e10cSrcweir if( xName != null ) { 134*cdf0e10cSrcweir System.err.println( "got the remote naming service !" ); 135*cdf0e10cSrcweir Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager" ); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir xMSF = (XMultiServiceFactory) 138*cdf0e10cSrcweir UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir else 141*cdf0e10cSrcweir System.out.println( "Error: Can't get XNamingService interface from url resolver!" ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir return xMSF; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148