Question about XThis

neo anderson <javadeveloper999-/[email protected]> Sat, 14 Nov 2009 11:13:45 -0800 (PST)
Newsgroups gmane.comp.java.beanshell.user
Message-ID <[email protected]>
I encounter a problem when obtaining Java object from beanshell script. The
error shows

java.lang.ClassCastException: bsh.XThis cannot be cast to
example.TransactionService

code snippet used to create that instance is

init_txservice(){

	import example.TransactionService;

	ts = new TransactionService(accountdao.initialize());

	return this;
}

txservice = init_txservice();

After re-reading the bsh docs, in `Scripted Objects '
(http://www.beanshell.org/manual/bshmanual.html ) it says that this can be
used to create scripted object using method closures. So it looks like my
code to create txservice is not correct; And when I switch to return ts ( ts
= new TransactionServcie(...) ) the error seems to go away. 

But now a question raises. I use `return this' in other method closure which
has similar way to return instance, but why other code snippet does not
throw the same error i.e. ClassCastException?

Other code like 

init_mock_datasource(){

	import org.clin4j.framework.domain.mock.Driver;
	
        d = "com.mockdb.jdbc.Driver";
        url = "jdbc:mockdb://localhost/ecommerce";
        id = "user";
        pass = "password";

	driver = new Driver(d, url, id, pass);

	return this;
}


when objecting java object using this code snippet, everything works well.

Does any reason can explain this problem? 

Thanks for help.
-- 
View this message in context: http://old.nabble.com/Question-about-XThis-tp26352954p26352954.html
Sent from the BeanShell - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july