merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / ProfUNO / InterprocessConn / UrlResolver.java
blob462f9c71a91ed08a9f5946dcec08544cb7c0f54e
1 /*************************************************************************
3 * $RCSfile: UrlResolver.java,v $
5 * $Revision: 1.4 $
7 * last change: $Author: hr $ $Date: 2004-02-02 20:03:31 $
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.bridge.XUnoUrlResolver;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.uno.XNamingService;
45 import com.sun.star.uno.XComponentContext;
46 import com.sun.star.lang.XMultiComponentFactory;
49 class UrlResolver
51 public static void main( String [] args ) throws java.lang.Exception
53 if( args.length != 1 )
55 System.out.println( "usage: UrlResolver uno-url\n" +
56 " uno-url The uno-url identifying the object to\n" +
57 " be imported, for instance\n" +
58 " uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" +
59 " (use \" on unix shells to avoid ;-problems" );
60 System.exit( 1 );
63 // create default local component context
64 XComponentContext xLocalContext =
65 com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
67 // initial serviceManager
68 XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
70 // create a urlresolver
71 Object urlResolver = xLocalServiceManager.createInstanceWithContext(
72 "com.sun.star.bridge.UnoUrlResolver", xLocalContext );
74 // query for the XUnoUrlResolver interface
75 XUnoUrlResolver xUrlResolver =
76 (XUnoUrlResolver) UnoRuntime.queryInterface( XUnoUrlResolver.class, urlResolver );
78 try
80 // Import the object
81 Object rInitialObject = xUrlResolver.resolve( args[0] );
83 // XComponentContext
84 if( null != rInitialObject )
86 System.out.println( "initial object successfully retrieved" );
88 else
90 System.out.println( "given initial-object name unknown at server side" );
93 catch( com.sun.star.connection.NoConnectException e )
95 System.out.println( "Couldn't connect to remote server" );
96 System.out.println( e.getMessage() );
98 catch( com.sun.star.connection.ConnectionSetupException e )
100 System.out.println( "Couldn't access necessary local resource to establish the interprocess connection" );
101 System.out.println( e.getMessage() );
103 catch( com.sun.star.lang.IllegalArgumentException e )
105 System.out.println( "uno-url is syntactical illegal ( " + args[0] + " )" );
106 System.out.println( e.getMessage() );
108 catch( com.sun.star.uno.RuntimeException e )
110 System.out.println( "RuntimeException" );
111 System.out.println( e.getMessage() );
113 finally {
114 System.exit(0);