1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 package com
.sun
.star
.comp
.urlresolver
;
23 import com
.sun
.star
.bridge
.XBridge
;
24 import com
.sun
.star
.bridge
.XBridgeFactory
;
25 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
27 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
29 import com
.sun
.star
.connection
.ConnectionSetupException
;
30 import com
.sun
.star
.connection
.NoConnectException
;
31 import com
.sun
.star
.connection
.XConnection
;
32 import com
.sun
.star
.connection
.XConnector
;
34 import com
.sun
.star
.lang
.IllegalArgumentException
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.lang
.XSingleServiceFactory
;
38 import com
.sun
.star
.registry
.XRegistryKey
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
44 * This component gives a factory for an <code>UnoUrlResolver</code> service.
46 * @see com.sun.star.bridge.XBridgeFactory
47 * @see com.sun.star.connection.Connector
50 public class UrlResolver
{
51 public static class _UrlResolver
implements XUnoUrlResolver
{
52 private static final String __serviceName
= "com.sun.star.bridge.UnoUrlResolver";
54 private final XMultiServiceFactory _xMultiServiceFactory
;
56 public _UrlResolver(XMultiServiceFactory xMultiServiceFactory
) {
57 _xMultiServiceFactory
= xMultiServiceFactory
;
60 public Object
resolve(/*IN*/String dcp
) throws NoConnectException
, ConnectionSetupException
, IllegalArgumentException
, com
.sun
.star
.uno
.RuntimeException
{
65 if(dcp
.indexOf(';') == -1) {// use old style
68 rootOid
= "classic_uno";
71 int index
= dcp
.indexOf(':');
72 dcp
= dcp
.substring(index
+ 1).trim();
74 index
= dcp
.indexOf(';');
75 conDcp
= dcp
.substring(0, index
).trim();
76 dcp
= dcp
.substring(index
+ 1).trim();
78 index
= dcp
.indexOf(';');
79 protDcp
= dcp
.substring(0, index
).trim();
80 dcp
= dcp
.substring(index
+ 1).trim();
82 rootOid
= dcp
.trim().trim();
86 XBridgeFactory xBridgeFactory
;
88 xBridgeFactory
= UnoRuntime
.queryInterface(XBridgeFactory
.class,
89 _xMultiServiceFactory
.createInstance("com.sun.star.bridge.BridgeFactory"));
90 } catch (com
.sun
.star
.uno
.Exception e
) {
91 throw new com
.sun
.star
.uno
.RuntimeException(e
);
93 XBridge xBridge
= xBridgeFactory
.getBridge(conDcp
+ ";" + protDcp
);
98 connector
= _xMultiServiceFactory
.createInstance("com.sun.star.connection.Connector");
99 } catch (com
.sun
.star
.uno
.Exception e
) {
100 throw new com
.sun
.star
.uno
.RuntimeException(e
);
103 XConnector connector_xConnector
= UnoRuntime
.queryInterface(XConnector
.class, connector
);
105 // connect to the server
106 XConnection xConnection
= connector_xConnector
.connect(conDcp
);
108 xBridge
= xBridgeFactory
.createBridge(conDcp
+ ";" + protDcp
, protDcp
, xConnection
, null);
109 } catch (com
.sun
.star
.bridge
.BridgeExistsException e
) {
110 throw new com
.sun
.star
.uno
.RuntimeException(e
);
113 rootObject
= xBridge
.getInstance(rootOid
);
120 * Gives a factory for creating the service.
122 * <p>This method is called by the <code>JavaLoader</code>.</p>
124 * @param implName the name of the implementation for which a service is desired.
125 * @param multiFactory the service manager to be uses if needed.
126 * @param regKey the registryKey.
127 * @return returns a <code>XSingleServiceFactory</code> for creating the component.
129 * @see com.sun.star.comp.loader.JavaLoader
131 public static XSingleServiceFactory
__getServiceFactory(String implName
,
132 XMultiServiceFactory multiFactory
,
135 XSingleServiceFactory xSingleServiceFactory
= null;
137 if (implName
.equals(UrlResolver
.class.getName()) )
138 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(_UrlResolver
.class,
139 _UrlResolver
.__serviceName
,
143 return xSingleServiceFactory
;
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */