update dev300-m58
[ooovba.git] / embeddedobj / test / Container1 / EmbedContFrame.java
blob2a79686df37f1ab846dfec68f7cf11ec7bc2361f
1 package embeddedobj.test;
3 import java.awt.*;
4 import java.awt.event.*;
6 import com.sun.star.comp.servicemanager.ServiceManager;
8 import com.sun.star.lang.XMultiServiceFactory;
9 import com.sun.star.lang.XMultiComponentFactory;
10 import com.sun.star.connection.XConnector;
11 import com.sun.star.connection.XConnection;
13 import com.sun.star.bridge.XUnoUrlResolver;
14 import com.sun.star.uno.UnoRuntime;
15 import com.sun.star.uno.XInterface;
16 import com.sun.star.uno.XNamingService;
17 import com.sun.star.uno.XComponentContext;
19 import com.sun.star.container.*;
20 import com.sun.star.beans.*;
21 import com.sun.star.lang.*;
24 public class EmbedContFrame extends Frame
26 private EmbedContApp m_aApp;
28 WindowListener m_aCloser = new WindowAdapter()
30 public void windowClosing( WindowEvent e )
32 if ( m_aApp != null )
34 m_aApp.disposeObject();
35 m_aApp = null;
38 dispose();
39 System.exit( 0 );
43 public EmbedContFrame( String sName )
45 super( sName );
46 addWindowListener( m_aCloser );
49 public static void start()
51 EmbedContFrame aFrame = new EmbedContFrame( "Testing container." );
53 // connect to the office
54 XMultiServiceFactory aServiceFactory = null;
55 try {
56 aServiceFactory = connectOfficeGetServiceFactory();
58 catch( Exception e )
61 if ( aServiceFactory == null )
63 System.out.println( "Can't get service manager!\n" );
64 System.exit( 1 );
67 aFrame.m_aApp = new EmbedContApp( aFrame, aServiceFactory );
68 aFrame.m_aApp.init();
69 aFrame.m_aApp.start();
71 Dimension aSize = aFrame.m_aApp.getSize();
73 aFrame.add( "Center", aFrame.m_aApp );
74 aFrame.pack();
75 aFrame.setSize( aSize );
77 aFrame.setVisible( true );
80 public static void main( String args[] )
82 EmbedContFrame.start();
85 public static XMultiServiceFactory connectOfficeGetServiceFactory()
86 throws com.sun.star.uno.Exception,
87 com.sun.star.uno.RuntimeException,
88 Exception
90 String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService";
92 // Get component context
93 XComponentContext xComponentContext =
94 com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
96 // initial serviceManager
97 XMultiComponentFactory xLocalServiceManager = xComponentContext.getServiceManager();
99 // create a connector, so that it can contact the office
100 Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver",
101 xComponentContext );
102 XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( XUnoUrlResolver.class, oUrlResolver );
104 Object oInitialObject = xUrlResolver.resolve( sConnectionString );
105 XNamingService xName = (XNamingService)UnoRuntime.queryInterface( XNamingService.class, oInitialObject );
107 XMultiServiceFactory xMSF = null;
108 if( xName != null ) {
109 Object oMSF = xName.getRegisteredObject( "StarOffice.ServiceManager" );
110 xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF );
112 else
113 System.out.println( "Error: Can't get XNamingService interface from url resolver!" );
115 return xMSF;