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._regtypeprov.uno;
25 
26 import com.sun.star.beans.XPropertySet;
27 import com.sun.star.container.XEnumeration;
28 import com.sun.star.container.XEnumerationAccess;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XComponentContext;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.uno.AnyConverter;
34 import com.sun.star.uno.Type;
35 import java.io.PrintWriter;
36 import lib.Status;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.reflection.TypeDescriptionProvider</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::container::XHierarchicalNameAccess</code></li>
47 *  <li> <code>com::sun::star::lang::XComponent</code></li>
48 * </ul>
49 * This object test <b> is NOT </b> designed to be run in several
50 * threads concurently.
51 * @see com.sun.star.container.XHierarchicalNameAccess
52 * @see com.sun.star.lang.XComponent
53 * @see com.sun.star.reflection.TypeDescriptionProvider
54 * @see ifc.container._XHierarchicalNameAccess
55 * @see ifc.lang._XComponent
56 */
57 public class RegistryTypeDescriptionProvider extends TestCase {
58 
initialize( TestParameters Param, PrintWriter log)59     protected void initialize ( TestParameters Param, PrintWriter log) {
60 
61     }
62 
63     /**
64     * Creating a Testenvironment for the interfaces to be tested.
65     * Creates an instance of the service
66     * <code>com.sun.star.reflection.TypeDescriptionProvider</code>.
67     *     Object relations created :
68     * <ul>
69     *  <li> <code>'ElementName'</code> for
70     *      {@link ifc.container._XHierarchicalNameAccess} :
71     *      name of the existing element. Here it type name for
72     *      <code>com.sun.star.uno.XInterface</code> interface.</li>
73     * </ul>
74     */
createTestEnvironment(TestParameters Param, PrintWriter log)75     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
76         XInterface oObj = null;
77         Object oInterface = null;
78 
79         try {
80             XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
81             XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
82                                                 XPropertySet.class, xMSF);
83             // get context
84             XComponentContext xContext = (XComponentContext)
85                             UnoRuntime.queryInterface(XComponentContext.class,
86                             xProp.getPropertyValue("DefaultContext"));
87             // get the type description manager
88             Object o = xContext.getValueByName("/singletons/" +
89                         "com.sun.star.reflection.theTypeDescriptionManager");
90             // the manager contains all providers
91             XEnumerationAccess aProviderAccess = (XEnumerationAccess)
92                         UnoRuntime.queryInterface(XEnumerationAccess.class, o);
93             // collect enumeration
94             XEnumeration xProviderEnum;
95             if (aProviderAccess.hasElements())
96                 xProviderEnum = aProviderAccess.createEnumeration();
97             else
98                 throw new lib.StatusException(Status.failed(
99                                         "No TypeDescriptionProvider given"));
100             // take the first registry type description provider
101             oInterface = xProviderEnum.nextElement();
102             oObj = (XInterface) AnyConverter.toObject(
103                             new Type(XInterface.class),oInterface);
104         }
105         catch( com.sun.star.uno.Exception e ) {
106             log.println("Service not available" );
107         }
108 
109         //oObj = (XInterface) oInterface;
110 
111         log.println( "    creating a new environment for object" );
112         TestEnvironment tEnv = new TestEnvironment( oObj );
113 
114         // adding relation for XHierarchicalNameAccess
115         tEnv.addObjRelation("ElementName", "com.sun.star.uno.XInterface") ;
116         tEnv.addObjRelation("SearchString", "com.sun.star.loader");
117 
118         return tEnv;
119     } // finish method getTestEnvironment
120 
121 }
122 
123