Difference between revisions of "Documentation/DevGuide/WritingUNO/XComponent"
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Documentation/Developers Guide/Writing UNO Components) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/WritingUNO/XInitialization | |NextPage=Documentation/DevGuide/WritingUNO/XInitialization | ||
}} | }} | ||
+ | {{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/{{SUBPAGENAME}}}} | ||
{{DISPLAYTITLE:XComponent}} | {{DISPLAYTITLE:XComponent}} | ||
<!--<idltopic>com.sun.star.lang.XComponent</idltopic>--> | <!--<idltopic>com.sun.star.lang.XComponent</idltopic>--> | ||
Line 12: | Line 13: | ||
The interface <code>XComponent</code> specifies these operations: | The interface <code>XComponent</code> specifies these operations: | ||
− | < | + | <syntaxhighlight lang="idl"> |
// module com::sun::star::lang | // module com::sun::star::lang | ||
Line 21: | Line 22: | ||
void removeEventListener( [in] XEventListener aListener ); | void removeEventListener( [in] XEventListener aListener ); | ||
}; | }; | ||
− | </ | + | </syntaxhighlight> |
<code>XComponent</code> uses the interface <idl>com.sun.star.lang.XEventListener</idl>: | <code>XComponent</code> uses the interface <idl>com.sun.star.lang.XEventListener</idl>: | ||
− | < | + | <syntaxhighlight lang="idl"> |
// module com::sun::star::lang | // module com::sun::star::lang | ||
interface XEventListener: com::sun::star::uno::XInterface | interface XEventListener: com::sun::star::uno::XInterface | ||
Line 29: | Line 30: | ||
void disposing( [in] com::sun::star::lang::EventObject Source ); | void disposing( [in] com::sun::star::lang::EventObject Source ); | ||
}; | }; | ||
− | </ | + | </syntaxhighlight> |
=== Disposing of an XComponent === | === Disposing of an XComponent === | ||
Latest revision as of 17:20, 23 December 2020
If the implementation holds a reference to another UNO object internally, there may be a problem of cyclic references that might prevent your component and the other object from being destroyed forever. If it is probable that the other object may hold a reference to your component, implement com.sun.star.lang.XComponent that contains a method dispose()
. Chapter Lifetime of UNO Objects discusses the intricacies of this issue.
Supporting XComponent
in a C++ or Java component is simple, because there are helper classes to derive from that implement XComponent
. The following code is an example if you must implement XComponent
manually.
The interface XComponent
specifies these operations:
// module com::sun::star::lang interface XComponent: com::sun::star::uno::XInterface { void dispose(); void addEventListener( [in] XEventListener xListener ); void removeEventListener( [in] XEventListener aListener ); };
XComponent
uses the interface com.sun.star.lang.XEventListener:
// module com::sun::star::lang interface XEventListener: com::sun::star::uno::XInterface { void disposing( [in] com::sun::star::lang::EventObject Source ); };
Disposing of an XComponent
The idea behind XComponent
is that the object is instantiated by a third object that makes the third object the owner of first object. The owner is allowed to call dispose()
. When the owner calls dispose()
at your object, it must do three things:
- Release all references it holds.
- Inform registered XEventListeners that it is being disposed of by calling their method
disposing()
. - Behave as passive as possible afterwards. If the implementation is called after being disposed, throw a com.sun.star.lang.DisposedException if you cannot fulfill the method specification.
That way the owner of XComponent
objects can dissolve a possible cyclic reference.
Content on this page is licensed under the Public Documentation License (PDL). |