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 
24 /*
25 This example shows a UNO component that inherits com.sun.star.lib.uno.helper.PropertySet in
26 order to provide implementations of  these interfaces:
27 
28       com.sun.star.beans.XPropertySet
29       com.sun.star.beans.XMultiPropertySet
30       com.sun.star.beans.XFastPropertySet
31       com.sun.star.lang.XComponent
32       com.sun.star.uno.XWeak
33       com.sun.star.lang.XTypeProvider
34 */
35 import com.sun.star.lib.uno.helper.PropertySet;
36 import com.sun.star.comp.loader.FactoryHelper;
37 import com.sun.star.lang.XServiceInfo;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.lang.XSingleServiceFactory;
40 import com.sun.star.registry.XRegistryKey;
41 import com.sun.star.uno.Any;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.lang.XTypeProvider;
45 import com.sun.star.beans.PropertyAttribute;
46 
47 /**
48    This component contains the followin properties:
49  *  <table border>
50  *  <tr>
51  *  <th> Property Name </th>
52  *  <th> Type Name </th>
53  *  <th> PropertyAttribute </th>
54  *  <tr><td>boolA</td><td>BOOLEAN</td><td> - </td</tr>
55  *  <tr><td>charA</td><td>CHAR</td><td> - </td></tr>
56  *  <tr><td>byteA</td><td>BYTE</td><td> - </td></tr>
57  *  <tr><td>shortA</td><td>SHORT</td><td> - </td></tr>
58  *  <tr><td>intA</td><td>LONG</td><td> - </td></tr>
59  *  <tr><td>longA</td><td>HYPER</td><td> - </td></tr>
60  *  <tr><td>floatA</td><td>FLOAT</td><td> - </td></tr>
61  *  <tr><td>doubleA</td><td>DOUBLE</td><td> - </td></tr>
62  *  <tr><td>stringA</td><td>STRING</td><td> - </td></tr>
63  *  <tr><td>objectA</td><td>ANY</td><td> - </td></tr>
64  *  <tr><td>anyA</td><td>ANY</td><td> - </td></tr>
65  *  <tr><td>typeA</td><td>TYPE</td><td> - </td></tr>
66  *  <tr><td>xinterfaceA</td><td>INTERFACE</td><td> - </td></tr>
67  *  <tr><td>xtypeproviderA</td><td>INTERFACE</td><td> - </td></tr>
68  *  <tr><td>arBoolA</td><td>[]boolean</td><td> - </td></tr>
69  *  <tr><td>arCharA</td><td>[]char</td><td> - </td></tr>
70  *  <tr><td>arByteA</td><td>[]byte</td><td> - </td></tr>
71  *  <tr><td>arShortA</td><td>[]short</td><td> - </td></tr>
72  *  <tr><td>arIntA</td><td>[]long</td><td> - </td></tr>
73  *  <tr><td>arLongA</td><td>[]hyper</td><td> - </td></tr>
74  *  <tr><td>arFloatA</td><td>[]float</td><td> - </td></tr>
75  *  <tr><td>arDoubleA</td><td>[]double</td><td> - </td></tr>
76  *  <tr><td>arStringA</td><td>[]string</td><td> - </td></tr>
77  *  <tr><td>arObjectA</td><td>[]any</td><td> - </td></tr>
78  *  <tr><td>arXinterfaceA</td><td>[]com.sun.star.uno.XInterface</td><td> - </td></tr>
79  *  <tr><td>ar2BoolA</td><td>[][]boolean</td><td> - </td></tr>
80  *  <tr><td>boolClassA</td><td>boolean</td><td> - </td></tr>
81  *  <tr><td>charClassA</td><td>char</td><td> - </td></tr>
82  *  <tr><td>byteClassA</td><td>byte</td><td> - </td></tr>
83  *  <tr><td>shortClassA</td><td>short</td><td> - </td></tr>
84  *  <tr><td>intClassA</td><td>long</td><td> - </td></tr>
85  *  <tr><td>longClassA</td><td>hyper</td><td> - </td></tr>
86  *  <tr><td>floatClassA</td><td>float</td><td> - </td></tr>
87  *  <tr><td>doubleClassA</td><td>double</td><td> - </td></tr>
88  *  <tr><td>roIntA</td><td>long</td><td>READONLY</td></tr>
89  *  <tr><td>roIntClassA</td><td>long</td><td>READONLY</td></tr>
90  *  <tr><td>roObjectA</td><td>any</td><td>READONLY</td></tr>
91  *  <tr><td>roAnyA</td><td>any</td><td>READONLY</td></tr>
92  *  <tr><td>bcBoolA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr>
93  *  <tr><td>bcBoolClassA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr>
94  *  <tr><td>bcObjectA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr>
95  *  <tr><td>bcAnyA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr>
96  *  <tr><td>mvIntA</td><td>long</td><td>MAYBEVOID</td></tr>
97  *  <tr><td>mvObjectA</td><td>any</td><td>MAYBEVOID</td></tr>
98  *  <tr><td>mvAnyA</td><td>any</td><td>MAYBEVOID</td></tr>
99  *  <tr><td>mvXinterfaceA</td><td>any</td><td>MAYBEVOID</td></tr>
100  </table>
101 */
102 
103 public class PropTest extends PropertySet implements XServiceInfo
104 {
105 
106     public boolean boolA;
107     public char charA;
108     public byte byteA;
109     public short shortA;
110     public int intA;
111     public long longA;
112     public float floatA;
113     public double doubleA;
114     public String stringA; // MAYBEVOID
115     public Object objectA; // MAYBEVOID
116     public Any anyA; // MAYBEVOID
117     public Type typeA;// MAYBEVOID
118     public XInterface xinterfaceA;// MAYBEVOID
119     public XTypeProvider xtypeproviderA;// MAYBEVOID
120     public boolean[] arBoolA; // MAYBEVOID
121     public char[] arCharA; // MAYBEVOID
122     public byte[] arByteA; // MAYBEVOID
123     public short[] arShortA; // MAYBEVOID
124     public int[] arIntA; // MAYBEVOID
125     public long[] arLongA; // MAYBEVOID
126     public float[] arFloatA; // MAYBEVOID
127     public double[] arDoubleA; // MAYBEVOID
128     public String[] arStringA; // MAYBEVOID
129     public Object[] arObjectA; // MAYBEVOID
130     public Any[] arAnyA; // MAYBEVOID
131     public XInterface[] arXinterfaceA; // MAYBEVOID
132     public boolean[][] ar2BoolA; // MAYBEVOID
133     public Boolean boolClassA; // MAYBEVOID
134     public Character charClassA; // MAYBEVOID
135     public Byte byteClassA; // MAYBEVOID
136     public Short shortClassA; // MAYBEVOID
137     public Integer intClassA; // MAYBEVOID
138     public Long longClassA; // MAYBEVOID
139     public Float floatClassA; // MAYBEVOID
140     public Double doubleClassA; // MAYBEVOID
141 
142     // readonly
143     public int roIntA= 100;
144     public Integer roIntClassA= new Integer(100);
145     public Object roObjectA= new Integer(101);
146     public Any roAnyA= new Any( new Type(int.class), new Integer(102));
147 
148     // BOUND & CONSTRAINED
149     public boolean bcBoolA;
150     public Boolean bcBoolClassA; // MAYBEVOID
151     public Object bcObjectA; // MAYBEVOID
152     public Any bcAnyA;       // MAYBEVOID
153 
154     // MAYBEVOID
155     public Integer mvIntA;
156     public Object mvObjectA;
157     public Any mvAnyA;
158     public XInterface mvXinterfaceA;
159 
160     public static final String __serviceName="PropTest";
161 
PropTest()162     public PropTest() {
163         registerProperty("boolA", (short) 0);
164         registerProperty("charA", (short) 0);
165         registerProperty("byteA", (short) 0);
166         registerProperty("shortA", (short) 0);
167         registerProperty("intA", (short) 0);
168         registerProperty("longA", (short) 0);
169         registerProperty("floatA", (short) 0);
170         registerProperty("doubleA", (short) 0);
171         registerProperty("stringA", PropertyAttribute.MAYBEVOID);
172         registerProperty("objectA", PropertyAttribute.MAYBEVOID);
173         registerProperty("anyA", PropertyAttribute.MAYBEVOID);
174         registerProperty("typeA", PropertyAttribute.MAYBEVOID);
175         registerProperty("xinterfaceA", PropertyAttribute.MAYBEVOID);
176         registerProperty("xtypeproviderA", PropertyAttribute.MAYBEVOID);
177         registerProperty("arBoolA", PropertyAttribute.MAYBEVOID);
178         registerProperty("arCharA", PropertyAttribute.MAYBEVOID);
179         registerProperty("arByteA", PropertyAttribute.MAYBEVOID);
180         registerProperty("arShortA", PropertyAttribute.MAYBEVOID);
181         registerProperty("arIntA", PropertyAttribute.MAYBEVOID);
182         registerProperty("arLongA", PropertyAttribute.MAYBEVOID);
183         registerProperty("arFloatA", PropertyAttribute.MAYBEVOID);
184         registerProperty("arDoubleA", PropertyAttribute.MAYBEVOID);
185         registerProperty("arStringA", PropertyAttribute.MAYBEVOID);
186         registerProperty("arObjectA", PropertyAttribute.MAYBEVOID);
187         registerProperty("arAnyA", PropertyAttribute.MAYBEVOID);
188         registerProperty("arXinterfaceA", PropertyAttribute.MAYBEVOID);
189         registerProperty("ar2BoolA", PropertyAttribute.MAYBEVOID);
190         registerProperty("boolClassA", PropertyAttribute.MAYBEVOID);
191         registerProperty("charClassA", PropertyAttribute.MAYBEVOID);
192         registerProperty("byteClassA", PropertyAttribute.MAYBEVOID);
193         registerProperty("shortClassA", PropertyAttribute.MAYBEVOID);
194         registerProperty("intClassA", PropertyAttribute.MAYBEVOID);
195         registerProperty("longClassA", PropertyAttribute.MAYBEVOID);
196         registerProperty("floatClassA", PropertyAttribute.MAYBEVOID);
197         registerProperty("doubleClassA", PropertyAttribute.MAYBEVOID);
198         registerProperty("roIntA", PropertyAttribute.READONLY);
199         registerProperty("roIntClassA", PropertyAttribute.READONLY);
200         registerProperty("roObjectA", PropertyAttribute.READONLY);
201         registerProperty("roAnyA", PropertyAttribute.READONLY);
202         registerProperty("bcBoolA",(short) ( PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED));
203         registerProperty("bcBoolClassA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID));
204         registerProperty("bcObjectA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID));
205         registerProperty("bcAnyA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED |PropertyAttribute.MAYBEVOID));
206         registerProperty("mvIntA", PropertyAttribute.MAYBEVOID);
207         registerProperty("mvObjectA", PropertyAttribute.MAYBEVOID);
208         registerProperty("mvAnyA", PropertyAttribute.MAYBEVOID);
209         registerProperty("mvXinterfaceA", PropertyAttribute.MAYBEVOID);
210     }
211 
212 
213     // XServiceName
getImplementationName( )214     public String getImplementationName(  )
215     {
216         return getClass().getName();
217     }
218 
219     // XServiceName
supportsService( String name )220     public boolean supportsService( /*IN*/String name )
221     {
222         if (name.equals(__serviceName))
223             return true;
224         return false;
225     }
226 
227     //XServiceName
getSupportedServiceNames( )228     public String[] getSupportedServiceNames(  )
229     {
230         String[] retValue= new String[]{__serviceName};
231         return retValue;
232     }
233 
__getServiceFactory(String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)234     public static XSingleServiceFactory __getServiceFactory(String implName,
235     XMultiServiceFactory multiFactory,
236     XRegistryKey regKey)
237     {
238         XSingleServiceFactory xSingleServiceFactory = null;
239 
240         if (implName.equals( PropTest.class.getName()) )
241             xSingleServiceFactory = FactoryHelper.getServiceFactory( PropTest.class,
242             PropTest.__serviceName,
243             multiFactory,
244             regKey);
245 
246         return xSingleServiceFactory;
247     }
248 
249     // This method not longer necessary since OOo 3.4 where the component registration
250     // was changed to passive component registration. For more details see
251     // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
252 
253 //     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
254 //     {
255 //         return FactoryHelper.writeRegistryServiceInfo( PropTest.class.getName(),
256 //         PropTest.__serviceName, regKey);
257 //     }
258 }
259