134dd1e25SAndrew Rist /**************************************************************
234dd1e25SAndrew Rist  *
334dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
434dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
534dd1e25SAndrew Rist  * distributed with this work for additional information
634dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
734dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
834dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
934dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
1034dd1e25SAndrew Rist  *
1134dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1234dd1e25SAndrew Rist  *
1334dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1434dd1e25SAndrew Rist  * software distributed under the License is distributed on an
1534dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1634dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
1734dd1e25SAndrew Rist  * specific language governing permissions and limitations
1834dd1e25SAndrew Rist  * under the License.
1934dd1e25SAndrew Rist  *
2034dd1e25SAndrew Rist  *************************************************************/
2134dd1e25SAndrew Rist 
2234dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory;
25cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir import java.io.DataInputStream;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir public class TestInspector {
30cdf0e10cSrcweir 
main(String args[])31cdf0e10cSrcweir     public static void main(String args[]) {
32cdf0e10cSrcweir         com.sun.star.uno.XComponentContext xContext = null;
33cdf0e10cSrcweir         try {
34cdf0e10cSrcweir             // get the remote office component context
35cdf0e10cSrcweir             xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
36cdf0e10cSrcweir             if( xContext != null )
37cdf0e10cSrcweir                 System.out.println("Connected to a running office ...");
38cdf0e10cSrcweir         }
39cdf0e10cSrcweir         catch( Exception e) {
40cdf0e10cSrcweir             e.printStackTrace(System.out);
41cdf0e10cSrcweir             System.exit(1);
42cdf0e10cSrcweir         }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir         try {
45cdf0e10cSrcweir             com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
46cdf0e10cSrcweir             // Creating an instance of the instance inspector with arguments
47cdf0e10cSrcweir 
48cdf0e10cSrcweir             XSingleComponentFactory xFactory = Inspector.__getComponentFactory(Inspector._Inspector.class.getName());
49cdf0e10cSrcweir             Object obj= null;
50cdf0e10cSrcweir             if (xFactory != null) {
51cdf0e10cSrcweir                 obj = xFactory.createInstanceWithContext(xContext);
52cdf0e10cSrcweir             }
53cdf0e10cSrcweir             org.openoffice.XInstanceInspector xInstInspector = null;
54cdf0e10cSrcweir             if (obj != null) {
55cdf0e10cSrcweir                 xInstInspector = (org.openoffice.XInstanceInspector)UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj);
56cdf0e10cSrcweir             }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir             /* A desktop environment contains tasks with one or more
59cdf0e10cSrcweir                frames in which components can be loaded. Desktop is the
60cdf0e10cSrcweir                environment for components which can instanciate within
61cdf0e10cSrcweir                frames. */
62cdf0e10cSrcweir             com.sun.star.frame.XComponentLoader xCmpLoader =  (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class,
63cdf0e10cSrcweir                     xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
64cdf0e10cSrcweir 
65*a893be29SPedro Giffuni             // Load a new spreadsheet document, which will be automatically
66cdf0e10cSrcweir             // displayed and is used for inspection
67cdf0e10cSrcweir             com.sun.star.lang.XComponent xComp = xCmpLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, new com.sun.star.beans.PropertyValue[0] );
68cdf0e10cSrcweir             xInstInspector.inspect(xCmpLoader, "");
69cdf0e10cSrcweir             System.out.println("You can now inspect the new spreadsheet " + "document ...\n");
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir         catch( Exception e ) {
72cdf0e10cSrcweir             System.err.println( e + e.getMessage());
73cdf0e10cSrcweir             e.printStackTrace();
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir //        System.exit( 0 );
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir }
78