summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/Database/OpenQuery.java
diff options
context:
space:
mode:
authorRĂ¼diger Timm <rt@openoffice.org>2005-01-31 15:20:14 +0000
committerRĂ¼diger Timm <rt@openoffice.org>2005-01-31 15:20:14 +0000
commit19c27dc621807fe9649d99a5cf251793fd29eb70 (patch)
treee1fadb4eb0ec04d50e534611f9f1ad3bb3ed5689 /odk/examples/DevelopersGuide/Database/OpenQuery.java
parenta91c1051dc5fb9a52de378cfcf6d2bfdb8ded034 (diff)
INTEGRATION: CWS sdksample (1.4.40); FILE MERGED
2004/08/06 14:36:59 jsc 1.4.40.2: #i29308# use System.err for error output 2004/06/09 13:14:29 jsc 1.4.40.1: #i29308# use of new UNO bootstrap feature
Diffstat (limited to 'odk/examples/DevelopersGuide/Database/OpenQuery.java')
-rw-r--r--odk/examples/DevelopersGuide/Database/OpenQuery.java54
1 files changed, 17 insertions, 37 deletions
diff --git a/odk/examples/DevelopersGuide/Database/OpenQuery.java b/odk/examples/DevelopersGuide/Database/OpenQuery.java
index de809ad89190..9bed4bc70d42 100644
--- a/odk/examples/DevelopersGuide/Database/OpenQuery.java
+++ b/odk/examples/DevelopersGuide/Database/OpenQuery.java
@@ -2,9 +2,9 @@
*
* $RCSfile: OpenQuery.java,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: hr $ $Date: 2004-02-02 19:51:52 $
+ * last change: $Author: rt $ $Date: 2005-01-31 16:20:00 $
*
* The Contents of this file are made available subject to the terms of
* the BSD license.
@@ -58,8 +58,8 @@ import com.sun.star.beans.XPropertySet;
*/
public class OpenQuery {
- private XComponentContext xRemoteContext = null;
- private XMultiComponentFactory xRemoteServiceManager = null;
+ private XComponentContext xContext = null;
+ private XMultiComponentFactory xMCF = null;
/** Creates a new instance of OpenQuery */
public OpenQuery() {
@@ -82,12 +82,21 @@ public class OpenQuery {
}
protected void openQuery() throws com.sun.star.uno.Exception, java.lang.Exception {
- xRemoteServiceManager = this.getRemoteServiceManager(
- "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager");
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ xMCF = xContext.getServiceManager();
+ }
+ catch( Exception e) {
+ System.err.println("ERROR: can't get a component context from a running office ...");
+ e.printStackTrace();
+ System.exit(1);
+ }
// first we create our RowSet object and get its XRowSet interface
- Object rowSet = xRemoteServiceManager.createInstanceWithContext(
- "com.sun.star.sdb.RowSet", xRemoteContext);
+ Object rowSet = xMCF.createInstanceWithContext(
+ "com.sun.star.sdb.RowSet", xContext);
com.sun.star.sdbc.XRowSet xRowSet = (com.sun.star.sdbc.XRowSet)
UnoRuntime.queryInterface(com.sun.star.sdbc.XRowSet.class, rowSet);
@@ -156,33 +165,4 @@ public class OpenQuery {
xComp.dispose();
}
-
-
- protected XMultiComponentFactory getRemoteServiceManager(String unoUrl) throws java.lang.Exception {
- if (xRemoteContext == null) {
- // First step: create local component context, get local servicemanager and
- // ask it to create a UnoUrlResolver object with an XUnoUrlResolver interface
- XComponentContext xLocalContext =
- com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
-
- XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
-
- Object urlResolver = xLocalServiceManager.createInstanceWithContext(
- "com.sun.star.bridge.UnoUrlResolver", xLocalContext );
- // query XUnoUrlResolver interface from urlResolver object
- XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
- XUnoUrlResolver.class, urlResolver );
-
- // Second step: use xUrlResolver interface to import the remote StarOffice.ServiceManager,
- // retrieve its property DefaultContext and get the remote servicemanager
- Object initialObject = xUnoUrlResolver.resolve( unoUrl );
- XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(
- XPropertySet.class, initialObject);
- Object context = xPropertySet.getPropertyValue("DefaultContext");
- xRemoteContext = (XComponentContext)UnoRuntime.queryInterface(
- XComponentContext.class, context);
- }
- return xRemoteContext.getServiceManager();
- }
-
}