1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OServiceManager.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
40 import com
.sun
.star
.beans
.XPropertySet
;
41 import com
.sun
.star
.container
.XEnumeration
;
42 import com
.sun
.star
.container
.XSet
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XComponentContext
;
48 import com
.sun
.star
.uno
.XInterface
;
51 * Test for object which is represented by service
52 * <code>com.sun.star.comp.stoc.OServiceManager</code>. <p>
54 * Object implements the following interfaces :
56 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li>
57 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
58 * <li> <code>com::sun::star::container::XSet</code></li>
59 * <li> <code>com::sun::star::lang::XMultiComponentFactory</code></li>
60 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
61 * <li> <code>com::sun::star::container::XElementAccess</code></li>
62 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
63 * <li> <code>com::sun::star::lang::XComponent</code></li>
66 * This object test <b> is NOT </b> designed to be run in several
67 * threads concurently.
69 * @see com.sun.star.lang.XMultiServiceFactory
70 * @see com.sun.star.container.XContentEnumerationAccess
71 * @see com.sun.star.container.XSet
72 * @see com.sun.star.lang.XMultiComponentFactory
73 * @see com.sun.star.lang.XServiceInfo
74 * @see com.sun.star.container.XElementAccess
75 * @see com.sun.star.container.XEnumerationAccess
76 * @see com.sun.star.lang.XComponent
77 * @see ifc.lang._XMultiServiceFactory
78 * @see ifc.container._XContentEnumerationAccess
79 * @see ifc.container._XSet
80 * @see ifc.lang._XMultiComponentFactory
81 * @see ifc.lang._XServiceInfo
82 * @see ifc.container._XElementAccess
83 * @see ifc.container._XEnumerationAccess
84 * @see ifc.lang._XComponent
86 public class OServiceManager
extends TestCase
{
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.stoc.OServiceManager</code>.
92 * Object relations created :
94 * <li> <code>'NewElement'</code> for
95 * {@link ifc.container._XSet} :
96 * element to be inserted into manager. Here
97 * a new <code>ServiceManager</code> implementation is
99 * <code>tools.SOConnect.createSimpleServiceManager()</code>
100 * and one of services contained in it is taken.</li>
103 protected TestEnvironment createTestEnvironment
104 (TestParameters Param
, PrintWriter log
) {
106 XInterface oObj
= null;
107 Object oInterface
= null;
110 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
111 oInterface
= xMSF
.createInstance
112 ( "com.sun.star.comp.stoc.OServiceManager" );
113 } catch( com
.sun
.star
.uno
.Exception e
) {
114 log
.println("ServiceManager service not available" );
117 // adding a service to the manager
118 Object newElement
= null ;
119 XMultiServiceFactory srvMan
= null;
120 XComponentContext xContext
= null;
124 srvMan
= com
.sun
.star
.comp
.helper
.Bootstrap
.createSimpleServiceManager();
126 } catch ( java
.lang
.Exception ex
) {
127 log
.println("Error creating SimpleServiceManager :");
128 ex
.printStackTrace(log
);
132 XSet set
= (XSet
) UnoRuntime
.queryInterface
133 (XSet
.class, oInterface
) ;
134 XSet set1
= (XSet
) UnoRuntime
.queryInterface
135 (XSet
.class, srvMan
) ;
136 XEnumeration oEnum
= set1
.createEnumeration();
137 Object srv
= oEnum
.nextElement();
141 newElement
= oEnum
.nextElement();
143 XPropertySet xProp
= (XPropertySet
)UnoRuntime
.queryInterface(
144 XPropertySet
.class, oInterface
);
146 xContext
= (XComponentContext
) AnyConverter
.toObject(
147 new Type(XComponentContext
.class),
148 xProp
.getPropertyValue("DefaultContext"));
150 } catch (com
.sun
.star
.uno
.Exception e
) {
151 log
.println("Can't insert a service to the ServiceManager") ;
152 throw new StatusException("Can't create object environment", e
) ;
155 oObj
= (XInterface
) oInterface
;
157 log
.println( " creating a new environment for object" );
158 TestEnvironment tEnv
= new TestEnvironment( oObj
);
160 // adding relation for XSet interface
161 tEnv
.addObjRelation("NewElement", newElement
) ;
163 // adding relation for XPropertySet
164 tEnv
.addObjRelation("PTT",new String
[]{"DefaultContext","none","none"});
166 //adding relation for XMultiComponentFactory
167 if (xContext
!= null) {
168 tEnv
.addObjRelation("DC", xContext
);
171 } // finish method getTestEnvironment
173 } // finish class OServiceManager