1*cdf0e10cSrcweir import java.awt.*; 2*cdf0e10cSrcweir import java.awt.event.*; 3*cdf0e10cSrcweir 4*cdf0e10cSrcweir import com.sun.star.comp.servicemanager.ServiceManager; 5*cdf0e10cSrcweir 6*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 7*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 8*cdf0e10cSrcweir import com.sun.star.connection.XConnector; 9*cdf0e10cSrcweir import com.sun.star.connection.XConnection; 10*cdf0e10cSrcweir 11*cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 12*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 13*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 14*cdf0e10cSrcweir import com.sun.star.uno.XNamingService; 15*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 16*cdf0e10cSrcweir 17*cdf0e10cSrcweir import com.sun.star.container.*; 18*cdf0e10cSrcweir import com.sun.star.beans.*; 19*cdf0e10cSrcweir import com.sun.star.lang.*; 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir public class EmbedContFrame extends Frame 23*cdf0e10cSrcweir { 24*cdf0e10cSrcweir WindowListener m_aCloser = new WindowAdapter() 25*cdf0e10cSrcweir { 26*cdf0e10cSrcweir public void windowClosing( WindowEvent e ) 27*cdf0e10cSrcweir { 28*cdf0e10cSrcweir dispose(); 29*cdf0e10cSrcweir System.exit( 0 ); 30*cdf0e10cSrcweir } 31*cdf0e10cSrcweir }; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir public EmbedContFrame( String sName ) 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir super( sName ); 36*cdf0e10cSrcweir addWindowListener( m_aCloser ); 37*cdf0e10cSrcweir } 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir public static void start() 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir EmbedContFrame aFrame = new EmbedContFrame( "Testing container." ); 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // connect to the office 44*cdf0e10cSrcweir XMultiServiceFactory aServiceFactory = null; 45*cdf0e10cSrcweir try { 46*cdf0e10cSrcweir aServiceFactory = connectOfficeGetServiceFactory(); 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir catch( Exception e ) 49*cdf0e10cSrcweir {} 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir if ( aServiceFactory == null ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir System.out.println( "Can't get service manager!\n" ); 54*cdf0e10cSrcweir System.exit( 1 ); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir EmbedContApp aApp = new EmbedContApp( aFrame, aServiceFactory ); 58*cdf0e10cSrcweir aApp.init(); 59*cdf0e10cSrcweir aApp.start(); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir Dimension aSize = aApp.getSize(); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir aFrame.add( "Center", aApp ); 64*cdf0e10cSrcweir aFrame.pack(); 65*cdf0e10cSrcweir aFrame.setSize( aSize ); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir aFrame.setVisible( true ); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir public static void main( String args[] ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir EmbedContFrame.start(); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir public static XMultiServiceFactory connectOfficeGetServiceFactory() 76*cdf0e10cSrcweir throws com.sun.star.uno.Exception, 77*cdf0e10cSrcweir com.sun.star.uno.RuntimeException, 78*cdf0e10cSrcweir Exception 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService"; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // Get component context 83*cdf0e10cSrcweir XComponentContext xComponentContext = 84*cdf0e10cSrcweir com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null ); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir // initial serviceManager 87*cdf0e10cSrcweir XMultiComponentFactory xLocalServiceManager = xComponentContext.getServiceManager(); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // create a connector, so that it can contact the office 90*cdf0e10cSrcweir Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", 91*cdf0e10cSrcweir xComponentContext ); 92*cdf0e10cSrcweir XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( XUnoUrlResolver.class, oUrlResolver ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir Object oInitialObject = xUrlResolver.resolve( sConnectionString ); 95*cdf0e10cSrcweir XNamingService xName = (XNamingService)UnoRuntime.queryInterface( XNamingService.class, oInitialObject ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir XMultiServiceFactory xMSF = null; 98*cdf0e10cSrcweir if( xName != null ) { 99*cdf0e10cSrcweir Object oMSF = xName.getRegisteredObject( "StarOffice.ServiceManager" ); 100*cdf0e10cSrcweir xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF ); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir else 103*cdf0e10cSrcweir System.out.println( "Error: Can't get XNamingService interface from url resolver!" ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir return xMSF; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109