View Full Version : runtime compiler!
sally
07-11-2010, 08:59 PM
I found a compiler in run-time!
but I don't know how does it work?
it is a class named jcompiler in util package in shine pattern!
who can help me?
I found it at :
http://sourceforge.net/projects/shine-enterpris/files/
john.stalin.java
07-11-2010, 09:37 PM
i enjoy doing this:D
so follow my code and you enjoy this too.:)
filename :Engine .java
---------------------
package mypackage;
import org.j2sos.shine.jshooter.Application;
import org.j2sos.shine.maplet.Maplet;
public class Engine extends Maplet {
public String name;
public String body;
public void learning() {
try {
new Memory().addMethod("public String " + name +
"() throws Exception {" + body + "}");
out.println("Learned.");
} catch (Exception e) {
out.println(e.getMessage());
}
}
public void request() {
try {
Application app = new Application();
app.setObject(new Logic());
out.println(app.invokeMethod(name));
} catch (Exception e) {
out.println(e);
}
}
}
file name :Logic.java
-----------------------------
package mypackage;
public class Logic {
public String hello() throws Exception {
return "hello user!";
}
file name : Memory.java
--------------------------------
package mypackage;
import org.j2sos.shine.util.JCompiler;
public class Memory extends JCompiler
{
public void addMethod(String body)throws Exception{
new
Memory().addCommandToClassBodyInWindowsRuntime("mypackage.Logic",body);
}
}
file name : index.jsp
-------------------
<%@ page contentType="text/html;charset=windows-1252"%>
<H1>Virtual Human</H1>
<P>
<a href="Learning.jsp">Learning.jsp</a>
</P>
<P>
<a href="Request.jsp">Request.jsp</a>
</P>
file name : Learning.jsp
-----------------------
<%@ page contentType="text/html;charset=windows-1252"%>
<H1>Virtual Human</H1>
<form action="servlet/mypackage.Engine" method="get">
<P>Method Name:
<input type="text" name="name"/>
</P>
<P>Body:</P>
<P>
<textarea cols="40" rows="20" name="body"></textarea>
</P>
<P>
<input type="submit" value="Submit"/>
</P>
</form>
file name : Request.jsp
----------------------
<%@ page contentType="text/html;charset=windows-1252"%>
<H1>Virtual Human</H1>
<form action="servlet/mypackage.Engine" method="get">
<P>Method Name:
<input type="text" name="name"/>
</P>
<P>
<input type="submit" value="Submit"/>
</P>
</form>
replay me if there was any problem
or refer to shine doc (http://sourceforge.net/projects/shine-enterpris/files/ShineEnterpriseJavaPatternDoc/ShineENG.doc/download);)
sally
07-11-2010, 09:49 PM
wow!!! thank you I'll try it! and if had questions I'll ask you!
thanks a lot!
Powered by vBulletin® Version 4.2.2 Copyright © 2023 vBulletin Solutions, Inc. All rights reserved.