1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 import com.sun.star.bridge.XUnoUrlResolver;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XInterface;
27 import com.sun.star.uno.XNamingService;
28 import com.sun.star.uno.XComponentContext;
29 import com.sun.star.lang.XMultiComponentFactory;
30 
31 
32 class UrlResolver
33 {
main( String [] args )34     public static void main( String [] args ) throws java.lang.Exception
35     {
36         if( args.length != 1 )
37         {
38             System.out.println( "usage: UrlResolver uno-url\n" +
39                                 "       uno-url  The uno-url identifying the object to\n" +
40                                 "                be imported, for instance\n" +
41                                 "                uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" +
42                                 "                (use \" on unix shells to avoid ;-problems" );
43             System.exit( 1 );
44         }
45 
46         // create default local component context
47         XComponentContext xLocalContext =
48             com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
49 
50         // initial serviceManager
51         XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
52 
53         // create a urlresolver
54         Object urlResolver  = xLocalServiceManager.createInstanceWithContext(
55             "com.sun.star.bridge.UnoUrlResolver", xLocalContext );
56 
57         // query for the XUnoUrlResolver interface
58         XUnoUrlResolver xUrlResolver =
59             (XUnoUrlResolver) UnoRuntime.queryInterface( XUnoUrlResolver.class, urlResolver );
60 
61         try
62         {
63             // Import the object
64             Object rInitialObject = xUrlResolver.resolve( args[0] );
65 
66             // XComponentContext
67             if( null != rInitialObject )
68             {
69                 System.out.println( "initial object successfully retrieved" );
70             }
71             else
72             {
73                 System.out.println( "given initial-object name unknown at server side" );
74             }
75         }
76         catch( com.sun.star.connection.NoConnectException e )
77         {
78             System.out.println( "Couldn't connect to remote server" );
79             System.out.println( e.getMessage() );
80         }
81         catch( com.sun.star.connection.ConnectionSetupException e )
82         {
83             System.out.println( "Couldn't access necessary local resource to establish the interprocess connection" );
84             System.out.println( e.getMessage() );
85         }
86         catch( com.sun.star.lang.IllegalArgumentException e )
87         {
88             System.out.println( "uno-url is syntactical illegal ( " + args[0] + " )" );
89             System.out.println( e.getMessage() );
90         }
91         catch( com.sun.star.uno.RuntimeException e )
92         {
93             System.out.println( "RuntimeException" );
94             System.out.println( e.getMessage() );
95         }
96         finally {
97             System.exit(0);
98         }
99     }
100 }
101