private void registerBindingTypes(final ScriptContext context) { if (typeCheckingEnabled) { final Map<String, ClassNode> variableTypes = new HashMap<>(); clearVarTypes(); // use null for the classtype if the binding value itself is null - not fully sure if that is // a sound way to deal with that. didn't see a class type for null - maybe it should just be // unknown and be "Object". at least null is properly being accounted for now. context.getBindings(ScriptContext.GLOBAL_SCOPE).forEach((k, v) -> variableTypes.put(k, null == v ? null : ClassHelper.make(v.getClass()))); context.getBindings(ScriptContext.ENGINE_SCOPE).forEach((k, v) -> variableTypes.put(k, null == v ? null : ClassHelper.make(v.getClass()))); COMPILE_OPTIONS.get().put(COMPILE_OPTIONS_VAR_TYPES, variableTypes); } }
private void registerBindingTypes(final ScriptContext context) { if (typeCheckingEnabled) { final Map<String, ClassNode> variableTypes = new HashMap<>(); clearVarTypes(); // use null for the classtype if the binding value itself is null - not fully sure if that is // a sound way to deal with that. didn't see a class type for null - maybe it should just be // unknown and be "Object". at least null is properly being accounted for now. context.getBindings(ScriptContext.GLOBAL_SCOPE).forEach((k, v) -> variableTypes.put(k, null == v ? null : ClassHelper.make(v.getClass()))); context.getBindings(ScriptContext.ENGINE_SCOPE).forEach((k, v) -> variableTypes.put(k, null == v ? null : ClassHelper.make(v.getClass()))); COMPILE_OPTIONS.get().put(COMPILE_OPTIONS_VAR_TYPES, variableTypes); } }
public static void persistCurrentContext(AuthenticationContext context, ScriptEngine engine) { Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); Map<String, Object> persistableMap = new HashMap<>(); engineBindings.forEach((key, value) -> persistableMap.put(key, FrameworkUtils.toJsSerializable(value))); context.setProperty(JS_BINDING_CURRENT_CONTEXT, persistableMap); }
public static void persistCurrentContext(AuthenticationContext context, ScriptEngine engine) { Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); Map<String, Object> persistableMap = new HashMap<>(); engineBindings.forEach((key, value) -> persistableMap.put(key, FrameworkUtils.toJsSerializable(value))); context.setProperty(JS_BINDING_CURRENT_CONTEXT, persistableMap); }
@SuppressWarnings("rawtypes") @Override public void scanToAutoEnable() { List<Object> autoEnabled = new ArrayList<>(); getScriptEngine().getBindings(ScriptContext.ENGINE_SCOPE).forEach((key, value) -> { Object evalResult = value != null ? eval(key + ".class") : null; if (evalResult != null && evalResult instanceof Class) { Class cls = (Class) evalResult; if (PROCESSOR_CLASSES.values().stream() .filter(processorClass -> !cls.equals(processorClass) && ClassUtils.isAssignable(cls, processorClass)).findFirst() .isPresent()) { if (!isProcessorAbstract(key)) { autoEnabled.add(key); ((NashornKnowledgeBaseEngineOperations) getEngineOperations()).enable(value); } } } }); if (logger.isDebugEnabled() && !autoEnabled.isEmpty()) { logger.debug("Auto-enabling: {}", autoEnabled); } }