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

INTEGRATION: CWS sdksample (1.4.40); FILE MERGED

2004/11/16 08:28:35 jsc 1.4.40.4: #i29308# cleanup
2004/08/06 14:36:54 jsc 1.4.40.3: #i29308# use System.err for error output
2004/07/30 08:35:29 jsc 1.4.40.2: #i29308# integrate new multiple inheritance interface
2004/06/30 09:10:28 jsc 1.4.40.1: #i29308# use of new UNO features
üst 9ce96b7a
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: Thumbs.java,v $ * $RCSfile: Thumbs.java,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: hr $ $Date: 2004-02-02 19:50:54 $ * last change: $Author: rt $ $Date: 2005-01-31 16:17:43 $
* *
* 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.
...@@ -37,116 +37,49 @@ ...@@ -37,116 +37,49 @@
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*************************************************************************/ *************************************************************************/
/*
* contains static component methods for multiple service implementations
* in thumbs.jar and a main method to test service implementations
*
*/
package org.openoffice.comp.test; package org.openoffice.comp.test;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.comp.loader.FactoryHelper;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.beans.XPropertySet;
import org.openoffice.test.XImageShrink;
//import com.sun.star.test.XSomethingA;
/** /**
* * Test class for testing the ImageShrink service skeleton.
* @author dschulten * Note: the image shrink functionality is not implemented
*/ */
public class Thumbs { public class Thumbs {
static private XComponentContext xRemoteContext = null;
static private XMultiComponentFactory xRemoteServiceManager = null;
/** Creates a new instance of Thumbs */
public Thumbs() {
}
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
try { try {
xRemoteServiceManager = getRemoteServiceManager( // get the remote office component context
"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"); com.sun.star.uno.XComponentContext xRemoteContext =
com.sun.star.comp.helper.Bootstrap.bootstrap();
Object ob = xRemoteServiceManager.createInstanceWithContext( System.out.println("Connected to a running office ...");
"org.openoffice.test.ImageShrink", xRemoteContext);
XImageShrink xImageShrink = (XImageShrink) UnoRuntime.queryInterface( // use the generated default create method to instantiate a
XImageShrink.class, ob); // new ImageShrink object
xImageShrink.setSourceDirectory("file:///C:/"); org.openoffice.test.XImageShrinkFilter xImageShrinkFilter =
System.out.println(xImageShrink.getSourceDirectory()); org.openoffice.test.ImageShrink.create(xRemoteContext);
/* System.out.println("ImageShrink component succesfully instantiated");
System.out.println((xImageShrink.getSourceDirectory()));
*/ java.io.File f = new java.io.File(".");
System.out.println("set SourceDrectory ...");
xImageShrinkFilter.setSourceDirectory(f.getCanonicalPath());
System.out.println("source Directory = "
+ xImageShrinkFilter.getSourceDirectory());
} }
catch (java.lang.Exception e){ catch (java.lang.Exception e){
System.err.println("Error: " + e);
e.printStackTrace(); e.printStackTrace();
} }
finally { finally {
System.exit(0); System.exit(0);
} }
}
// static __getServiceFactory() Implementation
public static XSingleServiceFactory __getServiceFactory(String implName,
XMultiServiceFactory multiFactory,
com.sun.star.registry.XRegistryKey regKey) {
com.sun.star.lang.XSingleServiceFactory xSingleServiceFactory = null;
if (implName.equals( ImageShrink.class.getName()) )
xSingleServiceFactory = FactoryHelper.getServiceFactory( ImageShrink.class,
ImageShrink.__serviceName,
multiFactory,
regKey);
return xSingleServiceFactory;
}
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
//System.out.println(ImageShrink.class.getName());
return FactoryHelper.writeRegistryServiceInfo( ImageShrink.class.getName(),
ImageShrink.__serviceName,
regKey);
}
protected static 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();
} }
} }
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