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

INTEGRATION: CWS sdksample (1.4.40); FILE MERGED

2004/08/06 14:36:56 jsc 1.4.40.3: #i29308# use System.err for error output
2004/07/26 11:26:23 jsc 1.4.40.2: #i29308# insert temporary bugfix
2004/06/08 08:24:35 jsc 1.4.40.1: #i29308# use of new UNO features
üst d241b275
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: ConfigExamples.java,v $ * $RCSfile: ConfigExamples.java,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: hr $ $Date: 2004-02-03 11:18:27 $ * last change: $Author: rt $ $Date: 2005-01-31 16:19:00 $
* *
* 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.
...@@ -63,6 +63,7 @@ import com.sun.star.lang.XComponent; ...@@ -63,6 +63,7 @@ import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.EventObject; import com.sun.star.lang.EventObject;
...@@ -89,67 +90,51 @@ import com.sun.star.util.ChangesEvent; ...@@ -89,67 +90,51 @@ import com.sun.star.util.ChangesEvent;
o Resetting data to their defaults o Resetting data to their defaults
Each example is in a separate method call. Each example is in a separate method call.
It accepts one command line parameter in the form of a connection string,
if no connection string is specified it uses the default of
"socket,host=localhost,port=2083"
*/ */
public class ConfigExamples public class ConfigExamples
{ {
// The MultiServiceFactory interface of the ServiceManager // The ComponentContext interface of the remote component context
private XMultiServiceFactory mxServiceManager = null; private XComponentContext mxContext = null;
// The MultiComponentFactory interface of the ServiceManager
private XMultiComponentFactory mxServiceManager = null;
// The MultiServiceFactory interface of the ConfigurationProvider // The MultiServiceFactory interface of the ConfigurationProvider
private XMultiServiceFactory mxProvider = null; private XMultiServiceFactory mxProvider = null;
public static void main(String args[]) public static void main( String args[] )
{ {
String sConnection; try {
// Get the connect string, defaulting to localhost, port 2083 // get the remote office component context
// if non supplied as command line arguments com.sun.star.uno.XComponentContext xContext =
if( args.length == 0 ) com.sun.star.comp.helper.Bootstrap.bootstrap();
{
sConnection = "socket,host=localhost,port=2083"; if( xContext != null )
System.out.println( "Using default connect string: " + sConnection ); System.out.println("Connected to a running office ...");
} else
else System.out.println( "ERROR: Cannot connect - no remote component context available." );
{
sConnection = args[0];
System.out.println( "Using connect string: " + sConnection );
}
// Call connect, to get the MultiServiceFactory
// of a running office and execute the examples.
// If something goes wrong, print a stack trace and exit.
try
{
XMultiServiceFactory xServiceManager = connect( sConnection );
if (xServiceManager == null)
{
System.out.println( "ERROR: Cannot connect - no service manager available." );
return;
}
// Create an instance of the class and call it's run method // Create an instance of the class and call it's run method
ConfigExamples aExample = new ConfigExamples(xServiceManager); ConfigExamples aExample = new ConfigExamples(xContext);
aExample.run ( ); aExample.run( );
// if you own the service manager dispose it here // if you own the service manager dispose it here
// to ensure that the default provider is properly disposed and flushed // to ensure that the default provider is properly disposed and flushed
System.exit(0); System.exit(0);
} }
catch( Exception e ) catch( Exception e )
{ {
e.printStackTrace ( System.out ); e.printStackTrace();
System.exit(-1); System.exit(-1);
} }
} }
/** Create a ConfigExamples instance supplying a service factory /** Create a ConfigExamples instance supplying a service factory
*/ */
public ConfigExamples(XMultiServiceFactory xServiceManager) public ConfigExamples(XComponentContext xContext)
{ {
mxServiceManager = xServiceManager; mxContext = xContext;
mxServiceManager = xContext.getServiceManager();
} }
/** Run the examples with a default ConfigurationProvider /** Run the examples with a default ConfigurationProvider
...@@ -237,46 +222,12 @@ public class ConfigExamples ...@@ -237,46 +222,12 @@ public class ConfigExamples
} }
catch (com.sun.star.uno.RuntimeException e) catch (com.sun.star.uno.RuntimeException e)
{ {
System.out.println("ERROR: Failure while checking the provider services."); System.err.println("ERROR: Failure while checking the provider services.");
e.printStackTrace( System.out ); e.printStackTrace();
return false; return false;
} }
} }
/** Connect to a specified host which is running office and accepting
connections on the requested port. Set up a ServiceManager of the office
*/
public static XMultiServiceFactory connect( String sConnection )
throws com.sun.star.uno.Exception, Exception
{
XComponentContext xContext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
XMultiComponentFactory xLocalServiceManager = xContext.getServiceManager();
Object xUrlResolver = xLocalServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xContext );
XUnoUrlResolver urlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( XUnoUrlResolver.class, xUrlResolver );
Object rInitialObject = urlResolver.resolve( "uno:" + sConnection + ";urp;StarOffice.NamingService" );
XNamingService rName = (XNamingService)UnoRuntime.queryInterface(XNamingService.class, rInitialObject );
XMultiServiceFactory xFactory = null;
if( rName != null )
{
Object rXsmgr = rName.getRegisteredObject("StarOffice.ServiceManager" );
xFactory = (XMultiServiceFactory)
UnoRuntime.queryInterface( XMultiServiceFactory.class, rXsmgr );
}
return xFactory;
}
/** Get the service manager in use
*/
public XMultiServiceFactory getServiceManager( )
{
return mxServiceManager;
}
/** Get the provider we have /** Get the provider we have
*/ */
public XMultiServiceFactory getProvider( ) public XMultiServiceFactory getProvider( )
...@@ -289,14 +240,13 @@ public class ConfigExamples ...@@ -289,14 +240,13 @@ public class ConfigExamples
public XMultiServiceFactory createProvider( ) public XMultiServiceFactory createProvider( )
throws com.sun.star.uno.Exception throws com.sun.star.uno.Exception
{ {
XMultiServiceFactory xServiceManager = getServiceManager();
final String sProviderService = "com.sun.star.configuration.ConfigurationProvider"; final String sProviderService = "com.sun.star.configuration.ConfigurationProvider";
// create the provider and return it as a XMultiServiceFactory // create the provider and return it as a XMultiServiceFactory
XMultiServiceFactory xProvider = (XMultiServiceFactory) XMultiServiceFactory xProvider = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, UnoRuntime.queryInterface(XMultiServiceFactory.class,
xServiceManager.createInstance(sProviderService)); mxServiceManager.createInstanceWithContext(sProviderService,
mxContext));
return xProvider; return xProvider;
} }
...@@ -309,14 +259,13 @@ public class ConfigExamples ...@@ -309,14 +259,13 @@ public class ConfigExamples
public XMultiServiceFactory createAdminProvider(Object[] aAdminArguments) public XMultiServiceFactory createAdminProvider(Object[] aAdminArguments)
throws com.sun.star.uno.Exception throws com.sun.star.uno.Exception
{ {
XMultiServiceFactory xServiceManager = getServiceManager();
final String sAdminService = "com.sun.star.configuration.AdministrationProvider"; final String sAdminService = "com.sun.star.configuration.AdministrationProvider";
// create the provider and remember it as a XMultiServiceFactory // create the provider and remember it as a XMultiServiceFactory
XMultiServiceFactory xAdminProvider = (XMultiServiceFactory) XMultiServiceFactory xAdminProvider = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, UnoRuntime.queryInterface(XMultiServiceFactory.class,
xServiceManager.createInstanceWithArguments(sAdminService,aAdminArguments)); mxServiceManager.createInstanceWithArgumentsAndContext(
sAdminService, aAdminArguments, mxContext));
return xAdminProvider; return xAdminProvider;
} }
...@@ -412,7 +361,7 @@ public class ConfigExamples ...@@ -412,7 +361,7 @@ public class ConfigExamples
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace ( System.out ); e.printStackTrace();
} }
} }
...@@ -427,7 +376,7 @@ public class ConfigExamples ...@@ -427,7 +376,7 @@ public class ConfigExamples
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace ( System.out ); e.printStackTrace();
} }
} }
...@@ -442,7 +391,7 @@ public class ConfigExamples ...@@ -442,7 +391,7 @@ public class ConfigExamples
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace ( System.out ); e.printStackTrace();
} }
} }
...@@ -461,7 +410,7 @@ public class ConfigExamples ...@@ -461,7 +410,7 @@ public class ConfigExamples
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace ( System.out ); e.printStackTrace();
} }
} }
...@@ -476,7 +425,7 @@ public class ConfigExamples ...@@ -476,7 +425,7 @@ public class ConfigExamples
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace ( System.out ); e.printStackTrace();
} }
} }
...@@ -578,6 +527,10 @@ public class ConfigExamples ...@@ -578,6 +527,10 @@ public class ConfigExamples
XHierarchicalName xElementPath = XHierarchicalName xElementPath =
(XHierarchicalName) UnoRuntime.queryInterface(XHierarchicalName.class, xElement); (XHierarchicalName) UnoRuntime.queryInterface(XHierarchicalName.class, xElement);
// temporary check, we have to check why XHierarchicalName isn't supported
if ( xElementPath == null )
return;
String sPath = xElementPath.getHierarchicalName(); String sPath = xElementPath.getHierarchicalName();
aProcessor.processStructuralElement( sPath, xElement); aProcessor.processStructuralElement( sPath, xElement);
...@@ -648,7 +601,7 @@ public class ConfigExamples ...@@ -648,7 +601,7 @@ public class ConfigExamples
throws com.sun.star.uno.Exception throws com.sun.star.uno.Exception
{ {
final String sProviderService = "com.sun.star.configuration.ConfigurationProvider"; final String sProviderService = "com.sun.star.configuration.ConfigurationProvider";
final String sFilterKey = "/org.openoffice.Office.TypeDetection/Filters"; final String sFilterKey = "/org.openoffice.TypeDetection.Filter/Filters";
// browse the configuration, dumping filter information // browse the configuration, dumping filter information
browseConfiguration( sFilterKey, browseConfiguration( sFilterKey,
...@@ -768,8 +721,8 @@ public class ConfigExamples ...@@ -768,8 +721,8 @@ public class ConfigExamples
/// this method is called to report an error during dialog execution to the zuser /// this method is called to report an error during dialog execution to the zuser
public void informUserOfError(Exception e) { public void informUserOfError(Exception e) {
System.out.println("ERROR in GridEditor:"); System.err.println("ERROR in GridEditor:");
e.printStackTrace(System.out); e.printStackTrace();
} }
/// this method is called to allow the dialog to get feedback about changes occurring elsewhere /// this method is called to allow the dialog to get feedback about changes occurring elsewhere
...@@ -899,8 +852,8 @@ public class ConfigExamples ...@@ -899,8 +852,8 @@ public class ConfigExamples
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Could not change some data in a different view. An exception occurred:"); System.err.println("Could not change some data in a different view. An exception occurred:");
e.printStackTrace( System.out ); e.printStackTrace();
} }
} }
...@@ -1105,7 +1058,7 @@ public class ConfigExamples ...@@ -1105,7 +1058,7 @@ public class ConfigExamples
catch (Exception e) catch (Exception e)
{ {
// something went wrong, we retry with a new element // something went wrong, we retry with a new element
System.out.println("WARNING: An exception occurred while creating a view for an existing data source: " + e); System.err.println("WARNING: An exception occurred while creating a view for an existing data source: " + e);
xDataSourceDescriptor = null; xDataSourceDescriptor = null;
} }
} }
......
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