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