Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / odk / examples / java / PropertySet / PropTest.java
blobc77a905e870dc4885cd541e7f1cf1e2e23022694
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
37 This example shows a UNO component that inherits com.sun.star.lib.uno.helper.PropertySet in
38 order to provide implementations of these interfaces:
40 com.sun.star.beans.XPropertySet
41 com.sun.star.beans.XMultiPropertySet
42 com.sun.star.beans.XFastPropertySet
43 com.sun.star.lang.XComponent
44 com.sun.star.uno.XWeak
45 com.sun.star.lang.XTypeProvider
47 import com.sun.star.lib.uno.helper.PropertySet;
48 import com.sun.star.comp.loader.FactoryHelper;
49 import com.sun.star.lang.XServiceInfo;
50 import com.sun.star.lang.XMultiServiceFactory;
51 import com.sun.star.lang.XSingleServiceFactory;
52 import com.sun.star.registry.XRegistryKey;
53 import com.sun.star.uno.Any;
54 import com.sun.star.uno.Type;
55 import com.sun.star.uno.XInterface;
56 import com.sun.star.lang.XTypeProvider;
57 import com.sun.star.beans.PropertyAttribute;
59 /**
60 This component contains the following properties:
61 * <table border>
62 * <tr>
63 * <th> Property Name </th>
64 * <th> Type Name </th>
65 * <th> PropertyAttribute </th>
66 * <tr><td>boolA</td><td>BOOLEAN</td><td> - </td</tr>
67 * <tr><td>charA</td><td>CHAR</td><td> - </td></tr>
68 * <tr><td>byteA</td><td>BYTE</td><td> - </td></tr>
69 * <tr><td>shortA</td><td>SHORT</td><td> - </td></tr>
70 * <tr><td>intA</td><td>LONG</td><td> - </td></tr>
71 * <tr><td>longA</td><td>HYPER</td><td> - </td></tr>
72 * <tr><td>floatA</td><td>FLOAT</td><td> - </td></tr>
73 * <tr><td>doubleA</td><td>DOUBLE</td><td> - </td></tr>
74 * <tr><td>stringA</td><td>STRING</td><td> - </td></tr>
75 * <tr><td>objectA</td><td>ANY</td><td> - </td></tr>
76 * <tr><td>anyA</td><td>ANY</td><td> - </td></tr>
77 * <tr><td>typeA</td><td>TYPE</td><td> - </td></tr>
78 * <tr><td>xinterfaceA</td><td>INTERFACE</td><td> - </td></tr>
79 * <tr><td>xtypeproviderA</td><td>INTERFACE</td><td> - </td></tr>
80 * <tr><td>arBoolA</td><td>[]boolean</td><td> - </td></tr>
81 * <tr><td>arCharA</td><td>[]char</td><td> - </td></tr>
82 * <tr><td>arByteA</td><td>[]byte</td><td> - </td></tr>
83 * <tr><td>arShortA</td><td>[]short</td><td> - </td></tr>
84 * <tr><td>arIntA</td><td>[]long</td><td> - </td></tr>
85 * <tr><td>arLongA</td><td>[]hyper</td><td> - </td></tr>
86 * <tr><td>arFloatA</td><td>[]float</td><td> - </td></tr>
87 * <tr><td>arDoubleA</td><td>[]double</td><td> - </td></tr>
88 * <tr><td>arStringA</td><td>[]string</td><td> - </td></tr>
89 * <tr><td>arObjectA</td><td>[]any</td><td> - </td></tr>
90 * <tr><td>arXinterfaceA</td><td>[]com.sun.star.uno.XInterface</td><td> - </td></tr>
91 * <tr><td>ar2BoolA</td><td>[][]boolean</td><td> - </td></tr>
92 * <tr><td>boolClassA</td><td>boolean</td><td> - </td></tr>
93 * <tr><td>charClassA</td><td>char</td><td> - </td></tr>
94 * <tr><td>byteClassA</td><td>byte</td><td> - </td></tr>
95 * <tr><td>shortClassA</td><td>short</td><td> - </td></tr>
96 * <tr><td>intClassA</td><td>long</td><td> - </td></tr>
97 * <tr><td>longClassA</td><td>hyper</td><td> - </td></tr>
98 * <tr><td>floatClassA</td><td>float</td><td> - </td></tr>
99 * <tr><td>doubleClassA</td><td>double</td><td> - </td></tr>
100 * <tr><td>roIntA</td><td>long</td><td>READONLY</td></tr>
101 * <tr><td>roIntClassA</td><td>long</td><td>READONLY</td></tr>
102 * <tr><td>roObjectA</td><td>any</td><td>READONLY</td></tr>
103 * <tr><td>roAnyA</td><td>any</td><td>READONLY</td></tr>
104 * <tr><td>bcBoolA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr>
105 * <tr><td>bcBoolClassA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr>
106 * <tr><td>bcObjectA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr>
107 * <tr><td>bcAnyA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr>
108 * <tr><td>mvIntA</td><td>long</td><td>MAYBEVOID</td></tr>
109 * <tr><td>mvObjectA</td><td>any</td><td>MAYBEVOID</td></tr>
110 * <tr><td>mvAnyA</td><td>any</td><td>MAYBEVOID</td></tr>
111 * <tr><td>mvXinterfaceA</td><td>any</td><td>MAYBEVOID</td></tr>
112 </table>
115 public class PropTest extends PropertySet implements XServiceInfo
118 public boolean boolA;
119 public char charA;
120 public byte byteA;
121 public short shortA;
122 public int intA;
123 public long longA;
124 public float floatA;
125 public double doubleA;
126 public String stringA; // MAYBEVOID
127 public Object objectA; // MAYBEVOID
128 public Any anyA; // MAYBEVOID
129 public Type typeA;// MAYBEVOID
130 public XInterface xinterfaceA;// MAYBEVOID
131 public XTypeProvider xtypeproviderA;// MAYBEVOID
132 public boolean[] arBoolA; // MAYBEVOID
133 public char[] arCharA; // MAYBEVOID
134 public byte[] arByteA; // MAYBEVOID
135 public short[] arShortA; // MAYBEVOID
136 public int[] arIntA; // MAYBEVOID
137 public long[] arLongA; // MAYBEVOID
138 public float[] arFloatA; // MAYBEVOID
139 public double[] arDoubleA; // MAYBEVOID
140 public String[] arStringA; // MAYBEVOID
141 public Object[] arObjectA; // MAYBEVOID
142 public Any[] arAnyA; // MAYBEVOID
143 public XInterface[] arXinterfaceA; // MAYBEVOID
144 public boolean[][] ar2BoolA; // MAYBEVOID
145 public Boolean boolClassA; // MAYBEVOID
146 public Character charClassA; // MAYBEVOID
147 public Byte byteClassA; // MAYBEVOID
148 public Short shortClassA; // MAYBEVOID
149 public Integer intClassA; // MAYBEVOID
150 public Long longClassA; // MAYBEVOID
151 public Float floatClassA; // MAYBEVOID
152 public Double doubleClassA; // MAYBEVOID
154 // readonly
155 public int roIntA= 100;
156 public Integer roIntClassA= Integer.valueOf(100);
157 public Object roObjectA= Integer.valueOf(101);
158 public Any roAnyA= new Any( new Type(int.class), Integer.valueOf(102));
160 // BOUND & CONSTRAINED
161 public boolean bcBoolA;
162 public Boolean bcBoolClassA; // MAYBEVOID
163 public Object bcObjectA; // MAYBEVOID
164 public Any bcAnyA; // MAYBEVOID
166 // MAYBEVOID
167 public Integer mvIntA;
168 public Object mvObjectA;
169 public Any mvAnyA;
170 public XInterface mvXinterfaceA;
172 public static final String __serviceName="PropTest";
174 public PropTest() {
175 registerProperty("boolA", (short) 0);
176 registerProperty("charA", (short) 0);
177 registerProperty("byteA", (short) 0);
178 registerProperty("shortA", (short) 0);
179 registerProperty("intA", (short) 0);
180 registerProperty("longA", (short) 0);
181 registerProperty("floatA", (short) 0);
182 registerProperty("doubleA", (short) 0);
183 registerProperty("stringA", PropertyAttribute.MAYBEVOID);
184 registerProperty("objectA", PropertyAttribute.MAYBEVOID);
185 registerProperty("anyA", PropertyAttribute.MAYBEVOID);
186 registerProperty("typeA", PropertyAttribute.MAYBEVOID);
187 registerProperty("xinterfaceA", PropertyAttribute.MAYBEVOID);
188 registerProperty("xtypeproviderA", PropertyAttribute.MAYBEVOID);
189 registerProperty("arBoolA", PropertyAttribute.MAYBEVOID);
190 registerProperty("arCharA", PropertyAttribute.MAYBEVOID);
191 registerProperty("arByteA", PropertyAttribute.MAYBEVOID);
192 registerProperty("arShortA", PropertyAttribute.MAYBEVOID);
193 registerProperty("arIntA", PropertyAttribute.MAYBEVOID);
194 registerProperty("arLongA", PropertyAttribute.MAYBEVOID);
195 registerProperty("arFloatA", PropertyAttribute.MAYBEVOID);
196 registerProperty("arDoubleA", PropertyAttribute.MAYBEVOID);
197 registerProperty("arStringA", PropertyAttribute.MAYBEVOID);
198 registerProperty("arObjectA", PropertyAttribute.MAYBEVOID);
199 registerProperty("arAnyA", PropertyAttribute.MAYBEVOID);
200 registerProperty("arXinterfaceA", PropertyAttribute.MAYBEVOID);
201 registerProperty("ar2BoolA", PropertyAttribute.MAYBEVOID);
202 registerProperty("boolClassA", PropertyAttribute.MAYBEVOID);
203 registerProperty("charClassA", PropertyAttribute.MAYBEVOID);
204 registerProperty("byteClassA", PropertyAttribute.MAYBEVOID);
205 registerProperty("shortClassA", PropertyAttribute.MAYBEVOID);
206 registerProperty("intClassA", PropertyAttribute.MAYBEVOID);
207 registerProperty("longClassA", PropertyAttribute.MAYBEVOID);
208 registerProperty("floatClassA", PropertyAttribute.MAYBEVOID);
209 registerProperty("doubleClassA", PropertyAttribute.MAYBEVOID);
210 registerProperty("roIntA", PropertyAttribute.READONLY);
211 registerProperty("roIntClassA", PropertyAttribute.READONLY);
212 registerProperty("roObjectA", PropertyAttribute.READONLY);
213 registerProperty("roAnyA", PropertyAttribute.READONLY);
214 registerProperty("bcBoolA",(short) ( PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED));
215 registerProperty("bcBoolClassA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID));
216 registerProperty("bcObjectA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID));
217 registerProperty("bcAnyA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED |PropertyAttribute.MAYBEVOID));
218 registerProperty("mvIntA", PropertyAttribute.MAYBEVOID);
219 registerProperty("mvObjectA", PropertyAttribute.MAYBEVOID);
220 registerProperty("mvAnyA", PropertyAttribute.MAYBEVOID);
221 registerProperty("mvXinterfaceA", PropertyAttribute.MAYBEVOID);
225 // XServiceName
226 public String getImplementationName( )
228 return getClass().getName();
231 // XServiceName
232 public boolean supportsService( /*IN*/String name )
234 if (name.equals(__serviceName))
235 return true;
236 return false;
239 //XServiceName
240 public String[] getSupportedServiceNames( )
242 String[] retValue= new String[]{__serviceName};
243 return retValue;
246 public static XSingleServiceFactory __getServiceFactory(String implName,
247 XMultiServiceFactory multiFactory,
248 XRegistryKey regKey)
250 XSingleServiceFactory xSingleServiceFactory = null;
252 if (implName.equals( PropTest.class.getName()) )
253 xSingleServiceFactory = FactoryHelper.getServiceFactory( PropTest.class,
254 PropTest.__serviceName,
255 multiFactory,
256 regKey);
258 return xSingleServiceFactory;
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */