1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._javaloader.uno;
25 
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.uno.XInterface;
28 import java.io.PrintWriter;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.utils;
33 
34 /**
35 * Test for <code>com.sun.star.comp.stoc.Java2</code> service <p>
36 * Files which are used :
37 * <ul>
38 *  <li> <code>MyPersistObjectImpl.jar</code> : jar which will be loaded in
39 *    <code>XImplementationLoader</code> interface test. </li>
40 * <ul>
41 * Multithread testing compilant.
42 * @see com.sun.star.loader.XImplementationLoader
43 * @see com.sun.star.lang.XServiceInfo
44 * @see ifc.loader._XImplementationLoader
45 * @see ifc.lang._XServiceInfo
46 */
47 public class JavaComponentLoader extends TestCase {
48 
49     /**
50     * Creating a Testenvironment for the interfaces to be tested.
51     * Creates <code>com.sun.star.comp.stoc.Java2</code>
52     * service. <p>
53     * The following object relations created :
54     * <ul>
55     *  <li> <code>'ImplementationLoader'</code> : service which is
56     *    responsible for loading jar implementations. </li>
57     *  <li> <code>'ImplementationUrl'</code> : jar file location. </li>
58     *  <li> <code>'ImplementationName'</code> : Name of the implementation.</li>
59     * </ul>
60     */
createTestEnvironment(TestParameters Param, PrintWriter log)61     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
62         XInterface oObj = null;
63         Object oInterface = null;
64 
65         try {
66             XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
67             oInterface = xMSF.createInstance(
68                             "com.sun.star.comp.stoc.JavaComponentLoader" );
69         }
70         catch( Exception e ) {
71             log.println("JavaComponentLoader Service not available" );
72         }
73 
74         oObj = (XInterface) oInterface;
75 
76         log.println( "    creating a new environment for JavaComponentLoader object" );
77         TestEnvironment tEnv = new TestEnvironment( oObj );
78 
79         // adding object relation for XImplementationLoader ifc test
80         tEnv.addObjRelation("ImplementationLoader",
81                                 "com.sun.star.loader.JavaComponentLoader") ;
82 
83         String implURL = utils.getFullTestURL("qadevlibs/MyPersistObjectImpl.jar");
84         tEnv.addObjRelation("ImplementationUrl", implURL) ;
85         log.println("looking for shared lib: " + implURL);
86         tEnv.addObjRelation("ImplementationName",
87             "com.sun.star.cmp.MyPersistObject") ;
88 
89         return tEnv;
90     } // finish method createTestEnvironment
91 }
92 
93