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: _XImplementationLoader.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 lib
.MultiMethodTest
;
34 import lib
.StatusException
;
35 import util
.RegistryTools
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.lang
.XServiceInfo
;
39 import com
.sun
.star
.loader
.CannotActivateFactoryException
;
40 import com
.sun
.star
.loader
.XImplementationLoader
;
41 import com
.sun
.star
.registry
.CannotRegisterImplementationException
;
42 import com
.sun
.star
.registry
.XRegistryKey
;
43 import com
.sun
.star
.registry
.XSimpleRegistry
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
48 * Testing <code>com.sun.star.loader.XImplementationLoader</code>
51 * <li><code> activate()</code></li>
52 * <li><code> writeRegistryInfo()</code></li>
55 * The following object relations required :
57 * <li> <code>'ImplementationLoader'</code> : service which is
58 * responsible for loading implementations. </li>
59 * <li> <code>'ImplementationUrl'</code> : implementation file location. </li>
60 * <li> <code>'ImplementationName'</code> : Name of the implementation.</li>
62 * Object has to be recreated after this test. <p>
63 * Test is <b> Not </b> multithread compilant.
65 public class _XImplementationLoader
extends MultiMethodTest
{
67 public XImplementationLoader oObj
= null;
68 private String implLoader
= null ;
69 private String implUrl
= null ;
70 private String implName
= null ;
73 * Retrieves object relations.
74 * @throws StatusException If one of relations not found.
76 public void before() {
77 implLoader
= (String
) tEnv
.getObjRelation("ImplementationLoader") ;
78 implUrl
= (String
) tEnv
.getObjRelation("ImplementationUrl") ;
79 implName
= (String
) tEnv
.getObjRelation("ImplementationName") ;
81 if (implLoader
== null || implUrl
== null || implName
== null)
82 throw new StatusException("One of object relations not found",
83 new NullPointerException()) ;
87 * First registry file created, and the root key retrieved.
88 * Then method <code>writeRegistryInfo</code> called and it must
89 * write some info into the registry root key. After all registry
91 * Has OK status if some info was written into registry.
93 public void _writeRegistryInfo() {
95 XSimpleRegistry xReg
= null ;
97 String tmpDir
= util
.utils
.getOfficeTempDir((XMultiServiceFactory
)tParam
.getMSF());
100 xReg
= RegistryTools
.createRegistryService
101 ((XMultiServiceFactory
)tParam
.getMSF()) ;
103 xReg
.open(tmpDir
+ "XImpLoader_tmp.rdb", false, true) ;
105 key
= xReg
.getRootKey() ;
106 } catch (com
.sun
.star
.uno
.Exception e
) {
107 log
.println("Can not create registry for writing") ;
108 e
.printStackTrace(log
) ;
109 tRes
.tested("writeRegistryInfo()", false) ;
115 rc
= oObj
.writeRegistryInfo(key
, implLoader
, implUrl
) ;
116 } catch (CannotRegisterImplementationException e
) {
117 throw new StatusException("Can not register implementation", e
) ;
121 log
.println("Method returned false value") ;
125 keys
= key
.getKeyNames() ;
126 } catch (com
.sun
.star
.uno
.Exception e
) {
127 log
.println("Error retrieving key names from registry") ;
128 tRes
.tested("writeRegistryInfo()", false) ;
132 // destroying registry file
136 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
137 log
.println("Can't destroy registry file.") ;
140 tRes
.tested("writeRegistryInfo()", rc
&& keys
.length
> 0) ;
144 * Tries to activate the implementation. <p>
146 * Has OK status if not <code>null</code> value returned by method,
147 * if its implementation name is the same as expected.
149 public void _activate() {
151 XInterface factory
= null ;
154 factory
= (XInterface
) oObj
.activate
155 (implName
, implLoader
, implUrl
, null) ;
156 } catch (CannotActivateFactoryException e
) {
157 throw new StatusException("Can not activate factory", e
) ;
160 XServiceInfo xServInf
= (XServiceInfo
) UnoRuntime
.queryInterface
161 (XServiceInfo
.class, factory
) ;
163 if (xServInf
== null) {
164 if (factory
== null) {
165 log
.println("activate() returns null - FAILED.");
167 log
.println("Activated impementation doesn't support "+
168 "XServiceInfo - FAILED.");
172 String gImpName
= xServInf
.getImplementationName() ;
173 log
.println("Implementation name returned :" + gImpName
);
175 if (!gImpName
.equals(implName
)) {
176 log
.println("!!! But other name was expected :" + implName
);
181 tRes
.tested("activate()", ok
) ;
185 * Forces object recreation.
187 public void after() {
188 this.disposeEnvironment() ;