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 2004/11/29 11:23:28 UTC

Calling components from java

Hi,

I am trying to call a cocoon component from within a Java class - is 
this possible?

 From flow I use...

var my_component = cocoon.getComponent(Packages.MyComponent.ROLE);

... which works great. I have tried the following in my java class...

CocoonComponentManager manager = new CocoonComponentManager();
MyComponent my_component = (MyComponent) 
manager.lookup(MyComponent.ROLE);

- this results in  "java.lang.NullPointerException"

... when I try:

DefaultComponentManager = new DefaultComponentManager();
MyComponent my_component = (MyComponent) 
manager.lookup(MyComponent.ROLE);

I get " org.apache.avalon.framework.component.ComponentException: 
Unable to provide implementation. (key [MyComponent])"

Can anyone point me to samples of how I can access Cocoon components 
(declared in cocoon.xconf) in my java classes?

Thanks,

Robin


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


Re: Calling components from java

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

Thanks for the clarification...

Robin

On 29 Nov 2004, at 17:53, Ralph Goers wrote:

> Robin Wyles said:
>> Jorg,
>>
>> On 29 Nov 2004, at 12:20, Jorg Heymans wrote:
>>
>>> It is my understanding that you can only call / lookup components 
>>> from
>>> other components (i'ld love to be proven wrong on this btw).
>>> Write a component that implements the serviceable interface and use
>>> that servicemanager to lookup.
>>>
>>>
>>
>> That is what I suspected :-( Thanks for the info...
>>
>> Robin
>>
>
> That is not strictly true.  You simply have to have access to the
> ServiceManager.  Implementing Serviceable means you will provide a
> service() method that will cause the container to call your component 
> to
> give it the ServiceManager (assuming your component is configured).  
> This
> is by far the easiest way to do this, but if you have access to some 
> other
> component that implements Serviceable you can call a method in it to
> retrieve its ServiceManager reference.
>
> Ralph
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>


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


Re: Calling components from java

Posted by Ralph Goers <Ra...@dslextreme.com>.
Robin Wyles said:
> Jorg,
>
> On 29 Nov 2004, at 12:20, Jorg Heymans wrote:
>
>> It is my understanding that you can only call / lookup components from
>> other components (i'ld love to be proven wrong on this btw).
>> Write a component that implements the serviceable interface and use
>> that servicemanager to lookup.
>>
>>
>
> That is what I suspected :-( Thanks for the info...
>
> Robin
>

That is not strictly true.  You simply have to have access to the
ServiceManager.  Implementing Serviceable means you will provide a
service() method that will cause the container to call your component to
give it the ServiceManager (assuming your component is configured).  This
is by far the easiest way to do this, but if you have access to some other
component that implements Serviceable you can call a method in it to
retrieve its ServiceManager reference.

Ralph


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


Re: Calling components from java

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

On 29 Nov 2004, at 12:20, Jorg Heymans wrote:

> It is my understanding that you can only call / lookup components from 
> other components (i'ld love to be proven wrong on this btw).
> Write a component that implements the serviceable interface and use 
> that servicemanager to lookup.
>
>

That is what I suspected :-( Thanks for the info...

Robin


> HTH
> Jorg
>
> Robin Wyles wrote:
>> Hi,
>> I am trying to call a cocoon component from within a Java class - is 
>> this possible?
>>  From flow I use...
>> var my_component = cocoon.getComponent(Packages.MyComponent.ROLE);
>> ... which works great. I have tried the following in my java class...
>> CocoonComponentManager manager = new CocoonComponentManager();
>> MyComponent my_component = (MyComponent) 
>> manager.lookup(MyComponent.ROLE);
>> - this results in  "java.lang.NullPointerException"
>> ... when I try:
>> DefaultComponentManager = new DefaultComponentManager();
>> MyComponent my_component = (MyComponent) 
>> manager.lookup(MyComponent.ROLE);
>> I get " org.apache.avalon.framework.component.ComponentException: 
>> Unable to provide implementation. (key [MyComponent])"
>> Can anyone point me to samples of how I can access Cocoon components 
>> (declared in cocoon.xconf) in my java classes?
>> Thanks,
>> Robin
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>


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


Re: Calling components from java

Posted by Jorg Heymans <jh...@domek.be>.
It is my understanding that you can only call / lookup components from 
other components (i'ld love to be proven wrong on this btw).
Write a component that implements the serviceable interface and use that 
servicemanager to lookup.


HTH
Jorg

Robin Wyles wrote:
> Hi,
> 
> I am trying to call a cocoon component from within a Java class - is 
> this possible?
> 
>  From flow I use...
> 
> var my_component = cocoon.getComponent(Packages.MyComponent.ROLE);
> 
> ... which works great. I have tried the following in my java class...
> 
> CocoonComponentManager manager = new CocoonComponentManager();
> MyComponent my_component = (MyComponent) manager.lookup(MyComponent.ROLE);
> 
> - this results in  "java.lang.NullPointerException"
> 
> ... when I try:
> 
> DefaultComponentManager = new DefaultComponentManager();
> MyComponent my_component = (MyComponent) manager.lookup(MyComponent.ROLE);
> 
> I get " org.apache.avalon.framework.component.ComponentException: Unable 
> to provide implementation. (key [MyComponent])"
> 
> Can anyone point me to samples of how I can access Cocoon components 
> (declared in cocoon.xconf) in my java classes?
> 
> Thanks,
> 
> Robin


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