Hi,
Thanks for the reply. I added more details to my question.
(message bellow)
On Sun, Aug 9, 2009 at 11:49 AM, Vincent Massol <vincent(a)massol.net> wrote:
Hi Anamaria,
On Aug 9, 2009, at 2:39 AM, Anamaria Stoica wrote:
Hi,
In order to integrate Shindig with the XWiki datastore, 4 interfaces
have to
be implemented: PersonService, AppDataService, ActivityService and
MessagesService (javadocs here [0]). To this end, I have created the
xwiki-social-opensocial module [1].
While implementing PersonService (PersonServiceXW - [2]), I have
encountered
the following problem:
As I needed to access the datastore, I also made PersonServiceXW a
XWiki
Component in order to gain access to the DocumentAccessBridge
Component.
BUT, here is the problem, the DocumentAccessBridge never gets
initialized
and at runtime is null.
The reason this might happen, as Sergiu suggested, is that Shindig
uses
Guice to bind the services implementations in its code, thus the
PersonServiceXW component never gets to be registered with XWiki's
Component
Manager.
There's no magic. If the component is registered in components.txt and
if you're looking it up to access it the DAB will get set properly.
So it's just that you're no looking it up and there's no way it can be
injected with dependencies.
The component is registered in components.txt, see
https://svn.xwiki.org/svnroot/xwiki/sandbox/gsoc/opensocial/xwiki-social-op….
I'm not sure how I am supposed to look my component up, I mean where. I do
look up DAB from my component, but not my component from another place.
My question is
how do I get data in and out XWiki's datastore from the
PersonService implementation, if I cannot use the
DocumentAccessBridge this
way?
Why couldn't you use it?
I did manage to use it with the @Requirement annotation, but as I said, it's
null.
Can it be registered to the Component Manager
somehow, or is there a
completely different way this could be achieved?
You're not provided enough information so that we can help you.
From what I read the solution is extra simple: just look up the
component using XWiki's component manager and you're done.
OK, I tried this with the following code:
EmbeddableComponentManager ecm = new EmbeddableComponentManager();
ecm.initialize(this.getClass().getClassLoader());
documentAccessBridge = ecm.lookup(DocumentAccessBridge.class);
if (!documentAccessBridge.exists("XWiki.Julia"))
{ do smth }
But I get a NPE when trying to get the context from DefaultExtension:
java.lang.NullPointerException
at
org.xwiki.context.internal.DefaultExecution.getContext(DefaultExecution.java:67)
at
com.xpn.xwiki.doc.DefaultDocumentAccessBridge.getContext(DefaultDocumentAccessBridge.java:58)
at
com.xpn.xwiki.doc.DefaultDocumentAccessBridge.exists(DefaultDocumentAccessBridge.java:148)
(see full stacktrace here
http://ana-s-private-labs.pastebin.com/m655cdf70)
Now the only question is what shinding requires. Does it accept an
instance of PersonService or does it take a class. In other words does
it perform the instantiation itself (the new) or can you pass to it an
already instantiated object?
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 ?
2. How do I get the initialized PersonServiceXW instance from XWSocialModule
?
*IF* (and if) it controls the instantiation then you
need to do it
differently:
- knowing guice you can configure if to inject an instance instead of
a class so that might be a direction to look into
- otherwise simply make you person service impl a standard POJO and
have a setDAB method that you call after it's been instantiated by
shindig somehow.
[snip]
Thanks
-Vincent
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
Thanks a lot,
Anamaria