|
UDK 3.2.7 Java API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sun.star.lib.uno.helper
Class PropertySet
java.lang.Object com.sun.star.lib.uno.helper.WeakBase com.sun.star.lib.uno.helper.ComponentBase com.sun.star.lib.uno.helper.PropertySet
- All Implemented Interfaces:
- XFastPropertySet, XMultiPropertySet, XPropertySet, XComponent, XTypeProvider, XInterface, XWeak
public class PropertySet
- extends ComponentBase
- implements XPropertySet, XFastPropertySet, XMultiPropertySet
- extends ComponentBase
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
convertPropertyValue
,
setPropertyValueNoBroadcast
and
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 public
Properties have to be registered by one of the registerProperty methods. They take among other arguments an Object named id 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.
Example:
public class Foo extends PropertySet { protected int intProp; public Foo() { registerProperty("PropertyA", 0, new Type(int.class), (short)0, "intProp"); } }
Field Summary | |
---|---|
protected MultiTypeInterfaceContainer |
aBoundLC
|
protected MultiTypeInterfaceContainer |
aVetoableLC
|
protected XPropertySetInfo |
propertySetInfo
|
Fields inherited from class com.sun.star.lib.uno.helper.ComponentBase |
---|
bDisposed, bInDispose, listenerContainer |
Fields inherited from class com.sun.star.lib.uno.helper.WeakBase |
---|
_mapImplementationIds, _mapTypes |
Fields inherited from interface com.sun.star.beans.XPropertySet |
---|
UNOTYPEINFO |
Fields inherited from interface com.sun.star.beans.XFastPropertySet |
---|
UNOTYPEINFO |
Fields inherited from interface com.sun.star.beans.XMultiPropertySet |
---|
UNOTYPEINFO |
Fields inherited from interface com.sun.star.lang.XComponent |
---|
UNOTYPEINFO |
Fields inherited from interface com.sun.star.uno.XWeak |
---|
UNOTYPEINFO |
Fields inherited from interface com.sun.star.lang.XTypeProvider |
---|
UNOTYPEINFO |
Constructor Summary | |
---|---|
PropertySet()
|
Method Summary | |
---|---|
void |
addPropertiesChangeListener(String[] propNames,
XPropertiesChangeListener listener)
|
void |
addPropertyChangeListener(String str,
XPropertyChangeListener xPropertyChangeListener)
|
void |
addVetoableChangeListener(String str,
XVetoableChangeListener xVetoableChangeListener)
|
protected void |
assignPropertyId(Property prop,
Object id)
Assigns an identifyer object to a Property object so that the identifyer can be obtained by getPropertyId later on. |
protected boolean |
convertPropertyValue(Property property,
Object[] newVal,
Object[] curVal,
Object setVal)
Converts a value in a way so that it is appropriate for storing as a property value, that is setPropertyValueNoBroadcast can process the value without any further
conversion. |
protected void |
fire(Property[] properties,
Object[] newValues,
Object[] oldValues,
boolean bVetoable)
This method fires events to XPropertyChangeListener,XVetoableChangeListener and XPropertiesChangeListener event sinks. |
void |
firePropertiesChangeEvent(String[] propNames,
XPropertiesChangeListener listener)
|
Object |
getFastPropertyValue(int nHandle)
|
protected Property[] |
getProperties()
Returns an array of all Property objects or an array of length null if there are no properties. |
protected Property |
getProperty(String propertyName)
Returns the Property object for a given property name or null if that property does not exists (i.e. |
protected Property |
getPropertyByHandle(int nHandle)
Returns the Property object with a handle (Property.Handle) as specified by the argument nHandle. |
protected Object |
getPropertyId(Property prop)
Returns the identifyer object for a certain Property. |
XPropertySetInfo |
getPropertySetInfo()
|
protected Object |
getPropertyValue(Property property)
Retrieves the value of a property. |
Object |
getPropertyValue(String name)
|
Object[] |
getPropertyValues(String[] propNames)
If a value for a property could not be retrieved then the respective element in the returned array has the value null. |
protected void |
initMappings()
Initializes data structures used for mappings of property names to property object, property handles to property objects and property objects to id objects. |
protected void |
postDisposing()
Makes sure that listeners which are kept in aBoundLC (XPropertyChangeListener) and aVetoableLC (XVetoableChangeListener) receive a disposing call. |
protected void |
putProperty(Property prop)
Stores a Property object so that it can be retrieved subsequently by getProperty(String) ,getProperties() ,getPropertyByHandle(int) . |
protected void |
registerProperty(Property prop,
Object id)
Registers a property with this helper class and associates the argument id with it. |
protected void |
registerProperty(String name,
int handle,
Type type,
short attributes,
Object id)
Registers a property with this helper class and associates the argument id with it. |
protected void |
registerProperty(String propertyName,
short attributes)
Registers a property with this class. |
protected void |
registerProperty(String propertyName,
String memberName,
short attributes)
Registers a property with this class. |
protected void |
registerProperty(String name,
Type type,
short attributes,
Object id)
Registers a property with this class and associates the argument id with it. |
void |
removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener)
|
void |
removePropertyChangeListener(String propName,
XPropertyChangeListener listener)
|
void |
removeVetoableChangeListener(String propName,
XVetoableChangeListener listener)
|
void |
setFastPropertyValue(int nHandle,
Object aValue)
|
protected void |
setPropertyValue(Property prop,
Object value)
Sets the value of a property. |
void |
setPropertyValue(String name,
Object value)
Sets the value of a property. |
protected void |
setPropertyValueNoBroadcast(Property property,
Object newVal)
Sets the value of a property. |
void |
setPropertyValues(String[] propNames,
Object[] values)
If the array of property names containes an unknown property then it will be ignored. |
Methods inherited from class com.sun.star.lib.uno.helper.ComponentBase |
---|
addEventListener, dispose, finalize, preDisposing, removeEventListener |
Methods inherited from class com.sun.star.lib.uno.helper.WeakBase |
---|
getImplementationId, getTypes, queryAdapter |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
propertySetInfo
protected XPropertySetInfo propertySetInfo
aBoundLC
protected MultiTypeInterfaceContainer aBoundLC
aVetoableLC
protected MultiTypeInterfaceContainer aVetoableLC
Constructor Detail |
---|
PropertySet
public PropertySet()
Method Detail |
---|
registerProperty
protected void registerProperty(Property prop, Object id)
- Registers a property with this helper class and associates the argument id with it.
id is used to identify the storage of the property value. How property values are stored
and retrieved is determined by the methods
convertPropertyValue
,setPropertyValueNoBroadcast
andgetPropertyValue
These methods expect id 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).- Parameters:
prop
- The property to be registered.id
- Identifies the properties storage.- See Also:
getPropertyId(com.sun.star.beans.Property)
registerProperty
protected void registerProperty(String name, int handle, Type type, short attributes, Object id)
- Registers a property with this helper class and associates the argument id with it.
It does the same as
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)- Parameters:
name
- The property's name (Property.Name).handle
- The property's handle (Property.Handle).Type
- The property's type (Property.Type).attributes
- The property's attributes (Property.Attributes).id
- Identifies the property's storage.
registerProperty
protected void registerProperty(String name, Type type, short attributes, Object id)
- Registers a property with this class and associates the argument id with it.
It does the same as
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).- Parameters:
name
- The property's name (Property.Name).handle
- The property's handle (Property.Handle).Type
- The property's type (Property.Type).attributes
- The property's attributes (Property.Attributes).id
- Identifies the property's storage.
registerProperty
protected void registerProperty(String propertyName, String memberName, short attributes)
- Registers a property with this class. This method expects that property values
are stored in member variables as is the case if the methods convertPropertyValue,
setPropertyValueNoBroadcast and getPropertyValue(Property) are not overridden.
It is presumed that the type of the member variable
corresponds Property.Type. For example, if the TypeClass of Property.Type is to be
a TypeClass.SHORT then the member must be a short or java.lang.Short.
The handle for the property is generated.
If there is no member with the specified name or if the member has an incompatible type then a com.sun.star.uno.RuntimeException is thrown.- Parameters:
propertyName
- The name of the property.memberName
- The name of the member variable that holds the value of the property.attributes
- The property attributes.
registerProperty
protected void registerProperty(String propertyName, short attributes)
- Registers a property with this class.
It is presumed that the name of property is equal to the name of the member variable
that holds the property value.
- Parameters:
propertyName
- The name of the property and the member variable that holds the property's value.attributes
- The property attributes.- See Also:
registerProperty(String, String, short)
getProperty
protected Property getProperty(String propertyName)
- 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
initMappings()
,getProperties()
andputProperty(Property)
.- Parameters:
propertyName
- The name of the property (Property.Name)- Returns:
- The Property object with the name propertyName.
getPropertyByHandle
protected Property getPropertyByHandle(int nHandle)
- Returns the Property object with a handle (Property.Handle) as specified by the argument
nHandle. 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
initMappings()
,putProperty(Property)
.- Parameters:
nHandle
- The handle of the property (Property.Handle).- Returns:
- The Property object with the handle nHandle
getProperties
protected Property[] getProperties()
- 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
initMappings()
,getProperty(String)
andputProperty(com.sun.star.beans.Property)
.- Returns:
- Array of all Property objects.
putProperty
protected void putProperty(Property prop)
- Stores a Property object so that it can be retrieved subsequently by
getProperty(String)
,getProperties()
,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 overrideinitMappings()
,getProperty(String)
,getProperties()
,getPropertyByHandle(int)
.- Parameters:
prop
- The Property object that is to be stored.
assignPropertyId
protected void assignPropertyId(Property prop, Object id)
- Assigns an identifyer object to a Property object so that the identifyer
can be obtained by
getPropertyId
later on. The identifyer is used to specify a certain storage for the property's value. If you do not overridesetPropertyValueNoBroadcast
orgetPropertyValue(Property)
then the argument id 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 overrideinitMappings
andgetPropertyId
.- Parameters:
prop
- The Property object that is being assigned an id.id
- The object which identifies the storage used for the property's value.- See Also:
registerProperty(Property, Object)
getPropertyId
protected Object getPropertyId(Property prop)
- Returns the identifyer object for a certain Property. The object must have been
previously assigned to the Property object by
assignPropertyId
. Override this method if you want to implement your own mapping from Property objects to ids. Then you also need to overrideinitMappings
andassignPropertyId
.- Parameters:
prop
- The property for which the id is to be retrieved.- Returns:
- The id object that identifies the storage used for the property's value.
- See Also:
registerProperty(Property, Object)
initMappings
protected void initMappings()
- 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
putProperty
,getProperty
,getPropertyByHandle(int)
,assignPropertyId
andgetPropertyId
.
postDisposing
protected void postDisposing()
- Makes sure that listeners which are kept in aBoundLC (XPropertyChangeListener) and aVetoableLC
(XVetoableChangeListener) receive a disposing call. Also those listeners are relesased.
- Overrides:
postDisposing
in classComponentBase
addPropertyChangeListener
public void addPropertyChangeListener(String str, XPropertyChangeListener xPropertyChangeListener) throws UnknownPropertyException, WrappedTargetException
- Specified by:
addPropertyChangeListener
in interfaceXPropertySet
addVetoableChangeListener
public void addVetoableChangeListener(String str, XVetoableChangeListener xVetoableChangeListener) throws UnknownPropertyException, WrappedTargetException
- Specified by:
addVetoableChangeListener
in interfaceXPropertySet
getPropertySetInfo
public XPropertySetInfo getPropertySetInfo()
- Specified by:
getPropertySetInfo
in interfaceXMultiPropertySet
- Specified by:
getPropertySetInfo
in interfaceXPropertySet
getPropertyValue
public Object getPropertyValue(String name) throws UnknownPropertyException, WrappedTargetException
- Specified by:
getPropertyValue
in interfaceXPropertySet
removePropertyChangeListener
public void removePropertyChangeListener(String propName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException
- Specified by:
removePropertyChangeListener
in interfaceXPropertySet
removeVetoableChangeListener
public void removeVetoableChangeListener(String propName, XVetoableChangeListener listener) throws UnknownPropertyException, WrappedTargetException
- Specified by:
removeVetoableChangeListener
in interfaceXPropertySet
setPropertyValue
public void setPropertyValue(String name, Object value) throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException
- 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:
- java.lang.Boolean
- java.lang.Character
- java.lang.Byte
- java.lang.Short
- java.lang.Integer
- java.lang.Long
- java.lang.Float
- java.lang.Double
- java.lang.String
- com.sun.star.uno.Type
- objects which implement UNO interfaces
- arrays which contain elements of the types above
- com.sun.star.uno.Any containing an instance of one of the above types
- Specified by:
setPropertyValue
in interfaceXPropertySet
- Parameters:
name
- The name of the property.value
- The new value of the property. *- Throws:
UnknownPropertyException
PropertyVetoException
IllegalArgumentException
WrappedTargetException
setPropertyValue
protected void setPropertyValue(Property prop, Object value) throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException
- 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.
- Parameters:
prop
- The property whose value is to be set.value
- The new value for the property.- Throws:
UnknownPropertyException
PropertyVetoException
IllegalArgumentException
WrappedTargetException
convertPropertyValue
protected boolean convertPropertyValue(Property property, Object[] newVal, Object[] curVal, Object setVal) throws IllegalArgumentException, WrappedTargetException, UnknownPropertyException
- Converts a value in a way so that it is appropriate for storing as a property value, that is
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 must be public. A property must have been registered (e.g. byregisterProperty(Property, Object)
in order for this method to work. The identifyer argument (type Object) used in the registerProperty methods must be a java.lang.String, which 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 assetPropertyValueNoBroadcast
andgetPropertyValue(Property)
. This method is always called as a result of a call to one of the setter methods, such asXPropertySet.setPropertyValue
,XFastPropertySet.setFastPropertyValue
andXMultiPropertySet.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.
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.
Only if this method returns successfully further processing, such as listener notification and finally the modifiction of the property's value, will occur.
The actual modification of a property's value is done bysetPropertyValueNoBroadcast
which is called subsequent to convertPropertyValue.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:
set.setPropertyValue( "PropA", new Byte( (byte)111));
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 newVal. 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.The method handles Any arguments the same as Object arguments. That is, the setVal 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 setVal 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.
If a member is an Object or Any and the argument setVal 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 newVal returns the XInterface.
If a member is an UNO interface, then setVal is queried for this interface and the result is returned. If setVal is null then newVal will be null too after return.If a property value is stored using a primitive type the the out-parameters curVal and newVal contain the respective wrapper class (e.g.java.lang.Byte, etc.). curVal is used in calls to the XVetoableChangeListener and XPropertyChangeListener.
- Parameters:
property
- - in-param property for which the data is to be converted.newVal
- - out-param which contains the converted value on return.curVal
- - out-param the current value of the property. It is used in calls to the XVetoableChangeListener and XPropertyChangeListener.setVal
- - in-param. The value that is to be converted so that it matches Property and the internally used dataformat for that property.- Returns:
- true - Conversion was successful. newVal contains a valid value for the property. false - conversion failed for some reason.
- Throws:
IllegalArgumentException
- The value provided is unfit for the property.WrappedTargetException
- - An exception occured during the conversion, that is to be made known to the caller.UnknownPropertyException
setPropertyValueNoBroadcast
protected void setPropertyValueNoBroadcast(Property property, Object newVal) throws WrappedTargetException
- Sets the value of a property. In this implementation property values are stored in member variables
(see
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, theconvertPropertyValue
andgetPropertyValue(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.- Parameters:
property
- the property for which the new value is setvalue
- the new value for the property.- Throws:
WrappedTargetException
- An exception, which has to be made known to the caller, occured during the setting of the value.
getPropertyValue
protected Object getPropertyValue(Property property)
- Retrieves the value of a property. This implementation presumes that the values are stored in member variables
of the furthest inheriting class (see
convertPropertyValue
) and that the variables are public. The property must have been registered, for example byregisterProperty(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 asconvertPropertyValue(com.sun.star.beans.Property, java.lang.Object[], java.lang.Object[], java.lang.Object)
andsetPropertyValueNoBroadcast(com.sun.star.beans.Property, java.lang.Object)
.
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).- Parameters:
property
- The property for which the value is to be retrieved.- Returns:
- The value of the property.
fire
protected void fire(Property[] properties, Object[] newValues, Object[] oldValues, boolean bVetoable) throws PropertyVetoException
- This method fires events to XPropertyChangeListener,XVetoableChangeListener and
XPropertiesChangeListener event sinks.
To distinguish what listeners are to be called the argument bVetoable is to be set to true if
a XVetoableChangeListener is meant. For XPropertyChangeListener and XPropertiesChangeListener
it is to be set to false.
- Parameters:
properties
- Properties wich will be or have been affected.newValues
- the new values of the properties.oldValues
- the old values of the properties.bVetoable
- true means fire to VetoableChangeListener, false means fire to XPropertyChangedListener and XMultiPropertyChangedListener.- Throws:
PropertyVetoException
setFastPropertyValue
public void setFastPropertyValue(int nHandle, Object aValue) throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException
- Specified by:
setFastPropertyValue
in interfaceXFastPropertySet
getFastPropertyValue
public Object getFastPropertyValue(int nHandle) throws UnknownPropertyException, WrappedTargetException
- Specified by:
getFastPropertyValue
in interfaceXFastPropertySet
addPropertiesChangeListener
public void addPropertiesChangeListener(String[] propNames, XPropertiesChangeListener listener)
- Specified by:
addPropertiesChangeListener
in interfaceXMultiPropertySet
firePropertiesChangeEvent
public void firePropertiesChangeEvent(String[] propNames, XPropertiesChangeListener listener)
- Specified by:
firePropertiesChangeEvent
in interfaceXMultiPropertySet
getPropertyValues
public Object[] getPropertyValues(String[] propNames)
- If a value for a property could not be retrieved then the respective element in the returned
array has the value null.
- Specified by:
getPropertyValues
in interfaceXMultiPropertySet
removePropertiesChangeListener
public void removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener)
- Specified by:
removePropertiesChangeListener
in interfaceXMultiPropertySet
setPropertyValues
public void setPropertyValues(String[] propNames, Object[] values) throws PropertyVetoException, IllegalArgumentException, WrappedTargetException
- If the array of property names containes an unknown property then it will be ignored.
- Specified by:
setPropertyValues
in interfaceXMultiPropertySet
|
UDK 3.2.7 Java API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |