Java Code Examples for elemental.json.JsonArray#get()
The following examples show how to use
elemental.json.JsonArray#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PublishedServerEventHandlerRpcHandler.java From flow with Apache License 2.0 | 6 votes |
private static JsonArray unwrapVarArgs(JsonArray argsFromClient, Method method) { int paramCount = method.getParameterCount(); if (argsFromClient.length() == paramCount) { if (argsFromClient.get(paramCount - 1).getType() .equals(JsonType.ARRAY)) { return argsFromClient; } } JsonArray result = Json.createArray(); JsonArray rest = Json.createArray(); int newIndex = 0; for (int i = 0; i < argsFromClient.length(); i++) { JsonValue value = argsFromClient.get(i); if (i < paramCount - 1) { result.set(i, value); } else { rest.set(newIndex, value); newIndex++; } } result.set(paramCount - 1, rest); return result; }
Example 2
Source File: NodeUpdateImportsTest.java From flow with Apache License 2.0 | 6 votes |
private void assertTokenFileWithFallBack(JsonObject object) throws IOException { JsonObject fallback = object.getObject("chunks").getObject("fallback"); JsonArray modules = fallback.getArray("jsModules"); Set<String> modulesSet = new HashSet<>(); for (int i = 0; i < modules.length(); i++) { modulesSet.add(modules.getString(i)); } Assert.assertTrue(modulesSet.contains("@polymer/a.js")); Assert.assertTrue(modulesSet.contains("./extra-javascript.js")); JsonArray css = fallback.getArray("cssImports"); Assert.assertEquals(1, css.length()); JsonObject cssImport = css.get(0); Assert.assertEquals("extra-bar", cssImport.getString("include")); Assert.assertEquals("extra-foo", cssImport.getString("themeFor")); Assert.assertEquals("./extra-css.css", cssImport.getString("value")); }
Example 3
Source File: PolymerUtils.java From flow with Apache License 2.0 | 6 votes |
/** * Gets the custom element using {@code path} of indices starting from the * {@code root}. * * @param root * the root element to start from * @param path * the indices path identifying the custom element. * @return the element inside the {@code root} by the path of indices */ public static Element getCustomElement(Node root, JsonArray path) { Node current = root; for (int i = 0; i < path.length(); i++) { JsonValue value = path.get(i); current = getChildIgnoringStyles(current, (int) value.asNumber()); } if (current instanceof Element) { return (Element) current; } else if (current == null) { Console.warn( "There is no element addressed by the path '" + path + "'"); } else { Console.warn("The node addressed by path " + path + " is not an Element"); } return null; }
Example 4
Source File: ExecuteJavaScriptProcessor.java From flow with Apache License 2.0 | 5 votes |
private void handleInvocation(JsonArray invocation) { StateTree tree = registry.getStateTree(); // Last item is the script, the rest is parameters int parameterCount = invocation.length() - 1; String[] parameterNamesAndCode = new String[parameterCount + 1]; JsArray<Object> parameters = JsCollections.array(); JsMap<Object, StateNode> map = JsCollections.map(); for (int i = 0; i < parameterCount; i++) { JsonValue parameterJson = invocation.get(i); Object parameter = ClientJsonCodec.decodeWithTypeInfo(tree, parameterJson); parameters.push(parameter); parameterNamesAndCode[i] = "$" + i; StateNode stateNode = ClientJsonCodec.decodeStateNode(tree, parameterJson); if (stateNode != null) { if (isVirtualChildAwaitingInitialization(stateNode) || !isBound(stateNode)) { stateNode.addDomNodeSetListener(node -> { Reactive.addPostFlushListener( () -> handleInvocation(invocation)); return true; }); return; } map.set(parameter, stateNode); } } // Set the script source as the last parameter String expression = invocation.getString(invocation.length() - 1); parameterNamesAndCode[parameterNamesAndCode.length - 1] = expression; invoke(parameterNamesAndCode, parameters, map); }
Example 5
Source File: RootImpl.java From serverside-elements with Apache License 2.0 | 5 votes |
public void handleCallback(JsonArray arguments) { JsonArray attributeChanges = arguments.getArray(1); for (int i = 0; i < attributeChanges.length(); i++) { JsonArray attributeChange = attributeChanges.getArray(i); int id = (int) attributeChange.getNumber(0); String attribute = attributeChange.getString(1); JsonValue value = attributeChange.get(2); NodeImpl target = idToNode.get(Integer.valueOf(id)); if (value.getType() == JsonType.NULL) { target.node.removeAttr(attribute); } else { target.node.attr(attribute, value.asString()); } } JsonArray callbacks = arguments.getArray(0); for (int i = 0; i < callbacks.length(); i++) { JsonArray call = callbacks.getArray(i); int elementId = (int) call.getNumber(0); int cid = (int) call.getNumber(1); JsonArray params = call.getArray(2); ElementImpl element = (ElementImpl) idToNode .get(Integer.valueOf(elementId)); if (element == null) { System.out.println(cid + " detached?"); return; } JavaScriptFunction callback = element.getCallback(cid); callback.call(params); } }