bump product version to 5.0.4.1
[LibreOffice.git] / jurt / com / sun / star / comp / urlresolver / UrlResolver.java
blob76058e95a6b4a81eb00caf9f2a1eb065ce67678d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.comp.urlresolver;
22 import com.sun.star.bridge.XBridge;
23 import com.sun.star.bridge.XBridgeFactory;
24 import com.sun.star.bridge.XUnoUrlResolver;
26 import com.sun.star.comp.loader.FactoryHelper;
28 import com.sun.star.connection.ConnectionSetupException;
29 import com.sun.star.connection.NoConnectException;
30 import com.sun.star.connection.XConnection;
31 import com.sun.star.connection.XConnector;
33 import com.sun.star.lang.IllegalArgumentException;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.lang.XSingleServiceFactory;
37 import com.sun.star.registry.XRegistryKey;
39 import com.sun.star.uno.UnoRuntime;
42 /**
43 * This component gives a factory for an <code>UnoUrlResolver</code> service.
45 * @see com.sun.star.bridge.XBridgeFactory
46 * @see com.sun.star.connection.Connector
47 * @since UDK1.0
49 public class UrlResolver {
50 static public class _UrlResolver implements XUnoUrlResolver {
51 static private final String __serviceName = "com.sun.star.bridge.UnoUrlResolver";
53 private final XMultiServiceFactory _xMultiServiceFactory;
55 public _UrlResolver(XMultiServiceFactory xMultiServiceFactory) {
56 _xMultiServiceFactory = xMultiServiceFactory;
59 public Object resolve(/*IN*/String dcp) throws NoConnectException, ConnectionSetupException, IllegalArgumentException, com.sun.star.uno.RuntimeException {
60 String conDcp ;
61 String protDcp ;
62 String rootOid ;
64 if(dcp.indexOf(';') == -1) {// use old style
65 conDcp = dcp;
66 protDcp = "iiop";
67 rootOid = "classic_uno";
69 else { // new style
70 int index = dcp.indexOf(':');
71 dcp = dcp.substring(index + 1).trim();
73 index = dcp.indexOf(';');
74 conDcp = dcp.substring(0, index).trim();
75 dcp = dcp.substring(index + 1).trim();
77 index = dcp.indexOf(';');
78 protDcp = dcp.substring(0, index).trim();
79 dcp = dcp.substring(index + 1).trim();
81 rootOid = dcp.trim().trim();
84 Object rootObject ;
85 XBridgeFactory xBridgeFactory ;
86 try {
87 xBridgeFactory = UnoRuntime.queryInterface(XBridgeFactory.class,
88 _xMultiServiceFactory.createInstance("com.sun.star.bridge.BridgeFactory"));
89 } catch (com.sun.star.uno.Exception e) {
90 throw new com.sun.star.uno.RuntimeException(e);
92 XBridge xBridge = xBridgeFactory.getBridge(conDcp + ";" + protDcp);
94 if(xBridge == null) {
95 Object connector ;
96 try {
97 connector = _xMultiServiceFactory.createInstance("com.sun.star.connection.Connector");
98 } catch (com.sun.star.uno.Exception e) {
99 throw new com.sun.star.uno.RuntimeException(e);
102 XConnector connector_xConnector = UnoRuntime.queryInterface(XConnector.class, connector);
104 // connect to the server
105 XConnection xConnection = connector_xConnector.connect(conDcp);
106 try {
107 xBridge = xBridgeFactory.createBridge(conDcp + ";" + protDcp, protDcp, xConnection, null);
108 } catch (com.sun.star.bridge.BridgeExistsException e) {
109 throw new com.sun.star.uno.RuntimeException(e);
112 rootObject = xBridge.getInstance(rootOid);
113 return rootObject;
119 * Gives a factory for creating the service.
121 * <p>This method is called by the <code>JavaLoader</code>.</p>
123 * @param implName the name of the implementation for which a service is desired.
124 * @param multiFactory the service manager to be uses if needed.
125 * @param regKey the registryKey.
126 * @return returns a <code>XSingleServiceFactory</code> for creating the component.
128 * @see com.sun.star.comp.loader.JavaLoader
130 public static XSingleServiceFactory __getServiceFactory(String implName,
131 XMultiServiceFactory multiFactory,
132 XRegistryKey regKey)
134 XSingleServiceFactory xSingleServiceFactory = null;
136 if (implName.equals(UrlResolver.class.getName()) )
137 xSingleServiceFactory = FactoryHelper.getServiceFactory(_UrlResolver.class,
138 _UrlResolver.__serviceName,
139 multiFactory,
140 regKey);
142 return xSingleServiceFactory;