Property Change Listeners

TM4J provides a generic way for any client application to detect changes made in a topic map. This architecture enables TM4J to act as a Model in the popular Model-View-Controller (MVC) application architecture. This facility is provided by allowing client objects to register themselves with any core topic map object as a property change listener. A property change listener is simply a class that implements the java.beans.PropertyChangeListener interface and, as the name suggests, it may be registered to listen for changes made to a named property of the object or to changes made to any of the properties of the object. Each subclass of TopicMapObjectImpl defines a number of named properties, which are shown in the table below.

Table 5.1. Properties of TM4J Objects

ClassProperty NameDescription
TopicMapObjectsourceLocatorsThe Locator of the XTM element(s) from which this object was created.
TopicsubjectThe single Locator addressing the subject of this topic.
 subjectIndicatorsThe collection of Locators of subject indicators of this topic.
 typesThe Topics which type this Topic
 namesThe BaseNames of this Topic
 occurrencesThe Occurrences of this Topic.
 rolesPlayedThe Members of which this Topic is a part.
 baseTopicThe topic with which this topic is merged.
BaseNamestringThe string value of this name
 variantsThe set of child Variants of this BaseName
 scopeStringThe string encoding of the scope of this BaseName
VariantstringThe string value of the name
 variantsThe set of child Variants of this Variant
 variantNameThe child VariantName of this Variant
VariantNameresourceRefThe URI of the resource which is the value of the VariantName
 resourceThe string which is the value of the VariantName
AssociationmembersThe Members of this Association
 typeThe Topic which types this Association
MemberparentThe Association of which this Member is part.
 roleSpecThe Topic which defines the role played by this Member in the Association
 playersThe Topics which participate in the role played by this Member in the Association
OccurrencetypeThe Topic which defines the type of the Occurrence
 resourceRefThe URI of the resource which is the value of this Occurrence
 resourceThe string which is the value of this Occurrence.
ScopedObjectscopeThe Scope object which defines the collection of scoping topics applied to the ScopedObject.

When a property of an object is altered, the propertyChange() method is invoked on each listener registered against that property (or against all properties) of the object. The propertyChange() method receives a single parameter - a PropertyChangeEvent object. From this object, the listener may determine which object was changed (the 'source' of the property change event); which property was changed; the value of that property prior to its alteration and its value after the alteration has been made.

Note

Some of the properties are reflexive, modifying the rolesPlayed property of a Topic object also modifies the players property of one or more Member objects - in cases such as this, both events are generated by TM4J.

There are some limitations to the current implementation of the property change listeners, which are worth noting here.

  1. The notifications are generated after the alteration to the object is made and as a result the listener is not allowed to veto the change (although enough information is provided to allow the listener to change the value of the object back to its original setting).
  2. The order in which multiple listeners on the same property are invoked is arbitrary, and is not even guaranteed to be the same from one property change notification to the next.
  3. The notification takes place in the same thread as the property change.

This last detail has three implications. Firstly, it means that code that makes the change is blocked until all listeners have received and processed the notification. Secondly it means that it is important for implementers of change listeners to ensure that a live-lock situation is not caused by a series of property change listeners altering properties of the same object. Finally, it means that in systems which have a multi-user database backend such as a remote Ozone database back-end or a relational database back-end, you must not assume that your code will be notified of all changes taking place on the topic map - any changes made by applications in other JVMs or even in other threads of your application will not necessarily be notified to your listeners.