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 package test.cppuhelper.propertysetmixin.comp; 25 26 import com.sun.star.beans.Ambiguous; 27 import com.sun.star.beans.Defaulted; 28 import com.sun.star.beans.Optional; 29 import com.sun.star.beans.UnknownPropertyException; 30 import com.sun.star.beans.PropertyValue; 31 import com.sun.star.beans.PropertyVetoException; 32 import com.sun.star.beans.XFastPropertySet; 33 import com.sun.star.beans.XPropertyAccess; 34 import com.sun.star.beans.XPropertyChangeListener; 35 import com.sun.star.beans.XPropertySet; 36 import com.sun.star.beans.XPropertySetInfo; 37 import com.sun.star.beans.XVetoableChangeListener; 38 import com.sun.star.comp.loader.FactoryHelper; 39 import com.sun.star.lang.WrappedTargetException; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.lang.XEventListener; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.lang.XSingleServiceFactory; 44 import com.sun.star.lib.uno.helper.WeakBase; 45 import com.sun.star.lib.uno.helper.PropertySetMixin; 46 import com.sun.star.registry.XRegistryKey; 47 import com.sun.star.uno.Any; 48 import com.sun.star.uno.IQueryInterface; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.XComponentContext; 51 import test.cppuhelper.propertysetmixin.XSupplier; 52 import test.cppuhelper.propertysetmixin.XTest3; 53 54 public final class JavaSupplier extends WeakBase implements XSupplier { JavaSupplier(XComponentContext context)55 public JavaSupplier(XComponentContext context) { 56 this.context = context; 57 } 58 getEmpty1()59 public XComponent getEmpty1() { return new Empty1(); } 60 getEmpty2()61 public XComponent getEmpty2() { return new Empty2(); } 62 getFull()63 public XTest3 getFull() { return new Full(); } 64 __getServiceFactory( String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)65 public static XSingleServiceFactory __getServiceFactory( 66 String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey) 67 { 68 return implName.equals(implementationName) 69 ? FactoryHelper.getServiceFactory( 70 JavaSupplier.class, serviceName, multiFactory, regKey) 71 : null; 72 } 73 74 private static final String implementationName 75 = JavaSupplier.class.getName(); 76 private static final String serviceName 77 = "test.cppuhelper.propertysetmixin.JavaSupplier"; 78 79 private final class Empty1 extends WeakBase implements XComponent { Empty1()80 public Empty1() {} 81 dispose()82 public void dispose() { 83 prop.dispose(); 84 } 85 addEventListener(XEventListener listener)86 public void addEventListener(XEventListener listener) {} 87 removeEventListener(XEventListener listener)88 public void removeEventListener(XEventListener listener) {} 89 90 private final PropertySetMixin prop = new PropertySetMixin( 91 context, this, new Type(XComponent.class), null); 92 } 93 94 private final class Empty2 extends WeakBase 95 implements XComponent, XPropertySet, XFastPropertySet, XPropertyAccess 96 { Empty2()97 public Empty2() {} 98 dispose()99 public void dispose() { 100 prop.dispose(); 101 } 102 addEventListener(XEventListener listener)103 public void addEventListener(XEventListener listener) {} 104 removeEventListener(XEventListener listener)105 public void removeEventListener(XEventListener listener) {} 106 getPropertySetInfo()107 public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() { 108 return prop.getPropertySetInfo(); 109 } 110 setPropertyValue(String propertyName, Object value)111 public void setPropertyValue(String propertyName, Object value) 112 throws UnknownPropertyException, PropertyVetoException, 113 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 114 { 115 prop.setPropertyValue(propertyName, value); 116 } 117 getPropertyValue(String propertyName)118 public Object getPropertyValue(String propertyName) 119 throws UnknownPropertyException, WrappedTargetException 120 { 121 return prop.getPropertyValue(propertyName); 122 } 123 addPropertyChangeListener( String propertyName, XPropertyChangeListener listener)124 public void addPropertyChangeListener( 125 String propertyName, XPropertyChangeListener listener) 126 throws UnknownPropertyException, WrappedTargetException 127 { 128 prop.addPropertyChangeListener(propertyName, listener); 129 } 130 removePropertyChangeListener( String propertyName, XPropertyChangeListener listener)131 public void removePropertyChangeListener( 132 String propertyName, XPropertyChangeListener listener) 133 throws UnknownPropertyException, WrappedTargetException 134 { 135 prop.removePropertyChangeListener(propertyName, listener); 136 } 137 addVetoableChangeListener( String propertyName, XVetoableChangeListener listener)138 public void addVetoableChangeListener( 139 String propertyName, XVetoableChangeListener listener) 140 throws UnknownPropertyException, WrappedTargetException 141 { 142 prop.addVetoableChangeListener(propertyName, listener); 143 } 144 removeVetoableChangeListener( String propertyName, XVetoableChangeListener listener)145 public void removeVetoableChangeListener( 146 String propertyName, XVetoableChangeListener listener) 147 throws UnknownPropertyException, WrappedTargetException 148 { 149 prop.removeVetoableChangeListener(propertyName, listener); 150 } 151 setFastPropertyValue(int handle, Object value)152 public void setFastPropertyValue(int handle, Object value) 153 throws UnknownPropertyException, PropertyVetoException, 154 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 155 { 156 prop.setFastPropertyValue(handle, value); 157 } 158 getFastPropertyValue(int handle)159 public Object getFastPropertyValue(int handle) 160 throws UnknownPropertyException, WrappedTargetException 161 { 162 return prop.getFastPropertyValue(handle); 163 } 164 getPropertyValues()165 public PropertyValue[] getPropertyValues() { 166 return prop.getPropertyValues(); 167 } 168 setPropertyValues(PropertyValue[] props)169 public void setPropertyValues(PropertyValue[] props) 170 throws UnknownPropertyException, PropertyVetoException, 171 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 172 { 173 prop.setPropertyValues(props); 174 } 175 176 private final PropertySetMixin prop = new PropertySetMixin( 177 context, this, new Type(XComponent.class), null); 178 } 179 180 private final class Full extends WeakBase 181 implements XTest3, XPropertySet, XFastPropertySet, XPropertyAccess 182 { Full()183 public Full() {} 184 getFirst()185 public synchronized int getFirst() { 186 return a1; 187 } 188 setFirst(int value)189 public void setFirst(int value) { 190 prop.prepareSet("First", null); 191 synchronized (this) { 192 a1 = value; 193 } 194 } 195 getSecond()196 public synchronized Ambiguous getSecond() 197 throws UnknownPropertyException 198 { 199 return a2; 200 } 201 setSecond(Ambiguous value)202 public void setSecond(Ambiguous value) 203 throws PropertyVetoException, UnknownPropertyException 204 { 205 PropertySetMixin.BoundListeners l 206 = new PropertySetMixin.BoundListeners(); 207 prop.prepareSet( 208 "Second", Any.VOID, 209 (((Optional) ((Defaulted) value.Value).Value).IsPresent 210 ? ((Optional) ((Defaulted) value.Value).Value).Value 211 : Any.VOID), 212 l); 213 synchronized (this) { 214 a2 = value; 215 } 216 l.notifyListeners(); 217 } 218 getThird()219 public int getThird() throws UnknownPropertyException { 220 throw new UnknownPropertyException("Third", this); 221 } 222 setThird(int value)223 public void setThird(int value) throws UnknownPropertyException { 224 throw new UnknownPropertyException("Third", this); 225 } 226 getFourth()227 public int getFourth() throws UnknownPropertyException { 228 throw new UnknownPropertyException("Fourth", this); 229 } 230 setFourth(int value)231 public void setFourth(int value) throws UnknownPropertyException { 232 throw new UnknownPropertyException("Fourth", this); 233 } 234 getPropertySetInfo()235 public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() { 236 return prop.getPropertySetInfo(); 237 } 238 setPropertyValue(String propertyName, Object value)239 public void setPropertyValue(String propertyName, Object value) 240 throws UnknownPropertyException, PropertyVetoException, 241 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 242 { 243 prop.setPropertyValue(propertyName, value); 244 } 245 getPropertyValue(String propertyName)246 public Object getPropertyValue(String propertyName) 247 throws UnknownPropertyException, WrappedTargetException 248 { 249 return prop.getPropertyValue(propertyName); 250 } 251 addPropertyChangeListener( String propertyName, XPropertyChangeListener listener)252 public void addPropertyChangeListener( 253 String propertyName, XPropertyChangeListener listener) 254 throws UnknownPropertyException, WrappedTargetException 255 { 256 prop.addPropertyChangeListener(propertyName, listener); 257 } 258 removePropertyChangeListener( String propertyName, XPropertyChangeListener listener)259 public void removePropertyChangeListener( 260 String propertyName, XPropertyChangeListener listener) 261 throws UnknownPropertyException, WrappedTargetException 262 { 263 prop.removePropertyChangeListener(propertyName, listener); 264 } 265 addVetoableChangeListener( String propertyName, XVetoableChangeListener listener)266 public void addVetoableChangeListener( 267 String propertyName, XVetoableChangeListener listener) 268 throws UnknownPropertyException, WrappedTargetException 269 { 270 prop.addVetoableChangeListener(propertyName, listener); 271 } 272 removeVetoableChangeListener( String propertyName, XVetoableChangeListener listener)273 public void removeVetoableChangeListener( 274 String propertyName, XVetoableChangeListener listener) 275 throws UnknownPropertyException, WrappedTargetException 276 { 277 prop.removeVetoableChangeListener(propertyName, listener); 278 } 279 setFastPropertyValue(int handle, Object value)280 public void setFastPropertyValue(int handle, Object value) 281 throws UnknownPropertyException, PropertyVetoException, 282 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 283 { 284 prop.setFastPropertyValue(handle, value); 285 } 286 getFastPropertyValue(int handle)287 public Object getFastPropertyValue(int handle) 288 throws UnknownPropertyException, WrappedTargetException 289 { 290 return prop.getFastPropertyValue(handle); 291 } 292 getPropertyValues()293 public PropertyValue[] getPropertyValues() { 294 return prop.getPropertyValues(); 295 } 296 setPropertyValues(PropertyValue[] props)297 public void setPropertyValues(PropertyValue[] props) 298 throws UnknownPropertyException, PropertyVetoException, 299 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 300 { 301 prop.setPropertyValues(props); 302 } 303 304 private final PropertySetMixin prop = new PropertySetMixin( 305 context, this, new Type(XTest3.class), new String[] { "Third" }); 306 307 private int a1 = 0; 308 private Ambiguous a2 = new Ambiguous( 309 new Defaulted(new Optional(), true), false); 310 } 311 312 private final XComponentContext context; 313 } 314