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