diff options
author | Joachim Lingner <jl@openoffice.org> | 2002-04-25 10:36:26 +0000 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2002-04-25 10:36:26 +0000 |
commit | e0206b45a2f176fa4d0e08aeeb22937bb52cc1c1 (patch) | |
tree | d0579d7856b561bf817b9d22291fab0c7b7e4987 /javaunohelper | |
parent | 8a82aa622c98d2d2b0cf7c6711221c97b1b84f9a (diff) |
#97746#
Diffstat (limited to 'javaunohelper')
-rw-r--r-- | javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java | 1073 | ||||
-rw-r--r-- | javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java | 1607 |
2 files changed, 2680 insertions, 0 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java new file mode 100644 index 000000000..6b657f743 --- /dev/null +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java @@ -0,0 +1,1073 @@ +/************************************************************************* + * + * $RCSfile: PropertySet.java,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jl $ $Date: 2002-04-25 11:31:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +package com.sun.star.lib.uno.helper; + +import com.sun.star.uno.Type; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.XInterface; +import com.sun.star.uno.Any; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertiesChangeListener; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XFastPropertySet; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.XMultiPropertySet; +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; +import java.util.Collection; +import java.util.HashMap; +import java.lang.reflect.Field; + + +/** This class is an implementation of the interfaces com.sun.star.beans.XPropertySet, + * com.sun.star.beans.XFastPropertySet and com.sun.star.beans.XMultiPropertySet. This + * class has to be inherited to be used. The values of properties are stored in member + * variables of the inheriting class. By overriding the methods + * {@link #convertPropertyValue convertPropertyValue}, + * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and + * {@link #getPropertyValue(Property)} one can determine how + * property values are stored. + * When using the supplied implementations of this class then the member variables which + * hold property values have to be declared in the class which inherits last in the inheriting + * chain and they have to be of public, protected or package access.<p> + * Properties have to be registered by one of the registerProperty methods. They take among other + * arguments an Object named <em>id</em> which has to be a String that represents the name of + * the member variable. The registering has to occur in the constructor of the inheriting class. + * It is no allowed to add or change properties later on.<p> + * Example: + * <pre> + * public class Foo extends PropertySet + * { + * protected int intProp; + * + * public Foo() + * { + * registerProperty("PropertyA", 0, new Type(int.class), (short)0, "intProp"); + * } + * } + * + * </pre> + */ +public class PropertySet extends ComponentBase implements XPropertySet, XFastPropertySet, +XMultiPropertySet +{ + private HashMap _nameToPropertyMap; + private HashMap _handleToPropertyMap; + private HashMap _propertyToIdMap; + private Property[] arProperties; + + private int lastHandle= 1; + + protected XPropertySetInfo propertySetInfo; + protected MultiTypeInterfaceContainer aBoundLC= new MultiTypeInterfaceContainer(); + protected MultiTypeInterfaceContainer aVetoableLC= new MultiTypeInterfaceContainer(); + public PropertySet() + { + super(); + initMappings(); + } + + /** Registers a property with this helper class and associates the argument <em>id</em> with it. + * <em>id</em> is used to identify the storage of the property value. How property values are stored + * and retrieved is determined by the methods {@link #convertPropertyValue convertPropertyValue}, + * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and {@link #getPropertyValue(Property) getPropertyValue} + * These methods expect <em>id</em> to be a java.lang.String which represents the name of a member variable + * which holds the property value. + * Only properties which are registered can be accessed. Registration has to occur during + * initialization of the inheriting class (i.e. within the contructor). + * @param prop The property to be registered. + * @param id Identifies the properties storage. + * @see #getPropertyId + */ + protected void registerProperty(Property prop, Object id) + { + putProperty(prop); + assignPropertyId(prop, id); + } + + /** Registers a property with this helper class and associates the argument id with it. + * It does the same as {@link #registerProperty(Property, Object)}. The first four + * arguments are used to construct a Property object. + * Registration has to occur during + * initialization of the inheriting class (i.e. within the contructor) + * @param name The property's name (Property.Name). + * @param handle The property's handle (Property.Handle). + * @param Type The property's type (Property.Type). + * @param attributes The property's attributes (Property.Attributes). + * @param id Identifies the property's storage. + */ + protected void registerProperty(String name, int handle, Type type, short attributes, Object id) + { + Property p= new Property(name, handle, type, attributes); + registerProperty(p, id); + } + + /** Registers a property with this helper class and associates the argument id with it. + * It does the same as {@link #registerProperty(Property, Object)}. The first three + * arguments are used to construct a Property object. The value for the Property.Handle + * is generated and does not have to be specified here. Use this method for registering + * a property if you do not care about the Property's handles. + * Registration has to occur during + * initialization of the inheriting class (i.e. within the contructor). + * @param name The property's name (Property.Name). + * @param handle The property's handle (Property.Handle). + * @param Type The property's type (Property.Type). + * @param attributes The property's attributes (Property.Attributes). + * @param id Identifies the property's storage. + */ + protected void registerProperty(String name, Type type, short attributes, Object id) + { + Property p= new Property(name, lastHandle++, type, attributes); + registerProperty(p, id); + } + + /** Returns the Property object for a given property name or null if that property does + * not exists (i.e. it has not been registered). Override this method + * if you want to implement your own mapping from property names to Property objects. + * Then you also have to override {@link #initMappings}, {@link #getProperties()} and + * {@link #putProperty(Property)}. + * @param propertyName The name of the property (Property.Name) + * @return The Property object with the name <em>propertyName</em>. + */ + protected Property getProperty(String propertyName) + { + return (Property) _nameToPropertyMap.get(propertyName); + } + + /** Returns the Property object with a handle (Property.Handle) as specified by the argument + * <em>nHandle</em>. The method returns null if there is no such property (i.e. it has not + * been registered). Override this method if you want to implement your own mapping from handles + * to Property objects. Then you also have to override {@link #initMappings}, {@link #putProperty(Property)}. + * @param nHandle The handle of the property (Property.Handle). + * @return The Property object with the handle <em>nHandle</em> + */ + protected Property getPropertyByHandle(int nHandle) + { + return (Property) _handleToPropertyMap.get(new Integer(nHandle)); + } + + /** Returns an array of all Property objects or an array of length null if there + * are no properties. Override this method if you want to implement your own mapping from names + * to Property objects. Then you also have to override {@link #initMappings}, {@link #getProperty(String)} and + * {@link #putProperty}. + * @return Array of all Property objects. + */ + protected Property[] getProperties() + { + if (arProperties == null) + { + Collection values= _nameToPropertyMap.values(); + arProperties= (Property[]) values.toArray(new Property[_nameToPropertyMap.size()]); + } + return arProperties; + } + + /** Stores a Property object so that it can be retrieved subsequently by + * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. + * Override this method if you want to implement your own mapping from handles + * to Property objects and names to Property objects. Then you also need to override {@link #initMappings}, + * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. + * @param prop The Property object that is to be stored. + */ + protected void putProperty(Property prop) + { + _nameToPropertyMap.put(prop.Name, prop); + if (prop.Handle != -1) + _handleToPropertyMap.put(new Integer(prop.Handle), prop); + } + + /** Assigns an identifyer object to a Property object so that the identifyer + * can be obtained by {@link #getPropertyId getPropertyId} later on. The identifyer + * is used to specify a certain storage for the property's value. If you do not + * override {@link #setPropertyValueNoBroadcast() setPropertyValueNoBroadcast} or {@link #getPropertyValue(Property)} + * then the argument <em>id</em> has to be a java.lang.String that equals the name of + * the member variable that holds the Property's value. + * Override this method if you want to implement your own mapping from Property objects to ids or + * if you need ids of a type other then java.lang.String. + * Then you also need to override {@link #initMappings initMappings} and {@link #getPropertyId getPropertyId}. + * @param prop The Property object that is being assigned an id. + * @param id The object which identifies the storage used for the property's value. + * @see #registerProperty(Property, Object) + */ + protected void assignPropertyId(Property prop, Object id) + { + if (id instanceof String && ((String) id).equals("") == false) + _propertyToIdMap.put(prop, id); + } + + /** Returns the identifyer object for a certain Property. The object must have been + * previously assigned to the Property object by {@link #assignPropertyId assignPropertyId}. + * Override this method if you want to implement your own mapping from Property objects to ids. + * Then you also need to override {@link #initMappings initMappings} and {@link #assignPropertyId assignPropertyId}. + * @param prop The property for which the id is to be retrieved. + * @return The id object that identifies the storage used for the property's value. + * @see #registerProperty(Property, Object) + */ + protected Object getPropertyId(Property prop) + { + return _propertyToIdMap.get(prop); + } + + /** Initializes data structures used for mappings of property names to property object, + * property handles to property objects and property objects to id objects. + * Override this method if you want to implement your own mappings. Then you also need to + * override {@link #putProperty putProperty},{@link #getProperty getProperty}, {@link #getPropertyByHandle}, + * {@link #assignPropertyId assignPropertyId} and {@link #getPropertyId getPropertyId}. + */ + protected void initMappings() + { + _nameToPropertyMap= new HashMap(); + _handleToPropertyMap= new HashMap(); + _propertyToIdMap= new HashMap(); + } + + /** Makes sure that listeners which are kept in aBoundLC (XPropertyChangeListener) and aVetoableLC + * (XVetoableChangeListener) receive a disposing call. Also those listeners are relesased. + */ + protected void postDisposing() + { + // Create an event with this as sender + EventObject aEvt= new EventObject(this); + + // inform all listeners to reelease this object + aBoundLC.disposeAndClear(aEvt); + aVetoableLC.disposeAndClear(aEvt); + } + + //XPropertySet ---------------------------------------------------- + synchronized public void addPropertyChangeListener(String str, XPropertyChangeListener xPropertyChangeListener) + throws UnknownPropertyException, WrappedTargetException + { + // only add listeners if you are not disposed + if (! bInDispose && ! bDisposed) + { + if (str.length() > 0) + { + Property prop= getProperty(str); + if (prop == null) + throw new UnknownPropertyException(); + + // Add listener for a certain property + if ((prop.Attributes & PropertyAttribute.BOUND) > 0) + aBoundLC.addInterface(str, xPropertyChangeListener); + else + //ignore silently + return; + } + else + // Add listener for all properties + listenerContainer.addInterface(XPropertyChangeListener.class, xPropertyChangeListener); + } + } + //XPropertySet ---------------------------------------------------- + synchronized public void addVetoableChangeListener(String str, com.sun.star.beans.XVetoableChangeListener xVetoableChangeListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException + { + // only add listeners if you are not disposed + if (! bInDispose && ! bDisposed) + { + if (str.length() > 0) + { + Property prop= getProperty(str); + if (prop == null) + throw new UnknownPropertyException(); + + // Add listener for a certain property + if ((prop.Attributes & PropertyAttribute.CONSTRAINED) > 0) + aVetoableLC.addInterface(str, xVetoableChangeListener); + else + //ignore silently + return; + } + else + // Add listener for all properties + listenerContainer.addInterface(XVetoableChangeListener.class, xVetoableChangeListener); + } + } + //XPropertySet ---------------------------------------------------- + public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() + { + if (propertySetInfo == null) + { + synchronized (this) + { + if (propertySetInfo == null) + propertySetInfo= new PropertySetInfo(); + } + } + return propertySetInfo; + } + //XPropertySet ---------------------------------------------------- + public Object getPropertyValue(String name) throws UnknownPropertyException, WrappedTargetException + { + Object ret= null; + if (bInDispose || bDisposed) + throw new com.sun.star.lang.DisposedException(); + + Property prop= getProperty(name); + if (prop == null) + throw new UnknownPropertyException(); + if ((prop.Attributes & PropertyAttribute.READONLY) == PropertyAttribute.READONLY) + return null; + + synchronized (this) + { + ret= getPropertyValue(prop); + } + return ret; + } + + //XPropertySet ---------------------------------------------------- + synchronized public void removePropertyChangeListener(String str, com.sun.star.beans.XPropertyChangeListener xPropertyChangeListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException + { // all listeners are automaticly released in a dispose call + if (!bInDispose && !bDisposed) + { + if (str.length() > 0) + { + Property prop = getProperty(str); + if (prop == null) + throw new UnknownPropertyException(); + aBoundLC.removeInterface(str, xPropertyChangeListener); + } + else + listenerContainer.removeInterface(XPropertyChangeListener.class, xPropertyChangeListener); + } + } + + //XPropertySet ---------------------------------------------------- + synchronized public void removeVetoableChangeListener(String str, com.sun.star.beans.XVetoableChangeListener xVetoableChangeListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException + {// all listeners are automaticly released in a dispose call + if (!bInDispose && !bDisposed) + { + if (str.length() > 0) + { + Property prop = getProperty(str); + if (prop == null) + throw new UnknownPropertyException(); + aVetoableLC.removeInterface(str, xVetoableChangeListener); + } + else + listenerContainer.removeInterface(XVetoableChangeListener.class, xVetoableChangeListener); + } + } + + //XPropertySet ---------------------------------------------------- + /** Sets the value of a property. + * The idl description for this interfaces, stipulates that the argument value is an Any. Since a java.lang.Object + * reference has the same meaning as an Any this function accepts + * java anys (com.sun.star.uno.Any) and all other appropriate objects as arguments. The value argument can be one + * of these: + * <ul> + * <li>java.lang.Boolean</li> + * <li>java.lang.Character</li> + * <li>java.lang.Byte</li> + * <li>java.lang.Short</li> + * <li>java.lang.Integer</li> + * <li>java.lang.Long</li> + * <li>java.lang.Float</li> + * <li>java.lang.Double</li> + * <li>java.lang.String</li> + * <li>com.sun.star.uno.Type</li> + * <li><em>objects which implement UNO interfaces</em></li> + * <li><em>arrays which contain elements of the types above</em></li> + * <li>com.sun.star.uno.Any containing an instance of one of the above types</li> + * </ul> + * + * Properties can have the attribute com.sun.star.beans.PropertyAttribute.MAYBEVOID, which means that the value + * (not the type) can be void. In order to assign a void value to a property one can either pass an Any which + * contains a null reference or pass null directly. In bothe cases the null reference is only accepted if + * the PropertyAttribute.MAYBEVOID attribute is set for the property. + * + * Properties which have the attribute MAYBEVOID set (Property.Attributes) can have a void value. The following + * considerations presume that the Property has that attribute set. Further, when mentioning an Any's value we + * actually refer to the object returned by Any.getObject. + * If the argument <em>value</em> is null, or it is an Any whose value is null (but with a valid Type) + * then the member variable used for storing the property's value is set to null. + * Therefore those properties can only be stored in objects + * and primitive types are not allowed (one can use the wrapper classes instead,e.g. java.lang.Byte) . + * If a property's value is kept in a member variable of type Any and that reference is still null + * then when setPropertyValue is called with + * <em>value</em> = null then the member variable is assigned an Any with type void and a null value. + * Or if the argument is an Any with a null value then it is assigned to the member variable. + * Further, if the variable already + * references an Any and setPropertyValue is called with <em>value</em> = null, then the variable is assigned + * a new Any with the same type as the previously referenced Any and with a null value. + * @param name The name of the property. + * @param value The new value of the property. + * * */ + public void setPropertyValue(String name, Object value) throws com.sun.star.beans.UnknownPropertyException, + com.sun.star.beans.PropertyVetoException, com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException + { + Property prop= getProperty(name); + setPropertyValue(prop, value); + } + + /** Sets the value of a property. It checks if the property's attributes (READONLY,MAYBEVOID), allow that the + * new value can be set. It also causes the notification of listeners. + * @param prop The property whose value is to be set. + * @param value The new value for the property. + */ + protected void setPropertyValue(Property prop, Object value) throws com.sun.star.beans.UnknownPropertyException, + com.sun.star.beans.PropertyVetoException, com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException + { + if (prop == null) + throw new UnknownPropertyException(); + if ((prop.Attributes & PropertyAttribute.READONLY) == PropertyAttribute.READONLY) + throw new com.sun.star.beans.PropertyVetoException(); + // The value may be null only if MAYBEVOID attribute is set + boolean bVoidValue= false; + if (value instanceof Any) + bVoidValue= ((Any) value).getObject() == null; + else + bVoidValue= value == null; + if (bVoidValue && (prop.Attributes & PropertyAttribute.MAYBEVOID) == 0) + throw new com.sun.star.lang.IllegalArgumentException("The property must have a value; the MAYBEVOID attribute is not set!"); + if (bInDispose || bDisposed) + throw new com.sun.star.lang.DisposedException(); + + //Check if the argument is allowed + boolean bValueOk= false; + if (value instanceof Any) + bValueOk= checkType(((Any) value).getObject()); + else + bValueOk= checkType(value); + if (! bValueOk) + throw new com.sun.star.lang.IllegalArgumentException("No valid UNO type"); + + + boolean bConversionOk= false; + Object[] outConvertedVal= new Object[1]; + Object[] outOldValue= new Object[1]; + synchronized (this) + { + bConversionOk= convertPropertyValue(prop, outConvertedVal, outOldValue, value); + } + + //The next step following the conversion is to set the new value of the property. Prior to this + // the XVetoableChangeListener s have to be notified. + if (bConversionOk) + { + // If the property is CONSTRAINED, then we must notify XVetoableChangeListener. The listener can throw a com.sun.star.lang.beans.PropertyVetoException which + // will cause this method to return (the exception is not caught here). + fire( new Property[]{prop}, outConvertedVal, outOldValue, true); + + synchronized (this) + { + setPropertyValueNoBroadcast(prop, outConvertedVal[0]); + } + // fire a change event (XPropertyChangeListener, PropertyAttribute.BOUND + fire( new Property[]{prop}, outConvertedVal, outOldValue, false); + } + } + + /** Converts a value in a way so that its appropriate for storing as a property value, that is + * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} can process the value without any further + * conversion. This implementation presumes that + * the values are stored in member variables of the furthest inheriting class. For example, + * class A inherits this class then members of class A + * can hold property values. If there is a class B which inherits A then only members of B can hold + * property values. The variables can have + * public, protected or package level access. A property must have been registered (e.g. by + * {@link #registerProperty(Property, Object)} in order for this method to work. The identifyer Object argument + * used in the registerProperty methods must + * be a java.lang.String that is the name of the member variable that holds the property value. + * If one opts to store values differently then one may override + * this method, as well as {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and + * {@link #getPropertyValue(Property) getPropertyValue(Property)}. + * This method is always called as a result of a call to one of the setter methods, such as + * {@link #setPropertyValue(String,Object) XPropertySet.setPropertyValue}, + * {@link #setFastPropertyValue XFastPropertySet.setFastPropertyValue} + * and {@link #setPropertyValues XMultiPropertySet.setPropertyValues}. + * If this method fails, that is, it returns false or throws an exception, then no listeners are notified and the + * property value, that was intended to be changed, remains untouched.<br /> This method does not have to deal with property attributes, such as + * PropertyAttribute.READONLY or PropertyAttribute.MAYBEVOID. The processing of these attributes occurs + * in the calling methods.<br /> + * Only if this method returns successfully further processing, such + * as listener notification and finally the modifiction of the property's value, will occur.<br /> + * + * The actual modification of a property's value is done by {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} + * which is called subsequent to convertPropertyValue. + *<p> + * This method converts values by help of the com.sun.star.uno.AnyConverter which only does a few widening + * conversions on integer types and floating point types. For example, there is the property PropA with a Type equivalent + * to int.class and the + * value of the property is to be stored in a member variable of type int with name intProp. Then setPropertyValue is + * called: + * <pre> + * set.setPropertyValue( "PropA", new Byte( (byte)111)); + * </pre> + * At some point setPropertyValue will call convertPropertyValue and pass in the Byte object. Since we allow + * that Byte values can be used with the property and know that the value is to be stored in intProp (type int) + * we convert the Byte object into an Integer object which is then returned in the out-parameter <em>newVal</em>. This + * conversion is actually performed by the AnyConverter. Later + * the setPropertyValueNoBroadcast is called with that Integer object and the int value can be easily extracted + * from the object and be assigned to the member intProp. + * <p> + * The method handles Any arguments the same as Object arguments. That is, the <em>setVal</em> argument can + * be a java.lang.Boolean or a com.sun.star.uno.Any containing a java.lang.Boolean. Likewise, a member + * containing a property value can be a com.sun.star.uno.Any or an java.lang.Object. + * Then, no conversion is necessary, since they can hold all possible values. However, if + * the member is an Object and <em>setVal</em> is an Any then the object contained in the any is assigned to + * the member. The extra type information which exists as Type object in the Any will get lost. If this is not + * intended then use an Any variable rather then an Object.<br /> + * If a member is an Object or Any and the argument <em>setVal</em> is an Object, other than String or array, + * then it is presumed to be an UNO object and queried for XInterface. If successful, the out-param <em>newVal</em> + * returns the XInterface.<br /> + * If a member is an UNO interface, then <em>setVal</em> is queried for this interface and the result is returned. + * If <em>setVal</em> is null then <em>newVal</em> will be null too after return. + * <p> + * If a property value is stored using a primitive type the the out-parameters + * <em>curVal</em> and <em>newVal</em> contain the respective wrapper class (e.g.java.lang.Byte, etc.). + * curVal is used in calls to the XVetoableChangeListener and XPropertyChangeListener. + * + * @param property - in-param property for which the data is to be converted. + * @param newVal - out-param which contains the converted value on return. + * @param curVal - out-param the current value of the property. It is used in calls to the + * XVetoableChangeListener and XPropertyChangeListener. + * @param setVal - in-param. The value that is to be converted so that it matches Property and the internally used + * dataformat for that property. + * @return true - Conversion was successful. <em>newVal</em> contains a valid value for the property. false - + * conversion failed for some reason. + * @throws com.sun.star.lang.IllegalArgumentException The value provided is unfit for the property. + * @throws com.sun.star.lang.WrappedTargetException - An exception occured during the conversion, that is to be made known + * to the caller. + */ + protected boolean convertPropertyValue(Property property, Object[] newVal, Object[]curVal, Object setVal) + throws com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + boolean ret= true; + try + { + // get the member name + String sMember= (String) getPropertyId(property); + if (sMember != null) + { + // use reflection to obtain the field that holds the property value + // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to + // also get inherited fields, but only those which are public. + Field propField= getClass().getDeclaredField(sMember); + if (propField != null) + { + curVal[0]= propField.get(this); + Class memberClass= propField.getType(); + + // MAYBEVOID: if setVal == null or it is an Any and getObject returns null, then a void value is to be set + // This works only if there are no primitive types. For those we use the respective wrapper classes. + // In this implementation, a null reference means void value. + boolean bVoidValue= false; + boolean bAnyVal= setVal instanceof Any; + if (bAnyVal) + bVoidValue= ((Any) setVal).getObject() == null; + else + bVoidValue= setVal == null; + if (bVoidValue && memberClass.isPrimitive()) + throw new com.sun.star.lang.IllegalArgumentException("The implementation does not support the MAYBEVOID attribute for this property"); + + Object convObj= null; + //The member that keeps the value of the Property is an Any. It can contain all possible + //types, therefore a conversion is not necessary. + if (memberClass.equals(Any.class)) + { + if (bAnyVal) + //parameter setVal is also an Any and can be used without further processing + convObj= setVal; + else + { + // Parameter setVal is not an Any. We need to construct an Any that contains + // the argument setVal. + // If setVal is an interface implementation then, we cannot constuct the + // Any with setVal.getClass(), because the Any.Type._typeClass would be TypeClass.UNKNOWN. + // We try to get an XInterface of setVal and set an XInterface type. + if (setVal instanceof XInterface) + { + XInterface xint= (XInterface) UnoRuntime.queryInterface(XInterface.class, setVal); + if (xint != null) + convObj= new Any(new Type(XInterface.class), xint); + } + // The member is an any, and the past in argument was null reference (MAYBEVOID is set) + else if (setVal == null) + { + // if the any member is still null we create a void any + if (curVal[0] == null) + convObj= new Any(new Type(), null); + else + { + //otherwise we create an Any with the same type as a value of null; + convObj= new Any( ((Any)curVal[0]).getType(), null); + } + } + else + convObj= new Any(new Type(setVal.getClass()), setVal); + } + } + else + convObj= convert(memberClass, setVal); + newVal[0]= convObj; + } + } + } + catch (java.lang.NoSuchFieldException e) + { + throw new com.sun.star.lang.WrappedTargetException("Field does not exist", this, e); + } + catch (java.lang.IllegalAccessException e) + { + throw new com.sun.star.lang.WrappedTargetException("", this ,e); + } + return ret; + } + + private boolean checkType(Object obj) + { + if (obj == null + || obj instanceof Boolean + || obj instanceof Character + || obj instanceof Number + || obj instanceof String + || obj instanceof XInterface + || obj instanceof Type + || obj.getClass().isArray()) + return true; + return false; + } + + // Param object can be an Any or other object. If obj is null then the return value is null + private Object convert( Class cl, Object obj) throws com.sun.star.lang.IllegalArgumentException + { + Object retVal= null; + //The member that keeps the value of the Property is an Object.Objects are similar to Anys in that they can + // hold all types. + if (obj == null || (obj instanceof Any && ((Any) obj).getObject() == null)) + retVal= null; + else if(cl.equals(Object.class)) + { + if (obj instanceof Any) + obj= ((Any) obj).getObject(); + retVal= obj; + } + else if(cl.equals(boolean.class)) + retVal= new Boolean(AnyConverter.toBoolean(obj)); + else if (cl.equals(char.class)) + retVal= new Character(AnyConverter.toChar(obj)); + else if (cl.equals(byte.class)) + retVal= new Byte(AnyConverter.toByte(obj)); + else if (cl.equals(short.class)) + retVal= new Short(AnyConverter.toShort(obj)); + else if (cl.equals(int.class)) + retVal= new Integer(AnyConverter.toInt(obj)); + else if (cl.equals(long.class)) + retVal= new Long(AnyConverter.toLong(obj)); + else if (cl.equals(float.class)) + retVal= new Float(AnyConverter.toFloat(obj)); + else if (cl.equals(double.class)) + retVal= new Double(AnyConverter.toDouble(obj)); + else if (cl.equals(String.class)) + retVal= AnyConverter.toString(obj); + else if (cl.isArray()) + retVal= AnyConverter.toArray(obj); + else if (cl.equals(Type.class)) + retVal= AnyConverter.toType(obj); + else if (cl.equals(Boolean.class)) + retVal= new Boolean(AnyConverter.toBoolean(obj)); + else if (cl.equals(Character.class)) + retVal= new Character(AnyConverter.toChar(obj)); + else if (cl.equals(Byte.class)) + retVal= new Byte(AnyConverter.toByte(obj)); + else if (cl.equals(Short.class)) + retVal= new Short(AnyConverter.toShort(obj)); + else if (cl.equals(Integer.class)) + retVal= new Integer(AnyConverter.toInt(obj)); + else if (cl.equals(Long.class)) + retVal= new Long(AnyConverter.toLong(obj)); + else if (cl.equals(Float.class)) + retVal= new Float(AnyConverter.toFloat(obj)); + else if (cl.equals(Double.class)) + retVal= new Double(AnyConverter.toDouble(obj)); + else if (XInterface.class.isAssignableFrom(cl)) + retVal= AnyConverter.toObject(new Type(cl), obj); + else + throw new com.sun.star.lang.IllegalArgumentException(); + return retVal; + } + + /** Sets the value of a property. In this implementation property values are stored in member variables + * (see {@link #convertPropertyValue convertPropertyValue} Notification of property listeners + * does not occur in this method. By overriding this method one can take full control about how property values + * are stored. But then, the {@link #convertPropertyValue convertPropertyValue} and + * {@link getPropertyValue(Property)} must be overridden too. + * + * A Property with the MAYBEVOID attribute set, is stored as null value. Therefore the member variable must be + * an Object in order to make use of the property attribute. An exception is Any. The Any variable can be initially null, but + * once it is set the reference will not become null again. If the value is to be set to + * void then a new Any will be stored + * with a valid type but without a value (i.e. Any.getObject returns null). + * If a property has the READONLY attribute set, and one of the setter methods, such as setPropertyValue, has been + * called, then this method is not going to be called. + * @param property the property for which the new value is set + * @param value the new value for the property. + * @throws com.sun.star.lang.WrappedTargetException An exception, which has to be made known to the caller, + * occured during the setting of the value. + */ + protected void setPropertyValueNoBroadcast(Property property, Object newVal) + throws com.sun.star.lang.WrappedTargetException + { + try + { + // get the member name + String sMember= (String) getPropertyId(property); + if (sMember != null) + { + // use reflection to obtain the field that holds the property value + // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to + // also get inherited fields, but only those which are public. + Field propField= getClass().getDeclaredField(sMember); + if (propField != null) + propField.set(this, newVal); + } + } + catch(java.lang.Exception e) + { + throw new com.sun.star.lang.WrappedTargetException("PropertySet.setPropertyValue_NoBroadcast", this, e); + } + } + /** Retrieves the value of a property. This implementation presumes that the values are stored in member variables + * of the furthest inheriting class (see {@link #convertPropertyValue convertPropertyValue}) and that the + * variables have public, protected or package level access. The property must have + * been registered, for example by {@link #registerProperty(Property, Object)}. The identifyer Object argument + * must have been a java.lang.String which was the name of the member variable holding the property value. + * When properties are to be stored differently one has to override this method as well as + * {@link #convertPropertyValue} and {@link #setPropertyValueNoBroadcast}. <br> + * If a value is stored in a variable of a primitive type then this method returns an instance of the respective + * wrapper class (e.g. java.lang.Boolean). + * @param property The property for which the value is to be retrieved. + * @return The value of the property. + */ + protected Object getPropertyValue(Property property) + throws com.sun.star.lang.WrappedTargetException + { + Object ret= null; + try + { + // get the member name + String sMember= (String) getPropertyId(property); + if (sMember != null) + { + // use reflection to obtain the field that holds the property value + // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to + // also get inherited fields, but only those which are public. + Field propField= getClass().getDeclaredField(sMember); + if (propField != null) + ret= propField.get(this); + } + } + catch(java.lang.Exception e) + { + throw new WrappedTargetException("PropertySet.setPropertyValue_NoBroadcast", this, e); + } + return ret; + } + + /** + * This method fires events to XPropertyChangeListener,XVetoableChangeListener and + * XPropertiesChangeListener event sinks. + * To distinguish what listeners are to be called the argument <em>bVetoable</em> is to be set to true if + * a XVetoableChangeListener is meant. For XPropertyChangeListener and XPropertiesChangeListener + * it is to be set to false. + * + * @param properties Properties wich will be or have been affected. + * @param newValues the new values of the properties. + * @param oldValues the old values of the properties. + * @param bVetoable true means fire to VetoableChangeListener, false means fire to + * XPropertyChangedListener and XMultiPropertyChangedListener. + */ + protected void fire( + Property[] properties, + Object[] newValues, + Object[] oldValues, + boolean bVetoable ) throws PropertyVetoException + { + // Only fire, if one or more properties changed + int nNumProps= properties.length; + if (nNumProps > 0) + { + PropertyChangeEvent[] arEvts= new PropertyChangeEvent[nNumProps]; + int nAffectedProps= 0; + // Loop over all changed properties to fill the event struct + for (int i= 0; i < nNumProps; i++) + { + if ((bVetoable && (properties[i].Attributes & PropertyAttribute.CONSTRAINED) > 0) + || (!bVetoable && (properties[i].Attributes & PropertyAttribute.BOUND) > 0)) + { + arEvts[i]= new PropertyChangeEvent(this, properties[i].Name, false, + properties[i].Handle, oldValues[i], newValues[i]); + nAffectedProps++; + } + } + // fire the events for all changed properties + for (int i= 0; i < nAffectedProps; i++) + { + // get the listener container for the property name + InterfaceContainer lc= null; + if (bVetoable) + lc= aVetoableLC.getContainer(arEvts[i].PropertyName); + else + lc= aBoundLC.getContainer(arEvts[i].PropertyName); + if (lc != null) + { + Iterator it= lc.iterator(); + while( it.hasNext()) + { + Object listener= it.next(); + if (bVetoable) + ((XVetoableChangeListener) listener).vetoableChange(arEvts[i]); + else + ((XPropertyChangeListener) listener).propertyChange(arEvts[i]); + } + } + // broadcast to all listeners with "" property name + if(bVetoable) + lc= listenerContainer.getContainer(XVetoableChangeListener.class); + else + lc= listenerContainer.getContainer(XPropertyChangeListener.class); + if(lc != null) + { + Iterator it= lc.iterator(); + while(it.hasNext() ) + { + Object listener= it.next(); + if( bVetoable ) // fire change Events? + ((XVetoableChangeListener) listener).vetoableChange(arEvts[i]); + else + ((XPropertyChangeListener) listener).propertyChange(arEvts[i]); + } + } + } + // fire at XPropertiesChangeListeners + // if nAffectedProps == 0 then there are no BOUND properties + if (!bVetoable && nAffectedProps > 0) + { + + PropertyChangeEvent[] arReduced= new PropertyChangeEvent[nAffectedProps]; + System.arraycopy(arEvts, 0, arReduced, 0, nAffectedProps); + InterfaceContainer lc= listenerContainer.getContainer(XPropertiesChangeListener.class); + if (lc != null) + { + // !!! Here is a Bug, unbound properties are also fired + Iterator it= lc.iterator(); + while (it.hasNext()) + { + XPropertiesChangeListener listener = (XPropertiesChangeListener) it.next(); + // fire the hole event sequence to the XPropertiesChangeListener's + listener.propertiesChange( arEvts ); + } + } + } + } + } + // XFastPropertySet-------------------------------------------------------------------------------- + public void setFastPropertyValue(int nHandle, Object aValue ) throws UnknownPropertyException, + PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + Property prop= getPropertyByHandle(nHandle); + setPropertyValue(prop, aValue); + } + + // XFastPropertySet -------------------------------------------------------------------------------- + public Object getFastPropertyValue(int nHandle ) throws UnknownPropertyException, + WrappedTargetException + { + Property prop= getPropertyByHandle(nHandle); + return getPropertyValue(prop); + } + + // XMultiPropertySet ----------------------------------------------------------------------------------- + public void addPropertiesChangeListener(String[] propNames, XPropertiesChangeListener xPropertiesChangeListener) + { + listenerContainer.addInterface(XPropertiesChangeListener.class, xPropertiesChangeListener); + } + + // XMultiPropertySet ----------------------------------------------------------------------------------- + public void firePropertiesChangeEvent(String[] propNames, XPropertiesChangeListener listener) + { + // Build the events. + PropertyChangeEvent[] arEvents= new PropertyChangeEvent[propNames.length]; + int eventCount= 0; + // get a snapshot of the current property values + synchronized (this) + { + for (int i= 0; i < propNames.length; i++) + { + Property prop= getProperty(propNames[i]); + if (prop != null) + { + Object value= null; + try + { + value= getPropertyValue(prop); + } + catch(WrappedTargetException e) + { + continue; + } + arEvents[eventCount]= new PropertyChangeEvent(this, prop.Name, + false, prop.Handle, value, value); + eventCount++; + } + } + } + + // fire events from unsynchronized section so as to prevent deadlocks + if (eventCount > 0) + { + // Reallocate the array of the events if necessary + if (arEvents.length != eventCount) + { + PropertyChangeEvent[] arPropsTmp= new PropertyChangeEvent[eventCount]; + System.arraycopy(arEvents, 0, arPropsTmp, 0, eventCount); + arEvents= arPropsTmp; + } + listener.propertiesChange(arEvents); + } + } + // XMultiPropertySet ----------------------------------------------------------------------------------- + /** If a value for a property could not be retrieved then the respective element in the returned + * array has the value null. + */ + public Object[] getPropertyValues(String[] propNames) + { + Object[] arValues= new Object[propNames.length]; + synchronized (this) + { + for (int i= 0; i < propNames.length; i++) + { + Object value= null; + try + { + value= getPropertyValue(propNames[i]); + } + catch (Exception e) + { + } + arValues[i]= value; + } + } + return arValues; + } + // XMultiPropertySet ----------------------------------------------------------------------------------- + public void removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener) + { + listenerContainer.removeInterface(XPropertiesChangeListener.class, xPropertiesChangeListener); + } + // XMultiPropertySet ----------------------------------------------------------------------------------- + /** If the array of property names containes an unknown property then it will be ignored. + */ + public void setPropertyValues(String[] propNames, Object[] values) throws PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException + { + for (int i= 0; i < propNames.length; i++) + { + try + { + setPropertyValue(propNames[i], values[i]); + } + catch (UnknownPropertyException e) + { + continue; + } + + } + } + + private class PropertySetInfo implements XPropertySetInfo + { + public com.sun.star.beans.Property[] getProperties() + { + return PropertySet.this.getProperties(); + } + + public com.sun.star.beans.Property getPropertyByName(String name) throws UnknownPropertyException + { + return getProperty(name); + } + + public boolean hasPropertyByName(String name) + { + return getProperty(name) != null; + } + + } +} + + + + + diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java new file mode 100644 index 000000000..11374891a --- /dev/null +++ b/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java @@ -0,0 +1,1607 @@ +/************************************************************************* + * + * $RCSfile: PropertySet_Test.java,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jl $ $Date: 2002-04-25 11:36:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.uno.helper; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.DisposedException; +import com.sun.star.uno.Type; +import com.sun.star.uno.XInterface; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.Any; +import com.sun.star.uno.XWeak; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XPropertiesChangeListener; + +import java.util.Arrays; + +public class PropertySet_Test +{ + + /** Creates a new instance of PropertySet_Test */ + public PropertySet_Test() + { + } + + public boolean convertPropertyValue() + { + System.out.println("PropertySet.convertPropertyValue"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + r[i++]= cl.test_convertPropertyValue(); + }catch(java.lang.Exception e){ + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean setPropertyValueNoBroadcast() + { + System.out.println("PropertySet.setValueNoBroadcast"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + r[i++]= cl.test_setPropertyValueNoBroadcast(); + }catch(java.lang.Exception e){ + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean setPropertyValue() + { + System.out.println("PropertySet.setPropertyValue"); + boolean[] r= new boolean[150]; + int i= 0; + + TestClass cl= new TestClass(); + try { + cl.resetPropertyMembers(); + Object value; + Object ret; + value= new Boolean(true); + cl.setPropertyValue("PropBoolA", value); + ret= cl.getPropertyValue("PropBoolA"); + r[i++]= ((Boolean) ret).equals( (Boolean) value); + value= new Character('A'); + cl.setPropertyValue("PropCharA",value); + ret= cl.getPropertyValue("PropCharA"); + r[i++]= ((Character) ret).equals((Character) value); + value= new Byte((byte) 111); + cl.setPropertyValue("PropByteA",value); + ret= cl.getPropertyValue("PropByteA"); + r[i++]= ((Byte) ret).equals((Byte) value); + value= new Short((short)112); + cl.setPropertyValue("PropShortA", value); + ret= cl.getPropertyValue("PropShortA"); + r[i++]= ((Short) ret).equals((Short) value); + value= new Integer(113); + cl.setPropertyValue("PropIntA", value); + ret= cl.getPropertyValue("PropIntA"); + r[i++]= ((Integer) ret).equals((Integer) value); + value= new Long(115); + cl.setPropertyValue("PropLongA", value); + ret= cl.getPropertyValue("PropLongA"); + r[i++]= ((Long) ret).equals((Long) value); + value= new Float(3.14); + cl.setPropertyValue("PropFloatA", value); + ret= cl.getPropertyValue("PropFloatA"); + r[i++]= ((Float) ret).equals((Float) value); + value= new Double(3.145); + cl.setPropertyValue("PropDoubleA",value); + ret= cl.getPropertyValue("PropDoubleA"); + r[i++]= ((Double) ret).equals((Double) value); + value= new String("string"); + cl.setPropertyValue("PropStringA",value); + ret= cl.getPropertyValue("PropStringA"); + r[i++]= ((String) ret).equals((String) value); + value= new ComponentBase(); + cl.setPropertyValue("PropXInterfaceA",value); + ret= cl.getPropertyValue("PropXInterfaceA"); + r[i++]= ((XInterface) ret).equals((XInterface) value); + value= new ComponentBase(); + cl.setPropertyValue("PropXWeakA",value); + ret= cl.getPropertyValue("PropXWeakA"); + r[i++]= ((XWeak) ret).equals((XWeak) value); + value= new byte[]{1,2,3}; + cl.setPropertyValue("PropArrayByteA", value); + ret= cl.getPropertyValue("PropArrayByteA"); + r[i++]= ((byte[]) ret).equals((byte[]) value); + value= new Type(String.class); + cl.setPropertyValue("PropTypeA", value); + ret= cl.getPropertyValue("PropTypeA"); + r[i++]= ((Type) ret).equals(value); + + // test protected,package,private members + value= new Boolean(true); + cl.setPropertyValue("PropBoolB", value); + ret= cl.getPropertyValue("PropBoolB"); + r[i++]= ((Boolean) ret).equals((Boolean) value); + cl.setPropertyValue("PropBoolC", value); + ret= cl.getPropertyValue("PropBoolC"); + r[i++]= ((Boolean) ret).equals((Boolean) value); + + try{ + cl.setPropertyValue("PropBoolD", value); + i++; + }catch (Exception e) + { + r[i++]= true; + } + cl.resetPropertyMembers(); + + value= new Boolean(true); + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Boolean) ret).equals((Boolean) value); + value= new Character('A'); + cl.setPropertyValue("PropObjectA",value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Character) ret).equals((Character) value); + value= new Byte((byte) 111); + cl.setPropertyValue("PropObjectA",value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Byte) ret).equals((Byte) value); + value= new Short((short)112); + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Short) ret).equals((Short) value); + value= new Integer(113); + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Integer) ret).equals((Integer) value); + value= new Long(115); + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Long) ret).equals((Long) value); + value= new Float(3.14); + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Float) ret).equals((Float) value); + value= new Double(3.145); + cl.setPropertyValue("PropObjectA",value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Double) ret).equals((Double) value); + value= new String("string"); + cl.setPropertyValue("PropObjectA",value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((String) ret).equals((String) value); + value= new ComponentBase(); + cl.setPropertyValue("PropObjectA",value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((XInterface) ret).equals((XInterface) value); + value= new ComponentBase(); + cl.setPropertyValue("PropObjectA",value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((XWeak) ret).equals((XWeak) value); + value= new byte[]{1,2,3}; + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((byte[]) ret).equals((byte[]) value); + value= new Type(String.class); + cl.setPropertyValue("PropObjectA", value); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Type) ret).equals(value); + cl.setPropertyValue("PropObjectA", new Any( new Type(byte.class), new Byte((byte)1))); + ret= cl.getPropertyValue("PropObjectA"); + r[i++]= ((Byte) ret).byteValue() == 1; + + cl.resetPropertyMembers(); + value= new Boolean(true); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Character('A'); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Byte((byte) 111); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Short((short)112); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Integer(113); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Long(115); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Float(3.14); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Double(3.145); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new String("string"); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new ComponentBase(); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new ComponentBase(); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new byte[]{1,2,3}; + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Type(String.class); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + + cl.resetPropertyMembers(); + value= new Any(new Type(boolean.class), new Boolean(true)); + cl.setPropertyValue("PropBoolA", value); + ret= cl.getPropertyValue("PropBoolA"); + r[i++]= ret instanceof Boolean && util.anyEquals(value, ret); + value= new Any (new Type(char.class), new Character('A')); + cl.setPropertyValue("PropCharA",value); + ret= cl.getPropertyValue("PropCharA"); + r[i++]= ret instanceof Character && util.anyEquals(value, ret); + value= new Any(new Type(byte.class), new Byte((byte) 111)); + cl.setPropertyValue("PropByteA",value); + ret= cl.getPropertyValue("PropByteA"); + r[i++]= ret instanceof Byte && util.anyEquals(value, ret); + value= new Any(new Type(short.class), new Short((short)112)); + cl.setPropertyValue("PropShortA", value); + ret= cl.getPropertyValue("PropShortA"); + r[i++]= ret instanceof Short && util.anyEquals(value, ret); + value= new Any(new Type(int.class), new Integer(113)); + cl.setPropertyValue("PropIntA", value); + ret= cl.getPropertyValue("PropIntA"); + r[i++]= ret instanceof Integer && util.anyEquals(value, ret); + value= new Any(new Type(long.class), new Long(115)); + cl.setPropertyValue("PropLongA", value); + ret= cl.getPropertyValue("PropLongA"); + r[i++]= ret instanceof Long && util.anyEquals(value, ret); + value= new Any(new Type(float.class), new Float(3.14)); + cl.setPropertyValue("PropFloatA", value); + ret= cl.getPropertyValue("PropFloatA"); + r[i++]= ret instanceof Float && util.anyEquals(value, ret); + value= new Any(new Type(double.class),new Double(3.145)); + cl.setPropertyValue("PropDoubleA",value); + ret= cl.getPropertyValue("PropDoubleA"); + r[i++]= ret instanceof Double && util.anyEquals(value, ret); + value= new Any(new Type(String.class), new String("string")); + cl.setPropertyValue("PropStringA",value); + ret= cl.getPropertyValue("PropStringA"); + r[i++]= ret instanceof String && util.anyEquals(value, ret); + value= new Any(new Type(ComponentBase.class), new ComponentBase()); + cl.setPropertyValue("PropXInterfaceA",value); + ret= cl.getPropertyValue("PropXInterfaceA"); + r[i++]= ret instanceof ComponentBase && util.anyEquals(value, ret); + value= new Any( new Type(ComponentBase.class), new ComponentBase()); + cl.setPropertyValue("PropXWeakA",value); + ret= cl.getPropertyValue("PropXWeakA"); + r[i++]= ret instanceof ComponentBase && util.anyEquals(value, ret); + value= new Any(new Type(byte[].class), new byte[]{1,2,3}); + cl.setPropertyValue("PropArrayByteA", value); + ret= cl.getPropertyValue("PropArrayByteA"); + r[i++]= ret instanceof byte[] && util.anyEquals(value, ret); + value= new Any(new Type(Type.class), new Type(String.class)); + cl.setPropertyValue("PropTypeA", value); + ret= cl.getPropertyValue("PropTypeA"); + r[i++]= ret instanceof Type && util.anyEquals(value, ret); + + + cl.resetPropertyMembers(); + value= new Any(new Type(boolean.class), new Boolean(true)); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any (new Type(char.class), new Character('A')); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(byte.class), new Byte((byte) 111)); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(short.class), new Short((short)112)); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(int.class), new Integer(113)); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(long.class), new Long(115)); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(float.class), new Float(3.14)); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(double.class),new Double(3.145)); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(String.class), new String("string")); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(ComponentBase.class), new ComponentBase()); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any( new Type(ComponentBase.class), new ComponentBase()); + cl.setPropertyValue("PropAnyA",value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(byte[].class), new byte[]{1,2,3}); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + value= new Any(new Type(Type.class), new Type(String.class)); + cl.setPropertyValue("PropAnyA", value); + ret= cl.getPropertyValue("PropAnyA"); + r[i++]= ret instanceof Any && util.anyEquals(value, ret); + + + // ------------------------------------------------------------------------------ + cl.resetPropertyMembers(); + value= new Boolean(true); + cl.setPropertyValue("PropBoolClass", value); + ret= cl.getPropertyValue("PropBoolClass"); + r[i++]= ((Boolean) ret).equals( (Boolean) value); + value= new Character('A'); + cl.setPropertyValue("PropCharClass",value); + ret= cl.getPropertyValue("PropCharClass"); + r[i++]= ((Character) ret).equals((Character) value); + value= new Byte((byte) 111); + cl.setPropertyValue("PropByteClass",value); + ret= cl.getPropertyValue("PropByteClass"); + r[i++]= ((Byte) ret).equals((Byte) value); + value= new Short((short)112); + cl.setPropertyValue("PropShortClass", value); + ret= cl.getPropertyValue("PropShortClass"); + r[i++]= ((Short) ret).equals((Short) value); + value= new Integer(113); + cl.setPropertyValue("PropIntClass", value); + ret= cl.getPropertyValue("PropIntClass"); + r[i++]= ((Integer) ret).equals((Integer) value); + value= new Long(115); + cl.setPropertyValue("PropLongClass", value); + ret= cl.getPropertyValue("PropLongClass"); + r[i++]= ((Long) ret).equals((Long) value); + value= new Float(3.14); + cl.setPropertyValue("PropFloatClass", value); + ret= cl.getPropertyValue("PropFloatClass"); + r[i++]= ((Float) ret).equals((Float) value); + value= new Double(3.145); + cl.setPropertyValue("PropDoubleClass",value); + ret= cl.getPropertyValue("PropDoubleClass"); + r[i++]= ((Double) ret).equals((Double) value); + + cl.resetPropertyMembers(); + + cl.resetPropertyMembers(); + value= new Any(new Type(boolean.class), new Boolean(true)); + cl.setPropertyValue("PropBoolClass", value); + ret= cl.getPropertyValue("PropBoolClass"); + r[i++]= ret instanceof Boolean && util.anyEquals(value, ret); + value= new Any (new Type(char.class), new Character('A')); + cl.setPropertyValue("PropCharClass",value); + ret= cl.getPropertyValue("PropCharClass"); + r[i++]= ret instanceof Character && util.anyEquals(value, ret); + value= new Any(new Type(byte.class), new Byte((byte) 111)); + cl.setPropertyValue("PropByteClass",value); + ret= cl.getPropertyValue("PropByteClass"); + r[i++]= ret instanceof Byte && util.anyEquals(value, ret); + value= new Any(new Type(short.class), new Short((short)112)); + cl.setPropertyValue("PropShortClass", value); + ret= cl.getPropertyValue("PropShortClass"); + r[i++]= ret instanceof Short && util.anyEquals(value, ret); + value= new Any(new Type(int.class), new Integer(113)); + cl.setPropertyValue("PropIntClass", value); + ret= cl.getPropertyValue("PropIntClass"); + r[i++]= ret instanceof Integer && util.anyEquals(value, ret); + value= new Any(new Type(long.class), new Long(115)); + cl.setPropertyValue("PropLongClass", value); + ret= cl.getPropertyValue("PropLongClass"); + r[i++]= ret instanceof Long && util.anyEquals(value, ret); + value= new Any(new Type(float.class), new Float(3.14)); + cl.setPropertyValue("PropFloatClass", value); + ret= cl.getPropertyValue("PropFloatClass"); + r[i++]= ret instanceof Float && util.anyEquals(value, ret); + value= new Any(new Type(double.class),new Double(3.145)); + cl.setPropertyValue("PropDoubleClass",value); + ret= cl.getPropertyValue("PropDoubleClass"); + r[i++]= ret instanceof Double && util.anyEquals(value, ret); + value= new Any(new Type(String.class), new String("string")); + + + + // PropertyAttribute.READONLY + cl.propBoolA.Attributes= PropertyAttribute.READONLY; + try{ + cl.setPropertyValue("PropBoolA", new Boolean(true)); + i++; + }catch (com.sun.star.beans.PropertyVetoException e) + { + r[i++]= true; + } + cl.propBoolA.Attributes= 0; + + // MAYBEVOID + cl.resetPropertyMembers(); + // first MAYBEVOID not set + + //primitive members: must not work + + cl.boolPropA= false; + try { + cl.setPropertyValue("PropBoolA", null); i++; + } catch (com.sun.star.lang.IllegalArgumentException e) { + r[i++]= true; + } + try { + cl.setPropertyValue("PropBoolA", new Any(new Type(boolean.class), null)); i++; + } catch (com.sun.star.lang.IllegalArgumentException e) { + r[i++]= true; + } + cl.propBoolA.Attributes= PropertyAttribute.MAYBEVOID; + try{ + cl.setPropertyValue("PropBoolA", null); i++; + } catch (com.sun.star.lang.IllegalArgumentException e) { + r[i++]= true; + } + cl.propBoolA.Attributes= 0; + + cl.propBoolClass.Attributes= PropertyAttribute.MAYBEVOID; + cl.boolClassProp= null; + cl.setPropertyValue("PropBoolClass", null); + r[i++]= cl.boolClassProp == null; + cl.boolClassProp= new Boolean(true); + cl.setPropertyValue("PropBoolClass", null); + r[i++]= cl.boolClassProp == null; + cl.boolClassProp= new Boolean(false); + cl.setPropertyValue("PropBoolClass", new Any(new Type(boolean.class),null)); + r[i++]= cl.boolClassProp == null; + + cl.anyPropA= null; + try{ + cl.setPropertyValue("PropAnyA", null); i++; + }catch (com.sun.star.lang.IllegalArgumentException e) { + r[i++]= true; + } + cl.anyPropA= null; + cl.propAnyA.Attributes= PropertyAttribute.MAYBEVOID; + + Type _t= new Type(Object.class); + cl.setPropertyValue("PropAnyA", null); + r[i++]= cl.anyPropA.getType().equals(new Type(void.class)) && + cl.anyPropA.getObject() == null; + + cl.anyPropA= new Any(new Type(byte.class),new Byte((byte) 111)); + cl.setPropertyValue("PropAnyA", null); + r[i++]= cl.anyPropA.getType().equals(new Type(byte.class)) && + cl.anyPropA.getObject() == null; + + cl.anyPropA= null; + try{ + cl.setPropertyValue("PropAnyA", new Object()); i++; + }catch (com.sun.star.lang.IllegalArgumentException e) + { + r[i++]= true; + } + + cl.propObjectA.Attributes= 0; + try{ + cl.setPropertyValue("PropObjectA", null); i++; + }catch (com.sun.star.lang.IllegalArgumentException e) + { + r[i++]= true; + } + try{ + cl.setPropertyValue("PropObjectA", new Any( new Type(byte.class), null)); i++; + } catch (com.sun.star.lang.IllegalArgumentException e) + { + r[i++]= true; + } + + cl.propObjectA.Attributes= PropertyAttribute.MAYBEVOID; + cl.propObjectA= null; + cl.setPropertyValue("PropObjectA", null); + r[i++]= cl.propObjectA == null; + + cl.propObjectA= null; + cl.setPropertyValue("PropObjectA", new Any( new Type(byte.class), null)); + r[i++]= cl.propObjectA == null; + + + // + + }catch(java.lang.Exception e){ + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean addPropertyChangeListener() + { + System.out.println("PropertySet.addPropertyChangeListener,\n" + + "PropertySet.removePropertChangeListener," + + "PropertySet.addVetoableChangeListener, \n" + + "PropertySet.removeVetoableChangeListener" + + "Notification of listeners"); + boolean[] r= new boolean[50]; + int i= 0; + try { + TestClass cl= new TestClass(); + Listener li= new Listener(); + cl.addPropertyChangeListener("PropByteA", li); + Byte val1= new Byte((byte)115); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0; + cl.propByteA.Attributes = PropertyAttribute.BOUND; + cl.addPropertyChangeListener("PropByteA", li); + Byte val2= new Byte((byte)116); + cl.setPropertyValue("PropByteA", val2); + r[i++]= li.nChangeCalled == 1 && li.nVetoCalled == 0; + r[i++]= li.evt.OldValue.equals(val1) && li.evt.NewValue.equals(val2) && li.evt.Source == cl; + + li.reset(); + Listener li2= new Listener(); + cl.addPropertyChangeListener("PropByteA", li2); + Byte val3= new Byte((byte) 117); + cl.setPropertyValue("PropByteA", val3); + r[i++]= li.nChangeCalled == 1 && li.nVetoCalled == 0 + && li2.nChangeCalled == 1 && li2.nVetoCalled == 0; + r[i++]= li.evt.OldValue.equals(val2) && li.evt.NewValue.equals(val3) && li.evt.Source == cl + && li2.evt.OldValue.equals(val2) && li2.evt.NewValue.equals(val3) && li2.evt.Source == cl ; + + li.reset(); + li2.reset(); + Listener li3= new Listener(); + val1= new Byte((byte)118); + cl.addPropertyChangeListener("", li3); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 1 && li.nVetoCalled == 0 + && li2.nChangeCalled == 1 && li2.nVetoCalled == 0 + && li3.nChangeCalled == 1 && li3.nVetoCalled == 0; + r[i++]= li.evt.OldValue.equals(val3) && li.evt.NewValue.equals(val1) && li.evt.Source == cl; + r[i++]= li2.evt.OldValue.equals(val3) && li2.evt.NewValue.equals(val1) && li2.evt.Source == cl; + r[i++]= li3.evt.OldValue.equals(val3) && li3.evt.NewValue.equals(val1) && li3.evt.Source == cl ; + + li.reset(); + li2.reset(); + li3.reset(); + cl.removePropertyChangeListener("PropByteA",li); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0 + && li2.nChangeCalled == 1 && li2.nVetoCalled == 0 + && li3.nChangeCalled == 1 && li3.nVetoCalled == 0; + cl.removePropertyChangeListener("PropByteA", li2); + li.reset(); + li2.reset(); + li3.reset(); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 0 + && li3.nChangeCalled == 1 && li3.nVetoCalled == 0; + + cl.removePropertyChangeListener("", li3); + li.reset(); + li2.reset(); + li3.reset(); + cl.setPropertyValue("PropByteA", val2); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 0 + && li3.nChangeCalled == 0 && li3.nVetoCalled == 0; + + cl.addPropertyChangeListener("PropByteA", li); + cl.addPropertyChangeListener("PropByteA", li2); + cl.addPropertyChangeListener("", li3); + cl.dispose(); + li.reset(); + li2.reset(); + li3.reset(); + try { + cl.setPropertyValue("PropByteA", val2); i++; + }catch (DisposedException e) + { + r[i++]= true; + } + + //Vetoable tests + cl= new TestClass(); + li.reset(); + li2.reset(); + li3.reset(); + cl.addVetoableChangeListener("PropByteA", li); + val1= new Byte((byte)115); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0; + cl.propByteA.Attributes = PropertyAttribute.CONSTRAINED; + cl.addVetoableChangeListener("PropByteA", li); + val2= new Byte((byte)116); + li.reset(); + cl.setPropertyValue("PropByteA", val2); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 1; + r[i++]= li.evt.OldValue.equals(val1) && li.evt.NewValue.equals(val2) && li.evt.Source == cl; + + li.reset(); + li2.reset(); + li3.reset(); + cl.addVetoableChangeListener("PropByteA", li2); + val3= new Byte((byte) 117); + cl.setPropertyValue("PropByteA", val3); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 1 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 1; + r[i++]= li.evt.OldValue.equals(val2) && li.evt.NewValue.equals(val3) && li.evt.Source == cl + && li2.evt.OldValue.equals(val2) && li2.evt.NewValue.equals(val3) && li2.evt.Source == cl ; + + li.reset(); + li2.reset(); + li3.reset(); + val1= new Byte((byte)118); + cl.addVetoableChangeListener("", li3); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 1 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 1 + && li3.nChangeCalled == 0 && li3.nVetoCalled == 1; + r[i++]= li.evt.OldValue.equals(val3) && li.evt.NewValue.equals(val1) && li.evt.Source == cl; + r[i++]= li2.evt.OldValue.equals(val3) && li2.evt.NewValue.equals(val1) && li2.evt.Source == cl; + r[i++]= li3.evt.OldValue.equals(val3) && li3.evt.NewValue.equals(val1) && li3.evt.Source == cl ; + + li.reset(); + li2.reset(); + li3.reset(); + // Test Veto Exception + cl.setPropertyValue("PropByteA", val1); + li.bVeto= true; + try { + cl.setPropertyValue("PropByteA", val2);i++; + } catch (PropertyVetoException e) + { + r[i++]= true; + } + r[i++]= cl.bytePropA == val1.byteValue(); + li.bVeto= false; + + li.reset(); + li2.reset(); + li3.reset(); + cl.removeVetoableChangeListener("PropByteA",li); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 1 + && li3.nChangeCalled == 0 && li3.nVetoCalled == 1; + cl.removeVetoableChangeListener("PropByteA", li2); + li.reset(); + li2.reset(); + li3.reset(); + cl.setPropertyValue("PropByteA", val1); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 0 + && li3.nChangeCalled == 0 && li3.nVetoCalled == 1; + + cl.removeVetoableChangeListener("", li3); + li.reset(); + li2.reset(); + li3.reset(); + cl.setPropertyValue("PropByteA", val2); + r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0 + && li2.nChangeCalled == 0 && li2.nVetoCalled == 0 + && li3.nChangeCalled == 0 && li3.nVetoCalled == 0; + + cl.addVetoableChangeListener("PropByteA", li); + cl.addVetoableChangeListener("PropByteA", li2); + cl.addVetoableChangeListener("", li3); + cl.dispose(); + li.reset(); + li2.reset(); + li3.reset(); + try { + cl.setPropertyValue("PropByteA", val2); + }catch (DisposedException e) + { + r[i++]= true; + } + }catch (Exception e) + { + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean getPropertySetInfo() + { + System.out.println("PropertySet.getPropertySetInfo"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + XPropertySetInfo info= cl.getPropertySetInfo(); + Property[] arProps= info.getProperties(); + Property[] arRegProps= cl.getRegisteredProperties(); + r[i++]= arProps.length == arRegProps.length; + for (int j= 0; j < arProps.length; j++) + { + boolean bFound= false; + for (int k= 0; k < arRegProps.length; k++) + { + if (arProps[j] == arRegProps[k]) + { + bFound= true; + break; + } + } + if ( !bFound) + r[i++]= false; + } + + for (int j= 0; j < arRegProps.length; j++) + { + Property prop= info.getPropertyByName(arRegProps[j].Name); + if (prop != arRegProps[j]) + r[i++]= false; + if (! info.hasPropertyByName(arRegProps[j].Name)) + r[i++]= false; + } + + + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean setFastPropertyValue() + { + System.out.println("PropertySet.setFastPropertyValue"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + cl.setFastPropertyValue(5, new Integer(111)); + r[i++]= cl.intPropA == 111; + try { + cl.setFastPropertyValue(-1, new Integer(1)); i++; + } catch(UnknownPropertyException e) + { + r[i++]= true; + } + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean getFastPropertyValue() + { + System.out.println("PropertySet.setFastPropertyValue"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + cl.setFastPropertyValue(5, new Integer(111)); + Integer aInt= (Integer) cl.getFastPropertyValue(5); + r[i++]= aInt.intValue() == 111; + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean setPropertyValues() + { + System.out.println("PropertySet.setPropertyValues"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + cl.setPropertyValues(new String[0], new Object[0]); + String[] arNames= new String[] {"PropCharA","PropIntClass","PropObjectA"}; + Character aChar= new Character('A'); + Integer aInt= new Integer(111); + Byte aByte= new Byte((byte)11); + Object[] values= new Object[]{aChar, aInt, aByte}; + cl.setPropertyValues(arNames, values); + r[i++]= cl.charPropA == 'A' && cl.intClassProp.intValue() == 111 && ((Byte)cl.objectPropA).byteValue() == 11; + + arNames= new String[] {"blabla","PropIntClass","PropObjectA"}; + cl.resetPropertyMembers(); + cl.setPropertyValues(arNames, values); + r[i++]= cl.intClassProp.intValue() == 111 && ((Byte)cl.objectPropA).byteValue() == 11; + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean getPropertyValues() + { + System.out.println("PropertySet.getPropertyValues"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + cl.charPropA= 'A'; + cl.intClassProp= new Integer(111); + cl.objectPropA= new Byte((byte)11); + Object[] values= cl.getPropertyValues(new String[] {"PropCharA","PropIntClass","PropObjectA"}); + + r[i++]= ((Character) values[0]).charValue() == 'A' && ((Integer) values[1]).intValue() == 111 + && ((Byte) values[2]).byteValue() == 11; + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + // Currently the listeners are always notified if one of properties has changed. + // The property names in the first argument are ignored. + public boolean addPropertiesChangeListener() + { + System.out.println("PropertySet.addPropertiesChangeListener\n" + + "PropertySet.removePropertiesChangeListener\n" + + "notification of such listeners"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + Listener li1= new Listener(); + Listener li2= new Listener(); + cl.addPropertiesChangeListener(new String[]{"PropCharA"}, li1); + cl.setPropertyValue("PropCharA", new Character('B')); + r[i++]= li1.nPropertiesChange == 0; + cl.propCharA.Attributes= PropertyAttribute.BOUND; + cl.setPropertyValue("PropCharA", new Character('C')); + r[i++]= li1.nPropertiesChange == 1; + + PropertyChangeEvent evt= li1.arEvt[0]; + r[i++]= evt.PropertyName.equals("PropCharA") && ((Character)evt.OldValue).charValue() == 'B' + && ((Character) evt.NewValue).charValue() == 'C'; + li1.reset(); + cl.removePropertiesChangeListener(li1); + cl.setPropertyValue("PropCharA", new Character('F')); + r[i++]= li1.nPropertiesChange == 0; + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean firePropertiesChangeEvent() + { + System.out.println("PropertySet.firePropertiesChangeEvent"); + boolean[] r= new boolean[50]; + int i= 0; + + TestClass cl= new TestClass(); + try { + Listener li1= new Listener(); + cl.intClassProp= new Integer(111); + cl.charPropA= 'A'; + cl.firePropertiesChangeEvent(new String[]{"PropCharA","PropIntClass"}, li1); + r[i++]= li1.nPropertiesChange == 1; + PropertyChangeEvent[] arEvt= li1.arEvt; + r[i++]= arEvt[0].PropertyName.equals("PropCharA") + && ((Character) arEvt[0].OldValue).charValue() == 'A' + && ((Character) arEvt[0].NewValue).charValue() == 'A'; + r[i++]= arEvt[1].PropertyName.equals("PropIntClass") + && ((Integer) arEvt[1].OldValue).intValue() == 111 + && ((Integer) arEvt[1].NewValue).intValue() == 111; + }catch(java.lang.Exception e){ + System.out.println(e.getMessage()); + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + + public boolean registerProperty1() + { + TestClass2 cl= new TestClass2(); + return cl.test_registerProperty1(); + } + public static boolean test() + { + PropertySet_Test test= new PropertySet_Test(); + boolean r[]= new boolean[50]; + int i= 0; + r[i++]= test.convertPropertyValue(); + r[i++]= test.setPropertyValueNoBroadcast(); + r[i++]= test.setPropertyValue(); + r[i++]= test.addPropertyChangeListener(); + r[i++]= test.getPropertySetInfo(); + r[i++]= test.setFastPropertyValue(); + r[i++]= test.getFastPropertyValue(); + r[i++]= test.setPropertyValues(); + r[i++]= test.getPropertyValues(); + r[i++]= test.addPropertiesChangeListener(); + r[i++]= test.firePropertiesChangeEvent(); + r[i++]= test.registerProperty1(); + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Errors occured!"); + else + System.out.println("No errors."); + return bOk; + } + public static void main(String[] args) + { + test(); + } +} + +class TestClass extends PropertySet +{ + public Property propBoolA= new Property("PropBoolA", 1, new Type(Boolean.TYPE), (short)0); + public boolean boolPropA; + public Property propCharA= new Property("PropCharA", 2, new Type(Character.TYPE), (short) 0); + public char charPropA; + public Property propByteA= new Property("PropByteA", 3, new Type(Byte.TYPE), (short) 0); + public byte bytePropA; + public Property propShortA= new Property("PropShortA", 4, new Type(Short.TYPE), (short) 0); + public short shortPropA; + public Property propIntA= new Property("PropIntA", 5, new Type(Integer.TYPE), (short) 0); + public int intPropA; + public Property propLongA= new Property("PropLongA", 6, new Type(Long.TYPE), (short) 0); + public long longPropA; + public Property propFloatA= new Property("PropFloatA", 7, new Type(Float.TYPE), (short) 0); + public float floatPropA; + public Property propDoubleA= new Property("PropDoubleA", 8, new Type(Double.TYPE), (short) 0); + public double doublePropA; + public Property propStringA= new Property("PropStringA", 9, new Type(String.class), (short) 0); + public String stringPropA; + public Property propArrayByteA= new Property("PropArrayByteA", 10, new Type(byte[].class), (short) 0); + public byte[] arBytePropA; + public Property propTypeA= new Property("PropTypeA", 11, new Type(Type.class), (short) 0); + public Type typePropA; + public Property propObjectA= new Property("PropObjectA",12, new Type(Object.class), (short) 0); + public Object objectPropA; + public Property propAnyA= new Property("PropAnyA", 13, new Type(Any.class), (short) 0); + public Any anyPropA; + public Property propXInterfaceA= new Property("PropXInterfaceA", 13, new Type(Any.class), (short) 0); + public XInterface xInterfacePropA; + public Property propXWeakA= new Property("PropXWeakA", 13, new Type(Any.class), (short) 0); + public XWeak xWeakPropA; + // Test private, protected, package access, Anys as arguments and members, members whith a value + + public Property propBoolB= new Property("PropBoolB", 101, new Type(Boolean.TYPE), (short) 0); + protected boolean boolPropB; + + public Property propBoolC= new Property("PropBoolC", 201, new Type(Boolean.TYPE), (short) 0); + boolean boolPropC; + + public Property propBoolD= new Property("PropBoolD", 301, new Type(Boolean.TYPE), (short) 0); + private boolean boolPropD; + + public Property propBoolClass= new Property("PropBoolClass", 1001, new Type(Boolean.class), (short) 0); + public Boolean boolClassProp; + public Property propCharClass= new Property("PropCharClass", 1002, new Type(Character.class), (short) 0); + public Character charClassProp; + public Property propByteClass= new Property("PropByteClass", 1003, new Type(Byte.class), (short) 0); + public Byte byteClassProp; + public Property propShortClass= new Property("PropShortClass", 1004, new Type(Short.class), (short) 0); + public Short shortClassProp; + public Property propIntClass= new Property("PropIntClass", 1005, new Type(Integer.class), (short) 0); + public Integer intClassProp; + public Property propLongClass= new Property("PropLongClass", 1006, new Type(Long.class), (short) 0); + public Long longClassProp; + public Property propFloatClass= new Property("PropFloatClass", 1007, new Type(Float.class), (short) 0); + public Float floatClassProp; + public Property propDoubleClass= new Property("PropDoubleClass", 1008, new Type(Double.class), (short) 0); + public Double doubleClassProp; + + + public TestClass() + { + + super(); +// When adding properties then modify the getRegisteredProperties method + //registerProperty(String name, int handle, Type type, short attributes, String memberName) + registerProperty(propBoolA, "boolPropA"); + registerProperty(propCharA, "charPropA"); + registerProperty(propByteA, "bytePropA"); + registerProperty(propShortA, "shortPropA"); + registerProperty(propIntA, "intPropA"); + registerProperty(propLongA, "longPropA"); + registerProperty(propFloatA, "floatPropA"); + registerProperty(propDoubleA, "doublePropA"); + registerProperty(propStringA, "stringPropA"); + registerProperty(propArrayByteA, "arBytePropA"); + registerProperty(propTypeA, "typePropA"); + registerProperty(propObjectA, "objectPropA"); + registerProperty(propAnyA, "anyPropA"); + registerProperty(propXInterfaceA, "xInterfacePropA"); + registerProperty(propXWeakA, "xWeakPropA"); + registerProperty(propBoolB, "boolPropB"); + registerProperty(propBoolC, "boolPropC"); + registerProperty(propBoolD, "boolPropD"); + registerProperty(propBoolClass, "boolClassProp"); + registerProperty(propCharClass, "charClassProp"); + registerProperty(propByteClass, "byteClassProp"); + registerProperty(propShortClass, "shortClassProp"); + registerProperty(propIntClass, "intClassProp"); + registerProperty(propLongClass, "longClassProp"); + registerProperty(propFloatClass, "floatClassProp"); + registerProperty(propDoubleClass, "doubleClassProp"); + } + + /** When adding properties then modify the getRegisteredProperties method + */ + public Property[] getRegisteredProperties() + { + return new Property[] { + propBoolA, propCharA, propByteA, propShortA, + propIntA, propLongA, propFloatA, propDoubleA, + propStringA, propArrayByteA, propTypeA, propObjectA, + propAnyA, propXInterfaceA, propXWeakA, propBoolB, + propBoolC, propBoolD, propBoolClass, propCharClass, + propByteClass, propShortClass, propIntClass, propLongClass, + propFloatClass, propDoubleClass + }; + + } + public boolean test_convertPropertyValue() + { + boolean[] r= new boolean[150]; + int i= 0; + + resetPropertyMembers(); + Object[] outOldVal= new Object[1]; + Object[] outNewVal= new Object[1]; + + Object value= new Boolean(true); + try + { + r[i++]= convertPropertyValue(propBoolA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Boolean && outNewVal[0].equals(value) && outOldVal[0].equals(new Boolean(false)); + value= new Character('A'); + r[i++]= convertPropertyValue(propCharA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Character && outNewVal[0].equals(value) && outOldVal[0].equals(new Character((char)0)); + charPropA= 'B'; + r[i++]= convertPropertyValue(propCharA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Character && outNewVal[0].equals(value) && outOldVal[0].equals(new Character('B')); + value= new Byte((byte) 111); + r[i++]= convertPropertyValue(propByteA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Byte && outNewVal[0].equals(value); + value= new Short((short) 112); + r[i++]= convertPropertyValue(propShortA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Short && outNewVal[0].equals(value); + value= new Integer( 113); + r[i++]= convertPropertyValue(propIntA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Integer && outNewVal[0].equals(value); + value= new Long(114); + r[i++]= convertPropertyValue(propLongA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Long && outNewVal[0].equals(value); + value= new Float(3.14); + r[i++]= convertPropertyValue(propFloatA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Float && outNewVal[0].equals(value); + value= new Double(3.145); + r[i++]= convertPropertyValue(propDoubleA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Double && outNewVal[0].equals(value); + value= "string"; + r[i++]= convertPropertyValue(propStringA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof String && outNewVal[0].equals(value); + value= new byte[]{1,2,3}; + arBytePropA= null; + r[i++]= convertPropertyValue(propArrayByteA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof byte[] && outNewVal[0].equals(value) && outOldVal[0] == null; + r[i++]= convertPropertyValue(propArrayByteA, outNewVal, outOldVal, value); + r[i++]= outOldVal[0] == null; + value= new Type(XInterface.class); + r[i++]= convertPropertyValue(propTypeA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Type && outNewVal[0].equals(value); + + value= new Object(); // TypeClass.VOID + r[i++]= convertPropertyValue(propObjectA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Object && outNewVal[0].equals(value); + value= new Integer(111); + r[i++]= convertPropertyValue(propObjectA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Integer && outNewVal[0].equals(value); + value= new ComponentBase(); + r[i++]= convertPropertyValue(propObjectA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Object && outNewVal[0].equals(value); + value= new Integer(111); + r[i++]= convertPropertyValue(propAnyA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Any && ((Any)outNewVal[0]).getType().equals(new Type(Integer.class)) + && ((Any)outNewVal[0]).getObject().equals(value); + XWeak oWeak= new ComponentBase(); + value= oWeak; + // The returned Any must contain an XInterface + r[i++]= convertPropertyValue(propAnyA, outNewVal, outOldVal, value); + r[i++]= ((Any) outNewVal[0]).getType().equals(new Type(XInterface.class)) + && ((Any) outNewVal[0]).getObject() == oWeak; + value= new ComponentBase(); + r[i++]= convertPropertyValue(propXInterfaceA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof XInterface && outNewVal[0].equals(value); + r[i++]= convertPropertyValue(propXWeakA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof XWeak && outNewVal[0].equals(value); + + // Any arguments ------------------------------------------------------------------ + value= new Any( new Type(Integer.class),new Integer(111)); + r[i++]= convertPropertyValue(propIntA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Integer && ((Integer)outNewVal[0]).equals( ((Any)value).getObject()); + value= new Any(new Type(Boolean.class), new Boolean(true)); + r[i++]= convertPropertyValue(propBoolA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Boolean && ((Boolean)outNewVal[0]).equals(((Any) value).getObject()); + //Character, Byte, Short, Long + // must fail + value= new Any(new Type(Object.class), new Object()); + r[i++]= convertPropertyValue(propObjectA, outNewVal, outOldVal, value); + r[i++]= convertPropertyValue(propAnyA, outNewVal, outOldVal, value); + value= new Any(new Type(Integer.class), new Integer(111)); + r[i++]= convertPropertyValue(propObjectA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Integer && outNewVal[0].equals( ((Any)value).getObject()); + r[i++]= convertPropertyValue(propAnyA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Any && ((Any) outNewVal[0]).getType().equals( ((Any) value).getType()) + && ((Any) outNewVal[0]).getObject().equals( ((Any) value).getObject()); + value= new Any(new Type(XInterface.class), new ComponentBase()); + r[i++]= convertPropertyValue(propObjectA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof XInterface && outNewVal[0] == ((Any) value).getObject(); + r[i++]= convertPropertyValue(propXInterfaceA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] == ((Any) value).getObject(); + value= new Any(new Type(byte[].class), new byte[]{1,2,3}); + r[i++]= convertPropertyValue(propArrayByteA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof byte[]; + + + + // test private, protected, package fields + value= new Boolean(true); + r[i++]= convertPropertyValue(propBoolB, outNewVal, outOldVal, value); + r[i++]= ((Boolean)value).booleanValue() == ((Boolean) outNewVal[0]).booleanValue(); + r[i++]= convertPropertyValue(propBoolC, outNewVal, outOldVal, value); + r[i++]= ((Boolean)value).booleanValue() == ((Boolean) outNewVal[0]).booleanValue(); + // must fail because the the member boolPropD is private + try{ + convertPropertyValue(propBoolD, outNewVal, outOldVal, value); + i++; + }catch (Exception e) + { + r[i++]= true; + } + + // Properties member of type Byte,Short etc. + value= new Boolean(true); + r[i++]= convertPropertyValue(propBoolClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Boolean && outNewVal[0].equals(value); + value= new Character('A'); + r[i++]= convertPropertyValue(propCharClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Character && outNewVal[0].equals(value); + value= new Byte((byte) 111); + r[i++]= convertPropertyValue(propByteClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Byte && outNewVal[0].equals(value); + value= new Short((short) 112); + r[i++]= convertPropertyValue(propShortClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Short && outNewVal[0].equals(value); + value= new Integer( 113); + r[i++]= convertPropertyValue(propIntClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Integer && outNewVal[0].equals(value); + value= new Long(114); + r[i++]= convertPropertyValue(propLongClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Long && outNewVal[0].equals(value); + value= new Float(3.14); + r[i++]= convertPropertyValue(propFloatClass, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Float && outNewVal[0].equals(value); + value= new Double(3.145); + r[i++]= convertPropertyValue(propDoubleA, outNewVal, outOldVal, value); + r[i++]= outNewVal[0] instanceof Double && outNewVal[0].equals(value); + }catch (com.sun.star.uno.Exception e) + { + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + + return bOk; + } + + public boolean test_setPropertyValueNoBroadcast() + { + boolean[] r= new boolean[150]; + int i= 0; + resetPropertyMembers(); + try { + Object value= new Boolean(true); + setPropertyValueNoBroadcast(propBoolA, value); + r[i++]= boolPropA == ((Boolean) value).booleanValue(); + value= new Character('A'); + setPropertyValueNoBroadcast(propCharA, value); + r[i++]= charPropA == ((Character) value).charValue(); + value= new Byte((byte) 111); + setPropertyValueNoBroadcast(propByteA, value); + r[i++]= bytePropA == ((Byte)value).byteValue(); + value= new Short((short) 112); + setPropertyValueNoBroadcast(propShortA, value); + r[i++]= shortPropA == ((Short) value).shortValue(); + value= new Integer( 113); + setPropertyValueNoBroadcast(propIntA, value); + r[i++]= intPropA == ((Integer) value).intValue(); + value= new Long(114); + setPropertyValueNoBroadcast(propLongA, value); + r[i++]= longPropA == ((Long) value).longValue(); + value= new Float(3.14); + setPropertyValueNoBroadcast(propFloatA, value); + r[i++]= floatPropA == ((Float) value).floatValue(); + value= new Double(3.145); + setPropertyValueNoBroadcast(propDoubleA, value); + r[i++]= doublePropA == ((Double) value).doubleValue(); + value= "string"; + setPropertyValueNoBroadcast(propStringA, value); + r[i++]= stringPropA.equals(value); + value= new byte[]{1,2,3}; + setPropertyValueNoBroadcast(propArrayByteA, value); + r[i++]= arBytePropA.equals(value); + value= new Type(XInterface.class); + setPropertyValueNoBroadcast(propTypeA, value); + r[i++]= typePropA.equals(value); + value= new Integer(111); + setPropertyValueNoBroadcast(propObjectA, value); + r[i++]= objectPropA.equals(value); + value= (XInterface) new ComponentBase(); + setPropertyValueNoBroadcast(propObjectA, value); + r[i++]= objectPropA.equals(value); + value= new Any( new Type(Integer.TYPE), new Integer(111)); + setPropertyValueNoBroadcast(propAnyA, value); + r[i++]= util.anyEquals(anyPropA, value); + value= new ComponentBase(); + setPropertyValueNoBroadcast(propXInterfaceA, value); + r[i++]= xInterfacePropA instanceof XInterface && xInterfacePropA.equals(value); + setPropertyValueNoBroadcast(propXWeakA, value); + r[i++]= xInterfacePropA instanceof XWeak && xInterfacePropA.equals(value); + objectPropA= new Object(); + + + value= new Boolean(true); + setPropertyValueNoBroadcast(propBoolB, value); + r[i++]= boolPropB == ((Boolean) value).booleanValue(); + setPropertyValueNoBroadcast(propBoolC, value); + r[i++]= boolPropC == ((Boolean) value).booleanValue(); + // must fail because the the member boolPropD is private + try{ + setPropertyValueNoBroadcast(propBoolD, value); + }catch(com.sun.star.lang.WrappedTargetException e) + { + r[i++]= true; + } + }catch (java.lang.Exception e) + { + i++; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + return bOk; + } + + void resetPropertyMembers() + { + boolPropA= false; + charPropA= (char) 0; + bytePropA= 0; + shortPropA= 0; + intPropA= 0; + longPropA= 0; + floatPropA= 0; + doublePropA= 0.; + stringPropA= null; + arBytePropA= null; + typePropA= null; + objectPropA= null; + anyPropA= null; + xInterfacePropA= null; + xWeakPropA= null; + boolPropB= false; + boolPropC= false; + boolPropD= false; + boolClassProp= null; + charClassProp= null; + byteClassProp= null; + shortClassProp= null; + intClassProp= null; + longClassProp= null; + floatClassProp= null; + doubleClassProp= null; + } +} + +class TestClass2 extends PropertySet +{ + public TestClass2() + { + } + + boolean test_registerProperty1() + { + System.out.println("registerProperty Test 1"); + boolean r[]= new boolean[50]; + int i= 0; + + registerProperty("PropChar", new Type(char.class), (short) 0, "PropChar"); + registerProperty("PropInt", new Type(int.class), (short) 0, "PropInt"); + registerProperty("PropString", new Type(String.class), (short) 0, "PropString"); + + XPropertySetInfo info= getPropertySetInfo(); + Property[] props= info.getProperties(); + for (int j= 0; j < props.length; j++) + { + Property aProp= props[j]; + if (aProp.Name.equals("PropChar") && aProp.Type.equals(new Type(char.class)) && + aProp.Attributes == 0) + r[i++]= true; + else if (aProp.Name.equals("PropInt") && aProp.Type.equals(new Type(int.class)) && + aProp.Attributes == 0) + r[i++]= true; + else if (aProp.Name.equals("PropString") && aProp.Type.equals(new Type(String.class)) && + aProp.Attributes == 0) + r[i++]= true; + else + r[i++]= false; + } + + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } +} + +class util +{ + // An Object is considered an Any with TypeClass.VOID and no value. + static boolean anyEquals(Object val1, Object val2) + { + Object obj1= null; + Object obj2= null; + Type t1= null; + Type t2= null; + if (val1 instanceof Any) + { + obj1= ((Any) val1).getObject(); + t1= ((Any) val1).getType(); + } + else + obj1= val1; + + if (val2 instanceof Any) + { + obj2= ((Any) val2).getObject(); + t2= ((Any) val2).getType(); + } + else + obj2= val2; + + if (obj1 != null && obj1.equals(obj2)) + return true; + else if ((obj1 == null && obj2 == null) && t1 != null && t1.equals(t2)) + return true; + return false; + } +} + +class Listener implements XPropertyChangeListener, XVetoableChangeListener, +XPropertiesChangeListener +{ + int nChangeCalled; + int nPropertiesChange; + int nVetoCalled; + int nDisposingCalled; + boolean bVeto= false; + PropertyChangeEvent evt; + PropertyChangeEvent[] arEvt; + // XPropertyChangeListener + public void propertyChange(PropertyChangeEvent evt ) + { + nChangeCalled++; + this.evt= evt; + } + + //VetoableChangeListener + public void vetoableChange(PropertyChangeEvent evt ) throws PropertyVetoException + { + nVetoCalled++; + this.evt= evt; + if (bVeto) + throw new PropertyVetoException(); + } + + public void disposing( /*IN*/EventObject Source ) + { + nDisposingCalled++; + } + + public void reset() + { + nChangeCalled= 0; + nPropertiesChange= 0; + nVetoCalled= 0; + nDisposingCalled= 0; + evt= null; + arEvt= null; + bVeto= false; + } + // XPropertiesChangeListener + public void propertiesChange(PropertyChangeEvent[] propertyChangeEvent) + { + nPropertiesChange++; + arEvt= propertyChangeEvent; + } + +}
\ No newline at end of file |