You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Aur Gal <Au...@dovesolutions.com> on 2000/10/20 16:36:34 UTC

ClassCastException again

Hello,

I am trying to extend my ActionMapping functionality with a couple of new
attributes and their corresponding get set methods.

The problem I am trying to solve:

I need support for permission checking, and initialization. 

What I tried to do was: 

add the attributes to my extension of SessionActionMapping and then invoke
the methods inside an overriden ActionServlet.proccess() method. However,
ActionServlet creates variable "mapping" as an ActionMapping interface which
does not define the added methods. I tried creating a new interface which
does define the new methods and then cast "mapping" into it and this is
where I get the ClassCastException. I have solved it temporarily, for the
sake of continued developement, by adding the methods to the the actual
ActionMapping interface and the implementations to ActionMappingBase.

is there any way to get around this exception and extend ActionMapping's
functionality in an elegant manner?

here are some code snippets:

action.xml
	<action    path="viewProfile"
		initform="yes"
		permissions="9"
		formAttribute="ProfileForm"
	    	formClass="com.prizehub.formbeans.ProfileForm">
		actionClass="com.prizehub.action.NullAction">

		<forward name="success" path="/Profile.jsp?action=profile"/>
		<forward name="faliure" path="/Error.jsp?err=cantinit"/>
	</action> 

added methods and attributes ( in ActionMappingBase )
	/**
	*specifies what permission levels this mapping accepts
	*/
	private String permissions="0";

	public void setPermissions(String value)
	{
		permissions=value;
	}

	public String getPermissions()
	{
		return permissions;
	}

	public boolean permit(String perm)
	{
		boolean s=permissions.equals("0");

		if (!s)
		{
			for (int i=0;i<perm.length() ;i++ )
			{
				if (permissions.indexOf(perm.charAt(i))>-1)
				{
					s=true;
					break;
				}
			}
		}

		return s;
	}

	/**
	*determines if to init the mapping's underlying form. Set to true if
attribute is found.
	*/
	protected String initForm="no";

	public void setInitform(String value)
	{
		initForm="yes";
	}

	public String getInitform()
	{ return initForm; }


attempted usage in extension of ActionServlet

// Look up the corresponding mapping
ActionMapping mapping =processMapping(path);

//invoke the method permit(String perm)
(MyImplementationOfMapping)mapping.permit("124");

thanks

Aur Gal
Dove Solutions
515-469-5877 x126



Re: ClassCastException again

Posted by Christophe Thiebaud <ct...@stylo.it>.
On Fri, 20 Oct 2000, you wrote:
> (...) However,
> ActionServlet creates variable "mapping" as an ActionMapping interface which
> does not define the added methods. 

did you try to add a className attribute to the action xml element ?

The Digester documentation says "(...) If the <action> element includes an
attribute named className, the value of that attribute must be the fully
qualified Java class name of the object to be created. Otherwise, the class
name is taken from the mappingClass instance variable."

Christophe