On Dec 3, 2009, at 5:14 PM, Lewis Denizen wrote:

> Actually...  seems like componentDescriptor.addComponentDependency()  
> doesn't
> add the dependency either :-(  Just ends up being null when  
> retrieving it.
> Is there something that needs to be done before injection happens on  
> these
> objects?

Nothing to do. It just works normally. We're using that in some tests  
so it should work fine.

Basically you register your component with deps and next time you do a  
lookup() it'll get instantiated and its dependencies too.

-Vincent

>
> On Fri, Dec 4, 2009 at 12:34 AM, Lewis Denizen <[email protected]>  
> wrote:
>
>> Thanks Vincent!  That's exactly what I needed :-)  Just one more  
>> question,
>> though..  Is it possible to inject dependencies by using the  
>> attributes
>> defined within the class then?  Right now, using the
>> DefaultComponentDescriptor, I can inject dependencies using:
>>
>> componentDescriptor.addComponentDependency(QueryManager.class,  
>> "default")
>>
>> but would be nice if it could auto-inject into something like:
>>
>>
>> class UserXWQLDAO implements UserDAO
>> {
>>    @Requirement
>>    def QueryManager queryManager
>>    //...
>> }
>>
>> Thanks again for a great wiki!
>>
>>
>> On Wed, Dec 2, 2009 at 3:56 AM, Vincent Massol <[email protected]>  
>> wrote:
>>
>>> Hi Lewis,
>>>
>>> On Dec 1, 2009, at 7:12 PM, Lewis Denizen wrote:
>>>
>>>> Hi xwiki-users,
>>>>
>>>> I'm trying to bootstrap a component from the wiki itself (via
>>>> Groovy).  I
>>>> have an interface defined as follows:
>>>>
>>>> // This is the text inside the User.UserDAO document
>>>> {{groovy}}
>>>> interface UserDAO
>>>> {
>>>>   def ROLE = UserDAO.class.name
>>>>
>>>>   /**
>>>>    * Returns the current user name.
>>>>    */
>>>>   def getUserName()
>>>>
>>>>   /**
>>>>    * Returns the current user's password
>>>>    */
>>>>   def getPassword()
>>>> }
>>>> {{/groovy}}
>>>>
>>>> I also have a dummy implementation defined as follows:
>>>>
>>>> // This is the text inside the User.UserXWQLDAO document
>>>> {{include document="User.UserDAO" /}}
>>>> {{groovy}}
>>>> import org.xwiki.component.annotation.Component
>>>> import org.xwiki.component.annotation.Requirement
>>>> import org.xwiki.component.descriptor.DefaultComponentDescriptor
>>>> import org.xwiki.query.Query
>>>> import org.xwiki.query.QueryManager
>>>>
>>>> import com.xpn.xwiki.web.Utils
>>>>
>>>> @Component(roles = [ UserDAO.class ])
>>>> class UserXWQLDAO implements UserDAO
>>>> {
>>>>   @Requirement
>>>>   def QueryManager queryManager
>>>>
>>>>   /**
>>>>    * Returns the current user name.
>>>>    */
>>>>   def getUserName() {
>>>>       return "bleh"
>>>>   }
>>>>
>>>>   /**
>>>>    * Returns the current user's password
>>>>    */
>>>>   def getPassword() {
>>>>       return "bleh"
>>>>   }
>>>> }
>>>>
>>>> if(!Utils.componentManager.hasComponent(UserDAO.class))
>>>> {
>>>>   def componentDescriptor = new DefaultComponentDescriptor()
>>>>   componentDescriptor.setImplementation(UserDAO.class)
>>>>
>>>>   Utils.componentManager.registerComponent(componentDescriptor, new
>>>> UserXWQLDAO())
>>>> }
>>>> {{/groovy}}
>>>>
>>>> The first problem I ran into was that Groovy 1.6.5 ran into
>>>> IncompatibleClassChangeErrors (
>>> http://jira.codehaus.org/browse/GROOVY-3830
>>>> ).
>>>> Upgrading to 1.6.6 fixed this issue.  But, then I ran into a NPE:
>>>>
>>>> *exception*
>>>>
>>>> javax.servlet.ServletException: Failed to initialize Request/
>>>> Response or Session
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki 
>>>> .web.XWikiAction.initializeContainerComponent(XWikiAction.java:
>>>> 391)
>>>>
>>>> com
>>>> .xpn.xwiki.web.XWikiAction.initializeXWikiContext(XWikiAction.java:
>>>> 372)
>>>>      com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:112)
>>>>
>>>> org
>>>> .apache
>>>> .struts
>>>> .action 
>>>> .RequestProcessor.processActionPerform(RequestProcessor.java:
>>>> 431)
>>>>
>>>> org
>>>> .apache 
>>>> .struts.action.RequestProcessor.process(RequestProcessor.java:
>>>> 236)
>>>>       
>>>> org.apache.struts.action.ActionServlet.process(ActionServlet.java:
>>>> 1196)
>>>>
>>> org.apache.struts.action.ActionServlet.doPost(ActionServlet.java: 
>>> 432)
>>>>      javax.servlet.http.HttpServlet.service(Unknown Source)
>>>>      javax.servlet.http.HttpServlet.service(Unknown Source)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki
>>>> .wysiwyg
>>>> .server.filter.ConversionFilter.doFilter(ConversionFilter.java:152)
>>>>      com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:119)
>>>>
>>>> com
>>>> .xpn 
>>>> .xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:
>>>> 68)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki
>>>> .web
>>>> .SavedRequestRestorerFilter 
>>>> .doFilter(SavedRequestRestorerFilter.java:
>>>> 295)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki
>>>> .web
>>>> .SetCharacterEncodingFilter 
>>>> .doFilter(SetCharacterEncodingFilter.java:
>>>> 112)
>>>>
>>>> *root cause*
>>>>
>>>> org.xwiki.container.servlet.ServletContainerException: Failed to
>>>> initialize request
>>>>
>>>> org
>>>> .xwiki
>>>> .container
>>>> .servlet
>>>> .internal
>>>> .DefaultServletContainerInitializer
>>>> .initializeRequest(DefaultServletContainerInitializer.java:98)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki 
>>>> .web.XWikiAction.initializeContainerComponent(XWikiAction.java:
>>>> 387)
>>>>
>>>> com
>>>> .xpn.xwiki.web.XWikiAction.initializeXWikiContext(XWikiAction.java:
>>>> 372)
>>>>      com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:112)
>>>>
>>>> org
>>>> .apache
>>>> .struts
>>>> .action 
>>>> .RequestProcessor.processActionPerform(RequestProcessor.java:
>>>> 431)
>>>>
>>>> org
>>>> .apache 
>>>> .struts.action.RequestProcessor.process(RequestProcessor.java:
>>>> 236)
>>>>       
>>>> org.apache.struts.action.ActionServlet.process(ActionServlet.java:
>>>> 1196)
>>>>
>>> org.apache.struts.action.ActionServlet.doPost(ActionServlet.java: 
>>> 432)
>>>>      javax.servlet.http.HttpServlet.service(Unknown Source)
>>>>      javax.servlet.http.HttpServlet.service(Unknown Source)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki
>>>> .wysiwyg
>>>> .server.filter.ConversionFilter.doFilter(ConversionFilter.java:152)
>>>>      com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:119)
>>>>
>>>> com
>>>> .xpn 
>>>> .xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:
>>>> 68)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki
>>>> .web
>>>> .SavedRequestRestorerFilter 
>>>> .doFilter(SavedRequestRestorerFilter.java:
>>>> 295)
>>>>
>>>> com
>>>> .xpn
>>>> .xwiki
>>>> .web
>>>> .SetCharacterEncodingFilter 
>>>> .doFilter(SetCharacterEncodingFilter.java:
>>>> 112)
>>>>
>>>> *root cause*
>>>>
>>>> java.lang.NullPointerException
>>>>
>>>>
>>>> Haven't investigated any further than this, but has anyone
>>>> successfully
>>>> created components completely within a wiki document?  That would
>>>> just be so
>>>> cool!  Great work!
>>>
>>> Yes, I've done that several times.
>>>
>>> Here's an example:
>>>
>>> http://svn.xwiki.org/svnroot/xwiki/platform/xwiki-applications/trunk/ircbot/src/main/resources/IRC/JiraBotlet.xml
>>> (search for registerComponent).
>>>
>>> Hope it helps,
>>> -Vincent
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to