1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.awt
.event
.*;
23 import com
.sun
.star
.comp
.servicemanager
.ServiceManager
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.lang
.XMultiComponentFactory
;
27 import com
.sun
.star
.connection
.XConnector
;
28 import com
.sun
.star
.connection
.XConnection
;
30 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
33 import com
.sun
.star
.uno
.XNamingService
;
34 import com
.sun
.star
.uno
.XComponentContext
;
36 import com
.sun
.star
.container
.*;
37 import com
.sun
.star
.beans
.*;
38 import com
.sun
.star
.lang
.*;
41 public class EmbedContFrame
extends Frame
43 WindowListener m_aCloser
= new WindowAdapter()
45 public void windowClosing( WindowEvent e
)
52 public EmbedContFrame( String sName
)
55 addWindowListener( m_aCloser
);
58 public static void start()
60 EmbedContFrame aFrame
= new EmbedContFrame( "Testing container." );
62 // connect to the office
63 XMultiServiceFactory aServiceFactory
= null;
65 aServiceFactory
= connectOfficeGetServiceFactory();
70 if ( aServiceFactory
== null )
72 System
.out
.println( "Can't get service manager!\n" );
76 EmbedContApp aApp
= new EmbedContApp( aFrame
, aServiceFactory
);
80 Dimension aSize
= aApp
.getSize();
82 aFrame
.add( "Center", aApp
);
84 aFrame
.setSize( aSize
);
86 aFrame
.setVisible( true );
89 public static void main( String args
[] )
91 EmbedContFrame
.start();
94 public static XMultiServiceFactory
connectOfficeGetServiceFactory()
95 throws com
.sun
.star
.uno
.Exception
,
96 com
.sun
.star
.uno
.RuntimeException
,
99 String sConnectionString
= "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService";
101 // Get component context
102 XComponentContext xComponentContext
=
103 com
.sun
.star
.comp
.helper
.Bootstrap
.createInitialComponentContext( null );
105 // initial serviceManager
106 XMultiComponentFactory xLocalServiceManager
= xComponentContext
.getServiceManager();
108 // create a connector, so that it can contact the office
109 Object oUrlResolver
= xLocalServiceManager
.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver",
111 XUnoUrlResolver xUrlResolver
= (XUnoUrlResolver
)UnoRuntime
.queryInterface( XUnoUrlResolver
.class, oUrlResolver
);
113 Object oInitialObject
= xUrlResolver
.resolve( sConnectionString
);
114 XNamingService xName
= (XNamingService
)UnoRuntime
.queryInterface( XNamingService
.class, oInitialObject
);
116 XMultiServiceFactory xMSF
= null;
117 if( xName
!= null ) {
118 Object oMSF
= xName
.getRegisteredObject( "StarOffice.ServiceManager" );
119 xMSF
= (XMultiServiceFactory
)UnoRuntime
.queryInterface( XMultiServiceFactory
.class, oMSF
);
122 System
.out
.println( "Error: Can't get XNamingService interface from url resolver!" );
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */