interface XComponent in module com::sun::star::lang::

(Global Index)

Syntax

interface XComponent : com::sun::star::uno::XInterface ;

Description

controls the lifetime of components.

Actually the real lifetime of an UNO object is controlled by references kept on interfaces of this object. But there are two distinct meanings in keeping a reference to an interface: 1st to own the object and 2nd to know the object. Especially in case of cyclic references, the objects would never get destroyed.

You are only allowed to keep references of interfaces to UNO objects if you are by definition the owner of that object or your reference is very temporary or you have registered an EventListener at that object and cleared the reference when "disposing" is called.

Method Summary

dispose The owner of a component calls this method to get rid of it.

addEventListener adds an event listener to the object.

removeEventListener removes an event listener from the listener list.

Method Details



dispose

Syntax

void dispose ();

Description

The owner of a component calls this method to get rid of it.

Only the owner of this object calls the dispose method if the object should be destroyed. All objects and components must release the references to the objects. If the object is a broadcaster, then all listeners are removed and the method XEventListener::disposing is called on all listeners.

Due to the importance of the concept of the method XComponent::dispose , we provide a figurative example:

Imagine there was a hole in the floor and some people around it are holding a box (our component). Everyone who holds the box for a longer time than just temporaryly (i.e. to put something in or get something out) has to watch a light bulb which is attached to the box (listening to the XEventListener::disposing event). Now, when the owner of the box switches the light on (calling XComponent::dispose ), everybody holding the box has to take his hands off (clear the interface handles). If and only if everyone does that, then the box falls (getting deleted). But only the owner is allowed to switch the light on!

After this method is called the instance has to throw the DisposedException for all calls not non-event-methods; event-methods have to be ignored.

Example

 void dispose()
 {
 // make a copy
 Listener [] aTmpListeners = MyListeners.clone();

 // clear all listeners (against recursion)
 MyListeners.clear();

 // call all listeners
 EventObject aEvt = new EventObject();
 aEvt.xSource = this;
 for( i = 0; i <aTmpListeners.length; i++ )
 aTmpListeners[i].disposing( aEvt );
 }

addEventListener

Syntax

void addEventListener (
com::sun::star::lang::XEventListener xListener );

Description

adds an event listener to the object.

The broadcaster fires the disposing method of this listener if the XComponent::dispose method is called.

See also

XComponent::removeEventListener

removeEventListener

Syntax

void removeEventListener (
com::sun::star::lang::XEventListener aListener );

Description

removes an event listener from the listener list.

It is a "noop" if the specified listener is not registered.

See also

XComponent::addEventListener
Top of Page