struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: ActionMapping/ActionConfig cast in
Date Sat, 25 Jan 2003 06:47:46 GMT

On Fri, 24 Jan 2003, Bueno Carlos  M wrote:

> Date: Fri, 24 Jan 2003 16:18:49 -0500
> From: Bueno Carlos  M <>
> Reply-To: Struts Users Mailing List <>
> To: "''" <>
> Subject: ActionMapping/ActionConfig cast in
> Howdy --
> I have what is I guess a noob question, but I simply can't figure out these
> seemingly important lines of code in
> 646        ActionMapping mapping = (ActionMapping)
> 647            moduleConfig.findActionConfig(path);
> This appears on lines 646-7 in both 1.02 and 1.1. ActionMapping is a
> *subclass* of ActionConfig, so how does this execute without throwing a
> ClassCastException? I can cast an ActionMapping as an ActionConfig but not
> the other way around. Yet, somehow, RequestProcessor seems to be doing just
> that. Below is some sample code to illustrate my question. Can anyone shed
> some light on this? It's too much majic for me.

It really is magic ... more so than I normally like to employ, but it was
necessary for backwards compatibility.

In Struts 1.0, the name of the JavaBean that stored stuff from an
<action> element was ActionMapping -- and, this method was passed as an
argument to every Action in the world.

In Struts 1.1, we migrated the configuration objects to a new package
(org.apache.struts.config), and gave them all names consistent with the
element name that they represented (ActionConfig in this case).  However,
it wasn't a good idea to break everyone's existing Actions by changing the
calling sequence, so ActionMapping is now a subclass of ActionConfig.

The secret to making this work is that the objects stored (in
ModuleConfig) for this collection really are ActionMappings and not just
ActionConfigs -- so, when you pull them back out, the cast works.  It also
works for custom user subclasses, as long as the user extends
ActionMapping and not ActionConfig.

>  -- Carlos


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message