Tharindu Madushanka wrote:
> Hi,
> I have been looking at how to notify when an event has been finished. Here
> what I have currently understood and I got some confusion.
> In order to get notified when login event finished, I think I have to do the
> following things.
> 
> 1. Create a LoginListener class that implements EventListener
Yes

> 2. Create object of DefaultObservationManager class
> (DefaultObservationManager implements ObservationManager)
No, the component manager will give you the right instance. You should 
read about this here: http://en.wikipedia.org/wiki/Inversion_of_control 
and here: 
http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents
All you need to do is declare a dependency on the ObservationManager 
component.

> 3. Define class UserLoginEvent similar to DocumentSaveEvent
Yes

> 4. call addListener() of ObjectManager interface (using
> DefaultObjectManager) with parameters - object of UserLoginEvent and
> reference to login listener.
Yes. This is done by the client that wants to be notified of login 
events, which is different from the class sending those events.

> 5. get reference to DefaultObjectManager instance
See the observation on 2.

> 6. call notify() of DefaultObjectManager instance when user successfully
> logged in, with parameters - object of UserLoginEvent, doc and context
Yes. The tricky part is knowing when this happened, or what is the code 
that knows that.

> 7. Implement notify() in LoginListener class.
Yes.

> Q. But I have several confusions when I looked at XWiki class,
> saveDocument()
> 1. Where does it create and add a listener to ObservationManager object??
> 2. And also it takes ObservationManager object from Util.getComponent()but
> where does this observationManager instance is added or set ?

The component manager takes care of instantiating objects. There are 
several component frameworks, from the heavier Spring and OSGi to the 
lightweight picocontainer and Guice. We're currently using Plexus for this.

So, com.xpn.xwiki.XWiki does not create an instance of 
ObservationManager, it gets one from the ComponentManager through the 
Util class. Normally, other components should just declare a dependency 
on the needed component, and the CM would automatically inject it, 
without any calls to Util.getComponent, but the XWiki class is not a 
component yet, so it is not managed by the component manager. The code 
inside the xwiki-core module is not made of components yet, while most 
of the other core modules are 100% components, with a few exceptions 
(xwiki-webdav and xwiki-rest).

> Please clarify me on what I currently understood and let me know if its the
> right steps to go with.

Yes, the steps are almost right. Good job so far.

-- 
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to