On Mon, Aug 10, 2009 at 2:51 PM, Vincent Massol <vincent(a)massol.net> wrote:
On Aug 10, 2009, at 1:31 PM, Sergiu Dumitriu wrote:
Vincent Massol wrote:
> On Aug 10, 2009, at 12:41 PM, Sergiu Dumitriu wrote:
>
>> Anamaria Stoica wrote:
>>> It looks like you can bind an instance to type in Guice. This is
>>> done either
>>> with Instance Bindings,
>>> @Provides Methods or Provider Bindings, depending on the complexity
>>> of the
>>> class.
>>> (
http://code.google.com/p/google-guice/wiki/Bindings)
>>>
>>> All bindings are defined in a class that extends AbstractModule,
>>> this would
>>> be
>>> XWSocialModule in my code (
>>>
https://svn.xwiki.org/svnroot/xwiki/sandbox/gsoc/opensocial/xwiki-social-op…
)
>>> .
>>>
>>>
>>> These modules are then passed as arguments to
>>> Guice.createInjector(), which
>>> builds the injector.
>>> In my application, the injector is build by
>>> GuiceServletContextListener (
>>>
http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/common/src/mai…
)
> This servlet takes the context parameters defined
in my web.xml;
> these are:
>
> <context-param>
> <param-name>guice-modules</param-name>
> <param-value>
> org.apache.shindig.common.PropertiesModule:
> org.apache.shindig.gadgets.DefaultGuiceModule:
> org.apache.shindig.gadgets.oauth.OAuthModule:
> org.apache.shindig.common.cache.ehcache.EhCacheModule:
> org.xwiki.opensocial.social.XWSocialModule
> </param-value>
> </context-param>
>
> <listener>
>
> <listener-
> class>org.xwiki.container.servlet.XWikiServletContextListener</
> listener-class>
> </listener>
>
> Now, all I need to do is bind the instance of PersonServiceXW after
> it has
> been initialized by XWiki's Component Manager.
> The binding will be done in XWSocialModule, using one of the
> instance
> binding methods (Instance Bindings,
> @Provides Methods or Provider Bindings).
>
> My questions are:
> 1. How do I make sure PersonServiceXW has been initialized already
> by the
> XWiki CM before binding it for Guice ?
List GuiceServletContextListener AFTER XWikiServletContextListener
in
web.xml. The servlet spec specifies that listeners are called in the
order they are encountered in web.xml, and
XWikiServletContextListener
is the one that starts our component manager.
For the future: we should not use other servlet context listener
other
than the xwiki one. We need it to init the CM but once this is done
everything else should be done with it.
So ideally you should instead create an EventListener that listen for
the application start event and initizalize shindig in there rather
than use an environment-specific servlet context listener.
I'm not sure, but I think that Shindig works this way, there's nothing
we can do about it.
Just checked
http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/common/src/mai…
It doesn't do much, just init Guice in a few lines.
The important part is creating the injector:
Injector injector = Guice.createInjector(Stage.PRODUCTION, modules);
I don't know how setting/registering the context part works though.
Thanks
-Vincent
> -Vincent
>
>>> 2. How do I get the initialized PersonServiceXW instance from
>>> XWSocialModule?
>> com.xpn.xwiki.web.Utils.getComponent(PersonServiceXW.class)
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs