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