/** * Creates magmascript bindings for a given Entity. * * @param entity the entity to bind to the magmascript $ function * @param depth maximum depth to follow references when creating the entity value map * @return Bindings with $ function bound to the entity */ private Bindings createBindings(Entity entity, int depth) { Bindings bindings = new SimpleBindings(); JSObject global = (JSObject) magmaBindings.get("nashorn.global"); JSObject magmaScript = (JSObject) global.getMember(KEY_MAGMA_SCRIPT); JSObject dollarFunction = (JSObject) magmaScript.getMember(KEY_DOLLAR); JSObject bindFunction = (JSObject) dollarFunction.getMember(BIND); Object boundDollar = bindFunction.call(dollarFunction, toScriptEngineValueMap(entity, depth)); bindings.put(KEY_DOLLAR, boundDollar); bindings.put(KEY_NEW_VALUE, magmaScript.getMember(KEY_NEW_VALUE)); bindings.put(KEY_IS_NULL, magmaScript.getMember(KEY_IS_NULL)); return bindings; }
case XREF: Entity xrefEntity = entity.getEntity(attrName); value = toScriptEngineValueMap(xrefEntity, depth - 1); break; case CATEGORICAL_MREF: entity .getEntities(attrName) .forEach(mrefEntity -> mrefValues.add(toScriptEngineValueMap(mrefEntity, depth - 1))); value = jsArray; break;