Update ooo320-m1
[ooovba.git] / odk / examples / java / Inspector / TestInspector.java
blob29f5d20733b58c2b71cba0420c55a38bf9e43d6a
1 /*************************************************************************
3 * $RCSfile: TestInspector.java,v $
5 * $Revision: 1.3 $
7 * last change: $Author: hr $ $Date: 2007-01-02 15:01:35 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 import com.sun.star.lang.XSingleComponentFactory;
42 import com.sun.star.uno.UnoRuntime;
44 import java.io.DataInputStream;
46 public class TestInspector {
48 public static void main(String args[]) {
49 com.sun.star.uno.XComponentContext xContext = null;
50 try {
51 // get the remote office component context
52 xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
53 if( xContext != null )
54 System.out.println("Connected to a running office ...");
56 catch( Exception e) {
57 e.printStackTrace(System.out);
58 System.exit(1);
61 try {
62 com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
63 // Creating an instance of the instance inspector with arguments
65 XSingleComponentFactory xFactory = Inspector.__getComponentFactory(Inspector._Inspector.class.getName());
66 Object obj= null;
67 if (xFactory != null) {
68 obj = xFactory.createInstanceWithContext(xContext);
70 org.openoffice.XInstanceInspector xInstInspector = null;
71 if (obj != null) {
72 xInstInspector = (org.openoffice.XInstanceInspector)UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj);
75 /* A desktop environment contains tasks with one or more
76 frames in which components can be loaded. Desktop is the
77 environment for components which can instanciate within
78 frames. */
79 com.sun.star.frame.XComponentLoader xCmpLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class,
80 xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
82 // Load a new spreadsheet document, which will be automaticly
83 // displayed and is used for inspection
84 com.sun.star.lang.XComponent xComp = xCmpLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, new com.sun.star.beans.PropertyValue[0] );
85 xInstInspector.inspect(xCmpLoader, "");
86 System.out.println("You can now inspect the new spreadsheet " + "document ...\n");
88 catch( Exception e ) {
89 System.err.println( e + e.getMessage());
90 e.printStackTrace();
92 // System.exit( 0 );