Package elemental.json

Examples of elemental.json.JsonArray


                .getConnectorTracker().getDirtyVisibleConnectors();

        JsonObject hierarchyInfo = Json.createObject();
        for (ClientConnector connector : dirtyVisibleConnectors) {
            String connectorId = connector.getConnectorId();
            JsonArray children = Json.createArray();

            for (ClientConnector child : AbstractClientConnector
                    .getAllChildrenIterable(connector)) {
                if (LegacyCommunicationManager
                        .isConnectorVisibleToClient(child)) {
                    children.set(children.length(), child.getConnectorId());
                }
            }
            try {
                hierarchyInfo.put(connectorId, children);
            } catch (JsonException e) {
View Full Code Here


    public void write(UI ui, Writer writer) throws IOException {

        Collection<ClientMethodInvocation> pendingInvocations = collectPendingRpcCalls(ui
                .getConnectorTracker().getDirtyVisibleConnectors());

        JsonArray rpcCalls = Json.createArray();
        for (ClientMethodInvocation invocation : pendingInvocations) {
            // add invocation to rpcCalls
            try {
                JsonArray invocationJson = Json.createArray();
                invocationJson.set(0, invocation.getConnector().getConnectorId());
                invocationJson.set(1, invocation.getInterfaceName());
                invocationJson.set(2, invocation.getMethodName());
                JsonArray paramJson = Json.createArray();
                for (int i = 0; i < invocation.getParameterTypes().length; ++i) {
                    Type parameterType = invocation.getParameterTypes()[i];
                    JsonValue referenceParameter = null;
                    // TODO Use default values for RPC parameter types
                    // if (!JsonCodec.isInternalType(parameterType)) {
                    // try {
                    // referenceParameter = parameterType.newInstance();
                    // } catch (Exception e) {
                    // logger.log(Level.WARNING,
                    // "Error creating reference object for parameter of type "
                    // + parameterType.getName());
                    // }
                    // }
                    EncodeResult encodeResult = JsonCodec.encode(
                            invocation.getParameters()[i], referenceParameter,
                            parameterType, ui.getConnectorTracker());
                    paramJson.set(i, encodeResult.getEncodedValue());
                }
                invocationJson.set(3, paramJson);
                rpcCalls.set(rpcCalls.length(), invocationJson);
            } catch (JsonException e) {
                throw new PaintException(
View Full Code Here

     * {@link JavaScriptCallbackHelper#invokeCallback(String, Object...)}.
     * #12532
     */
    public void testClientMethodSerialization_WithJSONArray_ContentStaysSame()
            throws Exception {
        JsonArray originalArray = Json.createArray();
        originalArray.set(0, "callbackParameter1");
        originalArray.set(1, "callBackParameter2");
        originalArray.set(2, "12345");
        ClientMethodInvocation original = new ClientMethodInvocation(null,
                "interfaceName", JAVASCRIPT_CALLBACK_METHOD, new Object[] {
                        "callBackMethodName", originalArray });

        ClientMethodInvocation copy = (ClientMethodInvocation) serializeAndDeserialize(original);
        JsonArray copyArray = (JsonArray) copy.getParameters()[1];
        assertEquals(JsonUtil.stringify(originalArray), JsonUtil.stringify(copyArray));
    }
View Full Code Here

        ensureDecodedCorrectly(stateToStringMap, encodedMap, mapType);
    }

    public void testNullLegacyValue() throws JsonException {
        JsonArray inputArray = Json.createArray();
        inputArray.set(0, "n");
        inputArray.set(1, Json.createNull());
        UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
                UidlValue.class, true, inputArray, null);
        assertNull(decodedObject.getValue());
    }
View Full Code Here

        assertNull(decodedObject.getValue());
    }

    public void testNullTypeOtherValue() {
        try {
            JsonArray inputArray = Json.createArray();
            inputArray.set(0, "n");
            inputArray.set(1, "a");
            UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
                    UidlValue.class, true, inputArray, null);

            throw new AssertionFailedError("No JsonException thrown");
        } catch (JsonException e) {
View Full Code Here

            });

            addFunction("reportParentIds", new JavaScriptFunction() {
                @Override
                public void call(JsonArray arguments) {
                    JsonArray parentIds = arguments.getArray(0);
                    if (!parentIds.getString(0).equals(getConnectorId())) {
                        log.log("Connector ids doesn't match");
                    }

                    HasComponents parent = getParent();
                    int i = 1;
                    while (parent != null) {
                        if (!parentIds.getString(i).equals(
                                parent.getConnectorId())) {
                            log.log("parentIds[" + i + "] doesn't match");
                        }
                        i++;
                        parent = parent.getParent();
View Full Code Here

            uiConnectorTracker.cleanConnectorMap();
        }
    }

    private JsonArray toJsonArray(List<String> list) {
        JsonArray result = Json.createArray();
        for (int i = 0; i < list.size(); i++) {
            result.set(i, list.get(i));
        }

        return result;
    }
View Full Code Here

            ConnectorTracker connectorTracker) {
        if (jsonMap.getType() == JsonType.ARRAY) {
            // Client-side has no declared type information to determine
            // encoding method for empty maps, so these are handled separately.
            // See #8906.
            JsonArray jsonArray = (JsonArray) jsonMap;
            if (jsonArray.length() == 0) {
                return new HashMap<Object, Object>();
            }
        }

        if (!restrictToInternalTypes && targetType instanceof ParameterizedType) {
View Full Code Here

    private static Map<Object, Object> decodeObjectMap(Type keyType,
            Type valueType, JsonArray jsonMap, ConnectorTracker connectorTracker)
            {

        JsonArray keys = jsonMap.getArray(0);
        JsonArray values = jsonMap.getArray(1);

        assert (keys.length() == values.length());

        Map<Object, Object> map = new HashMap<Object, Object>(keys.length() * 2);
        for (int i = 0; i < keys.length(); i++) {
            Object key = decodeInternalOrCustomType(keyType, keys.get(i),
                    connectorTracker);
            Object value = decodeInternalOrCustomType(valueType, values.get(i),
                    connectorTracker);

            map.put(key, value);
        }

View Full Code Here

        }
    }

    private static JsonArray encodeArrayContents(Type componentType,
            Object array, ConnectorTracker connectorTracker) {
        JsonArray jsonArray = Json.createArray();
        for (int i = 0; i < Array.getLength(array); i++) {
            EncodeResult encodeResult = encode(Array.get(array, i), null,
                    componentType, connectorTracker);
            jsonArray.set(i, encodeResult.getEncodedValue());
        }
        return jsonArray;
    }
View Full Code Here

TOP

Related Classes of elemental.json.JsonArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.