You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Robin Wyles <ro...@robinwyles.com> on 2008/05/22 13:57:47 UTC

C2.2 Avalon/Spring component look up

Hi All,

What I hope are some simple questions...

1. What is the correct/preferred way to look up Avalon components  
from within a Spring bean?

2. How best to obtain the WebApplicationContext from within a java  
class?

Pointers to classes in the Cocoon source that do this are welcome!

Thanks,

Robin

Re: C2.2 Avalon/Spring component look up

Posted by Robin Wyles <ro...@robinwyles.com>.
Grzegorz,

On 22 May 2008, at 13:31, Grzegorz Kossakowski wrote:

> Robin Wyles pisze:
>> In this particular case it's an extension of the  
>> JackrabbitRepository from the JCR block.
>> I have it defined like so in my xconf:
>> <components>
>>     <include src="resource://org/apache/cocoon/jcr/jcr.roles"/>
>>     <jcr-repository class="com.jac.james.library.JamesRepository">
>>         <credentials login="guest" password="guest"/>
>>         <home src="file://users/robinwyles/work/james-data/james- 
>> library/repos"/>
>>         <configuration src="resource://META-INF/cocoon/jackrabbit/ 
>> repository.xml"/>
>>         <workspace name="james-library"/>
>>         <nodetypes src="resource://META-INF/cocoon/jackrabbit/ 
>> nodetypes.cnd"/>
>>     </jcr-repository>
>> </components>
>> .. The included jcr.roles looks like this...
>> <role-list>
>>   <role name="javax.jcr.Repository"
>>         shorthand="jcr-repository"/>
>> </role-list>
>
> Hmmm, not entirely sure in this case but have you tried:
> javax.jcr.Repository/com.jac.james.library.JamesRepository

That did not work, but using simply "javax.jcr.Repository"  as the  
bean ID did.
>
> I believe it should work.
>
>>> Is this class a Spring bean itself?
>> It might be, or it might not be :) This was a more general  
>> question really... Most likely I guess it will be a Spring bean.
>
> You should implement BeanFactoryAware interface, see:
> http://static.springframework.org/spring/docs/2.5.x/reference/ 
> beans.html#beans-factory-method-injection
>

Great!

Many thanks...

Robin


Re: C2.2 Avalon/Spring component look up

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Robin Wyles pisze:
> 
> In this particular case it's an extension of the JackrabbitRepository 
> from the JCR block.
> 
> I have it defined like so in my xconf:
> 
> <components>
>     <include src="resource://org/apache/cocoon/jcr/jcr.roles"/>
>     <jcr-repository class="com.jac.james.library.JamesRepository">
>         <credentials login="guest" password="guest"/>
>         <home 
> src="file://users/robinwyles/work/james-data/james-library/repos"/>
>         <configuration 
> src="resource://META-INF/cocoon/jackrabbit/repository.xml"/>
>         <workspace name="james-library"/>
>         <nodetypes 
> src="resource://META-INF/cocoon/jackrabbit/nodetypes.cnd"/>
>     </jcr-repository>
> </components>
> 
> .. The included jcr.roles looks like this...
> 
> <role-list>
>   <role name="javax.jcr.Repository"
>         shorthand="jcr-repository"/>
> </role-list>

Hmmm, not entirely sure in this case but have you tried:
javax.jcr.Repository/com.jac.james.library.JamesRepository

I believe it should work.

>> Is this class a Spring bean itself?
> 
> It might be, or it might not be :) This was a more general question 
> really... Most likely I guess it will be a Spring bean.

You should implement BeanFactoryAware interface, see:
http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-method-injection

-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: C2.2 Avalon/Spring component look up

Posted by Robin Wyles <ro...@robinwyles.com>.
Hi Grzegrorz!

On 22 May 2008, at 13:07, Grzegorz Kossakowski wrote:

> Robin Wyles pisze:
>> Hi All,
>
> Hi Robin!
>
>> What I hope are some simple questions...
>> 1. What is the correct/preferred way to look up Avalon components  
>> from within a Spring bean?
>
> Use dependency injection as they components were plain Spring  
> beans. This will work fine.
>
> You may wonder what's bean id in such case. There is some generic  
> template for Avalon-based components ids but I guess it will be  
> simpler if you tell me what components you are interested in.

In this particular case it's an extension of the JackrabbitRepository  
from the JCR block.

I have it defined like so in my xconf:

<components>
     <include src="resource://org/apache/cocoon/jcr/jcr.roles"/>
     <jcr-repository class="com.jac.james.library.JamesRepository">
         <credentials login="guest" password="guest"/>
         <home src="file://users/robinwyles/work/james-data/james- 
library/repos"/>
         <configuration src="resource://META-INF/cocoon/jackrabbit/ 
repository.xml"/>
         <workspace name="james-library"/>
         <nodetypes src="resource://META-INF/cocoon/jackrabbit/ 
nodetypes.cnd"/>
     </jcr-repository>
</components>

.. The included jcr.roles looks like this...

<role-list>
   <role name="javax.jcr.Repository"
         shorthand="jcr-repository"/>
</role-list>


>
>> 2. How best to obtain the WebApplicationContext from within a java  
>> class?
>
> Is this class a Spring bean itself?

It might be, or it might not be :) This was a more general question  
really... Most likely I guess it will be a Spring bean.

Thanks as always!

Robin



>
>
> -- 
> Grzegorz Kossakowski
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>


Re: C2.2 Avalon/Spring component look up

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Robin Wyles pisze:
> Hi All,

Hi Robin!

> What I hope are some simple questions...
> 
> 1. What is the correct/preferred way to look up Avalon components from 
> within a Spring bean?

Use dependency injection as they components were plain Spring beans. This will work fine.

You may wonder what's bean id in such case. There is some generic template for Avalon-based 
components ids but I guess it will be simpler if you tell me what components you are interested in.

> 2. How best to obtain the WebApplicationContext from within a java class?

Is this class a Spring bean itself?


-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org