You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Carlos Maté <cm...@gmail.com> on 2005/11/16 11:22:42 UTC

javaflow connection

Hi.
I'm using cocoon 2.1.7. In a javaflow class. I have this code:
*

if
*( getComponent(DataSourceComponent.ROLE +
"Selector")*instanceof*ComponentSelector);

{

ComponentSelector selector = (ComponentSelector) getComponent(
DataSourceComponent.ROLE + "Selector");

}

*But I obtain:*

ERROR (2005-11-16) 09:38.*57*:718 [sitemap.handled-errors]
(/*mysis/**login*.do)
http-8080-Processor25/ErrorHandlerHelper:
java.lang.ClassCastException

*¿How I can obtain a BD connection?*

*In a flowscript I wrote:*

var selector = cocoon.getComponent(Packages.*org*.apache.avalon.excalibur.datasource.DataSourceComponent.ROLE
+ "Selector");
var datasource = selector.select("NameOfPool");
var connection = datasource.getConnection();

*But I don't know how to do this in a java flow.*

*Thanks.*

Re: javaflow connection

Posted by Ralph Goers <Ra...@dslextreme.com>.

Carlos Maté wrote:

> Finally I sow the exact class.
> And I got the connection: 
>
> WrapperServiceSelector selector =(WrapperServiceSelector) 
> getComponent(DataSourceComponent.ROLE +
>
> "Selector");
>
> DataSourceComponent dataSource = (DataSourceComponent) selector.select(
>
> "connection");
>
> Connection conexion = dataSource.getConnection();
>
> Thank you very much.
>   

This makes sense, however you should use

ServiceSelector selector = 
(ServiceSelector)getComponent(DataSourceComponent.ROLE + "Selector");

What I don't under is why your instanceof test returned true.

Ralph

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


Re: javaflow connection

Posted by Carlos Maté <cm...@gmail.com>.
Finally I sow the exact class.
And I got the connection:

WrapperServiceSelector selector =(WrapperServiceSelector) getComponent(
DataSourceComponent.ROLE + "Selector");

DataSourceComponent dataSource = (DataSourceComponent) selector.select(
"connection");

Connection conexion = dataSource.getConnection();
Thank you very much.



 On 11/16/05, Torsten Curdt <tc...@apache.org> wrote:
>
> > Hi.
> > I'm using cocoon 2.1.7. In a javaflow class. I have this code:
> > if
> >
> > ( getComponent(DataSourceComponent.ROLE + "Selector")instanceof
> > ComponentSelector);
> > {
> >
> >
> > ComponentSelector selector = (ComponentSelector) getComponent
> > (DataSourceComponent.ROLE + "Selector");
> > }
> >
> > But I obtain:
> >
> > ERROR (2005-11-16) 09:38.57:718 [sitemap.handled-errors] (/
> > mysis/login.do) http-8080-Processor25/ErrorHandlerHelper:
> > java.lang.ClassCastException
>
> Hm... try something like this (from the top of my head)
>
> Object o = getComponent(DataSourceComponent.ROLE + "Selector");
>
> System.out.println(o.getClass() + "@" + o.getClass().getClassLoader());
> System.out.println(ComponentSelector.class + "@" +
> ComponentSelector.class.getClassLoader());
>
> That way you should see the exact class being returned as well
> as the classloader that has loaded it.
>
> > But I don't know how to do this in a java flow.
>
> Just like you would do in an action.
>
> HTH
>
> cheers
> --
> Torsten
>
>
>
>
>

Re: javaflow connection

Posted by Torsten Curdt <tc...@apache.org>.
> Hi.
> I'm using cocoon 2.1.7. In a  javaflow class. I have this code:
> if
>
> ( getComponent(DataSourceComponent.ROLE + "Selector")instanceof  
> ComponentSelector);
> {
>
>
> ComponentSelector selector = (ComponentSelector) getComponent 
> (DataSourceComponent.ROLE + "Selector");
> }
>
> But I obtain:
>
> ERROR   (2005-11-16) 09:38.57:718   [sitemap.handled-errors] (/ 
> mysis/login.do) http-8080-Processor25/ErrorHandlerHelper:
> java.lang.ClassCastException

Hm... try something like this (from the top of my head)

Object o = getComponent(DataSourceComponent.ROLE + "Selector");

System.out.println(o.getClass() + "@" + o.getClass().getClassLoader());
System.out.println(ComponentSelector.class + "@" +  
ComponentSelector.class.getClassLoader());

That way you should see the exact class being returned as well
as the classloader that has loaded it.

> But I don't know how to do this in a java flow.

Just like you would do in an action.

HTH

cheers
--
Torsten