summaryrefslogtreecommitdiff
path: root/javaunohelper/com/sun/star/comp/helper
diff options
context:
space:
mode:
Diffstat (limited to 'javaunohelper/com/sun/star/comp/helper')
-rw-r--r--javaunohelper/com/sun/star/comp/helper/Bootstrap.java329
-rw-r--r--javaunohelper/com/sun/star/comp/helper/BootstrapException.java91
-rw-r--r--javaunohelper/com/sun/star/comp/helper/ComponentContext.java310
-rw-r--r--javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java73
-rw-r--r--javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java168
-rw-r--r--javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java159
-rw-r--r--javaunohelper/com/sun/star/comp/helper/UnoInfo.java115
-rw-r--r--javaunohelper/com/sun/star/comp/helper/makefile.mk54
8 files changed, 1299 insertions, 0 deletions
diff --git a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java
new file mode 100644
index 000000000000..04bba081e37f
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java
@@ -0,0 +1,329 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.helper;
+
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.loader.JavaLoader;
+import com.sun.star.container.XSet;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.util.NativeLibraryLoader;
+import com.sun.star.loader.XImplementationLoader;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Random;
+
+/** Bootstrap offers functionality to obtain a context or simply
+ a service manager.
+ The service manager can create a few basic services, whose implementations are:
+ <ul>
+ <li>com.sun.star.comp.loader.JavaLoader</li>
+ <li>com.sun.star.comp.urlresolver.UrlResolver</li>
+ <li>com.sun.star.comp.bridgefactory.BridgeFactory</li>
+ <li>com.sun.star.comp.connections.Connector</li>
+ <li>com.sun.star.comp.connections.Acceptor</li>
+ <li>com.sun.star.comp.servicemanager.ServiceManager</li>
+ </ul>
+
+ Other services can be inserted into the service manager by
+ using its XSet interface:
+ <pre>
+ XSet xSet = UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
+ // insert the service manager
+ xSet.insert( aSingleComponentFactory );
+ </pre>
+*/
+public class Bootstrap {
+
+ private static void insertBasicFactories(
+ XSet xSet, XImplementationLoader xImpLoader )
+ throws Exception
+ {
+ // insert the factory of the loader
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.loader.JavaLoader", null, null, null ) );
+
+ // insert the factory of the URLResolver
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) );
+
+ // insert the bridgefactory
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null ) );
+
+ // insert the connector
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.connections.Connector", null, null, null ) );
+
+ // insert the acceptor
+ xSet.insert( xImpLoader.activate(
+ "com.sun.star.comp.connections.Acceptor", null, null, null ) );
+ }
+
+ /** Bootstraps an initial component context with service manager and basic
+ jurt components inserted.
+ @param context_entries the hash table contains mappings of entry names (type string) to
+ context entries (type class ComponentContextEntry).
+ @return a new context.
+ */
+ static public XComponentContext createInitialComponentContext( Hashtable context_entries )
+ throws Exception
+ {
+ XImplementationLoader xImpLoader = UnoRuntime.queryInterface(
+ XImplementationLoader.class, new JavaLoader() );
+
+ // Get the factory of the ServiceManager
+ XSingleComponentFactory smgr_fac = UnoRuntime.queryInterface(
+ XSingleComponentFactory.class, xImpLoader.activate(
+ "com.sun.star.comp.servicemanager.ServiceManager", null, null, null ) );
+
+ // Create an instance of the ServiceManager
+ XMultiComponentFactory xSMgr = UnoRuntime.queryInterface(
+ XMultiComponentFactory.class, smgr_fac.createInstanceWithContext( null ) );
+
+ // post init loader
+ XInitialization xInit = UnoRuntime.queryInterface(
+ XInitialization.class, xImpLoader );
+ Object[] args = new Object [] { xSMgr };
+ xInit.initialize( args );
+
+ // initial component context
+ if (context_entries == null)
+ context_entries = new Hashtable( 1 );
+ // add smgr
+ context_entries.put(
+ "/singletons/com.sun.star.lang.theServiceManager",
+ new ComponentContextEntry( null, xSMgr ) );
+ // ... xxx todo: add standard entries
+ XComponentContext xContext = new ComponentContext( context_entries, null );
+
+ // post init smgr
+ xInit = UnoRuntime.queryInterface(
+ XInitialization.class, xSMgr );
+ args = new Object [] { null, xContext }; // no registry, default context
+ xInit.initialize( args );
+
+ XSet xSet = UnoRuntime.queryInterface( XSet.class, xSMgr );
+ // insert the service manager
+ xSet.insert( smgr_fac );
+ // and basic jurt factories
+ insertBasicFactories( xSet, xImpLoader );
+
+ return xContext;
+ }
+
+ /**
+ * Bootstraps a servicemanager with the jurt base components registered.
+ * <p>
+ * @return a freshly boostrapped service manager
+ * @see com.sun.star.lang.ServiceManager
+ */
+ static public XMultiServiceFactory createSimpleServiceManager() throws Exception
+ {
+ return UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, createInitialComponentContext( null ).getServiceManager() );
+ }
+
+
+ /** Bootstraps the initial component context from a native UNO installation.
+
+ @see cppuhelper/defaultBootstrap_InitialComponentContext()
+ */
+ static public final XComponentContext defaultBootstrap_InitialComponentContext()
+ throws Exception
+ {
+ return defaultBootstrap_InitialComponentContext( null, null );
+ }
+ /** Bootstraps the initial component context from a native UNO installation.
+
+ @param ini_file
+ ini_file (may be null: uno.rc besides cppuhelper lib)
+ @param bootstrap_parameters
+ bootstrap parameters (maybe null)
+
+ @see cppuhelper/defaultBootstrap_InitialComponentContext()
+ */
+ static public final XComponentContext defaultBootstrap_InitialComponentContext(
+ String ini_file, Hashtable bootstrap_parameters )
+ throws Exception
+ {
+ // jni convenience: easier to iterate over array than calling Hashtable
+ String pairs [] = null;
+ if (null != bootstrap_parameters)
+ {
+ pairs = new String [ 2 * bootstrap_parameters.size() ];
+ Enumeration keys = bootstrap_parameters.keys();
+ int n = 0;
+ while (keys.hasMoreElements())
+ {
+ String name = (String)keys.nextElement();
+ pairs[ n++ ] = name;
+ pairs[ n++ ] = (String)bootstrap_parameters.get( name );
+ }
+ }
+
+ if (! m_loaded_juh)
+ {
+ NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" );
+ m_loaded_juh = true;
+ }
+ return UnoRuntime.queryInterface(
+ XComponentContext.class,
+ cppuhelper_bootstrap(
+ ini_file, pairs, Bootstrap.class.getClassLoader() ) );
+ }
+
+ static private boolean m_loaded_juh = false;
+ static private native Object cppuhelper_bootstrap(
+ String ini_file, String bootstrap_parameters [], ClassLoader loader )
+ throws Exception;
+
+ /**
+ * Bootstraps the component context from a UNO installation.
+ *
+ * @return a bootstrapped component context.
+ *
+ * @since UDK 3.1.0
+ */
+ public static final XComponentContext bootstrap()
+ throws BootstrapException {
+
+ XComponentContext xContext = null;
+
+ try {
+ // create default local component context
+ XComponentContext xLocalContext =
+ createInitialComponentContext( null );
+ if ( xLocalContext == null )
+ throw new BootstrapException( "no local component context!" );
+
+ // find office executable relative to this class's class loader
+ String sOffice =
+ System.getProperty( "os.name" ).startsWith( "Windows" ) ?
+ "soffice.exe" : "soffice";
+ File fOffice = NativeLibraryLoader.getResource(
+ Bootstrap.class.getClassLoader(), sOffice );
+ if ( fOffice == null )
+ throw new BootstrapException( "no office executable found!" );
+
+ // create random pipe name
+ String sPipeName = "uno" +
+ Long.toString( (new Random()).nextLong() & 0x7fffffffffffffffL );
+
+ // create call with arguments
+ String[] cmdArray = new String[7];
+ cmdArray[0] = fOffice.getPath();
+ cmdArray[1] = "-nologo";
+ cmdArray[2] = "-nodefault";
+ cmdArray[3] = "-norestore";
+ cmdArray[4] = "-nocrashreport";
+ cmdArray[5] = "-nolockcheck";
+ cmdArray[6] = "-accept=pipe,name=" + sPipeName + ";urp;";
+
+ // start office process
+ Process p = Runtime.getRuntime().exec( cmdArray );
+ pipe( p.getInputStream(), System.out, "CO> " );
+ pipe( p.getErrorStream(), System.err, "CE> " );
+
+ // initial service manager
+ XMultiComponentFactory xLocalServiceManager =
+ xLocalContext.getServiceManager();
+ if ( xLocalServiceManager == null )
+ throw new BootstrapException( "no initial service manager!" );
+
+ // create a URL resolver
+ XUnoUrlResolver xUrlResolver =
+ UnoUrlResolver.create( xLocalContext );
+
+ // connection string
+ String sConnect = "uno:pipe,name=" + sPipeName +
+ ";urp;StarOffice.ComponentContext";
+
+ // wait until office is started
+ for (int i = 0;; ++i) {
+ try {
+ // try to connect to office
+ Object context = xUrlResolver.resolve( sConnect );
+ xContext = UnoRuntime.queryInterface(
+ XComponentContext.class, context);
+ if ( xContext == null )
+ throw new BootstrapException( "no component context!" );
+ break;
+ } catch ( com.sun.star.connection.NoConnectException ex ) {
+ // Wait 500 ms, then try to connect again, but do not wait
+ // longer than 5 min (= 600 * 500 ms) total:
+ if (i == 600) {
+ throw new BootstrapException(ex.toString());
+ }
+ Thread.currentThread().sleep( 500 );
+ }
+ }
+ } catch ( BootstrapException e ) {
+ throw e;
+ } catch ( java.lang.RuntimeException e ) {
+ throw e;
+ } catch ( java.lang.Exception e ) {
+ throw new BootstrapException( e );
+ }
+
+ return xContext;
+ }
+
+ private static void pipe(
+ final InputStream in, final PrintStream out, final String prefix ) {
+
+ new Thread( "Pipe: " + prefix) {
+ public void run() {
+ BufferedReader r = new BufferedReader(
+ new InputStreamReader( in ) );
+ try {
+ for ( ; ; ) {
+ String s = r.readLine();
+ if ( s == null ) {
+ break;
+ }
+ out.println( prefix + s );
+ }
+ } catch ( java.io.IOException e ) {
+ e.printStackTrace( System.err );
+ }
+ }
+ }.start();
+ }
+}
diff --git a/javaunohelper/com/sun/star/comp/helper/BootstrapException.java b/javaunohelper/com/sun/star/comp/helper/BootstrapException.java
new file mode 100644
index 000000000000..4d84a4f7dd3f
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/BootstrapException.java
@@ -0,0 +1,91 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.helper;
+
+/**
+ * BootstrapException is a checked exception that wraps an exception
+ * thrown by the original target.
+ *
+ * @since UDK 3.1.0
+ */
+public class BootstrapException extends java.lang.Exception {
+
+ /**
+ * This field holds the target exception.
+ */
+ private Exception m_target = null;
+
+ /**
+ * Constructs a <code>BootstrapException</code> with <code>null</code> as
+ * the target exception.
+ */
+ public BootstrapException() {
+ super();
+ }
+
+ /**
+ * Constructs a <code>BootstrapException</code> with the specified
+ * detail message.
+ *
+ * @param message the detail message
+ */
+ public BootstrapException( String message ) {
+ super( message );
+ }
+
+ /**
+ * Constructs a <code>BootstrapException</code> with the specified
+ * detail message and a target exception.
+ *
+ * @param message the detail message
+ * @param target the target exception
+ */
+ public BootstrapException( String message, Exception target ) {
+ super( message );
+ m_target = target;
+ }
+
+ /**
+ * Constructs a <code>BootstrapException</code> with a target exception.
+ *
+ * @param target the target exception
+ */
+ public BootstrapException( Exception target ) {
+ super();
+ m_target = target;
+ }
+
+ /**
+ * Get the thrown target exception.
+ *
+ * @return the target exception
+ */
+ public Exception getTargetException() {
+ return m_target;
+ }
+}
diff --git a/javaunohelper/com/sun/star/comp/helper/ComponentContext.java b/javaunohelper/com/sun/star/comp/helper/ComponentContext.java
new file mode 100644
index 000000000000..25cce2236c9a
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/ComponentContext.java
@@ -0,0 +1,310 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.comp.helper;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Any;
+
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.EventObject;
+
+import java.util.Hashtable;
+import java.util.Enumeration;
+import java.util.Vector;
+
+
+//==================================================================================================
+class Disposer implements XEventListener
+{
+ private XComponent m_xComp;
+
+ //----------------------------------------------------------------------------------------------
+ Disposer( XComponent xComp )
+ {
+ m_xComp = xComp;
+ }
+ //______________________________________________________________________________________________
+ public void disposing( EventObject Source )
+ {
+ m_xComp.dispose();
+ }
+}
+
+/** Component context implementation.
+*/
+public class ComponentContext implements XComponentContext, XComponent
+{
+ private static final boolean DEBUG = false;
+ private static final String SMGR_NAME = "/singletons/com.sun.star.lang.theServiceManager";
+ private static final String TDMGR_NAME = "/singletons/com.sun.star.reflection.theTypeDescriptionManager";
+
+ private Hashtable m_table;
+ private XComponentContext m_xDelegate;
+
+ private XMultiComponentFactory m_xSMgr;
+ private boolean m_bDisposeSMgr;
+
+ private Vector m_eventListener;
+
+ /** Ctor to create a component context passing a hashtable for values and a delegator
+ reference. Entries of the passed hashtable are either direct values or
+ ComponentContextEntry objects.
+
+ @param table
+ entries
+ @param xDelegate
+ if values are not found, request is delegated to this object
+ */
+ public ComponentContext( Hashtable table, XComponentContext xDelegate )
+ {
+ m_eventListener = new Vector();
+ m_table = table;
+ m_xDelegate = xDelegate;
+ m_xSMgr = null;
+ m_bDisposeSMgr = false;
+
+ Object o = table.get( SMGR_NAME );
+ if (o != null)
+ {
+ if (o instanceof ComponentContextEntry)
+ {
+ o = ((ComponentContextEntry)o).m_value;
+ }
+ m_xSMgr = UnoRuntime.queryInterface(
+ XMultiComponentFactory.class, o );
+ }
+ if (m_xSMgr != null)
+ {
+ m_bDisposeSMgr = true;
+ }
+ else if (m_xDelegate != null)
+ {
+ m_xSMgr = m_xDelegate.getServiceManager();
+ }
+
+ // listen for delegate
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, m_xDelegate );
+ if (xComp != null)
+ {
+ xComp.addEventListener( new Disposer( this ) );
+ }
+ }
+
+ // XComponentContext impl
+ //______________________________________________________________________________________________
+ public Object getValueByName( String rName )
+ {
+ Object o = m_table.get( rName );
+ if (o != null)
+ {
+ if (o instanceof ComponentContextEntry)
+ {
+ ComponentContextEntry entry = (ComponentContextEntry)o;
+ if (entry.m_lateInit != null)
+ {
+ Object xInstance = null;
+
+ try
+ {
+ String serviceName = (String)entry.m_lateInit;
+ if (serviceName != null)
+ {
+ if (m_xSMgr != null)
+ {
+ xInstance = m_xSMgr.createInstanceWithContext( serviceName, this );
+ }
+ else
+ {
+ if (DEBUG)
+ System.err.println( "### no service manager instance for late init of singleton instance \"" + rName + "\"!" );
+ }
+ }
+ else
+ {
+ XSingleComponentFactory xCompFac =
+ UnoRuntime.queryInterface(
+ XSingleComponentFactory.class, entry.m_lateInit );
+ if (xCompFac != null)
+ {
+ xInstance = xCompFac.createInstanceWithContext( this );
+ }
+ else
+ {
+ if (DEBUG)
+ System.err.println( "### neither service name nor service factory given for late init of singleton instance \"" + rName + "\"!" );
+ }
+ }
+ }
+ catch (com.sun.star.uno.Exception exc)
+ {
+ if (DEBUG)
+ System.err.println( "### exception occurred on late init of singleton instance \"" + rName + "\": " + exc.getMessage() );
+ }
+
+ if (xInstance != null)
+ {
+ synchronized (entry)
+ {
+ if (entry.m_lateInit != null)
+ {
+ entry.m_value = xInstance;
+ entry.m_lateInit = null;
+ }
+ else // inited in the meantime
+ {
+ // dispose fresh service instance
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, xInstance );
+ if (xComp != null)
+ {
+ xComp.dispose();
+ }
+ }
+ }
+ }
+ else
+ {
+ if (DEBUG)
+ System.err.println( "### failed late init of singleton instance \"" + rName + "\"!" );
+ }
+ }
+ return entry.m_value;
+ }
+ else // direct value in map
+ {
+ return o;
+ }
+ }
+ else if (m_xDelegate != null)
+ {
+ return m_xDelegate.getValueByName( rName );
+ }
+ else
+ {
+ return Any.VOID;
+ }
+ }
+ //______________________________________________________________________________________________
+ public XMultiComponentFactory getServiceManager()
+ {
+ return m_xSMgr;
+ }
+
+ // XComponent impl
+ //______________________________________________________________________________________________
+ public void dispose()
+ {
+ if (DEBUG)
+ System.err.print( "> disposing context " + this );
+
+ // fire events
+ EventObject evt = new EventObject( this );
+ Enumeration eventListener = m_eventListener.elements();
+ while (eventListener.hasMoreElements())
+ {
+ XEventListener listener = (XEventListener)eventListener.nextElement();
+ listener.disposing( evt );
+ }
+ m_eventListener.removeAllElements();
+
+ XComponent tdmgr = null;
+ // dispose values, then service manager, then typdescription manager
+ Enumeration keys = m_table.keys();
+ while (keys.hasMoreElements())
+ {
+ String name = (String)keys.nextElement();
+ if (! name.equals( SMGR_NAME ))
+ {
+ Object o = m_table.get( name );
+ if (o instanceof ComponentContextEntry)
+ {
+ o = ((ComponentContextEntry)o).m_value;
+ }
+
+ XComponent xComp = UnoRuntime.queryInterface( XComponent.class, o );
+ if (xComp != null)
+ {
+ if (name.equals( TDMGR_NAME ))
+ {
+ tdmgr = xComp;
+ }
+ else
+ {
+ xComp.dispose();
+ }
+ }
+ }
+ }
+ m_table.clear();
+
+ // smgr
+ if (m_bDisposeSMgr)
+ {
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, m_xSMgr );
+ if (xComp != null)
+ {
+ xComp.dispose();
+ }
+ }
+ m_xSMgr = null;
+
+ // tdmgr
+ if (tdmgr != null)
+ {
+ tdmgr.dispose();
+ }
+
+ if (DEBUG)
+ System.err.println( "... finished" );
+ }
+ //______________________________________________________________________________________________
+ public void addEventListener( XEventListener xListener )
+ {
+ if (xListener == null)
+ throw new com.sun.star.uno.RuntimeException( "Listener must not be null" );
+ if (m_eventListener.contains( xListener ))
+ throw new com.sun.star.uno.RuntimeException( "Listener already registred." );
+
+ m_eventListener.addElement( xListener );
+ }
+ //______________________________________________________________________________________________
+ public void removeEventListener( XEventListener xListener )
+ {
+ if (xListener == null)
+ throw new com.sun.star.uno.RuntimeException( "Listener must not be null" );
+ if (! m_eventListener.contains( xListener ))
+ throw new com.sun.star.uno.RuntimeException( "Listener is not registered." );
+
+ m_eventListener.removeElement( xListener );
+ }
+}
diff --git a/javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java b/javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java
new file mode 100644
index 000000000000..52b116469f7a
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.comp.helper;
+
+/** Component context entry for constructing ComponentContext objects.
+ <p>
+ A ComponentContextEntry is separated into a late-init and direct-value
+ purpose.
+ The first one is commonly used for singleton objects of the component
+ context, that are raised on first-time retrieval of the key.
+ You have to pass a com.sun.star.lang.XSingleComponentFactory
+ or string (=> service name) object for this.
+ </p>
+*/
+public class ComponentContextEntry
+{
+ /** if late init of service instance, set service name (String) or
+ component factory (XSingleComponentFactory), null otherwise
+ */
+ public Object m_lateInit;
+ /** set entry value
+ */
+ public Object m_value;
+
+ /** Creating a late-init singleton entry component context entry.
+ The second parameter will be ignored and overwritten during
+ instanciation of the singleton instance.
+
+ @param lateInit
+ object factory or service string
+ @param value
+ pass null (dummy separating from second ctor signature)
+ */
+ public ComponentContextEntry( Object lateInit, Object value )
+ {
+ this.m_lateInit = lateInit;
+ this.m_value = value;
+ }
+ /** Creating a direct value component context entry.
+
+ @param value
+ pass null
+ */
+ public ComponentContextEntry( Object value )
+ {
+ this.m_lateInit = null;
+ this.m_value = value;
+ }
+}
diff --git a/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java b/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java
new file mode 100644
index 000000000000..826c812fa049
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java
@@ -0,0 +1,168 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+
+package com.sun.star.comp.helper;
+
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.RuntimeException;
+
+/** The class provides a set of methods which create instances of the
+ com.sun.star.lang.RegistryServiceManager service.
+
+ @deprecated use class Bootstrap instead
+*/
+public class RegistryServiceFactory {
+ static {
+ System.loadLibrary("juh");
+ }
+
+ private static native Object createRegistryServiceFactory(
+ String writeRegistryFile,
+ String readRegistryFile,
+ boolean readOnly,
+ ClassLoader loader);
+
+ /**
+ * This bootstraps an initial service factory working on a registry. If the first or both
+ * parameters contain a value then the service factory is initialized with a simple registry
+ * or a nested registry. Otherwise the service factory must be initialized later with a valid
+ * registry.
+ *<BR>
+ * @param writeRegistryFile file name of the simple registry or the first registry file of
+ * the nested registry which will be opened with read/write rights. This
+ * file will be created if necessary.
+ * @param readRegistryFile file name of the second registry file of the nested registry
+ * which will be opened with readonly rights.
+ * @return a new RegistryServiceFactory.
+ */
+ public static XMultiServiceFactory create(String writeRegistryFile, String readRegistryFile)
+ throws com.sun.star.uno.Exception
+ {
+ return create(writeRegistryFile, readRegistryFile, false);
+ }
+
+ /**
+ * This bootstraps an initial service factory working on a registry. If the first or both
+ * parameters contain a value then the service factory is initialized with a simple registry
+ * or a nested registry. Otherwise the service factory must be initialized later with a valid
+ * registry.
+ *<BR>
+ * @param writeRegistryFile file name of the simple registry or the first registry file of
+ * the nested registry which will be opened with read/write rights. This
+ * file will be created if necessary.
+ * @param readRegistryFile file name of the second registry file of the nested registry
+ * which will be opened with readonly rights.
+ * @param readOnly flag which specify that the first registry file will be opened with
+ * readonly rights. Default is FALSE. If this flag is used the registry
+ * will not be created if not exist.
+ *
+ * @return a new RegistryServiceFactory
+ */
+ public static XMultiServiceFactory create(String writeRegistryFile, String readRegistryFile, boolean readOnly)
+ throws com.sun.star.uno.Exception
+ {
+ // Ensure that we are on a native threads vm
+ // (binary UNO does use native threads).
+ String vm_info = System.getProperty("java.vm.info");
+ if(vm_info != null && vm_info.indexOf("green") != -1)
+ throw new RuntimeException(RegistryServiceFactory.class.toString() + ".create - can't use binary UNO with green threads");
+
+
+ if (writeRegistryFile == null && readRegistryFile == null)
+ throw new com.sun.star.uno.Exception("No registry is specified!");
+
+// if (writeRegistryFile != null) {
+// java.io.File file = new java.io.File(writeRegistryFile);
+
+// if (file.exists()) {
+// if (!file.isFile())
+// throw new com.sun.star.uno.Exception(writeRegistryFile + " is not a file!");
+// } else
+// throw new com.sun.star.uno.Exception(writeRegistryFile + " doese not exist!");
+// }
+
+// if (readRegistryFile != null) {
+// java.io.File file = new java.io.File(readRegistryFile);
+
+// if (file.exists()) {
+// if (!file.isFile())
+// throw new com.sun.star.uno.Exception(readRegistryFile + " is not a file!");
+// } else
+// throw new com.sun.star.uno.Exception(readRegistryFile + " doese not exist!");
+// }
+
+ Object obj = createRegistryServiceFactory(
+ writeRegistryFile, readRegistryFile, readOnly,
+ RegistryServiceFactory.class.getClassLoader() );
+ return UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, obj );
+ }
+
+ /**
+ * This bootstraps an initial service factory working on a registry file.
+ *<BR>
+ * @param registryFile file name of the registry to use/ create; if this is an empty
+ * string, the default registry is used instead
+ *
+ * @return a new RegistryServiceFactory.
+ */
+ public static XMultiServiceFactory create(String registryFile)
+ throws com.sun.star.uno.Exception
+ {
+ return create(registryFile, null, false);
+ }
+
+ /**
+ * This bootstraps an initial service factory working on a registry file.
+ *<BR>
+ * @param registryFile file name of the registry to use/ create; if this is an empty
+ * string, the default registry is used instead
+ * @param readOnly flag which specify that the registry file will be opened with
+ * readonly rights. Default is FALSE. If this flag is used the registry
+ * will not be created if not exist.
+ *
+ * @return a new RegistryServiceFactory.
+ */
+ public static XMultiServiceFactory create(String registryFile, boolean readOnly)
+ throws com.sun.star.uno.Exception
+ {
+ return create(registryFile, null, readOnly);
+ }
+
+ /**
+ * This bootstraps a service factory without initialize a registry.
+ *<BR>
+ * @return a new RegistryServiceFactory.
+ */
+ public static XMultiServiceFactory create() throws com.sun.star.uno.Exception {
+ return create( null, null, false );
+ }
+}
+
diff --git a/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java b/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java
new file mode 100644
index 000000000000..e077fe6bb9bd
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java
@@ -0,0 +1,159 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.comp.helper;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.registry.XRegistryKey;
+
+/**
+ * @deprecated use class Bootstrap bootstrapping a native UNO installation
+ * and use the shared library loader service.
+ *
+ * The <code>SharedLibraryLoader</code> class provides the functionality of the <code>com.sun.star.loader.SharedLibrary</code>
+ * service.
+ * <p>
+ * @see com.sun.star.loader.SharedLibrary
+ * @see com.sun.star.comp.servicemanager.ServiceManager
+ * @see com.sun.star.lang.ServiceManager
+ */
+public class SharedLibraryLoader {
+ /**
+ * The default library which contains the SharedLibraryLoader component
+ */
+ public static final String DEFAULT_LIBRARY = "shlibloader.uno";
+
+ /**
+ * The default implementation name
+ */
+ public static final String DEFAULT_IMPLEMENTATION = "com.sun.star.comp.stoc.DLLComponentLoader";
+
+ static {
+ System.loadLibrary("juh");
+ }
+
+ private static native boolean component_writeInfo(
+ String libName, XMultiServiceFactory smgr, XRegistryKey regKey,
+ ClassLoader loader );
+
+ private static native Object component_getFactory(
+ String libName, String implName, XMultiServiceFactory smgr,
+ XRegistryKey regKey, ClassLoader loader );
+
+ /**
+ * Supplies the ServiceFactory of the default SharedLibraryLoader.
+ * The defaults are "shlibloader.uno"
+ * for the library and "com.sun.star.comp.stoc.DLLComponentLoader"
+ * for the component name.
+ * <p>
+ * @return the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component.
+ * @param smgr the ServiceManager
+ * @param regKey the root registry key
+ * @see com.sun.star.loader.SharedLibrary
+ * @see com.sun.star.lang.ServiceManager
+ * @see com.sun.star.registry.RegistryKey
+ */
+ public static XSingleServiceFactory getServiceFactory(
+ XMultiServiceFactory smgr,
+ XRegistryKey regKey )
+ {
+ return UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ component_getFactory(
+ DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey,
+ SharedLibraryLoader.class.getClassLoader() ) );
+ }
+
+ /**
+ * Loads and returns a specific factory for a given library and implementation name.
+ * <p>
+ * @return the factory of the component
+ * @param libName the name of the shared library
+ * @param impName the implementation name of the component
+ * @param smgr the ServiceManager
+ * @param regKey the root registry key
+ * @see com.sun.star.loader.SharedLibrary
+ * @see com.sun.star.lang.ServiceManager
+ * @see com.sun.star.registry.RegistryKey
+ */
+ public static XSingleServiceFactory getServiceFactory(
+ String libName,
+ String impName,
+ XMultiServiceFactory smgr,
+ XRegistryKey regKey )
+ {
+ return UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ component_getFactory(
+ libName, impName, smgr, regKey,
+ SharedLibraryLoader.class.getClassLoader() ) );
+ }
+
+ /**
+ * Registers the SharedLibraryLoader under a RegistryKey.
+ * <p>
+ * @return true if the registration was successfull - otherwise false
+ * @param smgr the ServiceManager
+ * @param regKey the root key under that the component should be registered
+ * @see com.sun.star.loader.SharedLibrary
+ * @see com.sun.star.lang.ServiceManager
+ * @see com.sun.star.registry.RegistryKey
+ */
+ public static boolean writeRegistryServiceInfo(
+ com.sun.star.lang.XMultiServiceFactory smgr,
+ com.sun.star.registry.XRegistryKey regKey )
+ {
+ return component_writeInfo(
+ DEFAULT_LIBRARY, smgr, regKey,
+ SharedLibraryLoader.class.getClassLoader() );
+ }
+
+ /**
+ * Registers the SharedLibraryLoader under a RegistryKey.
+ * <p>
+ * @return true if the registration was successfull - otherwise false
+ * @param libName name of the shared library
+ * @param smgr the ServiceManager
+ * @param regKey the root key under that the component should be registered
+ * @see com.sun.star.loader.SharedLibrary
+ * @see com.sun.star.lang.ServiceManager
+ * @see com.sun.star.registry.RegistryKey
+ */
+ public static boolean writeRegistryServiceInfo(
+ String libName,
+ com.sun.star.lang.XMultiServiceFactory smgr,
+ com.sun.star.registry.XRegistryKey regKey )
+
+ throws com.sun.star.registry.InvalidRegistryException,
+ com.sun.star.uno.RuntimeException
+ {
+ return component_writeInfo(
+ libName, smgr, regKey, SharedLibraryLoader.class.getClassLoader() );
+ }
+}
+
diff --git a/javaunohelper/com/sun/star/comp/helper/UnoInfo.java b/javaunohelper/com/sun/star/comp/helper/UnoInfo.java
new file mode 100644
index 000000000000..d528f433ba59
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/UnoInfo.java
@@ -0,0 +1,115 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.helper;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * UnoInfo offers functionality to obtain the UNO jar files.
+ */
+public final class UnoInfo {
+
+ /**
+ * do not instantiate
+ */
+ private UnoInfo() {}
+
+ /**
+ * Gets the URL base.
+ *
+ * @return the URL base
+ */
+ private static String getBase() {
+
+ final String JUHJAR = "/juh.jar";
+
+ String base = null;
+
+ URLClassLoader cl = (URLClassLoader) UnoInfo.class.getClassLoader();
+ URL[] urls = cl.getURLs();
+ for ( int i = 0; i < urls.length; i++ ) {
+ String url = urls[i].toString();
+ if ( url.endsWith( JUHJAR ) )
+ {
+ int index = url.lastIndexOf( JUHJAR );
+ if ( index >= 0 ) {
+ base = url.substring( 0, index + 1 );
+ break;
+ }
+ }
+ }
+
+ return base;
+ }
+
+ /**
+ * Gets a list of URLs for the given jar files.
+ *
+ * @return the list of URLs
+ */
+ private static URL[] getURLs( String[] jarFileNames ) {
+
+ URL[] jars = new URL[jarFileNames.length];
+ String base = getBase();
+ for ( int i = 0; i < jarFileNames.length; i++ ) {
+ try {
+ jars[i] = new URL( base + jarFileNames[i] );
+ } catch ( MalformedURLException e ) {
+ return null;
+ }
+ }
+
+ return jars;
+ }
+
+ /**
+ * Gets the UNO jar files.
+ *
+ * @return the UNO jar files
+ */
+ public static URL[] getJars() {
+
+ String[] jarFileNames = new String[] {
+ "jurt.jar",
+ "ridl.jar",
+ "juh.jar" };
+
+ return getURLs( jarFileNames );
+ }
+
+ /**
+ * Gets the extra UNO types.
+ *
+ * @return the extra UNO types
+ */
+ public static URL[] getExtraTypes() {
+ return new URL[0];
+ }
+}
diff --git a/javaunohelper/com/sun/star/comp/helper/makefile.mk b/javaunohelper/com/sun/star/comp/helper/makefile.mk
new file mode 100644
index 000000000000..3752abc7dbda
--- /dev/null
+++ b/javaunohelper/com/sun/star/comp/helper/makefile.mk
@@ -0,0 +1,54 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..$/..$/..
+
+PRJNAME = juhelper
+PACKAGE = com$/sun$/star$/comp$/helper
+TARGET = com_sun_star_comp_helper
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+.INCLUDE: $(PRJ)$/util$/settings.pmk
+
+# --- Files --------------------------------------------------------
+
+JAVAFILES= \
+ ComponentContextEntry.java \
+ ComponentContext.java \
+ Bootstrap.java \
+ SharedLibraryLoader.java \
+ RegistryServiceFactory.java \
+ BootstrapException.java \
+ UnoInfo.java
+
+JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk