You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christoph Ender <ch...@spellbreaker.org> on 2004/05/24 14:22:52 UTC
ClassCastException calling ServiceManager.lookup()
Hi all,
I'm trying to implement a simple Action that has to access a datasource.
The datasource itself is okay (queries via SQL Transformer work) and
I've
also successfully implemented a simple Action that doesn't use the
database.
When trying to lookup
org.apache.avalon.excalibur.datasource.DataSourceComponentSelector
via the ServiceManager I get a ClassCastException. I've copied over as
much
code I could get from examples, but it looks like I'm still doing
something wrong. I'll
post the relevant lines here:
public class AddUser extends AbstractAction implements Serviceable
{
private ServiceManager servicemanager = null;
private String datasourcename = "Test-DB";
public Map act (Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters params)
{
DataSourceComponent datasource = null;
ComponentSelector selector = null;
try
{
String key = DataSourceComponent.ROLE+"Selector" ;
if (servicemanager.hasService(key))
getLogger().warn("Service present.");
getLogger().warn("Getting Selector: '" + key + "'");
selector
= (ComponentSelector)(servicemanager.lookup
(DataSourceComponent.ROLE + "Selector"));
...
The last line that assigns the ComponentSelector to selector fails with
the
ClassCastExceoption. The ServiceManager is correctly initialized by the
service(ServiceManager) method (it gets called correctly) and the
ServiceManager
returns a "true" value when calling
hasService(org.apache.avalon.excalibur.datasource.DataSourceComponentSel
ector).
Although it's a bit longer I'll also attach the StackTrace here, maybe
it helps.
java.lang.ClassCastException
at de.easyclin.cocoon.actions.AddUser.act(AddUser.java:53)
at
org.apache.cocoon.components.treeprocessor.sitemap.ActTypeNode.invoke(Ac
tTypeNode.java:159)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:84)
at
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i
nvoke(PreparableMatchNode.java:165)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:107)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P
ipelineNode.java:162)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:107)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(
PipelinesNode.java:136)
at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:371)
at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:312)
at
org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(Moun
tNode.java:133)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:84)
at
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i
nvoke(PreparableMatchNode.java:165)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:107)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P
ipelineNode.java:162)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:107)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(
PipelinesNode.java:136)
at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:371)
at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:312)
at org.apache.cocoon.Cocoon.process(Cocoon.java:656)
at
org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:356)
at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationH
andler.java:294)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1776)
at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationCon
text.java:514)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1726)
at org.mortbay.http.HttpServer.service(HttpServer.java:879)
at
org.mortbay.http.HttpConnection.service(HttpConnection.java:790)
at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:952)
at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)
at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:196
)
at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
at
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:487)
Any help here would be greatly appreciated.
Thanks in advance,
Christoph.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: ClassCastException calling ServiceManager.lookup()
Posted by Christoph Ender <ch...@spellbreaker.org>.
> On 24.05.2004 14:22, Christoph Ender wrote:
>> [...]
>> When trying to lookup
>> org.apache.avalon.excalibur.datasource.DataSourceComponentSelector
>> via the ServiceManager I get a ClassCastException. I've copied over
>> as much
>> code I could get from examples, but it looks like I'm still doing
>> something wrong. I'll
>> post the relevant lines here:
>> [...]
>> The last line that assigns the ComponentSelector to selector fails
>> with the
>> ClassCastExceoption.
Am Dienstag, 25.05.04 um 01:05 Uhr schrieb Joerg Heinicke:
> A ServiceManager does not return a ComponentSelector, but a
> ServiceSelector, so you must cast to SS instead of CS. Even if the
> implementation class only implements CS this works, as a wrapper is
> build around it.
Thank you VERY much. I've been using a few lines from the BlobSource,
not
knowing that BlobSource doesn't work in the current version (just found
that on
http://archives.real-time.com/pipermail/cocoon-users/2004-March/
047774.html).
Again, thanks for your quick help.
Regards,
Christoph.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: ClassCastException calling ServiceManager.lookup()
Posted by Joerg Heinicke <jo...@gmx.de>.
On 24.05.2004 14:22, Christoph Ender wrote:
> I'm trying to implement a simple Action that has to access a datasource.
> The datasource itself is okay (queries via SQL Transformer work) and I've
> also successfully implemented a simple Action that doesn't use the
> database.
>
> When trying to lookup
> org.apache.avalon.excalibur.datasource.DataSourceComponentSelector
> via the ServiceManager I get a ClassCastException. I've copied over as
> much
> code I could get from examples, but it looks like I'm still doing
> something wrong. I'll
> post the relevant lines here:
...
> The last line that assigns the ComponentSelector to selector fails with
> the
> ClassCastExceoption. The ServiceManager is correctly initialized by the
> service(ServiceManager) method (it gets called correctly) and the
> ServiceManager
> returns a "true" value when calling
> hasService(org.apache.avalon.excalibur.datasource.DataSourceComponentSel
> ector).
A ServiceManager does not return a ComponentSelector, but a
ServiceSelector, so you must cast to SS instead of CS. Even if the
implementation class only implements CS this works, as a wrapper is
build around it.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org