Re: Question about XThis
Alexey Zinger <inline_four-/[email protected]> Sat, 14 Nov 2009 18:31:09 -0800 (PST)
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <[email protected]> |
In the second example, what are you casting the object you get from BeanShell to? Alexey 2001 Honda CBR600F4i (CCS) 2002 Suzuki Bandit 1200S 1992 Kawasaki EX500 http://azinger.blogspot.com http://bsheet.sourceforge.net http://wcollage.sourceforge.net ________________________________ From: neo anderson <javadeveloper999-/[email protected]> To: beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Sent: Sat, November 14, 2009 2:13:45 PM Subject: [Beanshell-users] Question about XThis 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 _______________________________________________ Beanshell-users mailing list Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/beanshell-users ------------------------------------------------------------------------------ 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