NativeObject toNativeObject() { NativeObject obj = new NativeObject(); for (Map.Entry<String,String> ent : optMap.entrySet()) { obj.put(ent.getKey(), obj, ent.getValue()); } return obj; } }
NativeObject toNativeObject() { NativeObject obj = new NativeObject(); for (Map.Entry<String,String> ent : optMap.entrySet()) { obj.put(ent.getKey(), obj, ent.getValue()); } return obj; } }
@Override public Scriptable getConsoleAsScriptable(Scriptable scope) { NativeObject consoleNativeObject = new NativeObject(); Map<String, LogFunctionWrapper> functionWrapperMap = new HashMap<String, LogFunctionWrapper>(); for (Method method : Console.class.getDeclaredMethods()) { functionWrapperMap.put(method.getName(), LogFunctionWrapper.fromMethodWithDebugging(console, method, scope)); } for (Map.Entry<String, LogFunctionWrapper> stringFunctionWrapperEntry : functionWrapperMap.entrySet()) { consoleNativeObject.put(stringFunctionWrapperEntry.getKey(), consoleNativeObject, stringFunctionWrapperEntry.getValue()); } return consoleNativeObject; }
private void setPrefValue(String[] keys, Serializable value, NativeObject object) { NativeObject currentObject = object; int index = 0; for (String key : keys) { if (index == keys.length-1) { currentObject.put(key, currentObject, value); } else { NativeObject newObject = null; Object temp = currentObject.get(key, currentObject); if (temp == null || temp instanceof NativeObject == false) { newObject = new NativeObjectDV(); currentObject.put(key, currentObject, newObject); } else { newObject = (NativeObject)temp; } currentObject = newObject; } index ++; } }
private void setPrefValue(String[] keys, Serializable value, NativeObject object) { NativeObject currentObject = object; int index = 0; for (String key : keys) { if (index == keys.length-1) { currentObject.put(key, currentObject, value); } else { NativeObject newObject = null; Object temp = currentObject.get(key, currentObject); if (temp == null || temp instanceof NativeObject == false) { newObject = new NativeObjectDV(); currentObject.put(key, currentObject, newObject); } else { newObject = (NativeObject)temp; } currentObject = newObject; } index ++; } }
public static NativeArray jsFunction_getProperties(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws CarbonException { ResourceHostObject resourceHostObject = (ResourceHostObject) thisObj; if (arguments.length == 0) { List<NativeObject> props= new ArrayList<NativeObject>(); Properties properties = resourceHostObject.resource.getProperties(); Enumeration<?> propertyNames = properties.propertyNames(); while(propertyNames.hasMoreElements()) { NativeObject property = new NativeObject(); String key = (String) propertyNames.nextElement(); property.put("name", property, key); property.put("value", property, properties.get(key)); props.add(property); } return new NativeArray(props.toArray()); } else { throw new CarbonException("getProperties() method doesn't accept arguments"); } }
public BoundFunction(Context cx, Scriptable scope, Callable targetFunction, Scriptable boundThis, Object[] boundArgs) { this.targetFunction = targetFunction; this.boundThis = boundThis; this.boundArgs = boundArgs; if (targetFunction instanceof BaseFunction) { length = Math.max(0, ((BaseFunction) targetFunction).getLength() - boundArgs.length); } else { length = 0; } ScriptRuntime.setFunctionProtoAndParent(this, scope); Function thrower = ScriptRuntime.typeErrorThrower(); NativeObject throwing = new NativeObject(); throwing.put("get", throwing, thrower); throwing.put("set", throwing, thrower); throwing.put("enumerable", throwing, false); throwing.put("configurable", throwing, false); throwing.preventExtensions(); this.defineOwnProperty(cx, "caller", throwing, false); this.defineOwnProperty(cx, "arguments", throwing, false); }
public BoundFunction(Context cx, Scriptable scope, Callable targetFunction, Scriptable boundThis, Object[] boundArgs) { this.targetFunction = targetFunction; this.boundThis = boundThis; this.boundArgs = boundArgs; if (targetFunction instanceof BaseFunction) { length = Math.max(0, ((BaseFunction) targetFunction).getLength() - boundArgs.length); } else { length = 0; } ScriptRuntime.setFunctionProtoAndParent(this, scope); Function thrower = ScriptRuntime.typeErrorThrower(cx); NativeObject throwing = new NativeObject(); throwing.put("get", throwing, thrower); throwing.put("set", throwing, thrower); throwing.put("enumerable", throwing, false); throwing.put("configurable", throwing, false); throwing.preventExtensions(); this.defineOwnProperty(cx, "caller", throwing, false); this.defineOwnProperty(cx, "arguments", throwing, false); }
public BoundFunction(Context cx, Scriptable scope, Callable targetFunction, Scriptable boundThis, Object[] boundArgs) { this.targetFunction = targetFunction; this.boundThis = boundThis; this.boundArgs = boundArgs; if (targetFunction instanceof BaseFunction) { length = Math.max(0, ((BaseFunction) targetFunction).getLength() - boundArgs.length); } else { length = 0; } ScriptRuntime.setFunctionProtoAndParent(this, scope); Function thrower = ScriptRuntime.typeErrorThrower(cx); NativeObject throwing = new NativeObject(); throwing.put("get", throwing, thrower); throwing.put("set", throwing, thrower); throwing.put("enumerable", throwing, false); throwing.put("configurable", throwing, false); throwing.preventExtensions(); this.defineOwnProperty(cx, "caller", throwing, false); this.defineOwnProperty(cx, "arguments", throwing, false); }
public BoundFunction(Context cx, Scriptable scope, Callable targetFunction, Scriptable boundThis, Object[] boundArgs) { this.targetFunction = targetFunction; this.boundThis = boundThis; this.boundArgs = boundArgs; if (targetFunction instanceof BaseFunction) { length = Math.max(0, ((BaseFunction) targetFunction).getLength() - boundArgs.length); } else { length = 0; } ScriptRuntime.setFunctionProtoAndParent(this, scope); Function thrower = ScriptRuntime.typeErrorThrower(); NativeObject throwing = new NativeObject(); throwing.put("get", throwing, thrower); throwing.put("set", throwing, thrower); throwing.put("enumerable", throwing, false); throwing.put("configurable", throwing, false); throwing.preventExtensions(); this.defineOwnProperty(cx, "caller", throwing, false); this.defineOwnProperty(cx, "arguments", throwing, false); }
public static NativeObject getSSOProvider(String providerName, String providerVersion, String appName) { AppManagerConfiguration config = ServiceReferenceHolder.getInstance(). getAPIManagerConfigurationService().getAPIManagerConfiguration(); List<SSOEnvironment> ssoEnvironments = config.getSsoEnvironments(); NativeObject ssoProviderObj = new NativeObject(); for(SSOEnvironment env: ssoEnvironments) { try { if(env.getName().equals(providerName) && env.getVersion().equals(providerVersion)) { SSOConfigurator configurator = (SSOConfigurator) Class.forName(env.getProviderClass()).newInstance(); configurator.init(env.getParameters()); SSOProvider ssoProvider = configurator.getProvider(appName); ssoProviderObj.put("provider_name", ssoProviderObj, env.getName()); ssoProviderObj.put("provider_version", ssoProviderObj, env.getVersion()); ssoProviderObj.put("claims", ssoProviderObj, ssoProvider.getClaims()); ssoProviderObj.put("logout_url", ssoProviderObj, ssoProvider.getLogoutUrl()); return ssoProviderObj; } } catch (Exception e) { log.error("Unable to retrieve SSO Provider details for " + env.toString()); } } return null; }
public class AddPropertyToObject { public static void main(String[] args) { new ContextFactory().call(new ContextAction(){ @Override public Object run(Context ctx) { Scriptable scope = ctx.initStandardObjects(); try { Scriptable entity = ctx.newObject(scope); NativeObject result = (NativeObject) ctx.evaluateString( scope, "({age:3, name:'bob'})", "<inline>", 1, null); result.put("surname", result, "Smith"); for (Entry<Object, Object> p : result.entrySet()) { System.out.println(p.getKey() + ": " + p.getValue()); } } catch (Exception e) { e.printStackTrace(System.err); } return null; } }); } }
return Optional.ofNullable((Adaptable) contextFactory.call(cx -> { final NativeObject headersObj = new NativeObject(); message.getHeaders().forEach((key, value) -> headersObj.put(key, headersObj, value)); externalMessage.put(EXTERNAL_MESSAGE_HEADERS, externalMessage, headersObj); externalMessage.put(EXTERNAL_MESSAGE_TEXT_PAYLOAD, externalMessage, textPayload); externalMessage.put(EXTERNAL_MESSAGE_BYTE_PAYLOAD, externalMessage, bytePayload); externalMessage.put(EXTERNAL_MESSAGE_CONTENT_TYPE, externalMessage, contentType);
return Optional.ofNullable((Adaptable) contextFactory.call(cx -> { final NativeObject headersObj = new NativeObject(); message.getHeaders().forEach((key, value) -> headersObj.put(key, headersObj, value)); externalMessage.put(EXTERNAL_MESSAGE_HEADERS, externalMessage, headersObj); externalMessage.put(EXTERNAL_MESSAGE_TEXT_PAYLOAD, externalMessage, textPayload); externalMessage.put(EXTERNAL_MESSAGE_BYTE_PAYLOAD, externalMessage, bytePayload); externalMessage.put(EXTERNAL_MESSAGE_CONTENT_TYPE, externalMessage, contentType);