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