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