[Building Sakai] ClassCastException: Cannot cast org.sakaiproject.site.impl.BaseSite (id=260) to org.sakaiproject.site.impl.BaseSite

DAVID ROLDAN MARTINEZ darolmar at upvnet.upv.es
Wed Mar 11 01:32:49 PDT 2009


Hi Jose,

Maybe what you have to do it to use a site property instead of extending BaseSite. This, in fact, will make easier to maintain your application in the future.

Hope this helps.

David

-----Mensaje original-----
De: sakai-dev-bounces at collab.sakaiproject.org [mailto:sakai-dev-bounces at collab.sakaiproject.org] En nombre de Matthew Buckett
Enviado el: martes, 10 de marzo de 2009 22:12
Para: Jose Morell
CC: sakai-dev at collab.sakaiproject.org
Asunto: Re: [Building Sakai] ClassCastException: Cannot cast org.sakaiproject.site.impl.BaseSite (id=260) to org.sakaiproject.site.impl.BaseSite

On Tue, Mar 10, 2009 at 5:28 PM, Jose Morell
<jose.morell.at.sakai at gmail.com> wrote:
> Hi Matthew,
>
> I have a problem with this.
>
> I'm working in the site-manage-tool.
>
> I need to extend the Site class with another attribute visitedTime.
>
> I have created VisitedSiteImpl that extends from BaseSite and implements
> VisitedSited (that extends from Site).

Just to check, so you have created these classes in the site-manage-tool?

> The first problem with this, is that if I add the kernel-impl dependency
> with <scope>provided</scope>, then the classes from kernel-impl there isn't
> found in execution time, but if I add the dependency with the default scope,

The kernel-impl artifact shouldn't be depended on by tools, this is so
that the implementation can change without breaking all tools, which
should only be depending on the APIs. You tools shouldn't have any
knowledge of kernel-impl and in the standard deployment, the
classloader setup prevents you from accessing the implementations from
the tools (this is a deliberate design decision), and hence the reason
for the error you get.

> then the kernel-impl-1.0.jar is in components, and in the deployed
> site-manage, and I get the ClassCastException of the first mail.

This is because the tool and the component now have a copy of the
BaseSite class, and they have different classloaders which means you
cannot case from one to the other. Putting kernel-impl into a webapp
is always going to break tools.

The solution is not to extends BaseSite in a tool, either move the
concept of VisitedSite into the kernel or change your class design to
just depend on the Site interface.

-- 
  Matthew Buckett
_______________________________________________
sakai-dev mailing list
sakai-dev at collab.sakaiproject.org
http://collab.sakaiproject.org/mailman/listinfo/sakai-dev

TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"


More information about the sakai-dev mailing list