8.3 Observation

A compliant content repository may support observation. This feature enables applications to register interest in events that describe changes to a workspace, and then monitor and respond to those events. The observation mechanism dispatches events when a persistent change is made to the workspace.

Whether a particular implementation supports observation can be determined by querying the repository descriptor table with Repository.getDescriptor("OPTION_OBSERVATION_SUPPORTED") (a return value of true indicates support for observation, see 6.1.1.1 Repository Descriptors).

Note that (in those repositories that support transactions) in the case of changes made within a transaction, the corresponding events will only be dispatched upon commit of the transaction, whereas in the case of changes made outside a transaction the events will be dispatched upon save (or immediately in the case of direct-to-workspace methods). See 8.3.4 Event Production.

An object implementing the Event interface represents an event generated by a repository. It also contains the constants representing the five event types.

javax.jcr.observation.
Event

int

getType()

Returns the type of this event. A constant defined by in this interface. One of NODE_ADDED, NODE_REMOVED, PROPERTY_ADDED, PROPERTY_REMOVED and PROPERTY_CHANGED.

String

getPath()

Returns the absolute path of the item associated with this event. The interpretation given to the returned path depends upon the type of the event:

  • If the event type is NODE_ADDED then this method returns the absolute path of the node that was added.

  • If the event type is NODE_REMOVED then this method returns the absolute path of the node that was removed.

  • If the event type is PROPERTY_ADDED then this method returns the absolute path of the property that was added.

  • If the event type is PROPERTY_REMOVED then this method returns the path of the property that was removed.

  • If the event type is PROPERTY_CHANGED then this method returns the absolute path of the changed property.

A RepositoryException is thrown if an error occurs.

String

getUserID()

Returns the user ID connected with this event. This is the string returned by getUserID of the session that caused the event.

int

NODE_ADDED

An event of this type is generated when a node is added.

int

NODE_REMOVED

An event of this type is generated when a node is removed.

int

PROPERTY_ADDED

An event of this type is generated when a property is added.

int

PROPERTY_REMOVED

An event of this type is generated when a property is removed.

int

PROPERTY_CHANGED

An event of this type is generated when the value of a property is changed.