Package org.apache.bsf.engines.javascript

Source Code of org.apache.bsf.engines.javascript.RhinoServlet

package org.apache.bsf.engines.javascript;

import javax.script.ScriptEngine;
import javax.script.http.GenericHttpScriptContext;
import javax.script.http.HttpScriptContext;
import javax.script.http.HttpScriptServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.bsf.util.ScriptEnginePool;

public class RhinoServlet extends HttpScriptServlet {

    private ServletConfig config;
    private ScriptEnginePool pool;
      
    public HttpScriptContext getContext(HttpServletRequest req,
            HttpServletResponse res) throws ServletException {
       
        GenericHttpScriptContext context = new GenericHttpScriptContext();
        context.initialize(this, req, res);
        return context;
    }

    public ScriptEngine getEngine(HttpServletRequest req) {
        return pool.get();
    }
   
    public ServletConfig getServletConfig() {
        return config;
    }
   
    public String getServletInfo() {
        return "Rhino Script Servlet";               
    }
   
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
        pool = new ScriptEnginePool(new RhinoScriptEngineFactory());       
    }

    public void releaseEngine(ScriptEngine eng) {
        pool.free(eng);
    }

}
TOP

Related Classes of org.apache.bsf.engines.javascript.RhinoServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.