Re: CVS Update: Barracuda

"Diez B. Roggisch" <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hi guys,

whow, thats a lengthy discussion :) I have to admit that I didn't have 
the time to follow it thourougly, but from what I understand of jacobs 
last mail you basically use xml to initialize some objects at 
startuptime using ObjectAssembler and want to extend that behaviour.

I (as an admitting pythonista) stumbled across this article:

http://today.java.net/pub/a/today/2003/06/10/jython.html

And, on a somewhat related note, over this one:

http://www.computerworld.com/developmenttopics/development/java/story/0,10801,82058,00.html

I personally make a lot of use of jython - it does a great job when you 
want to fiddle around with objects and see how they actually work 
together or what actual instances of some interface you have. Or to 
prototype some complicated java-code. And I seriously think of utilizing 
it in the planned scripting extension for templates. Also I used it 
embedded into ant scripts to perform tasks that would be hard if not 
impossible to realize using ant's build-in tags.

Another alternative is BSH (That is beanshell), also a very powerful 
tool and maybe a little bit more appealing to those who love the java 
syntax.

My point here is that maybe using jython/bsh scripts with easy to write 
syntax _and_ the power of a full programming language might be a more 
suitable way of  configuring the application than to create some clumsy 
fully-parenthised syntax tree for a crippled programming-language. No 
offense intended, of course. Its just the way xml works, and it 
definitely has its merits on other fields.

Jacobs example:

<object name="$this">
   <method name="getServletContext" return="$sc"/>
</object>
<object class="org.enhydra.barracuda.core.util.dom.DefaultDOMLoader">
   <method name="getGlobalInstance" return="$dl" />
</object>
<object name="$df" 
class="org.enhydra.barracuda.core.util.dom.XMLCDeferredParsingDOMFactory">
   <method name="setServletContext" arg1="$sc" />
</object>
<object name="$dl">
   <method name="setDefaultDOMFactory" arg1="$df" />
</object>

rewritten in jython would look like this:

----------
from org.enhydra.barracuda.core.util.dom import DefaultDOMLoader
from org.enhydra.barracuda.core.util.dom import 
XMLCDeferredParsingDOMFactory

# wherever this comes from... But its no problem to declare it :)
sc = this.servletContext
dl = DefaultDOMLoader.globalInstance
df = XMLCDeferredParsingDOMFactory()
df.servletContext = sc
dl.defaultDOMFactory = df
-----------

As you can see, jython knows about the java-bean convention and you can 
use that to access get/set methods as if it were attributes of the 
class. And the more complex your example gets (multiple arguments), the 
more clear the jython example gets relative to the xml.

And of course, you could add any logic or calculate values you need on 
the fly.

Ok, just my .02 cents. You're hereby officially allowed to ignore this 
if you don't like it :)

Regards,

Diez
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.