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 
23 
24 package com.sun.star.comp.helper;
25 
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.AnyConverter;
28 
29 import com.sun.star.uno.XComponentContext;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 
33 
34 public class Bootstrap_Test {
35 
test( String ini_file, java.util.Hashtable bootstrap_parameters )36 	static public boolean test( String ini_file, java.util.Hashtable bootstrap_parameters )
37         throws java.lang.Exception
38     {
39 		boolean passed = false;
40 		System.err.println();
41 		System.out.println("*******************************************************************");
42 		System.err.println("Bootstrap - doing tests...");
43 		System.err.println();
44 
45 		try {
46             XComponentContext xContext =
47                 com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(
48                     ini_file, bootstrap_parameters );
49 
50             if (AnyConverter.isVoid(
51                     xContext.getValueByName(
52                         "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ))
53             {
54                 throw new Exception(
55                     "no /singletons/com.sun.star.reflection.theTypeDescriptionManager!" );
56             }
57 
58 			XMultiServiceFactory msf = UnoRuntime.queryInterface(
59                 XMultiServiceFactory.class, xContext.getServiceManager() );
60 			String services[] = msf.getAvailableServiceNames();
61 			System.out.println("Available services are:");
62 			System.err.println();
63 			if (services.length == 0)
64 				System.out.println("No services avialable!");
65 
66 			else
67 				for ( int i=0; i<services.length; i++ )
68 					System.out.println(services[i]);
69 
70             XComponent xComp = UnoRuntime.queryInterface(
71                 XComponent.class, xContext );
72             xComp.dispose();
73 
74 			passed = true;
75 		}
76 		catch (Exception e) {
77 			e.printStackTrace();
78 		}
79 		System.err.println();
80 		System.err.println("Bootstrap test passed? " + passed);
81 		System.out.println("*******************************************************************");
82 		System.err.println();
83 		return passed;
84 	}
85 
usage()86 	private static void usage() {
87 		System.out.println();
88 		System.out.println("usage:");
89 		System.out.println("java com.sun.star.comp.helper.Bootstrap_Test ini-file name=value ...");
90 		System.out.println("example:");
91 		System.out.println("java com.sun.star.comp.helper.Bootstrap_Test file:///c:/ooo10/program/uno.ini SYSBINDIR=file:///c:/ooo10/program");
92 		System.exit( -1 );
93 	}
94 
main(String args[])95 	static public void main(String args[]) throws java.lang.Exception {
96 		if ( args.length == 0 )
97 			usage();
98 
99         java.util.Hashtable bootstrap_parameters = new java.util.Hashtable();
100         for ( int nPos = 1; nPos < args.length; ++nPos )
101         {
102             String arg = args[ nPos ];
103             int n = arg.indexOf( '=' );
104             if (n > 0)
105             {
106                 bootstrap_parameters.put( arg.substring( 0, n ), arg.substring( n +1 ) );
107             }
108         }
109 
110 		System.exit( test(args[0], bootstrap_parameters) == true ? 0: -1 );
111 	}
112 }
113 
114