1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  *   Licensed to the Apache Software Foundation (ASF) under one or more
11  *   contributor license agreements. See the NOTICE file distributed
12  *   with this work for additional information regarding copyright
13  *   ownership. The ASF licenses this file to you under the Apache
14  *   License, Version 2.0 (the "License"); you may not use this file
15  *   except in compliance with the License. You may obtain a copy of
16  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 package test.cppuhelper.propertysetmixin.comp;
20 
21 import com.sun.star.beans.Ambiguous;
22 import com.sun.star.beans.Defaulted;
23 import com.sun.star.beans.Optional;
24 import com.sun.star.beans.UnknownPropertyException;
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.beans.PropertyVetoException;
27 import com.sun.star.beans.XFastPropertySet;
28 import com.sun.star.beans.XPropertyAccess;
29 import com.sun.star.beans.XPropertyChangeListener;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.beans.XPropertySetInfo;
32 import com.sun.star.beans.XVetoableChangeListener;
33 import com.sun.star.comp.loader.FactoryHelper;
34 import com.sun.star.lang.WrappedTargetException;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XEventListener;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.lang.XSingleServiceFactory;
39 import com.sun.star.lib.uno.helper.WeakBase;
40 import com.sun.star.lib.uno.helper.PropertySetMixin;
41 import com.sun.star.registry.XRegistryKey;
42 import com.sun.star.uno.Any;
43 import com.sun.star.uno.IQueryInterface;
44 import com.sun.star.uno.Type;
45 import com.sun.star.uno.XComponentContext;
46 import test.cppuhelper.propertysetmixin.XSupplier;
47 import test.cppuhelper.propertysetmixin.XTest3;
48 
49 public final class JavaSupplier extends WeakBase implements XSupplier {
JavaSupplier(XComponentContext context)50     public JavaSupplier(XComponentContext context) {
51         this.context = context;
52     }
53 
getEmpty1()54     public XComponent getEmpty1() { return new Empty1(); }
55 
getEmpty2()56     public XComponent getEmpty2() { return new Empty2(); }
57 
getFull()58     public XTest3 getFull() { return new Full(); }
59 
__getServiceFactory( String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)60     public static XSingleServiceFactory __getServiceFactory(
61         String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
62     {
63         return implName.equals(implementationName)
64             ? FactoryHelper.getServiceFactory(
65                 JavaSupplier.class, serviceName, multiFactory, regKey)
66             : null;
67     }
68 
69     private static final String implementationName
70     = JavaSupplier.class.getName();
71     private static final String serviceName
72     = "test.cppuhelper.propertysetmixin.JavaSupplier";
73 
74     private final class Empty1 extends WeakBase implements XComponent {
Empty1()75         public Empty1() {}
76 
dispose()77         public void dispose() {
78             prop.dispose();
79         }
80 
addEventListener(XEventListener listener)81         public void addEventListener(XEventListener listener) {}
82 
removeEventListener(XEventListener listener)83         public void removeEventListener(XEventListener listener) {}
84 
85         private final PropertySetMixin prop = new PropertySetMixin(
86             context, this, new Type(XComponent.class), null);
87     }
88 
89     private final class Empty2 extends WeakBase
90         implements XComponent, XPropertySet, XFastPropertySet, XPropertyAccess
91     {
Empty2()92         public Empty2() {}
93 
dispose()94         public void dispose() {
95             prop.dispose();
96         }
97 
addEventListener(XEventListener listener)98         public void addEventListener(XEventListener listener) {}
99 
removeEventListener(XEventListener listener)100         public void removeEventListener(XEventListener listener) {}
101 
getPropertySetInfo()102         public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() {
103             return prop.getPropertySetInfo();
104         }
105 
setPropertyValue(String propertyName, Object value)106         public void setPropertyValue(String propertyName, Object value)
107             throws UnknownPropertyException, PropertyVetoException,
108             com.sun.star.lang.IllegalArgumentException, WrappedTargetException
109         {
110             prop.setPropertyValue(propertyName, value);
111         }
112 
getPropertyValue(String propertyName)113         public Object getPropertyValue(String propertyName)
114             throws UnknownPropertyException, WrappedTargetException
115         {
116             return prop.getPropertyValue(propertyName);
117         }
118 
addPropertyChangeListener( String propertyName, XPropertyChangeListener listener)119         public void addPropertyChangeListener(
120             String propertyName, XPropertyChangeListener listener)
121             throws UnknownPropertyException, WrappedTargetException
122         {
123             prop.addPropertyChangeListener(propertyName, listener);
124         }
125 
removePropertyChangeListener( String propertyName, XPropertyChangeListener listener)126         public void removePropertyChangeListener(
127             String propertyName, XPropertyChangeListener listener)
128             throws UnknownPropertyException, WrappedTargetException
129         {
130             prop.removePropertyChangeListener(propertyName, listener);
131         }
132 
addVetoableChangeListener( String propertyName, XVetoableChangeListener listener)133         public void addVetoableChangeListener(
134             String propertyName, XVetoableChangeListener listener)
135             throws UnknownPropertyException, WrappedTargetException
136         {
137             prop.addVetoableChangeListener(propertyName, listener);
138         }
139 
removeVetoableChangeListener( String propertyName, XVetoableChangeListener listener)140         public void removeVetoableChangeListener(
141             String propertyName, XVetoableChangeListener listener)
142             throws UnknownPropertyException, WrappedTargetException
143         {
144             prop.removeVetoableChangeListener(propertyName, listener);
145         }
146 
setFastPropertyValue(int handle, Object value)147         public void setFastPropertyValue(int handle, Object value)
148             throws UnknownPropertyException, PropertyVetoException,
149             com.sun.star.lang.IllegalArgumentException, WrappedTargetException
150         {
151             prop.setFastPropertyValue(handle, value);
152         }
153 
getFastPropertyValue(int handle)154         public Object getFastPropertyValue(int handle)
155             throws UnknownPropertyException, WrappedTargetException
156         {
157             return prop.getFastPropertyValue(handle);
158         }
159 
getPropertyValues()160         public PropertyValue[] getPropertyValues() {
161             return prop.getPropertyValues();
162         }
163 
setPropertyValues(PropertyValue[] props)164         public void setPropertyValues(PropertyValue[] props)
165             throws UnknownPropertyException, PropertyVetoException,
166             com.sun.star.lang.IllegalArgumentException, WrappedTargetException
167         {
168             prop.setPropertyValues(props);
169         }
170 
171         private final PropertySetMixin prop = new PropertySetMixin(
172             context, this, new Type(XComponent.class), null);
173     }
174 
175     private final class Full extends WeakBase
176         implements XTest3, XPropertySet, XFastPropertySet, XPropertyAccess
177     {
Full()178         public Full() {}
179 
getFirst()180         public synchronized int getFirst() {
181             return a1;
182         }
183 
setFirst(int value)184         public void setFirst(int value) {
185             prop.prepareSet("First", null);
186             synchronized (this) {
187                 a1 = value;
188             }
189         }
190 
getSecond()191         public synchronized Ambiguous getSecond()
192             throws UnknownPropertyException
193         {
194             return a2;
195         }
196 
setSecond(Ambiguous value)197         public void setSecond(Ambiguous value)
198             throws PropertyVetoException, UnknownPropertyException
199         {
200             PropertySetMixin.BoundListeners l
201                 = new PropertySetMixin.BoundListeners();
202             prop.prepareSet(
203                 "Second", Any.VOID,
204                 (((Optional) ((Defaulted) value.Value).Value).IsPresent
205                  ? ((Optional) ((Defaulted) value.Value).Value).Value
206                  : Any.VOID),
207                 l);
208             synchronized (this) {
209                 a2 = value;
210             }
211             l.notifyListeners();
212         }
213 
getThird()214         public int getThird() throws UnknownPropertyException {
215             throw new UnknownPropertyException("Third", this);
216         }
217 
setThird(int value)218         public void setThird(int value) throws UnknownPropertyException {
219             throw new UnknownPropertyException("Third", this);
220         }
221 
getFourth()222         public int getFourth() throws UnknownPropertyException {
223             throw new UnknownPropertyException("Fourth", this);
224         }
225 
setFourth(int value)226         public void setFourth(int value) throws UnknownPropertyException {
227             throw new UnknownPropertyException("Fourth", this);
228         }
229 
getPropertySetInfo()230         public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() {
231             return prop.getPropertySetInfo();
232         }
233 
setPropertyValue(String propertyName, Object value)234         public void setPropertyValue(String propertyName, Object value)
235             throws UnknownPropertyException, PropertyVetoException,
236             com.sun.star.lang.IllegalArgumentException, WrappedTargetException
237         {
238             prop.setPropertyValue(propertyName, value);
239         }
240 
getPropertyValue(String propertyName)241         public Object getPropertyValue(String propertyName)
242             throws UnknownPropertyException, WrappedTargetException
243         {
244             return prop.getPropertyValue(propertyName);
245         }
246 
addPropertyChangeListener( String propertyName, XPropertyChangeListener listener)247         public void addPropertyChangeListener(
248             String propertyName, XPropertyChangeListener listener)
249             throws UnknownPropertyException, WrappedTargetException
250         {
251             prop.addPropertyChangeListener(propertyName, listener);
252         }
253 
removePropertyChangeListener( String propertyName, XPropertyChangeListener listener)254         public void removePropertyChangeListener(
255             String propertyName, XPropertyChangeListener listener)
256             throws UnknownPropertyException, WrappedTargetException
257         {
258             prop.removePropertyChangeListener(propertyName, listener);
259         }
260 
addVetoableChangeListener( String propertyName, XVetoableChangeListener listener)261         public void addVetoableChangeListener(
262             String propertyName, XVetoableChangeListener listener)
263             throws UnknownPropertyException, WrappedTargetException
264         {
265             prop.addVetoableChangeListener(propertyName, listener);
266         }
267 
removeVetoableChangeListener( String propertyName, XVetoableChangeListener listener)268         public void removeVetoableChangeListener(
269             String propertyName, XVetoableChangeListener listener)
270             throws UnknownPropertyException, WrappedTargetException
271         {
272             prop.removeVetoableChangeListener(propertyName, listener);
273         }
274 
setFastPropertyValue(int handle, Object value)275         public void setFastPropertyValue(int handle, Object value)
276             throws UnknownPropertyException, PropertyVetoException,
277             com.sun.star.lang.IllegalArgumentException, WrappedTargetException
278         {
279             prop.setFastPropertyValue(handle, value);
280         }
281 
getFastPropertyValue(int handle)282         public Object getFastPropertyValue(int handle)
283             throws UnknownPropertyException, WrappedTargetException
284         {
285             return prop.getFastPropertyValue(handle);
286         }
287 
getPropertyValues()288         public PropertyValue[] getPropertyValues() {
289             return prop.getPropertyValues();
290         }
291 
setPropertyValues(PropertyValue[] props)292         public void setPropertyValues(PropertyValue[] props)
293             throws UnknownPropertyException, PropertyVetoException,
294             com.sun.star.lang.IllegalArgumentException, WrappedTargetException
295         {
296             prop.setPropertyValues(props);
297         }
298 
299         private final PropertySetMixin prop = new PropertySetMixin(
300             context, this, new Type(XTest3.class), new String[] { "Third" });
301 
302         private int a1 = 0;
303         private Ambiguous a2 = new Ambiguous(
304             new Defaulted(new Optional(), true), false);
305     }
306 
307     private final XComponentContext context;
308 }
309