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 ************************************************************************/
31 package mod
._servicemgr
.uno
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.container
.XEnumeration
;
35 import com
.sun
.star
.container
.XSet
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XComponentContext
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import java
.io
.PrintWriter
;
41 import lib
.StatusException
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.comp.stoc.OServiceManager</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li>
55 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
56 * <li> <code>com::sun::star::container::XSet</code></li>
57 * <li> <code>com::sun::star::lang::XMultiComponentFactory</code></li>
58 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
59 * <li> <code>com::sun::star::container::XElementAccess</code></li>
60 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
61 * <li> <code>com::sun::star::lang::XComponent</code></li>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.lang.XMultiServiceFactory
68 * @see com.sun.star.container.XContentEnumerationAccess
69 * @see com.sun.star.container.XSet
70 * @see com.sun.star.lang.XMultiComponentFactory
71 * @see com.sun.star.lang.XServiceInfo
72 * @see com.sun.star.container.XElementAccess
73 * @see com.sun.star.container.XEnumerationAccess
74 * @see com.sun.star.lang.XComponent
75 * @see ifc.lang._XMultiServiceFactory
76 * @see ifc.container._XContentEnumerationAccess
77 * @see ifc.container._XSet
78 * @see ifc.lang._XMultiComponentFactory
79 * @see ifc.lang._XServiceInfo
80 * @see ifc.container._XElementAccess
81 * @see ifc.container._XEnumerationAccess
82 * @see ifc.lang._XComponent
84 public class OServiceManager
extends TestCase
{
87 * Creating a Testenvironment for the interfaces to be tested.
88 * Creates an instance of the service
89 * <code>com.sun.star.comp.stoc.OServiceManager</code>.
90 * Object relations created :
92 * <li> <code>'NewElement'</code> for
93 * {@link ifc.container._XSet} :
94 * element to be inserted into manager. Here
95 * a new <code>ServiceManager</code> implementation is
97 * <code>tools.SOConnect.createSimpleServiceManager()</code>
98 * and one of services contained in it is taken.</li>
101 protected TestEnvironment createTestEnvironment
102 (TestParameters Param
, PrintWriter log
) {
104 XInterface oObj
= null;
105 Object oInterface
= null;
108 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
109 oInterface
= xMSF
.createInstance
110 ( "com.sun.star.comp.stoc.OServiceManager" );
111 } catch( com
.sun
.star
.uno
.Exception e
) {
112 log
.println("ServiceManager service not available" );
115 // adding a service to the manager
116 Object newElement
= null ;
117 XMultiServiceFactory srvMan
= null;
118 XComponentContext xContext
= null;
122 srvMan
= com
.sun
.star
.comp
.helper
.Bootstrap
.createSimpleServiceManager();
124 } catch ( java
.lang
.Exception ex
) {
125 log
.println("Error creating SimpleServiceManager :");
126 ex
.printStackTrace(log
);
130 XSet set
= (XSet
) UnoRuntime
.queryInterface
131 (XSet
.class, oInterface
) ;
132 XSet set1
= (XSet
) UnoRuntime
.queryInterface
133 (XSet
.class, srvMan
) ;
134 XEnumeration oEnum
= set1
.createEnumeration();
135 Object srv
= oEnum
.nextElement();
139 newElement
= oEnum
.nextElement();
141 XPropertySet xProp
= (XPropertySet
)UnoRuntime
.queryInterface(
142 XPropertySet
.class, oInterface
);
144 xContext
= (XComponentContext
) AnyConverter
.toObject(
145 new Type(XComponentContext
.class),
146 xProp
.getPropertyValue("DefaultContext"));
148 } catch (com
.sun
.star
.uno
.Exception e
) {
149 log
.println("Can't insert a service to the ServiceManager") ;
150 throw new StatusException("Can't create object environment", e
) ;
153 oObj
= (XInterface
) oInterface
;
155 log
.println( " creating a new environment for object" );
156 TestEnvironment tEnv
= new TestEnvironment( oObj
);
158 // adding relation for XSet interface
159 tEnv
.addObjRelation("NewElement", newElement
) ;
161 // adding relation for XPropertySet
162 tEnv
.addObjRelation("PTT",new String
[]{"DefaultContext","none","none"});
164 //adding relation for XMultiComponentFactory
165 if (xContext
!= null) {
166 tEnv
.addObjRelation("DC", xContext
);
169 } // finish method getTestEnvironment
171 } // finish class OServiceManager