You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Upayavira <uv...@upaya.co.uk> on 2003/11/24 21:05:17 UTC

Re: Scriptable objects with BeanShell

Bertrand Delacretaz wrote:

>
> Le Vendredi, 21 nov 2003, à 22:20 Europe/Zurich, Upayavira a écrit :
>
>> Bertrand Delacretaz wrote:
>>
>>> ...This means that BeanShell (dunno if BSF does this too) scripts  
>>> could be called from flow *and* interpreted *and* implement Avalon 
>>> or  Cocoon interfaces. I haven't thought about all implications but 
>>> it  might be a nice intermediate solution between limited 
>>> interpreted  stuff and full-blown java coding.
>>
>>
>> Can you say more about how you do this? Give some examples? I would  
>> find that very useful.
>
>
> Still in wildthoughts mode here, I haven't tested this:
>
> 1) A BeanShellWrapper Component initializes BeanShell and provides 
> some  useful beans that scripts can access (similar to what the 
> current  ScriptGenerator does).
>
> Maybe BSF instead of BeanShell (as BSF can use BeanShell as a script  
> engine anyway), but I don't know if BSF does all this.
>
> 2) BeanShellWrapper provides methods for flowscripts to retrieve  
> scriptable objects, something like:
>
>   IMyBizObject =  
> (IMyBizObject)BSFWrapper.createObject(IMyBizObject.class,"MyBusinessScri 
> pt.bsl");
>
> At this point the BeanShell "dynamic adapter" feature [1] [2] is used  
> to provide an object of the specified interface, something like:
>
>   // in BeanShellWrapper:
>   public Object createObject(Class clazz,String scriptFilename) {
>      // first load scriptFilename in the (or a new) BeanShell  
> Interpreter
>      ...
>     // then cast the interpreter as required, it will call the  
> appropriate methods in
>     // the script if they exist and complain if not
>     return interpreter.getInterface(clazz);
>   }
>
> See what I mean? This is only a rough sketch, there are certainly a 
> lot  of "details" to consider. But it looks like all the essential 
> elements  are here.
>
> I'm also not sure if one of the BeanShell licenses [3] are ok for  
> distributing with Cocoon, but mocks could be used if it is not the case.
>
> Hope this helps,
> -Bertrand
>
>
> [1]  http://www.beanshell.org/javadoc/bsh/ 
> Interpreter.html#getInterface(java.lang.Class)
>
> [2]  http://www.beanshell.org/manual/ 
> bshmanual.html#%22Dummy%22_Adapters_and_Incomplete_Interfaces
>
> [3] http://www.beanshell.org/license.html
>
 From looking at the BeanShell docs, the Java is definitely 'scripted' 
java, and lacks Java's object orientedness. Therefore, whilst you're 
coding in more or less Java, I can't see a great advantage of using 
BeanShell over using Rhino. They're both scripted, and thus not able to 
create clear interfaces. (In BeanShell you can implement interfaces, but 
to do so you have to use 'anonymous classes', which IMO doesn't produce 
attractive or easy to read code.

Therefore, I think, for my case, I'm just going to have to use Java for 
my objects, to use Unit Tests to test them (rather than bothering to 
test them in a servlet environment), and hope for the day when someone 
gets Christopher's CompilingClassLoader working so that I can easily 
debug Java code from within a servlet.

Regards, Upayavira



Re: A general Note

Posted by Sylvain Wallez <sy...@apache.org>.
JD Daniels wrote:

>I just wanted to take moment and thank the cocoon community.
>
>Cocoon kicks butt.
>
>I make small to medium small business / personal web applications.
>Nothing fancy, basically alot of xsp + xsl templates (These alone match PHP I think)
>After the initial learning curve (which seems to extend a bit whenever I need something new), cocoon delivers speed and maintainability.
>
>I enjoy watching the dev list to see what is coming next. I have a lot of trouble with java in general (learning as I go with no formal training).
>However I hate PHP and perl now. I actually regret the time I spent developing with them.
>
>The time saved from endless hours of scanning thousands of lines of php code to change ridiculous things like html table layouts, or an email notification has allowed me to keep my small-town, small business viable. I am able to work at home with my wife and children around me.
>
>There are alot of ambitious goals for cocoon, and sometimes the lists gets so excited about new stuff, they might miss what has already been accomplished. But for me, Cocoon's existence has made a HUGE difference in my work *and* my home life.
>
>Thanks Guys :)
>  
>

Thank you for letting us know.

Cocoon has this "something special" compared to other frameworks: it is 
a software that you have a personal relation with, a feeling I already 
encountered in a nearby domain with Macintosh computers. I don't exactly 
know where this feeling comes from with Cocoon: is it because there are 
always some different creative ways to achieve your goal, with this 
large box full of multi-colored Lego bricks? Is it because you "feel" 
your site when designing sitemap patterns? Is it because it allows fast 
yet powerful work? Is it because you just 
save-and-reload-and-wow!-it's-nice?

Comparing with Macs, I think the common point is that both allow you to 
manipulate very high level abstractions without seeing them, or at least 
not too much. This is clearly outlined when you express the pleasure you 
have to use these hundreds of thousands line of Java without mastering Java.

One sure thing is that the Cocoon community is a nice and friendly place 
to be. And this certainly explains why this community's baby is so 
enjoyable. Have you looked at Stefano's slides at the GetTogether? If 
not, go there, look at the pictures and you'll understand this.

BTW, can we see your sites on the internet ?

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



Re: Scriptable objects with BeanShell

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le Lundi, 24 nov 2003, à 22:02 Europe/Zurich, Upayavira a écrit :
> ...Then I've effectively created a class. But it seems a bit around 
> the houses to me...

ok, see your point now, thanks.

Don't close the door on scripting stuff too soon though, there's a lot 
happening with Groovy [1] (not to mention LOAF;-) these days, even 
though it is very new it looks very interesting for writing test cases.

-Bertrand

[1] http://groovy.codehaus.org


Re: Scriptable objects with BeanShell

Posted by Upayavira <uv...@upaya.co.uk>.
Bertrand Delacretaz wrote:

> Le Lundi, 24 nov 2003, à 21:05 Europe/Zurich, Upayavira a écrit :
>
>> ...From looking at the BeanShell docs, the Java is definitely 
>> 'scripted' java, and lacks Java's object orientedness...
>
>
> But what about this example from the BeanShell docs:
>
> buttonHandler = new ActionListener() {
>     actionPerformed( event ) {
>         print(event);
>     }
> };
>
> button = new JButton();
> button.addActionListener( buttonHandler );
> frame(button);
>
> A new behaviour for ActionListener is indeed created in a script.
> Isn't this a good example of object orientedness, do you have a 
> counterexample?

Yup. But I can't code a class called User, and then invoke it with 'new 
User()', I have to do it inline.

I guess I could do:

newUser() {
    user = new Object() {
        setUsername(username) {
            this.username = username;
         }
         validatePassword(password) {
         ...etc
     }
}

And then do:
myUser = newUser();
myUser.setUsername("upayavira");
if (myUser.validatePassword("xyz")) {
  cocoon.sendPage(".....");
} else {
   ...
}

Then I've effectively created a class. But it seems a bit around the 
houses to me.

Regards, Upayavira


Re: Scriptable objects with BeanShell

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le Lundi, 24 nov 2003, à 21:05 Europe/Zurich, Upayavira a écrit :
> ...From looking at the BeanShell docs, the Java is definitely 
> 'scripted' java, and lacks Java's object orientedness...

But what about this example from the BeanShell docs:

buttonHandler = new ActionListener() {
     actionPerformed( event ) {
         print(event);
     }
};

button = new JButton();
button.addActionListener( buttonHandler );
frame(button);

A new behaviour for ActionListener is indeed created in a script.
Isn't this a good example of object orientedness, do you have a 
counterexample?

-Bertrand


Re: A general Note

Posted by Tony Collen <co...@umn.edu>.
JD Daniels wrote:
> I just wanted to take moment and thank the cocoon community.
> 
> Cocoon kicks butt.
> 
> I make small to medium small business / personal web applications.
> Nothing fancy, basically alot of xsp + xsl templates (These alone match PHP
> I think)
> After the initial learning curve (which seems to extend a bit whenever I
> need something new), cocoon delivers speed and maintainability.
> 
> I enjoy watching the dev list to see what is coming next. I have a lot of
> trouble with java in general (learning as I go with no formal training).
> However I hate PHP and perl now. I actually regret the time I spent
> developing with them.

I came from the PHP world as well.  I was able to get a lot of work done, and it introduced me to 
server-side programming.  I had quickly gotten fed up with mixing html with my code, and learned how 
to use some of the templating libraries.  The problem with them was that they were so @#% complex 
that I had to look up the syntax every time I wanted to use it.  Compared to that, Cocoon is a breeze :D

> The time saved from endless hours of scanning thousands of lines of php code
> to change ridiculous things like html table layouts, or an email
> notification has allowed me to keep my small-town, small business viable. I
> am able to work at home with my wife and children around me.
> 
> There are alot of ambitious goals for cocoon, and sometimes the lists gets
> so excited about new stuff, they might miss what has already been
> accomplished. But for me, Cocoon's existence has made a HUGE difference in
> my work *and* my home life.

It is hard to keep up with all of the stuff going on.  I haven't had all that much time to dive into 
Woody as much as I'd like.  Flow was around for a long time before people started using it -- and 
now other projects are finally picking up on the idea of using continuations on the web.  I'm 
excited to see where Cocoon goes after 2.2.

It's awesome to see how something like Cocoon can concretely impact not only people's work, but also 
their personal life :)

> 
> Thanks Guys :)
> 
> JD
> 



Regards,

Tony


Re: A general Note

Posted by Stefano Mazzocchi <st...@apache.org>.
On 24 Nov 2003, at 22:38, JD Daniels wrote:

> I just wanted to take moment and thank the cocoon community.
>
> Cocoon kicks butt.
>
> I make small to medium small business / personal web applications.
> Nothing fancy, basically alot of xsp + xsl templates (These alone 
> match PHP
> I think)
> After the initial learning curve (which seems to extend a bit whenever 
> I
> need something new), cocoon delivers speed and maintainability.
>
> I enjoy watching the dev list to see what is coming next. I have a lot 
> of
> trouble with java in general (learning as I go with no formal 
> training).
> However I hate PHP and perl now. I actually regret the time I spent
> developing with them.
>
> The time saved from endless hours of scanning thousands of lines of 
> php code
> to change ridiculous things like html table layouts, or an email
> notification has allowed me to keep my small-town, small business 
> viable. I
> am able to work at home with my wife and children around me.
>
> There are alot of ambitious goals for cocoon, and sometimes the lists 
> gets
> so excited about new stuff, they might miss what has already been
> accomplished. But for me, Cocoon's existence has made a HUGE 
> difference in
> my work *and* my home life.
>
> Thanks Guys :)

Thank you!

--
Stefano, tasting the warm feeling of these words in this cold, wet and 
dark afternoon.

I really needed this. I really did. Thank you.

A general Note

Posted by JD Daniels <jd...@datatrio.com>.
I just wanted to take moment and thank the cocoon community.

Cocoon kicks butt.

I make small to medium small business / personal web applications.
Nothing fancy, basically alot of xsp + xsl templates (These alone match PHP
I think)
After the initial learning curve (which seems to extend a bit whenever I
need something new), cocoon delivers speed and maintainability.

I enjoy watching the dev list to see what is coming next. I have a lot of
trouble with java in general (learning as I go with no formal training).
However I hate PHP and perl now. I actually regret the time I spent
developing with them.

The time saved from endless hours of scanning thousands of lines of php code
to change ridiculous things like html table layouts, or an email
notification has allowed me to keep my small-town, small business viable. I
am able to work at home with my wife and children around me.

There are alot of ambitious goals for cocoon, and sometimes the lists gets
so excited about new stuff, they might miss what has already been
accomplished. But for me, Cocoon's existence has made a HUGE difference in
my work *and* my home life.

Thanks Guys :)

JD