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.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
;
34 import com
.sun
.star
.bridge
.XBridge
;
35 import com
.sun
.star
.bridge
.XBridgeFactory
;
36 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
38 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
40 import com
.sun
.star
.connection
.ConnectionSetupException
;
41 import com
.sun
.star
.connection
.NoConnectException
;
42 import com
.sun
.star
.connection
.XConnection
;
43 import com
.sun
.star
.connection
.XConnector
;
45 import com
.sun
.star
.lang
.IllegalArgumentException
;
46 import com
.sun
.star
.lang
.XMultiServiceFactory
;
47 import com
.sun
.star
.lang
.XSingleServiceFactory
;
49 import com
.sun
.star
.registry
.XRegistryKey
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
55 * This component gives a factory for an <code>UnoUrlResolver</code> service.
57 * @version $Revision: 1.6 $ $ $Date: 2008-04-11 11:12:25 $
59 * @see com.sun.star.brige.XBrideFactory
60 * @see com.sun.star.connection.Connector
63 public class UrlResolver
{
64 static private final boolean DEBUG
= false;
67 static public class _UrlResolver
implements XUnoUrlResolver
{
68 static private final String __serviceName
= "com.sun.star.bridge.UnoUrlResolver";
70 private XMultiServiceFactory _xMultiServiceFactory
;
72 public _UrlResolver(XMultiServiceFactory xMultiServiceFactory
) {
73 _xMultiServiceFactory
= xMultiServiceFactory
;
76 public Object
resolve(/*IN*/String dcp
) throws NoConnectException
, ConnectionSetupException
, IllegalArgumentException
, com
.sun
.star
.uno
.RuntimeException
{
78 String protDcp
= null;
79 String rootOid
= null;
81 if(dcp
.indexOf(';') == -1) {// use old style
84 rootOid
= "classic_uno";
87 int index
= dcp
.indexOf(':');
88 String url
= dcp
.substring(0, index
).trim();
89 dcp
= dcp
.substring(index
+ 1).trim();
91 index
= dcp
.indexOf(';');
92 conDcp
= dcp
.substring(0, index
).trim();
93 dcp
= dcp
.substring(index
+ 1).trim();
95 index
= dcp
.indexOf(';');
96 protDcp
= dcp
.substring(0, index
).trim();
97 dcp
= dcp
.substring(index
+ 1).trim();
99 rootOid
= dcp
.trim().trim();
102 Object rootObject
= null;
103 XBridgeFactory xBridgeFactory
= null;
105 xBridgeFactory
= UnoRuntime
.queryInterface(XBridgeFactory
.class,
106 _xMultiServiceFactory
.createInstance("com.sun.star.bridge.BridgeFactory"));
107 } catch (com
.sun
.star
.uno
.Exception e
) {
108 throw new com
.sun
.star
.uno
.RuntimeException(e
.getMessage());
110 XBridge xBridge
= xBridgeFactory
.getBridge(conDcp
+ ";" + protDcp
);
112 if(xBridge
== null) {
113 Object connector
= null;
115 connector
= _xMultiServiceFactory
.createInstance("com.sun.star.connection.Connector");
116 } catch (com
.sun
.star
.uno
.Exception e
) {
117 throw new com
.sun
.star
.uno
.RuntimeException(e
.getMessage());
120 XConnector connector_xConnector
= UnoRuntime
.queryInterface(XConnector
.class, connector
);
122 // connect to the server
123 XConnection xConnection
= connector_xConnector
.connect(conDcp
);
125 xBridge
= xBridgeFactory
.createBridge(conDcp
+ ";" + protDcp
, protDcp
, xConnection
, null);
126 } catch (com
.sun
.star
.bridge
.BridgeExistsException e
) {
127 throw new com
.sun
.star
.uno
.RuntimeException(e
.getMessage());
130 rootObject
= xBridge
.getInstance(rootOid
);
137 * Gives a factory for creating the service.
138 * This method is called by the <code>JavaLoader</code>
140 * @return returns a <code>XSingleServiceFactory</code> for creating the component
141 * @param implName the name of the implementation for which a service is desired
142 * @param multiFactory the service manager to be uses if needed
143 * @param regKey the registryKey
144 * @see com.sun.star.comp.loader.JavaLoader
146 public static XSingleServiceFactory
__getServiceFactory(String implName
,
147 XMultiServiceFactory multiFactory
,
150 XSingleServiceFactory xSingleServiceFactory
= null;
152 if (implName
.equals(UrlResolver
.class.getName()) )
153 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(_UrlResolver
.class,
154 _UrlResolver
.__serviceName
,
158 return xSingleServiceFactory
;
162 * Writes the service information into the given registry key.
163 * This method is called by the <code>JavaLoader</code>
165 * @return returns true if the operation succeeded
166 * @param regKey the registryKey
167 * @see com.sun.star.comp.loader.JavaLoader
169 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
170 return FactoryHelper
.writeRegistryServiceInfo(_UrlResolver
.class.getName(), _UrlResolver
.__serviceName
, regKey
);