1*a5b190bfSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a5b190bfSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a5b190bfSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a5b190bfSAndrew Rist  * distributed with this work for additional information
6*a5b190bfSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a5b190bfSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a5b190bfSAndrew Rist  * "License"); you may not use this file except in compliance
9*a5b190bfSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a5b190bfSAndrew Rist  *
11*a5b190bfSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a5b190bfSAndrew Rist  *
13*a5b190bfSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a5b190bfSAndrew Rist  * software distributed under the License is distributed on an
15*a5b190bfSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a5b190bfSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a5b190bfSAndrew Rist  * specific language governing permissions and limitations
18*a5b190bfSAndrew Rist  * under the License.
19*a5b190bfSAndrew Rist  *
20*a5b190bfSAndrew Rist  *************************************************************/
21*a5b190bfSAndrew Rist 
22*a5b190bfSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.comp.helper;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
30cdf0e10cSrcweir import com.sun.star.lang.XComponent;
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir public class Bootstrap_Test {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 	static public boolean test( String ini_file, java.util.Hashtable bootstrap_parameters )
37cdf0e10cSrcweir         throws java.lang.Exception
38cdf0e10cSrcweir     {
39cdf0e10cSrcweir 		boolean passed = false;
40cdf0e10cSrcweir 		System.err.println();
41cdf0e10cSrcweir 		System.out.println("*******************************************************************");
42cdf0e10cSrcweir 		System.err.println("Bootstrap - doing tests...");
43cdf0e10cSrcweir 		System.err.println();
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 		try {
46cdf0e10cSrcweir             XComponentContext xContext =
47cdf0e10cSrcweir                 com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(
48cdf0e10cSrcweir                     ini_file, bootstrap_parameters );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir             if (AnyConverter.isVoid(
51cdf0e10cSrcweir                     xContext.getValueByName(
52cdf0e10cSrcweir                         "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ))
53cdf0e10cSrcweir             {
54cdf0e10cSrcweir                 throw new Exception(
55cdf0e10cSrcweir                     "no /singletons/com.sun.star.reflection.theTypeDescriptionManager!" );
56cdf0e10cSrcweir             }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 			XMultiServiceFactory msf = UnoRuntime.queryInterface(
59cdf0e10cSrcweir                 XMultiServiceFactory.class, xContext.getServiceManager() );
60cdf0e10cSrcweir 			String services[] = msf.getAvailableServiceNames();
61cdf0e10cSrcweir 			System.out.println("Available services are:");
62cdf0e10cSrcweir 			System.err.println();
63cdf0e10cSrcweir 			if (services.length == 0)
64cdf0e10cSrcweir 				System.out.println("No services avialable!");
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 			else
67cdf0e10cSrcweir 				for ( int i=0; i<services.length; i++ )
68cdf0e10cSrcweir 					System.out.println(services[i]);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir             XComponent xComp = UnoRuntime.queryInterface(
71cdf0e10cSrcweir                 XComponent.class, xContext );
72cdf0e10cSrcweir             xComp.dispose();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 			passed = true;
75cdf0e10cSrcweir 		}
76cdf0e10cSrcweir 		catch (Exception e) {
77cdf0e10cSrcweir 			e.printStackTrace();
78cdf0e10cSrcweir 		}
79cdf0e10cSrcweir 		System.err.println();
80cdf0e10cSrcweir 		System.err.println("Bootstrap test passed? " + passed);
81cdf0e10cSrcweir 		System.out.println("*******************************************************************");
82cdf0e10cSrcweir 		System.err.println();
83cdf0e10cSrcweir 		return passed;
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	private static void usage() {
87cdf0e10cSrcweir 		System.out.println();
88cdf0e10cSrcweir 		System.out.println("usage:");
89cdf0e10cSrcweir 		System.out.println("java com.sun.star.comp.helper.Bootstrap_Test ini-file name=value ...");
90cdf0e10cSrcweir 		System.out.println("example:");
91cdf0e10cSrcweir 		System.out.println("java com.sun.star.comp.helper.Bootstrap_Test file:///c:/ooo10/program/uno.ini SYSBINDIR=file:///c:/ooo10/program");
92cdf0e10cSrcweir 		System.exit( -1 );
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	static public void main(String args[]) throws java.lang.Exception {
96cdf0e10cSrcweir 		if ( args.length == 0 )
97cdf0e10cSrcweir 			usage();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         java.util.Hashtable bootstrap_parameters = new java.util.Hashtable();
100cdf0e10cSrcweir         for ( int nPos = 1; nPos < args.length; ++nPos )
101cdf0e10cSrcweir         {
102cdf0e10cSrcweir             String arg = args[ nPos ];
103cdf0e10cSrcweir             int n = arg.indexOf( '=' );
104cdf0e10cSrcweir             if (n > 0)
105cdf0e10cSrcweir             {
106cdf0e10cSrcweir                 bootstrap_parameters.put( arg.substring( 0, n ), arg.substring( n +1 ) );
107cdf0e10cSrcweir             }
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		System.exit( test(args[0], bootstrap_parameters) == true ? 0: -1 );
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114