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 import com.sun.star.uno.UnoRuntime; 23 import com.sun.star.accessibility.XAccessible; 24 import com.sun.star.accessibility.XAccessibleContext; 25 import com.sun.star.accessibility.AccessibleRelation; 26 import com.sun.star.accessibility.XAccessibleRelationSet; 27 import com.sun.star.accessibility.AccessibleRelationType; 28 import com.sun.star.lang.XServiceInfo; 29 import com.sun.star.lang.XTypeProvider; 30 import com.sun.star.uno.Type; 31 32 33 /** This handler displays lower level UNO information. These are the 34 supported services, interfaces, and the implementation name. 35 */ 36 class AccessibleUNOHandler 37 extends NodeHandler 38 { createHandler(XAccessibleContext xContext)39 public NodeHandler createHandler (XAccessibleContext xContext) 40 { 41 if (xContext == null) 42 return null; 43 else 44 return new AccessibleUNOHandler (xContext); 45 } 46 AccessibleUNOHandler()47 public AccessibleUNOHandler() 48 { 49 } 50 AccessibleUNOHandler(XAccessibleContext xContext)51 public AccessibleUNOHandler (XAccessibleContext xContext) 52 { 53 maChildList.setSize (3); 54 } 55 GetServiceInfo(AccessibleTreeNode aNode)56 private XServiceInfo GetServiceInfo (AccessibleTreeNode aNode) 57 { 58 XServiceInfo xServiceInfo = null; 59 if (aNode instanceof AccTreeNode) 60 xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( 61 XServiceInfo.class, ((AccTreeNode)aNode).getContext()); 62 return xServiceInfo; 63 } GetTypeProvider(AccessibleTreeNode aNode)64 private XTypeProvider GetTypeProvider (AccessibleTreeNode aNode) 65 { 66 XTypeProvider xTypeProvider = null; 67 if (aNode instanceof AccTreeNode) 68 xTypeProvider = (XTypeProvider)UnoRuntime.queryInterface( 69 XTypeProvider.class, ((AccTreeNode)aNode).getContext()); 70 return xTypeProvider; 71 } 72 createChild(AccessibleTreeNode aParent, int nIndex)73 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, 74 int nIndex) 75 { 76 AccessibleTreeNode aChild = null; 77 XServiceInfo xServiceInfo; 78 switch (nIndex) 79 { 80 case 0 : // Implemenation name. 81 xServiceInfo = GetServiceInfo (aParent); 82 aChild = new StringNode ("Implementation name: " + 83 (xServiceInfo!=null ? xServiceInfo.getImplementationName() 84 : "<XServiceInfo not supported>"), 85 aParent); 86 break; 87 case 1 : 88 xServiceInfo = GetServiceInfo (aParent); 89 if (xServiceInfo == null) 90 aChild = new StringNode ( 91 "Supported services: <XServiceInfo not supported>", 92 aParent); 93 else 94 aChild = CreateServiceTree (aParent, xServiceInfo); 95 break; 96 case 2 : 97 XTypeProvider xTypeProvider = GetTypeProvider (aParent); 98 if (xTypeProvider == null) 99 aChild = new StringNode ( 100 "Supported interfaces: <XTypeProvider not supported>", 101 aParent); 102 else 103 aChild = CreateInterfaceTree (aParent, xTypeProvider); 104 break; 105 } 106 107 return aChild; 108 } 109 110 CreateServiceTree(AccessibleTreeNode aParent, XServiceInfo xServiceInfo)111 private AccessibleTreeNode CreateServiceTree (AccessibleTreeNode aParent, 112 XServiceInfo xServiceInfo) 113 { 114 String[] aServiceNames = xServiceInfo.getSupportedServiceNames(); 115 VectorNode aNode = new VectorNode ("Supported Services", aParent); 116 117 int nCount = aServiceNames.length; 118 for (int i=0; i<nCount; i++) 119 aNode.addChild (new StringNode (aServiceNames[i], aParent)); 120 121 return aNode; 122 } 123 CreateInterfaceTree(AccessibleTreeNode aParent, XTypeProvider xTypeProvider)124 private AccessibleTreeNode CreateInterfaceTree (AccessibleTreeNode aParent, 125 XTypeProvider xTypeProvider) 126 { 127 Type[] aTypes = xTypeProvider.getTypes(); 128 VectorNode aNode = new VectorNode ("Supported Interfaces", aParent); 129 130 int nCount = aTypes.length; 131 for (int i=0; i<nCount; i++) 132 aNode.addChild (new StringNode (aTypes[i].getTypeName(), aParent)); 133 134 return aNode; 135 } 136 } 137