Package elemental.json

Examples of elemental.json.JsonObject


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

        Collection<ClientConnector> dirtyVisibleConnectors = ui
                .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) {
                throw new PaintException(
                        "Failed to send hierarchy information about "
                                + connectorId + " to the client: "
                                + e.getMessage(), e);
View Full Code Here


    }

    protected void appendMainScriptTagContents(BootstrapContext context,
            StringBuilder builder) throws IOException {
        JsonObject appConfig = getApplicationParameters(context);

        boolean isDebug = !context.getSession().getConfiguration()
                .isProductionMode();

        if (isDebug) {
View Full Code Here

            throws PaintException {
        VaadinRequest request = context.getRequest();
        VaadinSession session = context.getSession();
        VaadinService vaadinService = request.getService();

        JsonObject appConfig = Json.createObject();

        String themeName = context.getThemeName();
        if (themeName != null) {
            appConfig.put("theme", themeName);
        }

        // Ignore restartApplication that might be passed to UI init
        if (request
                .getParameter(VaadinService.URL_PARAMETER_RESTART_APPLICATION) != null) {
            appConfig.put("extraParams", "&" + IGNORE_RESTART_PARAM + "=1");
        }

        JsonObject versionInfo = Json.createObject();
        versionInfo.put("vaadinVersion", Version.getFullVersion());
        appConfig.put("versionInfo", versionInfo);

        appConfig.put("widgetset", context.getWidgetsetName());

        // Use locale from session if set, else from the request
        Locale locale = ServletPortletHelper.findLocale(null,
                context.getSession(), context.getRequest());
        // Get system messages
        SystemMessages systemMessages = vaadinService.getSystemMessages(locale,
                request);
        if (systemMessages != null) {
            // Write the CommunicationError -message to client
            JsonObject comErrMsg = Json.createObject();
            comErrMsg.put("caption",
                    systemMessages.getCommunicationErrorCaption());
            comErrMsg.put("message",
                    systemMessages.getCommunicationErrorMessage());
            if (systemMessages.getCommunicationErrorURL() == null) {
                comErrMsg.put("url", Json.createNull());
            } else {
                comErrMsg.put("url", systemMessages.getCommunicationErrorURL());
            }

            appConfig.put("comErrMsg", comErrMsg);

            JsonObject authErrMsg = Json.createObject();
            authErrMsg.put("caption",
                    systemMessages.getAuthenticationErrorCaption());
            authErrMsg.put("message",
                    systemMessages.getAuthenticationErrorMessage());
            if (systemMessages.getAuthenticationErrorURL() == null) {
                authErrMsg.put("url", Json.createNull());
            } else {
                authErrMsg.put("url",
                        systemMessages.getAuthenticationErrorURL());
            }

            appConfig.put("authErrMsg", authErrMsg);

            JsonObject sessExpMsg = Json.createObject();
            sessExpMsg
                    .put("caption", systemMessages.getSessionExpiredCaption());
            sessExpMsg
                    .put("message", systemMessages.getSessionExpiredMessage());
            if (systemMessages.getSessionExpiredURL() == null) {
                sessExpMsg.put("url", Json.createNull());
            } else {
                sessExpMsg.put("url", systemMessages.getSessionExpiredURL());
            }

            appConfig.put("sessExpMsg", sessExpMsg);
        }
View Full Code Here

            UI uI = getBrowserDetailsUI(request, session);

            session.getCommunicationManager().repaintAll(uI);

            JsonObject params = Json.createObject();
            params.put(UIConstants.UI_ID_PARAMETER, uI.getUIId());
            String initialUIDL = getInitialUidl(request, uI);
            params.put("uidl", initialUIDL);

            stringWriter.write(JsonUtil.stringify(params));
        } catch (JsonException e) {
            throw new IOException("Error producing initial UIDL", e);
        } finally {
View Full Code Here

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

        Collection<ClientConnector> dirtyVisibleConnectors = ui
                .getConnectorTracker().getDirtyVisibleConnectors();

        JsonObject sharedStates = Json.createObject();
        for (ClientConnector connector : dirtyVisibleConnectors) {
            // encode and send shared state
            try {
                JsonObject stateJson = connector.encodeState();

                if (stateJson != null && stateJson.keys().length != 0) {
                    sharedStates.put(connector.getConnectorId(), stateJson);
                }
            } catch (JsonException e) {
                throw new PaintException(
                        "Failed to serialize shared state for connector "
View Full Code Here

    static CvalInfo parseJson(String json) {
        if (json == null) {
            return null;
        }
        try {
            JsonObject o = JsonUtil.parse(json);
            return new CvalInfo(o);
        } catch (JsonException e) {
            return null;
        }
    }
View Full Code Here

            URL sessionURL = new URL("http://" + hostName + ":" + port
                    + "/grid/api/testsession?session=" + d.getSessionId());
            BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(
                    "POST", sessionURL.toExternalForm());
            HttpResponse response = client.execute(host, r);
            JsonObject object = extractObject(response);
            URL myURL = new URL(object.getString("proxyId"));
            if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
                return myURL.getHost();
            }
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

                message = details;
            } else if (details != null) {
                message += "<br/><br/>" + details;
            }

            JsonObject appError = Json.createObject();
            appError.put("caption", caption);
            appError.put("message", message);
            if (url == null) {
                appError.put("url", Json.createNull());
            } else {
                appError.put("url", url);
            }

            JsonObject meta = Json.createObject();
            meta.put("appError", appError);

            JsonObject json = Json.createObject();
            json.put("changes", Json.createObject());
            json.put("resources", Json.createObject());
            json.put("locales", Json.createObject());
            json.put("meta", meta);
            json.put(ApplicationConstants.SERVER_SYNC_ID, -1);
            returnString = JsonUtil.stringify(json);
        } catch (JsonException e) {
            getLogger().log(Level.WARNING,
                    "Error creating critical notification JSON message", e);
        }
View Full Code Here

    /*
     * Loops through the fields of value and encodes them.
     */
    private static EncodeResult encodeObject(Object value, Class<?> valueType,
            JsonObject referenceValue, ConnectorTracker connectorTracker) {
        JsonObject encoded = Json.createObject();
        JsonObject diff = Json.createObject();

        try {
            for (BeanProperty property : getProperties(valueType)) {
                String fieldName = property.getName();
                // We can't use PropertyDescriptor.getPropertyType() as it does
                // not support generics
                Type fieldType = property.getType();
                Object fieldValue = property.getValue(value);

                if (encoded.hasKey(fieldName)) {
                    throw new RuntimeException(
                            "Can't encode "
                                    + valueType.getName()
                                    + " as it has multiple properties with the name "
                                    + fieldName.toLowerCase()
                                    + ". This can happen if there are getters and setters for a public field (the framework can't know which to ignore) or if there are properties with only casing distinguishing between the names (e.g. getFoo() and getFOO())");
                }

                JsonValue fieldReference;
                if (referenceValue != null) {
                    fieldReference = referenceValue.get(fieldName);
                    if (fieldReference instanceof JsonNull) {
                        fieldReference = null;
                    }
                } else {
                    fieldReference = null;
                }

                EncodeResult encodeResult = encode(fieldValue, fieldReference,
                        fieldType, connectorTracker);
                encoded.put(fieldName, encodeResult.getEncodedValue());

                if (!jsonEquals(encodeResult.getEncodedValue(), fieldReference)) {
                    diff.put(fieldName, encodeResult.getDiffOrValue());
                }
            }
        } catch (Exception e) {
            // TODO: Should exceptions be handled in a different way?
            throw new RuntimeException(e);
View Full Code Here

    /*
     * Encodes a connector map. Invisible connectors are skipped.
     */
    private static JsonObject encodeConnectorMap(Type valueType, Map<?, ?> map,
            ConnectorTracker connectorTracker) {
        JsonObject jsonMap = Json.createObject();

        for (Entry<?, ?> entry : map.entrySet()) {
            ClientConnector key = (ClientConnector) entry.getKey();
            if (LegacyCommunicationManager.isConnectorVisibleToClient(key)) {
                EncodeResult encodedValue = encode(entry.getValue(), null,
                        valueType, connectorTracker);
                jsonMap.put(key.getConnectorId(),
                        encodedValue.getEncodedValue());
            }
        }

        return jsonMap;
View Full Code Here

TOP

Related Classes of elemental.json.JsonObject

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.