Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Development (http://www.go4expert.com/forums/web-development-forum/)
-   -   what is JCompiler? with a sample[CODE] (http://www.go4expert.com/forums/jcompiler-samplecode-t22700/)

omid128 13Jul2010 13:44

what is JCompiler? with a sample[CODE]
 
What is JCompiler?

This class considerably helps you to compile at the run time. For using it, you should inherit from the JCompiler class, then use the “addFileToWindowsRuntime”, create a new class. Afterward you can create an object from the created class by using JShooter.


Code:

********************
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);
      }
  }
}
********************************************************************************
package mypackage;
public class Logic {
  public String hello() throws Exception {
      return "hello user!";
  }
********************************************************************************
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);
 }
}
**********************************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>
**********************************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>
**********************************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>



All times are GMT +5.5. The time now is 20:43.