1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UrlResolver_Test.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.comp
.urlresolver
;
33 import com
.sun
.star
.uno
.XComponentContext
;
34 import com
.sun
.star
.comp
.helper
.Bootstrap
;
35 import com
.sun
.star
.lang
.XMultiComponentFactory
;
36 import com
.sun
.star
.bridge
.UnoUrlResolver
;
37 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
38 import com
.sun
.star
.beans
.XPropertySet
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 //import com.sun.star.connection.NoConnectionException;
42 /** start the office with these options <br>
43 soffice -accept=socket,host=localhost,port=8100;urp;
45 public class UrlResolver_Test
47 public static void main(String
[] args
) {
49 XComponentContext xcomponentcontext
= Bootstrap
.createInitialComponentContext( null );
51 // initial serviceManager
52 XMultiComponentFactory xLocalServiceManager
= xcomponentcontext
.getServiceManager();
54 // create a connector, so that it can contact the office
55 XUnoUrlResolver urlResolver
56 = UnoUrlResolver
.create( xcomponentcontext
);
58 Object initialObject
= urlResolver
.resolve(
59 "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" );
61 XMultiComponentFactory xOfficeFactory
= UnoRuntime
.queryInterface(
62 XMultiComponentFactory
.class, initialObject
);
64 // retrieve the component context (it's not yet exported from the office)
65 // Query for the XPropertySet interface.
66 XPropertySet xProperySet
= UnoRuntime
.queryInterface(
67 XPropertySet
.class, xOfficeFactory
);
69 // Get the default context from the office server.
70 Object oDefaultContext
= xProperySet
.getPropertyValue( "DefaultContext" );
72 // Query for the interface XComponentContext.
73 XComponentContext xOfficeComponentContext
= UnoRuntime
.queryInterface(
74 XComponentContext
.class, oDefaultContext
);
76 // now create the desktop service
77 // NOTE: use the office component context here !
78 Object oDesktop
= xOfficeFactory
.createInstanceWithContext("com.sun.star.frame.Desktop",
79 xOfficeComponentContext
);
80 } catch(com
.sun
.star
.connection
.NoConnectException e
) {
81 System
.out
.println(e
.getMessage());
83 } catch(com
.sun
.star
.connection
.ConnectionSetupException ce
) {
84 System
.out
.println(ce
.getMessage());
86 } catch(com
.sun
.star
.lang
.IllegalArgumentException ie
) {
87 System
.out
.println(ie
.getMessage());
89 } catch(com
.sun
.star
.beans
.UnknownPropertyException ue
) {
90 System
.out
.println(ue
.getMessage());
92 } catch(java
.lang
.Exception ee
) {
93 System
.out
.println(ee
.getMessage());