struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aur Gal <...@dovesolutions.com>
Subject ClassCastException again
Date Fri, 20 Oct 2000 14:36:34 GMT
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



Mime
View raw message