1 package com.calipso.reportgenerator.reportmanager; 2 3 6 7 import com.sun.star.uno.XComponentContext; 8 import com.sun.star.uno.UnoRuntime; 9 import com.sun.star.lang.XMultiComponentFactory; 10 import com.sun.star.bridge.XUnoUrlResolver; 11 import com.sun.star.beans.XPropertySet; 12 import com.sun.star.comp.helper.Bootstrap; 13 import com.calipso.reportgenerator.common.LanguageTraslator; 14 import com.calipso.reportgenerator.common.InfoException; 15 16 public class OOConnectionManager { 17 18 private XComponentContext xRemoteContext; 19 private String unoUrl; 20 21 public OOConnectionManager(String unoUrl) { 22 this.unoUrl = unoUrl; 23 xRemoteContext = null; 24 } 25 26 public XComponentContext getConnection() throws InfoException { 27 if(xRemoteContext == null) { 28 try { 29 XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null); 30 XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager(); 31 Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext); 32 XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver); 33 34 Object initialObject = xUnoUrlResolver.resolve(unoUrl); 35 XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, initialObject); 36 Object context = xPropertySet.getPropertyValue("DefaultContext"); 37 xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, context); 38 } catch (Exception e) { 39 throw new InfoException(LanguageTraslator.traslate("273"),e); 40 } 41 } 42 return xRemoteContext; 43 } 44 } 45 | Popular Tags |