2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package embeddedobj
.test
;
22 import java
.awt
.event
.*;
24 import com
.sun
.star
.comp
.servicemanager
.ServiceManager
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.lang
.XMultiComponentFactory
;
28 import com
.sun
.star
.connection
.XConnector
;
29 import com
.sun
.star
.connection
.XConnection
;
31 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.uno
.XNamingService
;
35 import com
.sun
.star
.uno
.XComponentContext
;
37 import com
.sun
.star
.container
.*;
38 import com
.sun
.star
.beans
.*;
39 import com
.sun
.star
.lang
.*;
42 public class EmbedContFrame
extends Frame
44 private EmbedContApp m_aApp
;
46 WindowListener m_aCloser
= new WindowAdapter()
48 public void windowClosing( WindowEvent e
)
52 m_aApp
.disposeObject();
61 public EmbedContFrame( String sName
)
64 addWindowListener( m_aCloser
);
67 public static void start()
69 EmbedContFrame aFrame
= new EmbedContFrame( "Testing container." );
71 // connect to the office
72 XMultiServiceFactory aServiceFactory
= null;
74 aServiceFactory
= connectOfficeGetServiceFactory();
79 if ( aServiceFactory
== null )
81 System
.out
.println( "Can't get service manager!\n" );
85 aFrame
.m_aApp
= new EmbedContApp( aFrame
, aServiceFactory
);
87 aFrame
.m_aApp
.start();
89 Dimension aSize
= aFrame
.m_aApp
.getSize();
91 aFrame
.add( "Center", aFrame
.m_aApp
);
93 aFrame
.setSize( aSize
);
95 aFrame
.setVisible( true );
98 public static void main( String args
[] )
100 EmbedContFrame
.start();
103 public static XMultiServiceFactory
connectOfficeGetServiceFactory()
104 throws com
.sun
.star
.uno
.Exception
,
105 com
.sun
.star
.uno
.RuntimeException
,
108 String sConnectionString
= "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService";
110 // Get component context
111 XComponentContext xComponentContext
=
112 com
.sun
.star
.comp
.helper
.Bootstrap
.createInitialComponentContext( null );
114 // initial serviceManager
115 XMultiComponentFactory xLocalServiceManager
= xComponentContext
.getServiceManager();
117 // create a connector, so that it can contact the office
118 Object oUrlResolver
= xLocalServiceManager
.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver",
120 XUnoUrlResolver xUrlResolver
= (XUnoUrlResolver
)UnoRuntime
.queryInterface( XUnoUrlResolver
.class, oUrlResolver
);
122 Object oInitialObject
= xUrlResolver
.resolve( sConnectionString
);
123 XNamingService xName
= (XNamingService
)UnoRuntime
.queryInterface( XNamingService
.class, oInitialObject
);
125 XMultiServiceFactory xMSF
= null;
126 if( xName
!= null ) {
127 Object oMSF
= xName
.getRegisteredObject( "StarOffice.ServiceManager" );
128 xMSF
= (XMultiServiceFactory
)UnoRuntime
.queryInterface( XMultiServiceFactory
.class, oMSF
);
131 System
.out
.println( "Error: Can't get XNamingService interface from url resolver!" );