PropertySet.java (80c1851d) | PropertySet.java (a8f4084d) |
---|---|
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 --- 71 unchanged lines hidden (view full) --- 80 */ 81public class PropertySet extends ComponentBase implements XPropertySet, XFastPropertySet, 82XMultiPropertySet 83{ 84 private HashMap _nameToPropertyMap; 85 private HashMap _handleToPropertyMap; 86 private HashMap _propertyToIdMap; 87 private Property[] arProperties; | 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 --- 71 unchanged lines hidden (view full) --- 80 */ 81public class PropertySet extends ComponentBase implements XPropertySet, XFastPropertySet, 82XMultiPropertySet 83{ 84 private HashMap _nameToPropertyMap; 85 private HashMap _handleToPropertyMap; 86 private HashMap _propertyToIdMap; 87 private Property[] arProperties; |
88 | 88 |
89 private int lastHandle= 1; | 89 private int lastHandle= 1; |
90 | 90 |
91 protected XPropertySetInfo propertySetInfo; 92 protected MultiTypeInterfaceContainer aBoundLC= new MultiTypeInterfaceContainer(); 93 protected MultiTypeInterfaceContainer aVetoableLC= new MultiTypeInterfaceContainer(); 94 public PropertySet() 95 { 96 super(); 97 initMappings(); 98 } --- 10 unchanged lines hidden (view full) --- 109 * @param id Identifies the properties storage. 110 * @see #getPropertyId 111 */ 112 protected void registerProperty(Property prop, Object id) 113 { 114 putProperty(prop); 115 assignPropertyId(prop, id); 116 } | 91 protected XPropertySetInfo propertySetInfo; 92 protected MultiTypeInterfaceContainer aBoundLC= new MultiTypeInterfaceContainer(); 93 protected MultiTypeInterfaceContainer aVetoableLC= new MultiTypeInterfaceContainer(); 94 public PropertySet() 95 { 96 super(); 97 initMappings(); 98 } --- 10 unchanged lines hidden (view full) --- 109 * @param id Identifies the properties storage. 110 * @see #getPropertyId 111 */ 112 protected void registerProperty(Property prop, Object id) 113 { 114 putProperty(prop); 115 assignPropertyId(prop, id); 116 } |
117 | 117 |
118 /** Registers a property with this helper class and associates the argument id with it. 119 * It does the same as {@link #registerProperty(Property, Object)}. The first four 120 * arguments are used to construct a Property object. 121 * Registration has to occur during 122 * initialization of the inheriting class (i.e. within the constructor) 123 * @param name The property's name (Property.Name). 124 * @param handle The property's handle (Property.Handle). 125 * @param type The property's type (Property.Type). 126 * @param attributes The property's attributes (Property.Attributes). 127 * @param id Identifies the property's storage. 128 */ 129 protected void registerProperty(String name, int handle, Type type, short attributes, Object id) 130 { 131 Property p= new Property(name, handle, type, attributes); 132 registerProperty(p, id); 133 } 134 | 118 /** Registers a property with this helper class and associates the argument id with it. 119 * It does the same as {@link #registerProperty(Property, Object)}. The first four 120 * arguments are used to construct a Property object. 121 * Registration has to occur during 122 * initialization of the inheriting class (i.e. within the constructor) 123 * @param name The property's name (Property.Name). 124 * @param handle The property's handle (Property.Handle). 125 * @param type The property's type (Property.Type). 126 * @param attributes The property's attributes (Property.Attributes). 127 * @param id Identifies the property's storage. 128 */ 129 protected void registerProperty(String name, int handle, Type type, short attributes, Object id) 130 { 131 Property p= new Property(name, handle, type, attributes); 132 registerProperty(p, id); 133 } 134 |
135 /** Registers a property with this class and associates the argument id with it. 136 * It does the same as {@link #registerProperty(Property, Object)}. The first three | 135 /** Registers a property with this class and associates the argument id with it. 136 * It does the same as {@link #registerProperty(Property, Object)}. The first three |
137 * arguments are used to construct a Property object. The value for the Property.Handle 138 * is generated and does not have to be specified here. Use this method for registering 139 * a property if you do not care about the Property's handles. 140 * Registration has to occur during | 137 * arguments are used to construct a Property object. The value for the Property.Handle 138 * is generated and does not have to be specified here. Use this method for registering 139 * a property if you do not care about the Property's handles. 140 * Registration has to occur during |
141 * initialization of the inheriting class (i.e. within the contructor). | 141 * initialization of the inheriting class (i.e. within the constructor). |
142 * @param name The property's name (Property.Name). 143 * @param type The property's type (Property.Type). 144 * @param attributes The property's attributes (Property.Attributes). 145 * @param id Identifies the property's storage. 146 */ 147 protected void registerProperty(String name, Type type, short attributes, Object id) 148 { 149 Property p= new Property(name, lastHandle++, type, attributes); --- 41 unchanged lines hidden (view full) --- 191 * @param propertyName The name of the property and the member variable that holds the property's value. 192 * @param attributes The property attributes. 193 * @see #registerProperty(String, String, short) 194 */ 195 protected void registerProperty(String propertyName, short attributes) 196 { 197 registerProperty(propertyName, propertyName, attributes); 198 } | 142 * @param name The property's name (Property.Name). 143 * @param type The property's type (Property.Type). 144 * @param attributes The property's attributes (Property.Attributes). 145 * @param id Identifies the property's storage. 146 */ 147 protected void registerProperty(String name, Type type, short attributes, Object id) 148 { 149 Property p= new Property(name, lastHandle++, type, attributes); --- 41 unchanged lines hidden (view full) --- 191 * @param propertyName The name of the property and the member variable that holds the property's value. 192 * @param attributes The property attributes. 193 * @see #registerProperty(String, String, short) 194 */ 195 protected void registerProperty(String propertyName, short attributes) 196 { 197 registerProperty(propertyName, propertyName, attributes); 198 } |
199 200 | |
201 202 /** Returns the Property object for a given property name or null if that property does 203 * not exists (i.e. it has not been registered). Override this method 204 * if you want to implement your own mapping from property names to Property objects. 205 * Then you also have to override {@link #initMappings}, {@link #getProperties()} and 206 * {@link #putProperty(Property)}. 207 * @param propertyName The name of the property (Property.Name) 208 * @return The Property object with the name <em>propertyName</em>. 209 */ 210 protected Property getProperty(String propertyName) 211 { 212 return (Property) _nameToPropertyMap.get(propertyName); 213 } | 199 200 /** Returns the Property object for a given property name or null if that property does 201 * not exists (i.e. it has not been registered). Override this method 202 * if you want to implement your own mapping from property names to Property objects. 203 * Then you also have to override {@link #initMappings}, {@link #getProperties()} and 204 * {@link #putProperty(Property)}. 205 * @param propertyName The name of the property (Property.Name) 206 * @return The Property object with the name <em>propertyName</em>. 207 */ 208 protected Property getProperty(String propertyName) 209 { 210 return (Property) _nameToPropertyMap.get(propertyName); 211 } |
214 | 212 |
215 /** Returns the Property object with a handle (Property.Handle) as specified by the argument 216 * <em>nHandle</em>. The method returns null if there is no such property (i.e. it has not 217 * been registered). Override this method if you want to implement your own mapping from handles 218 * to Property objects. Then you also have to override {@link #initMappings}, {@link #putProperty(Property)}. 219 * @param nHandle The handle of the property (Property.Handle). 220 * @return The Property object with the handle <em>nHandle</em> 221 */ 222 protected Property getPropertyByHandle(int nHandle) 223 { 224 return (Property) _handleToPropertyMap.get(nHandle); 225 } | 213 /** Returns the Property object with a handle (Property.Handle) as specified by the argument 214 * <em>nHandle</em>. The method returns null if there is no such property (i.e. it has not 215 * been registered). Override this method if you want to implement your own mapping from handles 216 * to Property objects. Then you also have to override {@link #initMappings}, {@link #putProperty(Property)}. 217 * @param nHandle The handle of the property (Property.Handle). 218 * @return The Property object with the handle <em>nHandle</em> 219 */ 220 protected Property getPropertyByHandle(int nHandle) 221 { 222 return (Property) _handleToPropertyMap.get(nHandle); 223 } |
226 | 224 |
227 /** Returns an array of all Property objects or an array of length null if there 228 * are no properties. Override this method if you want to implement your own mapping from names 229 * to Property objects. Then you also have to override {@link #initMappings}, {@link #getProperty(String)} and 230 * {@link #putProperty}. 231 * @return Array of all Property objects. 232 */ 233 protected Property[] getProperties() 234 { 235 if (arProperties == null) 236 { 237 Collection values= _nameToPropertyMap.values(); 238 arProperties= (Property[]) values.toArray(new Property[_nameToPropertyMap.size()]); 239 } 240 return arProperties; 241 } | 225 /** Returns an array of all Property objects or an array of length null if there 226 * are no properties. Override this method if you want to implement your own mapping from names 227 * to Property objects. Then you also have to override {@link #initMappings}, {@link #getProperty(String)} and 228 * {@link #putProperty}. 229 * @return Array of all Property objects. 230 */ 231 protected Property[] getProperties() 232 { 233 if (arProperties == null) 234 { 235 Collection values= _nameToPropertyMap.values(); 236 arProperties= (Property[]) values.toArray(new Property[_nameToPropertyMap.size()]); 237 } 238 return arProperties; 239 } |
242 | 240 |
243 /** Stores a Property object so that it can be retrieved subsequently by 244 * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. 245 * Override this method if you want to implement your own mapping from handles 246 * to Property objects and names to Property objects. Then you also need to override {@link #initMappings}, 247 * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. 248 * @param prop The Property object that is to be stored. 249 */ 250 protected void putProperty(Property prop) 251 { 252 _nameToPropertyMap.put(prop.Name, prop); 253 if (prop.Handle != -1) 254 _handleToPropertyMap.put(prop.Handle, prop); 255 } | 241 /** Stores a Property object so that it can be retrieved subsequently by 242 * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. 243 * Override this method if you want to implement your own mapping from handles 244 * to Property objects and names to Property objects. Then you also need to override {@link #initMappings}, 245 * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. 246 * @param prop The Property object that is to be stored. 247 */ 248 protected void putProperty(Property prop) 249 { 250 _nameToPropertyMap.put(prop.Name, prop); 251 if (prop.Handle != -1) 252 _handleToPropertyMap.put(prop.Handle, prop); 253 } |
256 257 /** Assigns an identifier object to a Property object so that the identifier | 254 255 /** Assigns an identifier object to a Property object so that the identifier |
258 * can be obtained by {@link #getPropertyId getPropertyId} later on. The identifier 259 * is used to specify a certain storage for the property's value. If you do not 260 * override {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} or {@link #getPropertyValue(Property)} | 256 * can be obtained by {@link #getPropertyId getPropertyId} later on. The identifier 257 * is used to specify a certain storage for the property's value. If you do not 258 * override {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} or {@link #getPropertyValue(Property)} |
261 * then the argument <em>id</em> has to be a java.lang.String that equals the name of | 259 * then the argument <em>id</em> has to be a java.lang.String that equals the name of |
262 * the member variable that holds the Property's value. | 260 * the member variable that holds the Property's value. |
263 * Override this method if you want to implement your own mapping from Property objects to ids or | 261 * Override this method if you want to implement your own mapping from Property objects to ids or |
264 * if you need ids of a type other then java.lang.String. | 262 * if you need ids of a type other then java.lang.String. |
265 * Then you also need to override {@link #initMappings initMappings} and {@link #getPropertyId getPropertyId}. | 263 * Then you also need to override {@link #initMappings initMappings} and {@link #getPropertyId getPropertyId}. |
266 * @param prop The Property object that is being assigned an id. 267 * @param id The object which identifies the storage used for the property's value. 268 * @see #registerProperty(Property, Object) 269 */ 270 protected void assignPropertyId(Property prop, Object id) 271 { 272 if (id instanceof String && ((String) id).equals("") == false) 273 _propertyToIdMap.put(prop, id); 274 } | 264 * @param prop The Property object that is being assigned an id. 265 * @param id The object which identifies the storage used for the property's value. 266 * @see #registerProperty(Property, Object) 267 */ 268 protected void assignPropertyId(Property prop, Object id) 269 { 270 if (id instanceof String && ((String) id).equals("") == false) 271 _propertyToIdMap.put(prop, id); 272 } |
275 | 273 |
276 /** Returns the identifier object for a certain Property. The object must have been 277 * previously assigned to the Property object by {@link #assignPropertyId assignPropertyId}. 278 * Override this method if you want to implement your own mapping from Property objects to ids. 279 * Then you also need to override {@link #initMappings initMappings} and {@link #assignPropertyId assignPropertyId}. 280 * @param prop The property for which the id is to be retrieved. 281 * @return The id object that identifies the storage used for the property's value. 282 * @see #registerProperty(Property, Object) 283 */ --- 87 unchanged lines hidden (view full) --- 371 if (propertySetInfo == null) 372 propertySetInfo= new PropertySetInfo(); 373 } 374 } 375 return propertySetInfo; 376 } 377 //XPropertySet ---------------------------------------------------- 378 public Object getPropertyValue(String name) throws UnknownPropertyException, WrappedTargetException | 274 /** Returns the identifier object for a certain Property. The object must have been 275 * previously assigned to the Property object by {@link #assignPropertyId assignPropertyId}. 276 * Override this method if you want to implement your own mapping from Property objects to ids. 277 * Then you also need to override {@link #initMappings initMappings} and {@link #assignPropertyId assignPropertyId}. 278 * @param prop The property for which the id is to be retrieved. 279 * @return The id object that identifies the storage used for the property's value. 280 * @see #registerProperty(Property, Object) 281 */ --- 87 unchanged lines hidden (view full) --- 369 if (propertySetInfo == null) 370 propertySetInfo= new PropertySetInfo(); 371 } 372 } 373 return propertySetInfo; 374 } 375 //XPropertySet ---------------------------------------------------- 376 public Object getPropertyValue(String name) throws UnknownPropertyException, WrappedTargetException |
379 { | 377 { |
380 Object ret= null; 381 if (bInDispose || bDisposed) 382 throw new com.sun.star.lang.DisposedException("The component has been disposed already"); 383 384 Property prop= getProperty(name); 385 if (prop == null) 386 throw new UnknownPropertyException("The property " + name + " is unknown"); | 378 Object ret= null; 379 if (bInDispose || bDisposed) 380 throw new com.sun.star.lang.DisposedException("The component has been disposed already"); 381 382 Property prop= getProperty(name); 383 if (prop == null) 384 throw new UnknownPropertyException("The property " + name + " is unknown"); |
387 | 385 |
388 synchronized (this) 389 { 390 ret= getPropertyValue(prop); 391 } 392 // null must not be returned. Either a void any is returned or an any containing 393 // an interface type and a null reference. 394 if (ret == null) 395 { 396 if (prop.Type.getTypeClass() == TypeClass.INTERFACE) 397 ret= new Any(prop.Type, null); 398 else 399 ret= new Any(new Type(void.class), null); 400 } 401 return ret; 402 } | 386 synchronized (this) 387 { 388 ret= getPropertyValue(prop); 389 } 390 // null must not be returned. Either a void any is returned or an any containing 391 // an interface type and a null reference. 392 if (ret == null) 393 { 394 if (prop.Type.getTypeClass() == TypeClass.INTERFACE) 395 ret= new Any(prop.Type, null); 396 else 397 ret= new Any(new Type(void.class), null); 398 } 399 return ret; 400 } |
403 | 401 |
404 //XPropertySet ---------------------------------------------------- 405 synchronized public void removePropertyChangeListener(String propName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException 406 { // all listeners are automatically released in a dispose call 407 if (!bInDispose && !bDisposed) 408 { 409 if (propName.length() > 0) 410 { 411 Property prop = getProperty(propName); --- 17 unchanged lines hidden (view full) --- 429 if (prop == null) 430 throw new UnknownPropertyException("Property " + propName + " is unknown"); 431 aVetoableLC.removeInterface(propName, listener); 432 } 433 else 434 listenerContainer.removeInterface(XVetoableChangeListener.class, listener); 435 } 436 } | 402 //XPropertySet ---------------------------------------------------- 403 synchronized public void removePropertyChangeListener(String propName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException 404 { // all listeners are automatically released in a dispose call 405 if (!bInDispose && !bDisposed) 406 { 407 if (propName.length() > 0) 408 { 409 Property prop = getProperty(propName); --- 17 unchanged lines hidden (view full) --- 427 if (prop == null) 428 throw new UnknownPropertyException("Property " + propName + " is unknown"); 429 aVetoableLC.removeInterface(propName, listener); 430 } 431 else 432 listenerContainer.removeInterface(XVetoableChangeListener.class, listener); 433 } 434 } |
437 | 435 |
438 //XPropertySet ---------------------------------------------------- 439 /** Sets the value of a property. 440 * The idl description for this interfaces, stipulates that the argument value is an Any. Since a java.lang.Object 441 * reference has the same meaning as an Any this function accepts 442 * java anys (com.sun.star.uno.Any) and all other appropriate objects as arguments. The value argument can be one 443 * of these: 444 * <ul> 445 * <li>java.lang.Boolean</li> --- 57 unchanged lines hidden (view full) --- 503 if (value instanceof Any) 504 bVoidValue= ((Any) value).getObject() == null; 505 else 506 bVoidValue= value == null; 507 if (bVoidValue && (prop.Attributes & PropertyAttribute.MAYBEVOID) == 0) 508 throw new com.sun.star.lang.IllegalArgumentException("The property must have a value; the MAYBEVOID attribute is not set!"); 509 if (bInDispose || bDisposed) 510 throw new DisposedException("Component is already disposed"); | 436 //XPropertySet ---------------------------------------------------- 437 /** Sets the value of a property. 438 * The idl description for this interfaces, stipulates that the argument value is an Any. Since a java.lang.Object 439 * reference has the same meaning as an Any this function accepts 440 * java anys (com.sun.star.uno.Any) and all other appropriate objects as arguments. The value argument can be one 441 * of these: 442 * <ul> 443 * <li>java.lang.Boolean</li> --- 57 unchanged lines hidden (view full) --- 501 if (value instanceof Any) 502 bVoidValue= ((Any) value).getObject() == null; 503 else 504 bVoidValue= value == null; 505 if (bVoidValue && (prop.Attributes & PropertyAttribute.MAYBEVOID) == 0) 506 throw new com.sun.star.lang.IllegalArgumentException("The property must have a value; the MAYBEVOID attribute is not set!"); 507 if (bInDispose || bDisposed) 508 throw new DisposedException("Component is already disposed"); |
511 | 509 |
512 //Check if the argument is allowed 513 boolean bValueOk= false; 514 if (value instanceof Any) 515 bValueOk= checkType(((Any) value).getObject()); 516 else 517 bValueOk= checkType(value); 518 if (! bValueOk) 519 throw new com.sun.star.lang.IllegalArgumentException("No valid UNO type"); 520 | 510 //Check if the argument is allowed 511 boolean bValueOk= false; 512 if (value instanceof Any) 513 bValueOk= checkType(((Any) value).getObject()); 514 else 515 bValueOk= checkType(value); 516 if (! bValueOk) 517 throw new com.sun.star.lang.IllegalArgumentException("No valid UNO type"); 518 |
521 | 519 |
522 boolean bConversionOk= false; 523 Object[] outConvertedVal= new Object[1]; 524 Object[] outOldValue= new Object[1]; 525 synchronized (this) 526 { 527 bConversionOk= convertPropertyValue(prop, outConvertedVal, outOldValue, value); 528 } | 520 boolean bConversionOk= false; 521 Object[] outConvertedVal= new Object[1]; 522 Object[] outOldValue= new Object[1]; 523 synchronized (this) 524 { 525 bConversionOk= convertPropertyValue(prop, outConvertedVal, outOldValue, value); 526 } |
529 | 527 |
530 //The next step following the conversion is to set the new value of the property. Prior to this 531 // the XVetoableChangeListener s have to be notified. 532 if (bConversionOk) 533 { 534 // If the property is CONSTRAINED, then we must notify XVetoableChangeListener. The listener can throw a com.sun.star.lang.beans.PropertyVetoException which 535 // will cause this method to return (the exception is not caught here). 536 fire( new Property[]{prop}, outConvertedVal, outOldValue, true); 537 538 synchronized (this) 539 { 540 setPropertyValueNoBroadcast(prop, outConvertedVal[0]); 541 } 542 // fire a change event (XPropertyChangeListener, PropertyAttribute.BOUND 543 fire( new Property[]{prop}, outConvertedVal, outOldValue, false); 544 } 545 } | 528 //The next step following the conversion is to set the new value of the property. Prior to this 529 // the XVetoableChangeListener s have to be notified. 530 if (bConversionOk) 531 { 532 // If the property is CONSTRAINED, then we must notify XVetoableChangeListener. The listener can throw a com.sun.star.lang.beans.PropertyVetoException which 533 // will cause this method to return (the exception is not caught here). 534 fire( new Property[]{prop}, outConvertedVal, outOldValue, true); 535 536 synchronized (this) 537 { 538 setPropertyValueNoBroadcast(prop, outConvertedVal[0]); 539 } 540 // fire a change event (XPropertyChangeListener, PropertyAttribute.BOUND 541 fire( new Property[]{prop}, outConvertedVal, outOldValue, false); 542 } 543 } |
546 | 544 |
547 /** Converts a value in a way so that it is appropriate for storing as a property value, that is 548 * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} can process the value without any further 549 * conversion. This implementation presumes that 550 * the values are stored in member variables of the furthest inheriting class. For example, 551 * class A inherits this class then members of class A 552 * can hold property values. If there is a class B which inherits A then only members of B can hold 553 * property values. The variables must be public. A property must have been registered (e.g. by 554 * {@link #registerProperty(Property, Object)} in order for this method to work. The identifier argument (type Object) --- 70 unchanged lines hidden (view full) --- 625 String sMember= (String) getPropertyId(property); 626 if (sMember != null) 627 { 628 // use reflection to obtain the field that holds the property value 629 // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to 630 // also get inherited fields, but only those which are public. 631 Field propField= getClass().getDeclaredField(sMember); 632 if (propField != null) | 545 /** Converts a value in a way so that it is appropriate for storing as a property value, that is 546 * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} can process the value without any further 547 * conversion. This implementation presumes that 548 * the values are stored in member variables of the furthest inheriting class. For example, 549 * class A inherits this class then members of class A 550 * can hold property values. If there is a class B which inherits A then only members of B can hold 551 * property values. The variables must be public. A property must have been registered (e.g. by 552 * {@link #registerProperty(Property, Object)} in order for this method to work. The identifier argument (type Object) --- 70 unchanged lines hidden (view full) --- 623 String sMember= (String) getPropertyId(property); 624 if (sMember != null) 625 { 626 // use reflection to obtain the field that holds the property value 627 // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to 628 // also get inherited fields, but only those which are public. 629 Field propField= getClass().getDeclaredField(sMember); 630 if (propField != null) |
633 { | 631 { |
634 curVal[0]= propField.get(this); 635 Class memberClass= propField.getType(); 636 637 // MAYBEVOID: if setVal == null or it is an Any and getObject returns null, then a void value is to be set 638 // This works only if there are no primitive types. For those we use the respective wrapper classes. 639 // In this implementation, a null reference means void value. 640 boolean bVoidValue= false; 641 boolean bAnyVal= setVal instanceof Any; --- 54 unchanged lines hidden (view full) --- 696 throw new WrappedTargetException("Field does not exist", this, e); 697 } 698 catch (java.lang.IllegalAccessException e) 699 { 700 throw new WrappedTargetException("", this ,e); 701 } 702 return ret; 703 } | 632 curVal[0]= propField.get(this); 633 Class memberClass= propField.getType(); 634 635 // MAYBEVOID: if setVal == null or it is an Any and getObject returns null, then a void value is to be set 636 // This works only if there are no primitive types. For those we use the respective wrapper classes. 637 // In this implementation, a null reference means void value. 638 boolean bVoidValue= false; 639 boolean bAnyVal= setVal instanceof Any; --- 54 unchanged lines hidden (view full) --- 694 throw new WrappedTargetException("Field does not exist", this, e); 695 } 696 catch (java.lang.IllegalAccessException e) 697 { 698 throw new WrappedTargetException("", this ,e); 699 } 700 return ret; 701 } |
704 | 702 |
705 private boolean checkType(Object obj) 706 { 707 if (obj == null 708 || obj instanceof Boolean 709 || obj instanceof Character 710 || obj instanceof Number 711 || obj instanceof String 712 || obj instanceof XInterface 713 || obj instanceof Type 714 || obj instanceof com.sun.star.uno.Enum 715 || obj.getClass().isArray()) 716 return true; 717 return false; 718 } | 703 private boolean checkType(Object obj) 704 { 705 if (obj == null 706 || obj instanceof Boolean 707 || obj instanceof Character 708 || obj instanceof Number 709 || obj instanceof String 710 || obj instanceof XInterface 711 || obj instanceof Type 712 || obj instanceof com.sun.star.uno.Enum 713 || obj.getClass().isArray()) 714 return true; 715 return false; 716 } |
719 | 717 |
720 // Param object can be an Any or other object. If obj is null then the return value is null 721 private Object convert( Class cl, Object obj) throws com.sun.star.lang.IllegalArgumentException 722 { 723 Object retVal= null; 724 //The member that keeps the value of the Property is an Object.Objects are similar to Anys in that they can 725 // hold all types. 726 if (obj == null || (obj instanceof Any && ((Any) obj).getObject() == null)) 727 retVal= null; --- 44 unchanged lines hidden (view full) --- 772 else if (XInterface.class.isAssignableFrom(cl)) 773 retVal= AnyConverter.toObject(new Type(cl), obj); 774 else if (com.sun.star.uno.Enum.class.isAssignableFrom(cl)) 775 retVal= AnyConverter.toObject(new Type(cl), obj); 776 else 777 throw new com.sun.star.lang.IllegalArgumentException("Could not convert the argument"); 778 return retVal; 779 } | 718 // Param object can be an Any or other object. If obj is null then the return value is null 719 private Object convert( Class cl, Object obj) throws com.sun.star.lang.IllegalArgumentException 720 { 721 Object retVal= null; 722 //The member that keeps the value of the Property is an Object.Objects are similar to Anys in that they can 723 // hold all types. 724 if (obj == null || (obj instanceof Any && ((Any) obj).getObject() == null)) 725 retVal= null; --- 44 unchanged lines hidden (view full) --- 770 else if (XInterface.class.isAssignableFrom(cl)) 771 retVal= AnyConverter.toObject(new Type(cl), obj); 772 else if (com.sun.star.uno.Enum.class.isAssignableFrom(cl)) 773 retVal= AnyConverter.toObject(new Type(cl), obj); 774 else 775 throw new com.sun.star.lang.IllegalArgumentException("Could not convert the argument"); 776 return retVal; 777 } |
780 | 778 |
781 /** Sets the value of a property. In this implementation property values are stored in member variables 782 * (see {@link #convertPropertyValue convertPropertyValue} Notification of property listeners 783 * does not occur in this method. By overriding this method one can take full control about how property values 784 * are stored. But then, the {@link #convertPropertyValue convertPropertyValue} and 785 * {@link #getPropertyValue(Property)} must be overridden too. 786 * 787 * A Property with the MAYBEVOID attribute set, is stored as null value. Therefore the member variable must be 788 * an Object in order to make use of the property attribute. An exception is Any. The Any variable can be initially null, but --- 63 unchanged lines hidden (view full) --- 852 throw new java.lang.RuntimeException(e); 853 } 854 catch(java.lang.IllegalAccessException e) 855 { 856 throw new java.lang.RuntimeException(e); 857 } 858 return ret; 859 } | 779 /** Sets the value of a property. In this implementation property values are stored in member variables 780 * (see {@link #convertPropertyValue convertPropertyValue} Notification of property listeners 781 * does not occur in this method. By overriding this method one can take full control about how property values 782 * are stored. But then, the {@link #convertPropertyValue convertPropertyValue} and 783 * {@link #getPropertyValue(Property)} must be overridden too. 784 * 785 * A Property with the MAYBEVOID attribute set, is stored as null value. Therefore the member variable must be 786 * an Object in order to make use of the property attribute. An exception is Any. The Any variable can be initially null, but --- 63 unchanged lines hidden (view full) --- 850 throw new java.lang.RuntimeException(e); 851 } 852 catch(java.lang.IllegalAccessException e) 853 { 854 throw new java.lang.RuntimeException(e); 855 } 856 return ret; 857 } |
860 | 858 |
861 /** 862 * This method fires events to XPropertyChangeListener,XVetoableChangeListener and 863 * XPropertiesChangeListener event sinks. 864 * To distinguish what listeners are to be called the argument <em>bVetoable</em> is to be set to true if 865 * a XVetoableChangeListener is meant. For XPropertyChangeListener and XPropertiesChangeListener 866 * it is to be set to false. 867 * 868 * @param properties Properties which will be or have been affected. --- 89 unchanged lines hidden (view full) --- 958 public void setFastPropertyValue(int nHandle, Object aValue ) throws UnknownPropertyException, 959 PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException 960 { 961 Property prop= getPropertyByHandle(nHandle); 962 if (prop == null) 963 throw new UnknownPropertyException(" The property with handle : " + nHandle +" is unknown"); 964 setPropertyValue(prop, aValue); 965 } | 859 /** 860 * This method fires events to XPropertyChangeListener,XVetoableChangeListener and 861 * XPropertiesChangeListener event sinks. 862 * To distinguish what listeners are to be called the argument <em>bVetoable</em> is to be set to true if 863 * a XVetoableChangeListener is meant. For XPropertyChangeListener and XPropertiesChangeListener 864 * it is to be set to false. 865 * 866 * @param properties Properties which will be or have been affected. --- 89 unchanged lines hidden (view full) --- 956 public void setFastPropertyValue(int nHandle, Object aValue ) throws UnknownPropertyException, 957 PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException 958 { 959 Property prop= getPropertyByHandle(nHandle); 960 if (prop == null) 961 throw new UnknownPropertyException(" The property with handle : " + nHandle +" is unknown"); 962 setPropertyValue(prop, aValue); 963 } |
966 | 964 |
967 // XFastPropertySet -------------------------------------------------------------------------------- 968 public Object getFastPropertyValue(int nHandle ) throws UnknownPropertyException, 969 WrappedTargetException 970 { 971 Property prop= getPropertyByHandle(nHandle); 972 if (prop == null) 973 throw new UnknownPropertyException("The property with handle : " + nHandle + " is unknown"); 974 return getPropertyValue(prop); 975 } 976 977 // XMultiPropertySet ----------------------------------------------------------------------------------- 978 public void addPropertiesChangeListener(String[] propNames, XPropertiesChangeListener listener) 979 { 980 listenerContainer.addInterface(XPropertiesChangeListener.class, listener); 981 } | 965 // XFastPropertySet -------------------------------------------------------------------------------- 966 public Object getFastPropertyValue(int nHandle ) throws UnknownPropertyException, 967 WrappedTargetException 968 { 969 Property prop= getPropertyByHandle(nHandle); 970 if (prop == null) 971 throw new UnknownPropertyException("The property with handle : " + nHandle + " is unknown"); 972 return getPropertyValue(prop); 973 } 974 975 // XMultiPropertySet ----------------------------------------------------------------------------------- 976 public void addPropertiesChangeListener(String[] propNames, XPropertiesChangeListener listener) 977 { 978 listenerContainer.addInterface(XPropertiesChangeListener.class, listener); 979 } |
982 | 980 |
983 // XMultiPropertySet ----------------------------------------------------------------------------------- 984 public void firePropertiesChangeEvent(String[] propNames, XPropertiesChangeListener listener) 985 { 986 // Build the events. 987 PropertyChangeEvent[] arEvents= new PropertyChangeEvent[propNames.length]; 988 int eventCount= 0; 989 // get a snapshot of the current property values 990 synchronized (this) --- 13 unchanged lines hidden (view full) --- 1004 continue; 1005 } 1006 arEvents[eventCount]= new PropertyChangeEvent(this, prop.Name, 1007 false, prop.Handle, value, value); 1008 eventCount++; 1009 } 1010 } 1011 } | 981 // XMultiPropertySet ----------------------------------------------------------------------------------- 982 public void firePropertiesChangeEvent(String[] propNames, XPropertiesChangeListener listener) 983 { 984 // Build the events. 985 PropertyChangeEvent[] arEvents= new PropertyChangeEvent[propNames.length]; 986 int eventCount= 0; 987 // get a snapshot of the current property values 988 synchronized (this) --- 13 unchanged lines hidden (view full) --- 1002 continue; 1003 } 1004 arEvents[eventCount]= new PropertyChangeEvent(this, prop.Name, 1005 false, prop.Handle, value, value); 1006 eventCount++; 1007 } 1008 } 1009 } |
1012 | 1010 |
1013 // fire events from unsynchronized section so as to prevent deadlocks 1014 if (eventCount > 0) 1015 { 1016 // Reallocate the array of the events if necessary 1017 if (arEvents.length != eventCount) 1018 { 1019 PropertyChangeEvent[] arPropsTmp= new PropertyChangeEvent[eventCount]; 1020 System.arraycopy(arEvents, 0, arPropsTmp, 0, eventCount); --- 21 unchanged lines hidden (view full) --- 1042 catch (Exception e) 1043 { 1044 } 1045 arValues[i]= value; 1046 } 1047 } 1048 return arValues; 1049 } | 1011 // fire events from unsynchronized section so as to prevent deadlocks 1012 if (eventCount > 0) 1013 { 1014 // Reallocate the array of the events if necessary 1015 if (arEvents.length != eventCount) 1016 { 1017 PropertyChangeEvent[] arPropsTmp= new PropertyChangeEvent[eventCount]; 1018 System.arraycopy(arEvents, 0, arPropsTmp, 0, eventCount); --- 21 unchanged lines hidden (view full) --- 1040 catch (Exception e) 1041 { 1042 } 1043 arValues[i]= value; 1044 } 1045 } 1046 return arValues; 1047 } |
1050 // XMultiPropertySet ----------------------------------------------------------------------------------- | 1048 // XMultiPropertySet ----------------------------------------------------------------------------------- |
1051 public void removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener) 1052 { 1053 listenerContainer.removeInterface(XPropertiesChangeListener.class, xPropertiesChangeListener); 1054 } | 1049 public void removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener) 1050 { 1051 listenerContainer.removeInterface(XPropertiesChangeListener.class, xPropertiesChangeListener); 1052 } |
1055 // XMultiPropertySet ----------------------------------------------------------------------------------- | 1053 // XMultiPropertySet ----------------------------------------------------------------------------------- |
1056 /** If the array of property names contains an unknown property then it will be ignored. 1057 */ 1058 public void setPropertyValues(String[] propNames, Object[] values) throws PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException 1059 { 1060 for (int i= 0; i < propNames.length; i++) 1061 { 1062 try 1063 { 1064 setPropertyValue(propNames[i], values[i]); 1065 } 1066 catch (UnknownPropertyException e) 1067 { 1068 continue; 1069 } 1070 1071 } 1072 } | 1054 /** If the array of property names contains an unknown property then it will be ignored. 1055 */ 1056 public void setPropertyValues(String[] propNames, Object[] values) throws PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException 1057 { 1058 for (int i= 0; i < propNames.length; i++) 1059 { 1060 try 1061 { 1062 setPropertyValue(propNames[i], values[i]); 1063 } 1064 catch (UnknownPropertyException e) 1065 { 1066 continue; 1067 } 1068 1069 } 1070 } |
1073 | 1071 |
1074 private class PropertySetInfo implements XPropertySetInfo 1075 { 1076 public com.sun.star.beans.Property[] getProperties() 1077 { 1078 return PropertySet.this.getProperties(); 1079 } 1080 1081 public com.sun.star.beans.Property getPropertyByName(String name) throws UnknownPropertyException 1082 { 1083 return getProperty(name); 1084 } 1085 1086 public boolean hasPropertyByName(String name) 1087 { 1088 return getProperty(name) != null; 1089 } 1090 1091 } 1092} | 1072 private class PropertySetInfo implements XPropertySetInfo 1073 { 1074 public com.sun.star.beans.Property[] getProperties() 1075 { 1076 return PropertySet.this.getProperties(); 1077 } 1078 1079 public com.sun.star.beans.Property getPropertyByName(String name) throws UnknownPropertyException 1080 { 1081 return getProperty(name); 1082 } 1083 1084 public boolean hasPropertyByName(String name) 1085 { 1086 return getProperty(name) != null; 1087 } 1088 1089 } 1090} |
1093 1094 1095 1096 | |
1097 | 1091 |
1092 |
|