Kaydet (Commit) ba360d4a authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS sdksample (1.3.124); FILE MERGED

2004/06/16 08:49:16 jsc 1.3.124.2: #i29308# explicit imports
2004/06/10 10:05:53 jsc 1.3.124.1: #i29308# use of new UNO bootstrap feature
üst e29106b6
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: Helper.java,v $ * $RCSfile: Helper.java,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: hr $ $Date: 2003-06-30 15:23:48 $ * last change: $Author: rt $ $Date: 2005-01-31 16:23:08 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* the BSD license. * the BSD license.
...@@ -40,57 +40,48 @@ ...@@ -40,57 +40,48 @@
// __________ Imports __________ // __________ Imports __________
// base classes
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.*;
// factory for creating components
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.frame.XComponentLoader;
// property access
import com.sun.star.beans.*;
public class Helper public class Helper
{ {
// __________ static helper methods __________ // __________ static helper methods __________
/** Connect to a running office that is accepting connections /** Connect to an office, if no office is running a new instance is started.
and return the ServiceManager to instantiate office components * A new connection is established and the service manger from the running
* offic eis returned.
*/ */
static public XMultiServiceFactory connect( String sConnection ) static public com.sun.star.uno.XComponentContext connect()
throws Exception throws Exception
{ {
XMultiServiceFactory xMultiServiceFactory = null; // get the remote office component context
XMultiServiceFactory xLocalServiceManager = com.sun.star.uno.XComponentContext xOfficeContext =
com.sun.star.comp.helper.Bootstrap.createSimpleServiceManager(); com.sun.star.comp.helper.Bootstrap.bootstrap();
XUnoUrlResolver aURLResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( // if connection fails an exception is thrown
XUnoUrlResolver.class, System.out.println("Connected to a running office ...");
xLocalServiceManager.createInstance( "com.sun.star.bridge.UnoUrlResolver" ) );
xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( return xOfficeContext;
XMultiServiceFactory.class,
aURLResolver.resolve( sConnection ) );
if ( xMultiServiceFactory == null )
throw new Exception( "couldn't not connect to:'" + sConnection + "'" );
return xMultiServiceFactory;
} }
/** creates and instantiates new document /** creates and instantiates new document
*/ */
static public XComponent createDocument( XMultiServiceFactory xMultiServiceFactory, static public com.sun.star.lang.XComponent createDocument(
String sURL, String sTargetFrame, int nSearchFlags, PropertyValue[] aArgs ) com.sun.star.uno.XComponentContext xOfficeContext,
String sURL, String sTargetFrame, int nSearchFlags,
com.sun.star.beans.PropertyValue[] aArgs )
throws Exception throws Exception
{ {
XComponent xComponent = null; com.sun.star.lang.XComponent xComponent = null;
XComponentLoader aLoader = (XComponentLoader)UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader aLoader =
XComponentLoader.class, (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
xMultiServiceFactory.createInstance( "com.sun.star.frame.Desktop" ) ); com.sun.star.frame.XComponentLoader.class,
xOfficeContext.getServiceManager().createInstanceWithContext(
"com.sun.star.frame.Desktop", xOfficeContext));
xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
aLoader.loadComponentFromURL( com.sun.star.lang.XComponent.class, aLoader.loadComponentFromURL(
sURL, sTargetFrame, nSearchFlags, aArgs ) ); sURL, sTargetFrame, nSearchFlags, aArgs ) );
if ( xComponent == null ) if ( xComponent == null )
throw new Exception( "could not create document: " + sURL ); throw new Exception( "could not create document: " + sURL );
return xComponent; return xComponent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment