summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertram Nolte <bnolte@openoffice.org>2001-12-12 12:32:15 +0000
committerBertram Nolte <bnolte@openoffice.org>2001-12-12 12:32:15 +0000
commit7da6f4aa3a5ad64a3e464e69a291d80246bb0840 (patch)
tree3038d1a7b637ad5b2368c720e7b4e00c644a6123
parent4b3ec1c079680b4444edbad49351dd3c66528b12 (diff)
#87796# Introduced component context.
-rw-r--r--odk/examples/java/MinimalComponent/TestMinimalComponent.java32
1 files changed, 23 insertions, 9 deletions
diff --git a/odk/examples/java/MinimalComponent/TestMinimalComponent.java b/odk/examples/java/MinimalComponent/TestMinimalComponent.java
index 372b43525cd2..382956f76038 100644
--- a/odk/examples/java/MinimalComponent/TestMinimalComponent.java
+++ b/odk/examples/java/MinimalComponent/TestMinimalComponent.java
@@ -1,5 +1,7 @@
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.container.XSet;
import com.sun.star.lang.XServiceInfo;
@@ -10,27 +12,37 @@ import MinimalComponent;
public class TestMinimalComponent {
public static void main(String args[]) {
try {
- /* Bootstraps a servicemanager with the jurt base components
- registered */
- XMultiServiceFactory xmultiservicefactory =
- com.sun.star.comp.helper.Bootstrap.createSimpleServiceManager();
+ /* Bootstraps a component context with the jurt base components
+ registered. Component context to be granted to a component for running.
+ Arbitrary values can be retrieved from the context. */
+ XComponentContext xcomponentcontext =
+ com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
- // Querying for the interface XSet on XMultiServiceFactory
+ /* Gets the service manager instance to be used (or null). This method has
+ been added for convenience, because the service manager is a often used
+ object. */
+ XMultiComponentFactory xmulticomponentfactory =
+ xcomponentcontext.getServiceManager();
+
+ // Querying for the interface XSet on XMultiComponentFactory
XSet xsetMultiServiceFactory = ( XSet ) UnoRuntime.queryInterface(
- XSet.class, xmultiservicefactory );
+ XSet.class, xmulticomponentfactory );
// Getting the XSingleServiceFactory for the minimal component
XSingleServiceFactory xsingleservicefactoryMinimalComponent =
MinimalComponent.__getServiceFactory(
- "MinimalComponent$MinimalComponentImplementation", xmultiservicefactory,
+ "MinimalComponent$MinimalComponentImplementation",
+ ( XMultiServiceFactory ) UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, xmulticomponentfactory ),
null );
// Inserting the XSingleServiceFactory into the container
xsetMultiServiceFactory.insert( xsingleservicefactoryMinimalComponent );
// Creating an instance of the minimal component
- Object objectMinimalComponent = xmultiservicefactory.createInstance(
- "org.OpenOffice.MinimalComponent" );
+ Object objectMinimalComponent =
+ xmulticomponentfactory.createInstanceWithContext(
+ "org.OpenOffice.MinimalComponent", xcomponentcontext );
XServiceInfo xserviceinfoMinimalComponent = ( XServiceInfo )
UnoRuntime.queryInterface( XServiceInfo.class,
@@ -42,6 +54,8 @@ public class TestMinimalComponent {
// Removing the XSingleServiceFactory of the minimal Component from the container
xsetMultiServiceFactory.remove( xsingleservicefactoryMinimalComponent );
+ xcomponentcontext = null;
+
System.exit(0);
}
catch( Exception exception ) {