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 package ifc.reflection; 24 25 import lib.MultiMethodTest; 26 27 import com.sun.star.reflection.TypeDescriptionSearchDepth; 28 import com.sun.star.reflection.XTypeDescription; 29 import com.sun.star.reflection.XTypeDescriptionEnumeration; 30 import com.sun.star.reflection.XTypeDescriptionEnumerationAccess; 31 import com.sun.star.uno.TypeClass; 32 33 /** 34 * Testing <code>com.sun.star.reflection.XTypeDescriptionEnumerationAccess 35 * </code><br> 36 * Needed object relation: 37 * <ul> 38 * <li><code>SearchString</code> 39 * A string to search for as a type description</li> 40 * </ul> 41 */ 42 public class _XTypeDescriptionEnumerationAccess extends MultiMethodTest { 43 public XTypeDescriptionEnumerationAccess oObj = null; 44 45 /** 46 * Search the type database for all information regarding the object 47 * relation 'SearchString'. Search depth is infinite and information 48 * about all types is gathered. 49 */ _createTypeDescriptionEnumeration()50 public void _createTypeDescriptionEnumeration() { 51 int i=0; 52 TypeClass[] tClass = new TypeClass[0]; 53 String sString = (String)tEnv.getObjRelation("SearchString"); 54 if (sString == null || sString.equals("")) { 55 System.out.println("Cannot get object relation 'SearchString'"); 56 tRes.tested("createTypeDescriptionEnumeration()", false); 57 return; 58 } 59 try { 60 XTypeDescriptionEnumeration oEnum = 61 oObj.createTypeDescriptionEnumeration(sString, tClass, 62 TypeDescriptionSearchDepth.INFINITE); 63 try { 64 log.println("Got an enumeration."); 65 while (true) { 66 XTypeDescription desc = oEnum.nextTypeDescription(); 67 i++; 68 log.println("\tdesc name: " + desc.getName()); 69 } 70 } 71 catch(com.sun.star.container.NoSuchElementException e) { 72 log.println( 73 "Correct exception caught for exiting enumeration."); 74 log.println("Returned were " + i + " type descriptions."); 75 } 76 catch(Exception e) { 77 log.println("Exception while accessing the enumeration."); 78 log.println("Index is " + i); 79 log.println(e.getMessage()); 80 tRes.tested("createTypeDescriptionEnumeration()", false); 81 return; 82 } 83 tRes.tested("createTypeDescriptionEnumeration()", i>0); 84 } 85 catch(Exception e) { 86 log.println("Cannot execute method."); 87 log.println(e.getMessage()); 88 tRes.tested("createTypeDescriptionEnumeration()", false); 89 } 90 } 91 } 92