1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XComponentContext
;
39 import com
.sun
.star
.lang
.XMultiComponentFactory
;
44 public static void main( String
[] args
) throws java
.lang
.Exception
46 if( args
.length
!= 1 )
48 System
.out
.println( "usage: UrlResolver uno-url\n" +
49 " uno-url The uno-url identifying the object to\n" +
50 " be imported, for instance\n" +
51 " uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" +
52 " (use \" on unix shells to avoid ;-problems" );
56 // create default local component context
57 XComponentContext xLocalContext
=
58 com
.sun
.star
.comp
.helper
.Bootstrap
.createInitialComponentContext(null);
60 // initial serviceManager
61 XMultiComponentFactory xLocalServiceManager
= xLocalContext
.getServiceManager();
63 // create a urlresolver
64 Object urlResolver
= xLocalServiceManager
.createInstanceWithContext(
65 "com.sun.star.bridge.UnoUrlResolver", xLocalContext
);
67 // query for the XUnoUrlResolver interface
68 XUnoUrlResolver xUrlResolver
=
69 UnoRuntime
.queryInterface( XUnoUrlResolver
.class, urlResolver
);
74 Object rInitialObject
= xUrlResolver
.resolve( args
[0] );
77 if( null != rInitialObject
)
79 System
.out
.println( "initial object successfully retrieved" );
83 System
.out
.println( "given initial-object name unknown at server side" );
86 catch( com
.sun
.star
.connection
.NoConnectException e
)
88 System
.out
.println( "Couldn't connect to remote server" );
89 System
.out
.println( e
.getMessage() );
91 catch( com
.sun
.star
.connection
.ConnectionSetupException e
)
93 System
.out
.println( "Couldn't access necessary local resource to establish the interprocess connection" );
94 System
.out
.println( e
.getMessage() );
96 catch( com
.sun
.star
.lang
.IllegalArgumentException e
)
98 System
.out
.println( "uno-url is syntactical illegal ( " + args
[0] + " )" );
99 System
.out
.println( e
.getMessage() );
101 catch( com
.sun
.star
.uno
.RuntimeException e
)
103 System
.out
.println( "RuntimeException" );
104 System
.out
.println( e
.getMessage() );
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */