/** * Gets the global variables from the knowledge runtime engine. * @param runtimeEngine the knowledge runtime engine * @return the global variables */ protected Map<String, Object> getGlobalVariables(KnowledgeRuntimeEngine runtimeEngine) { Map<String, Object> globalVariables = new HashMap<String, Object>(); if (runtimeEngine != null) { Globals globals = runtimeEngine.getSessionGlobals(); if (globals != null) { for (String key : globals.getGlobalKeys()) { Object value = globals.get(key); globalVariables.put(key, value); } } } return globalVariables; }
/** * Gets the global variables from the knowledge runtime engine. * @param runtimeEngine the knowledge runtime engine * @return the global variables */ protected Map<String, Object> getGlobalVariables(KnowledgeRuntimeEngine runtimeEngine) { Map<String, Object> globalVariables = new HashMap<String, Object>(); if (runtimeEngine != null) { Globals globals = runtimeEngine.getSessionGlobals(); if (globals != null) { for (String key : globals.getGlobalKeys()) { Object value = globals.get(key); globalVariables.put(key, value); } } } return globalVariables; }
/** * Sets the globals. * @param message the message * @param operation the operation * @param runtime the runtime engine * @param singleton singleton */ public static void setGlobals(Message message, KnowledgeOperation operation, KnowledgeRuntimeEngine runtime, boolean singleton) { Globals globals = runtime.getSessionGlobals(); if (globals != null) { Map<String, Object> globalsMap = new HashMap<String, Object>(); globalsMap.put(GLOBALS, new ConcurrentHashMap<String, Object>()); Map<String, Object> expressionMap = getMap(message, operation.getGlobalExpressionMappings(), null); if (expressionMap != null) { globalsMap.putAll(expressionMap); } for (Entry<String, Object> globalsEntry : globalsMap.entrySet()) { if (!singleton) { globals.set(globalsEntry.getKey(), globalsEntry.getValue()); } else { if (globals.get(globalsEntry.getKey()) == null || (globalsEntry.getValue() != null && (globalsEntry .getValue() instanceof Map && !((Map) globalsEntry .getValue()).isEmpty()))) { globals.set(globalsEntry.getKey(), globalsEntry.getValue()); } } } } }
/** * Sets the globals. * @param message the message * @param operation the operation * @param runtime the runtime engine * @param singleton singleton */ public static void setGlobals(Message message, KnowledgeOperation operation, KnowledgeRuntimeEngine runtime, boolean singleton) { Globals globals = runtime.getSessionGlobals(); if (globals != null) { Map<String, Object> globalsMap = new HashMap<String, Object>(); globalsMap.put(GLOBALS, new ConcurrentHashMap<String, Object>()); Map<String, Object> expressionMap = getMap(message, operation.getGlobalExpressionMappings(), null); if (expressionMap != null) { globalsMap.putAll(expressionMap); } for (Entry<String, Object> globalsEntry : globalsMap.entrySet()) { if (!singleton) { globals.set(globalsEntry.getKey(), globalsEntry.getValue()); } else { if (globals.get(globalsEntry.getKey()) == null || (globalsEntry.getValue() != null && (globalsEntry .getValue() instanceof Map && !((Map) globalsEntry .getValue()).isEmpty()))) { globals.set(globalsEntry.getKey(), globalsEntry.getValue()); } } } } }