wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes possibility of dynamic java code transfer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "possibility of dynamic java code transfer?" Watch "possibility of dynamic java code transfer?" New topic

possibility of dynamic java code transfer?

Kaushik Sathupadi

Joined: Jun 23, 2006
Posts: 18
This is going to be a little long. pls bear with me. My application consissts of two parts- the server-side code and the client side code. Client is a thick client written as a java applet. The server code is written in EJB and the server runs in the same network as the database server. So all the database code has to be in the server code. Right?

Now, the problem is that whenever I want to write simple functions in the client code that required to execute multiple sql statements, i have to put only those statements in the server coding and the rest(the UI related things) in the client code. This means that the logic in the function gets devided in two parts that makes it difficult to maintain.

So I want code something like this
in the client...
public void methodInClient(){
final String text = <textfield>.getText();
Transferable t = new Transferable(){
public Vector execute(){
String query = //construct quries based on the value of text
super.executeQuery(query);//Transferrable abstract class has
//methods like execute query.
// run multiple queries
//put the result in a vector
// return the vector.
Vector result = Transferer.transferData(t);
//do something with the result vector, say dispaly a message box to the user

.. And in the server code
public Vector executeAnySqlCodeFromClient(Transferable t){
Connection con = getDBConnection();
Vector res = t.execute();
return res;
... In the code above Iam not trying to transfer the data in the transferable object, but the code of the newly created class itself that could be polymorphically taken by the Transferrable abstract class is the server code.
But serialization would'nt allow me to do that. This is because it requires the exact class that is serialized to be present while deserializing it. How do I Proceed?

Thanks for reading this far.....
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
Are you sure you are not making things unecessarily complicated? Perhaps SOAP or XML-RPC with existing libraries could work.

If this was my problem and I had to write code on the fly to carry out the query, I would consider writing the code in a scripting language such as JPython and returning the results as an XML document rather than a serialized object.
The new Groovy scripting language might be better than JPython. I suggest you take a look at it.

Kaushik Sathupadi

Joined: Jun 23, 2006
Posts: 18
Thanks Bill. Good to meet you!

Are you sure you are not making things unecessarily complicated?

- Am I? I was only trying to make things simple!

All I wanted to do was to put all the code in one place so that
1) I can see the whole logic written in a single block of code.
2) When developing and testing(in an intranet environment) the developer may test the code from his local system without having to code session beans. And while deploying(to the internet environment) his code will be transparently taken to sssion beans and executed there.

I would consider writing the code in a scripting language

-- I don't know anything about scripting language. Are they used to write code on the fly. Can you please show me how the client code would look like if I used one of the scripting languages.

returning the results as an XML document rather than a serialized object

- While returning the results I don't see any problem. It works perfectly. Sending the "code" is the problem.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
Yes, scripting languages can be used "on the fly" to assemble programs. I'm going to quote from the www.jython.org site + a *** note:
Jython is an implementation of the high-level, dynamic, object-oriented language Python seamlessly integrated with the Java platform. The predecessor to Jython, JPython, is certified as 100% Pure Java. Jython is freely available for both commercial and non-commercial use and is distributed with source code. Jython is complementary to Java and is especially suited for the following tasks:
****** NOTE ************
Embedded scripting - Java programmers can add the Jython libraries to their system to allow end users to write simple or complicated scripts that add functionality to the application.
Interactive experimentation - Jython provides an interactive interpreter that can be used to interact with Java packages or with running Java applications. This allows programmers to experiment and debug any Java system using Jython.
Rapid application development - Python programs are typically 2-10X shorter than the equivalent Java program. This translates directly to increased programmer productivity. The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.

There are numerous alternative languages implemented for the Java VM. The following features help to separate Jython from the rest:
Dynamic compilation to Java bytecodes - leads to highest possible performance without sacrificing interactivity.
Ability to extend existing Java classes in Jython - allows effective use of abstract classes.
Optional static compilation - allows creation of applets, servlets, beans, ...
Bean Properties - make use of Java packages much easier.
Python Language - combines remarkable power with very clear syntax. It also supports a full object-oriented programming model which makes it a natural fit for Java's OO design.

But note that you may find Jython / Python syntax disturbing
See the wikipedia article.

Please let the group know your progress on this problem, sounds interesting.
Wendy Devolder

Joined: Jul 05, 2006
Posts: 2
If you are based in the UK and are interested in Dynamic programming with Java: Skills Matter is organising a free seminar on Agile and Dynamic Programming with Groovy and Grails, featuring Dierk Koenig, author of Manning's forthcoming Groovy in Action book, and Graeme Rocher, current Grails Project lead.

The seminar will be held on July 13th at Skills Matter in London and attandance is free for registered participants.

More information: <a href="http://skillsmatter.com/groovy-grails-seminar"><b> http://skillsmatter.com/groovy-grails-seminar</a>
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: possibility of dynamic java code transfer?
Similar Threads
my communication design - your opinions please
Need help with OO design
Hi , I need advice how return to client large amount of data
Tomcat & XML-rpc
Help please with drag and drop