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