Thursday, October 13, 2005

ADF : Class Casting Exception with ApplicationModule

1. I have written my Base applicationmodule(say, CatalogApplicationModuleImpl) extending ApplicationModuleImpl in my frameworkextension Project.
2. Then in the Model project which is dependent on this fwkextension project, I write my ApplicationModule(say, CatalogServiceImpl) extending CatalogApplicationModuleImpl.
3. Then I expose some of the methods of CatalogServiceImpl through a interface CatalogService to the DataAction classes in controller.
4. Now similar to AM, I've base controller CatalogDataForwardAction in fwkextension project which is extended by the actual dataaction classesin the viewController project. In the base controller i've the utility method:

protected CatalogApplicationModuleImpl getApplicationModule(String dataControlName,DataActionContext ctx)
{DCDataControl dc = ctx.getBindingContext().findDataControl(dataControlName);
if ((dc != null) && dc instanceof DCJboDataControl)
{return (CatalogApplicationModuleImpl) dc.getDataProvider();}
return null;}

5. This is the same method as in Toystore project of SMUENCH. The changeis I'm casting the CatalogServiceImpl(from dc.getDataProvider()) to itsbase class CatalogApplicationModuleImpl, so that I can invoke some methodson the base AM(CatalogApplicationModuleImpl) from the base controller(CatalogDataForwardAction). I need this since I'm writing some methods inthe base controller which need not be replicated in all the controllers implementing this class.
6. The problem is that the above casting fails. I understand that by the above I'm trying to cast a class to a Impl class which is not present in the client side(controller) and hence this exception. If that is the case, what is the wayI can access the methods in the base AM(CatalogApplicationModuleImpl)from the base controller(CatalogDataForwardAction)(these two classesare present in the fwkExtension project). i.e., how can I expose theCatalogApplicationModuleImpl to the controller(should I have to writethis Impl as implementing some interface and use that interface in thebase controller. If so, where should the base interface be created?
Thanks,Krishna.

No comments: