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.form.binding;
24 
25 import com.sun.star.form.binding.XBindableValue;
26 import com.sun.star.form.binding.XValueBinding;
27 import com.sun.star.uno.Type;
28 
29 import java.util.ArrayList;
30 
31 import lib.MultiMethodTest;
32 
33 
34 public class _XBindableValue extends MultiMethodTest {
35     public XBindableValue oObj;
36     protected XValueBinding xValueBinding = null;
37 
_getValueBinding()38     public void _getValueBinding() {
39         requiredMethod("setValueBinding");
40 
41         boolean res = true;
42         xValueBinding = oObj.getValueBinding();
43         res &= checkValueBinding(xValueBinding);
44         tRes.tested("getValueBinding()", res);
45     }
46 
_setValueBinding()47     public void _setValueBinding() {
48         String rightOne = "";
49 
50         try {
51             oObj.setValueBinding(new MyValueBinding());
52             rightOne = (String) oObj.getValueBinding().getValue(null);
53         } catch (com.sun.star.form.binding.IncompatibleTypesException e) {
54             e.printStackTrace();
55         }
56 
57         boolean res = rightOne.equals("MyValueBinding");
58 
59         if (!res) {
60             log.println("Excepted: MyValueBinding");
61             log.println("getting: " + rightOne);
62         }
63 
64         tRes.tested("setValueBinding()", res);
65     }
66 
checkValueBinding(XValueBinding xValueBinding)67     protected boolean checkValueBinding(XValueBinding xValueBinding) {
68         boolean res = true;
69         Type[] types = xValueBinding.getSupportedValueTypes();
70         log.println("Checking: ");
71 
72         for (int i = 0; i < types.length; i++) {
73             log.println("\t" + types[i].getTypeName());
74 
75             boolean localRes = xValueBinding.supportsType(types[i]);
76 
77             if (!localRes) {
78                 log.println("\t\tsupportsType returns false -- FAILED");
79             } else {
80                 log.println("\t\tis supported -- OK");
81             }
82 
83             res &= localRes;
84         }
85 
86         return res;
87     }
88 
89     class MyValueBinding implements XValueBinding {
90         private Type[] TypeArray;
91         private ArrayList types = new ArrayList();
92 
getSupportedValueTypes()93         public com.sun.star.uno.Type[] getSupportedValueTypes() {
94             return TypeArray;
95         }
96 
getValue(com.sun.star.uno.Type type)97         public Object getValue(com.sun.star.uno.Type type)
98             throws com.sun.star.form.binding.IncompatibleTypesException {
99             return "MyValueBinding";
100         }
101 
setValue(Object obj)102         public void setValue(Object obj)
103             throws com.sun.star.form.binding.IncompatibleTypesException,
104                    com.sun.star.lang.NoSupportException {
105         }
106 
supportsType(com.sun.star.uno.Type type)107         public boolean supportsType(com.sun.star.uno.Type type) {
108             types.add(type);
109             TypeArray = new Type[types.size()];
110 
111             for (int i = 0; i < types.size(); i++) {
112                 TypeArray[i] = (Type) types.toArray()[i];
113             }
114 
115             return true;
116         }
117     }
118 }