@Override
  public void clear() {
    HashMap<String, Object> bindings = getBindings();
    for (String s : bindings.keySet()) {
      bindings.put(s, null);
      py.set(s, null);
    }

    // let Jython do its housekeeping
    py.cleanup();
  }
 /**
  * Creates a jython object instance for the script cache.
  *
  * @param key the path to the jython script
  * @return an instantiated jython object
  * @throws Exception if the jython object failed to be instantiated
  */
 @Override
 public Object createEntry(Object key) throws Exception {
   // log.debug("createEntry({})", key);
   String path = key.toString();
   int qmarkPos = path.lastIndexOf("?");
   if (qmarkPos != -1) {
     path = path.substring(0, qmarkPos);
   }
   int slashPos = path.indexOf("/");
   String portalId = path.substring(0, slashPos);
   PyObject scriptObject = null;
   InputStream in = velocityService.getResource(path);
   if (in == null) {
     log.debug("Failed to load script: '{}'", path);
   } else {
     // add current and default portal directories to python sys.path
     addSysPaths(portalId, Py.getSystemState());
     // setup the python interpreter
     PythonInterpreter python = PythonInterpreter.threadLocalStateInterpreter(null);
     // expose services for backward compatibility - deprecated
     python.set("Services", scriptingServices);
     // python.setLocals(scriptObject);
     JythonLogger jythonLogger = new JythonLogger(path);
     python.setOut(jythonLogger);
     python.setErr(jythonLogger);
     python.execfile(in, path);
     String scriptClassName = StringUtils.capitalize(FilenameUtils.getBaseName(path)) + "Data";
     PyObject scriptClass = python.get(scriptClassName);
     if (scriptClass != null) {
       scriptObject = scriptClass.__call__();
     } else {
       log.debug("Failed to find class '{}'", scriptClassName);
     }
     python.cleanup();
   }
   return scriptObject;
 }
 /** {@inheritDoc} */
 @Override
 public void close() {
   if (interpreter != null) {
     interpreter.cleanup();
   }
 }