1 package embeddedobj
.test
;
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
)
34 m_aApp
.disposeObject();
43 public EmbedContFrame( String 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;
56 aServiceFactory
= connectOfficeGetServiceFactory();
61 if ( aServiceFactory
== null )
63 System
.out
.println( "Can't get service manager!\n" );
67 aFrame
.m_aApp
= new EmbedContApp( aFrame
, aServiceFactory
);
69 aFrame
.m_aApp
.start();
71 Dimension aSize
= aFrame
.m_aApp
.getSize();
73 aFrame
.add( "Center", aFrame
.m_aApp
);
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
,
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",
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
);
113 System
.out
.println( "Error: Can't get XNamingService interface from url resolver!" );