1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: JavaSupplier.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package test
.cppuhelper
.propertysetmixin
.comp
;
33 import com
.sun
.star
.beans
.Ambiguous
;
34 import com
.sun
.star
.beans
.Defaulted
;
35 import com
.sun
.star
.beans
.Optional
;
36 import com
.sun
.star
.beans
.UnknownPropertyException
;
37 import com
.sun
.star
.beans
.PropertyValue
;
38 import com
.sun
.star
.beans
.PropertyVetoException
;
39 import com
.sun
.star
.beans
.XFastPropertySet
;
40 import com
.sun
.star
.beans
.XPropertyAccess
;
41 import com
.sun
.star
.beans
.XPropertyChangeListener
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.beans
.XPropertySetInfo
;
44 import com
.sun
.star
.beans
.XVetoableChangeListener
;
45 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
46 import com
.sun
.star
.lang
.WrappedTargetException
;
47 import com
.sun
.star
.lang
.XComponent
;
48 import com
.sun
.star
.lang
.XEventListener
;
49 import com
.sun
.star
.lang
.XMultiServiceFactory
;
50 import com
.sun
.star
.lang
.XSingleServiceFactory
;
51 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
52 import com
.sun
.star
.lib
.uno
.helper
.PropertySetMixin
;
53 import com
.sun
.star
.registry
.XRegistryKey
;
54 import com
.sun
.star
.uno
.Any
;
55 import com
.sun
.star
.uno
.IQueryInterface
;
56 import com
.sun
.star
.uno
.Type
;
57 import com
.sun
.star
.uno
.XComponentContext
;
58 import test
.cppuhelper
.propertysetmixin
.XSupplier
;
59 import test
.cppuhelper
.propertysetmixin
.XTest3
;
61 public final class JavaSupplier
extends WeakBase
implements XSupplier
{
62 public JavaSupplier(XComponentContext context
) {
63 this.context
= context
;
66 public XComponent
getEmpty1() { return new Empty1(); }
68 public XComponent
getEmpty2() { return new Empty2(); }
70 public XTest3
getFull() { return new Full(); }
72 public static XSingleServiceFactory
__getServiceFactory(
73 String implName
, XMultiServiceFactory multiFactory
, XRegistryKey regKey
)
75 return implName
.equals(implementationName
)
76 ? FactoryHelper
.getServiceFactory(
77 JavaSupplier
.class, serviceName
, multiFactory
, regKey
)
81 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
82 return FactoryHelper
.writeRegistryServiceInfo(
83 implementationName
, serviceName
, regKey
);
86 private static final String implementationName
87 = JavaSupplier
.class.getName();
88 private static final String serviceName
89 = "test.cppuhelper.propertysetmixin.JavaSupplier";
91 private final class Empty1
extends WeakBase
implements XComponent
{
94 public void dispose() {
98 public void addEventListener(XEventListener listener
) {}
100 public void removeEventListener(XEventListener listener
) {}
102 private final PropertySetMixin prop
= new PropertySetMixin(
103 context
, this, new Type(XComponent
.class), null);
106 private final class Empty2
extends WeakBase
107 implements XComponent
, XPropertySet
, XFastPropertySet
, XPropertyAccess
111 public void dispose() {
115 public void addEventListener(XEventListener listener
) {}
117 public void removeEventListener(XEventListener listener
) {}
119 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo() {
120 return prop
.getPropertySetInfo();
123 public void setPropertyValue(String propertyName
, Object value
)
124 throws UnknownPropertyException
, PropertyVetoException
,
125 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
127 prop
.setPropertyValue(propertyName
, value
);
130 public Object
getPropertyValue(String propertyName
)
131 throws UnknownPropertyException
, WrappedTargetException
133 return prop
.getPropertyValue(propertyName
);
136 public void addPropertyChangeListener(
137 String propertyName
, XPropertyChangeListener listener
)
138 throws UnknownPropertyException
, WrappedTargetException
140 prop
.addPropertyChangeListener(propertyName
, listener
);
143 public void removePropertyChangeListener(
144 String propertyName
, XPropertyChangeListener listener
)
145 throws UnknownPropertyException
, WrappedTargetException
147 prop
.removePropertyChangeListener(propertyName
, listener
);
150 public void addVetoableChangeListener(
151 String propertyName
, XVetoableChangeListener listener
)
152 throws UnknownPropertyException
, WrappedTargetException
154 prop
.addVetoableChangeListener(propertyName
, listener
);
157 public void removeVetoableChangeListener(
158 String propertyName
, XVetoableChangeListener listener
)
159 throws UnknownPropertyException
, WrappedTargetException
161 prop
.removeVetoableChangeListener(propertyName
, listener
);
164 public void setFastPropertyValue(int handle
, Object value
)
165 throws UnknownPropertyException
, PropertyVetoException
,
166 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
168 prop
.setFastPropertyValue(handle
, value
);
171 public Object
getFastPropertyValue(int handle
)
172 throws UnknownPropertyException
, WrappedTargetException
174 return prop
.getFastPropertyValue(handle
);
177 public PropertyValue
[] getPropertyValues() {
178 return prop
.getPropertyValues();
181 public void setPropertyValues(PropertyValue
[] props
)
182 throws UnknownPropertyException
, PropertyVetoException
,
183 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
185 prop
.setPropertyValues(props
);
188 private final PropertySetMixin prop
= new PropertySetMixin(
189 context
, this, new Type(XComponent
.class), null);
192 private final class Full
extends WeakBase
193 implements XTest3
, XPropertySet
, XFastPropertySet
, XPropertyAccess
197 public synchronized int getFirst() {
201 public void setFirst(int value
) {
202 prop
.prepareSet("First", null);
203 synchronized (this) {
208 public synchronized Ambiguous
getSecond()
209 throws UnknownPropertyException
214 public void setSecond(Ambiguous value
)
215 throws PropertyVetoException
, UnknownPropertyException
217 PropertySetMixin
.BoundListeners l
218 = new PropertySetMixin
.BoundListeners();
221 (((Optional
) ((Defaulted
) value
.Value
).Value
).IsPresent
222 ?
((Optional
) ((Defaulted
) value
.Value
).Value
).Value
225 synchronized (this) {
231 public int getThird() throws UnknownPropertyException
{
232 throw new UnknownPropertyException("Third", this);
235 public void setThird(int value
) throws UnknownPropertyException
{
236 throw new UnknownPropertyException("Third", this);
239 public int getFourth() throws UnknownPropertyException
{
240 throw new UnknownPropertyException("Fourth", this);
243 public void setFourth(int value
) throws UnknownPropertyException
{
244 throw new UnknownPropertyException("Fourth", this);
247 public com
.sun
.star
.beans
.XPropertySetInfo
getPropertySetInfo() {
248 return prop
.getPropertySetInfo();
251 public void setPropertyValue(String propertyName
, Object value
)
252 throws UnknownPropertyException
, PropertyVetoException
,
253 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
255 prop
.setPropertyValue(propertyName
, value
);
258 public Object
getPropertyValue(String propertyName
)
259 throws UnknownPropertyException
, WrappedTargetException
261 return prop
.getPropertyValue(propertyName
);
264 public void addPropertyChangeListener(
265 String propertyName
, XPropertyChangeListener listener
)
266 throws UnknownPropertyException
, WrappedTargetException
268 prop
.addPropertyChangeListener(propertyName
, listener
);
271 public void removePropertyChangeListener(
272 String propertyName
, XPropertyChangeListener listener
)
273 throws UnknownPropertyException
, WrappedTargetException
275 prop
.removePropertyChangeListener(propertyName
, listener
);
278 public void addVetoableChangeListener(
279 String propertyName
, XVetoableChangeListener listener
)
280 throws UnknownPropertyException
, WrappedTargetException
282 prop
.addVetoableChangeListener(propertyName
, listener
);
285 public void removeVetoableChangeListener(
286 String propertyName
, XVetoableChangeListener listener
)
287 throws UnknownPropertyException
, WrappedTargetException
289 prop
.removeVetoableChangeListener(propertyName
, listener
);
292 public void setFastPropertyValue(int handle
, Object value
)
293 throws UnknownPropertyException
, PropertyVetoException
,
294 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
296 prop
.setFastPropertyValue(handle
, value
);
299 public Object
getFastPropertyValue(int handle
)
300 throws UnknownPropertyException
, WrappedTargetException
302 return prop
.getFastPropertyValue(handle
);
305 public PropertyValue
[] getPropertyValues() {
306 return prop
.getPropertyValues();
309 public void setPropertyValues(PropertyValue
[] props
)
310 throws UnknownPropertyException
, PropertyVetoException
,
311 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
313 prop
.setPropertyValues(props
);
316 private final PropertySetMixin prop
= new PropertySetMixin(
317 context
, this, new Type(XTest3
.class), new String
[] { "Third" });
320 private Ambiguous a2
= new Ambiguous(
321 new Defaulted(new Optional(), true), false);
324 private final XComponentContext context
;