001package com.killcoding.jsplus; 002 003import java.io.File; 004import com.killcoding.log.Logger; 005import com.killcoding.log.LoggerFactory; 006 007public abstract class JsPlusContext { 008 009 protected String scriptCipherAesKey = null; 010 protected Logger log = null; 011 protected String engineName = null; 012 protected boolean allowAllAccess = true; 013 014 public JsPlusContext(String engineName) { 015 super(); 016 this.engineName = engineName.trim(); 017 log = LoggerFactory.getLogger(this.getClass()); 018 } 019 020 public static boolean isGraalJs(String engineName){ 021 try{ 022 return engineName.matches("^((?i)GraalVM\\.).*$"); 023 }catch(Exception e){ 024 return false; 025 } 026 } 027 028 public static boolean isNashornJs(String engineName){ 029 try{ 030 return engineName.matches("^((?i)Nashorn[^\\S]*)$"); 031 }catch(Exception e){ 032 return false; 033 } 034 } 035 036 public void setAllowAllAccess(boolean allowAllAccess){ 037 this.allowAllAccess = allowAllAccess; 038 } 039 040 public boolean isAllowAllAccess(){ 041 return this.allowAllAccess; 042 } 043 044 public void setScriptCipherAesKey(String scriptCipherAesKey){ 045 this.scriptCipherAesKey = scriptCipherAesKey; 046 } 047 048 public void remove(){ 049 String tid = Thread.currentThread().getId() + ""; 050 remove(tid); 051 } 052 053 public void put(Object value){ 054 String tid = Thread.currentThread().getId() + ""; 055 put(tid,value); 056 } 057 058 public Object get() { 059 String tid = Thread.currentThread().getId() + ""; 060 return get(tid); 061 } 062 063 public abstract String getEngineName(); 064 065 public abstract Object getBindings(); 066 067 public abstract Object getEngine(); 068 069 public abstract Object getContext(); 070 071 public abstract void close(); 072 073 public abstract void remove(String name); 074 075 public abstract void put(String name,Object value); 076 077 public abstract Object get(String name); 078 079 public abstract void initScriptEngineManager() throws Exception; 080 081 public abstract Object eval(String scriptPath) throws Exception; 082 083 public abstract Object eval(File scriptPath) throws Exception; 084 085 public abstract Object evalScript(String script) throws Exception; 086 087}