You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Daniel McOrmond <dm...@gmail.com> on 2005/02/22 17:10:18 UTC

Java Class Casting within Flow

Here's a simple example:


importClass( Packages.com.company.GenericObject );
importClass( Packages.com.company.SpecificObject );
importClass( Packages.com.company.ObjectLoaderUtil );

function doSomethingUseful() {
  var loader = cocoon.createObject( ObjectLoaderUtil );
  var myObject = loader.getGenericObject();
}



Suppose I wanted to cast the GenericObject to a SpecificObject, like this:

  var myObject = (SpecificObject) loader.getGenericObject();



Obviously there are other ways I could handle this. But I just
wondered, is there a way to do this within flow?

-Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Java Class Casting within Flow

Posted by Brian Vargas <ar...@procrastinators.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Daniel and Leszek,

> AFAIU rhino (flowscript engine) uses reflection to resolve methods and
> fields. It doesn't really matter that you pass some narrow interface
> because reflection will expose full underlying object functionality.

Rhino is an implementation of ECMAScript (a.k.a JavaScript).  Such
casting is not necessary because ECMAScript is not a statically-typed
language.  The Rhino implemenation is capable of wrapping plain old Java
objects and exposing them as script objects, almost certainly using
reflection.

You should check out the spec some time.  It's a boring read, but some
of the higher-level things you can do with ECMAScript are really cool.

http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: What is this? http://pgp.ardvaark.net

iD8DBQFCHJx83YdPnMKx1eMRA7sTAJ0eqmdovY8rNdgVnLznvQhVG2RJpACfblqm
+ggquWl2uDhDUb1Ha6+p7d8=
=WXjS
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Java Class Casting within Flow

Posted by Leszek Gawron <lg...@apache.org>.
Daniel McOrmond wrote:
> Just a follow up on this thread. I tried Leszek's solution again and
> it worked properly. I suspect that I most likely misspelled something
> on my first attempt!
> 
> Thanks for your help. When I get a chance, I'm going to dig in and
> figure out exactly _how_ that works.
AFAIU rhino (flowscript engine) uses reflection to resolve methods and 
fields. It doesn't really matter that you pass some narrow interface 
because reflection will expose full underlying object functionality.


-- 
Leszek Gawron                                                 MobileBox
lgawron@apache.org                              http://www.mobilebox.pl

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Java Class Casting within Flow

Posted by Daniel McOrmond <dm...@gmail.com>.
Just a follow up on this thread. I tried Leszek's solution again and
it worked properly. I suspect that I most likely misspelled something
on my first attempt!

Thanks for your help. When I get a chance, I'm going to dig in and
figure out exactly _how_ that works.

-Daniel



On Tue, 22 Feb 2005 11:34:31 -0500, Daniel McOrmond <dm...@gmail.com> wrote:
> Hmm. I would be interested to understand why you suggest that?
> 
> In this case the SpecificObject has additional methods not contained
> in the GenericObject. When I try to call those methods, Flow complains
> ( as I expect ) that the method is not available.
> 
> -Daniel
> 
> 
> On Tue, 22 Feb 2005 17:25:20 +0100, Leszek Gawron <lg...@mobilebox.pl> wrote:
> >
> > you do not need a cast - just call SpecificObject methods.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Java Class Casting within Flow

Posted by Daniel McOrmond <dm...@gmail.com>.
Hmm. I would be interested to understand why you suggest that?

In this case the SpecificObject has additional methods not contained
in the GenericObject. When I try to call those methods, Flow complains
( as I expect ) that the method is not available.

-Daniel


On Tue, 22 Feb 2005 17:25:20 +0100, Leszek Gawron <lg...@mobilebox.pl> wrote:
>
> you do not need a cast - just call SpecificObject methods.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Java Class Casting within Flow

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Daniel McOrmond wrote:
> Here's a simple example:
> 
> 
> importClass( Packages.com.company.GenericObject );
> importClass( Packages.com.company.SpecificObject );
> importClass( Packages.com.company.ObjectLoaderUtil );
> 
> function doSomethingUseful() {
>   var loader = cocoon.createObject( ObjectLoaderUtil );
>   var myObject = loader.getGenericObject();
> }
> 
> 
> 
> Suppose I wanted to cast the GenericObject to a SpecificObject, like this:
> 
>   var myObject = (SpecificObject) loader.getGenericObject();
you do not need a cast - just call SpecificObject methods.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org