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 mod
._servicemgr
.uno
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.container
.XEnumeration
;
23 import com
.sun
.star
.container
.XSet
;
24 import com
.sun
.star
.lang
.XMultiServiceFactory
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.uno
.XComponentContext
;
27 import com
.sun
.star
.uno
.XInterface
;
28 import java
.io
.PrintWriter
;
29 import lib
.StatusException
;
31 import lib
.TestEnvironment
;
32 import lib
.TestParameters
;
33 import com
.sun
.star
.uno
.AnyConverter
;
34 import com
.sun
.star
.uno
.Type
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.stoc.OServiceManager</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li>
43 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
44 * <li> <code>com::sun::star::container::XSet</code></li>
45 * <li> <code>com::sun::star::lang::XMultiComponentFactory</code></li>
46 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
48 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
49 * <li> <code>com::sun::star::lang::XComponent</code></li>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
55 * @see com.sun.star.lang.XMultiServiceFactory
56 * @see com.sun.star.container.XContentEnumerationAccess
57 * @see com.sun.star.container.XSet
58 * @see com.sun.star.lang.XMultiComponentFactory
59 * @see com.sun.star.lang.XServiceInfo
60 * @see com.sun.star.container.XElementAccess
61 * @see com.sun.star.container.XEnumerationAccess
62 * @see com.sun.star.lang.XComponent
63 * @see ifc.lang._XMultiServiceFactory
64 * @see ifc.container._XContentEnumerationAccess
65 * @see ifc.container._XSet
66 * @see ifc.lang._XMultiComponentFactory
67 * @see ifc.lang._XServiceInfo
68 * @see ifc.container._XElementAccess
69 * @see ifc.container._XEnumerationAccess
70 * @see ifc.lang._XComponent
72 public class OServiceManager
extends TestCase
{
75 * Creating a Testenvironment for the interfaces to be tested.
76 * Creates an instance of the service
77 * <code>com.sun.star.comp.stoc.OServiceManager</code>.
78 * Object relations created :
80 * <li> <code>'NewElement'</code> for
81 * {@link ifc.container._XSet} :
82 * element to be inserted into manager. Here
83 * a new <code>ServiceManager</code> implementation is
85 * <code>tools.SOConnect.createSimpleServiceManager()</code>
86 * and one of services contained in it is taken.</li>
90 protected TestEnvironment createTestEnvironment
91 (TestParameters Param
, PrintWriter log
) {
93 XInterface oObj
= null;
94 Object oInterface
= null;
97 XMultiServiceFactory xMSF
= Param
.getMSF();
98 oInterface
= xMSF
.createInstance
99 ( "com.sun.star.comp.stoc.OServiceManager" );
100 } catch( com
.sun
.star
.uno
.Exception e
) {
101 log
.println("ServiceManager service not available" );
104 // adding a service to the manager
105 Object newElement
= null ;
106 XMultiServiceFactory srvMan
= null;
107 XComponentContext xContext
= null;
111 srvMan
= com
.sun
.star
.comp
.helper
.Bootstrap
.createSimpleServiceManager();
113 } catch ( java
.lang
.Exception ex
) {
114 log
.println("Error creating SimpleServiceManager :");
115 ex
.printStackTrace(log
);
119 XSet set
= UnoRuntime
.queryInterface
120 (XSet
.class, oInterface
) ;
121 XSet set1
= UnoRuntime
.queryInterface
122 (XSet
.class, srvMan
) ;
123 XEnumeration oEnum
= set1
.createEnumeration();
124 Object srv
= oEnum
.nextElement();
128 newElement
= oEnum
.nextElement();
130 XPropertySet xProp
= UnoRuntime
.queryInterface(
131 XPropertySet
.class, oInterface
);
133 xContext
= (XComponentContext
) AnyConverter
.toObject(
134 new Type(XComponentContext
.class),
135 xProp
.getPropertyValue("DefaultContext"));
137 } catch (com
.sun
.star
.uno
.Exception e
) {
138 log
.println("Can't insert a service to the ServiceManager") ;
139 throw new StatusException("Can't create object environment", e
) ;
142 oObj
= (XInterface
) oInterface
;
144 log
.println( " creating a new environment for object" );
145 TestEnvironment tEnv
= new TestEnvironment( oObj
);
147 // adding relation for XSet interface
148 tEnv
.addObjRelation("NewElement", newElement
) ;
150 // adding relation for XPropertySet
151 tEnv
.addObjRelation("PTT",new String
[]{"DefaultContext","none","none"});
153 //adding relation for XMultiComponentFactory
154 if (xContext
!= null) {
155 tEnv
.addObjRelation("DC", xContext
);
158 } // finish method getTestEnvironment
160 } // finish class OServiceManager