Package com.google.gwt.json.client

Examples of com.google.gwt.json.client.JSONValue


  @Override
  public <X> boolean isModified(Key<X, ?> key, X value) {
    ErraiEntityType<X> entityType = key.getEntityType();
    String keyJson = key.toJson();
    JSONValue newValueJson = entityType.toJson(em, value);
    JSONValue oldValueJson = JSONParser.parseStrict(getImpl(keyJson));
    boolean modified = !JsonUtil.equals(newValueJson, oldValueJson);
    if (modified) {
      System.out.println("Detected modified entity " + key);
      System.out.println("   Old: " + oldValueJson);
      System.out.println("   New: " + newValueJson);
View Full Code Here


  }

  public static List<Message> decodePayload(final String jsonString) {
    if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList();

    final JSONValue val = JSONParser.parseStrict(jsonString);

    if (val == null || val.isArray() == null) {
      throw new RuntimeException("illegal payload: must be JSONArray");
    }

    final JSONArray jsonArray = val.isArray();
    final List<Message> messageList = new ArrayList<Message>(jsonArray.size());
    for (int i = 0; i < jsonArray.size(); i++) {
       messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i))));
    }
View Full Code Here

  public String toString(){
    return world.getTitle()+"-"+levelNumber;
  }
  public void buildLevel(){
    JSONObject levelCreations=jsonContext.get("creations").isObject();
    JSONValue unknownCreation;
    LevelBuilder builder;
   
    JSONArray creationArray;
   
    int i;
   
    for(String key:levelCreations.keySet()){
      unknownCreation=levelCreations.get(key);
      builder=BUILDER_MAP.get(key);
      if(unknownCreation.isArray()!=null){
        creationArray=unknownCreation.isArray();
       
        for(i=0;i<creationArray.size();i++){
          builder.build(creationArray.get(i).isObject());
        }
      }else{
        builder.build(unknownCreation.isObject());
      }
    }
  }
View Full Code Here

  }

  public static List<Message> decodePayload(final String jsonString) {
    if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList();

    final JSONValue val = JSONParser.parseStrict(jsonString);

    if (val == null || val.isArray() == null) {
      throw new RuntimeException("illegal payload: must be JSONArray");
    }

    final JSONArray jsonArray = val.isArray();
    final List<Message> messageList = new ArrayList<Message>(jsonArray.size());
    for (int i = 0; i < jsonArray.size(); i++) {
       messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i))));
    }
View Full Code Here

                + "ms");

            JSONArray array = null;
            try {
              long start = System.currentTimeMillis();
              JSONValue json = JSONParser.parse(markerJSON);
              array = json.isArray();
              log(1,
                  "JSON parsed in "
                      + (System.currentTimeMillis() - start)
                      + "ms");
              if (array == null) {
View Full Code Here

    }

    private void handleMarkerJSON(JSONArray array) {
      synchronized (knownMarkers) {

        JSONValue value;
        long startTime = System.currentTimeMillis();
        int initSize = knownMarkers.size();
        List<String> markersFromThisUpdate = new ArrayList<String>();

        for (int i = 0; i < array.size(); i++) {
          JSONObject jsMarker;
          JSONString jsMID, jsTitle, jsIcon;
          JSONNumber jsLat, jsLng;
          JSONBoolean jsVisible, jsHasInfo, jsDraggable;
          Marker marker = null;
          boolean isOldMarker = false;
          boolean replaceMarker = false;

          if ((jsMarker = array.get(i).isObject()) == null) {
            continue;
          }

          // Read marker id
          if ((value = jsMarker.get("mid")) == null) {
            continue;
          }
          if ((jsMID = value.isString()) == null) {
            continue;
          }

          if ((value = jsMarker.get("draggable")) == null) {
            continue;
          } else {
            if (knownMarkers.containsKey(jsMID.toString())) {
              marker = knownMarkers.get(jsMID.toString());
              marker.setDraggingEnabled((((JSONBoolean) jsMarker
                  .get("draggable")).booleanValue()));
              isOldMarker = true;
            }
          }

          // Add maker to list of markers in this update
          markersFromThisUpdate.add(jsMID.toString());

          // Read marker latitude
          if ((value = jsMarker.get("lat")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsLat = value.isNumber()) == null) {
            if (!isOldMarker)
              continue;
          }

          // Read marker longitude
          if ((value = jsMarker.get("lng")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsLng = value.isNumber()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            // marker.setLatLng(jsLng.doubleValue());
          }

          // Read marker title
          if ((value = jsMarker.get("title")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsTitle = value.isString()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            if (isOldMarker && marker != null) {
              String title = marker.getTitle();

              // if title is changed
              if (!jsTitle.stringValue().equals(title)) {
                replaceMarker = true;
                log(1, "Title changed: " + marker.getTitle());
              }
            }
          }

          // Read marker visibility
          if ((value = jsMarker.get("visible")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsVisible = value.isBoolean()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            if (marker != null) {
              boolean old = marker.isVisible();

              marker.setVisible(jsVisible.booleanValue());

              if (old != marker.isVisible()) {
                log(1,
                    "Toggled marker '" + marker.getTitle()
                        + "' visibility to "
                        + jsVisible.booleanValue());
              }
            }
          }

          // Read marker draggability (is that a word? :)
          if ((value = jsMarker.get("draggable")) == null) {
            if (!isOldMarker)
              continue;
          }

          if ((jsDraggable = value.isBoolean()) == null) {
            if (!isOldMarker)
              continue;
          }

          // Change position, if changed
          if (marker != null && jsLat != null && jsLng != null
              && marker.getLatLng() != null) {
            LatLng llang = marker.getLatLng();

            LatLng llang2 = LatLng.newInstance(jsLat.doubleValue(),
                jsLng.doubleValue());
            if (!llang.isEquals(llang2)) {
              marker.setLatLng(llang2);
            }
          }

          // Read marker icon
          if ((value = jsMarker.get("icon")) == null) {
            jsIcon = null;
            if (marker != null) {
              String currentURL = getMarkerIconURL(marker);
              if (!currentURL
                  .startsWith("http://maps.gstatic.com")
                  && currentURL != null && currentURL != "") {
                replaceMarker = true;
                log(1, "Icon url changed " + marker.getTitle()
                    + " from '" + currentURL + "'");
              }
            }
          } else if ((jsIcon = value.isString()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            if (marker != null
                && getMarkerIconURL(marker) != jsIcon
                    .toString()) {
              replaceMarker = true;
              log(1, "Icon url changed 2 " + marker.getTitle());
            }
          }

          int iconAnchorX = 0;
          if ((value = jsMarker.get("iconAnchorX")) != null) {
            JSONNumber jsAnchorX;
            if ((jsAnchorX = value.isNumber()) != null) {
              log(1, "Anchor X: " + jsAnchorX.toString());
              iconAnchorX = (int) Math.round(jsAnchorX
                  .doubleValue());
            } else {
              log(1, "Anchor X NaN");
            }
          }

          int iconAnchorY = 0;
          if ((value = jsMarker.get("iconAnchorY")) != null) {
            JSONNumber jsAnchorY;
            if ((jsAnchorY = value.isNumber()) != null) {
              iconAnchorY = (int) Math.round(jsAnchorY
                  .doubleValue());
            }
          }

          // do not create new one if old found (only if we want to
          // replace it)
          if (isOldMarker && !replaceMarker)
            continue;

          if (!isOldMarker)
            replaceMarker = false; // Never replace a marker if
                        // there is no previous one

          if (replaceMarker) {
            log(1, "Replacing marker " + marker.getTitle());
            map.removeOverlay(marker);
            markersFromThisUpdate.remove(marker);
          }

          marker = createMarker(jsLat, jsLng, jsTitle, jsVisible,
              jsIcon, iconAnchorX, iconAnchorY, jsDraggable);

          if (marker != null) {
            map.addOverlay(marker);

            // Add dragEnd handlers to marker
            marker.addMarkerDragEndHandler(VGoogleMap.this);

            // Read boolean telling if marker has a info window
            if ((value = jsMarker.get("info")) != null) {
              if ((jsHasInfo = value.isBoolean()) != null
                  && jsHasInfo.booleanValue()) {
                marker.addMarkerClickHandler(new InfoWindowOpener(
                    jsMID.stringValue()));

              }
View Full Code Here

   *
   * @param jsonString the Json string
   * @return the map
   */
  public static Map<String, Object> decode(String jsonString) {
    JSONValue v = JSONParser.parse(jsonString);
    if (v.isObject() != null) {
      return decode(v.isObject());
    } else {
      return null;
    }
  }
View Full Code Here

   * @return the map
   */
  public static Map<String, Object> decode(JSONObject jso) {
    Map<String, Object> map = new FastMap<Object>();
    for (String key : jso.keySet()) {
      JSONValue j = jso.get(key);
      if (j.isObject() != null) {
        map.put(key, decode(j.isObject()));
      } else if (j.isArray() != null) {
        map.put(key, decodeToList(j.isArray()));
      } else if (j.isBoolean() != null) {
        map.put(key, j.isBoolean().booleanValue());
      } else if (j.isString() != null) {
        map.put(key, decodeValue(j.isString().stringValue()));
      }
    }
    return map;
  }
View Full Code Here

  }

  protected static List<Object> decodeToList(JSONArray array) {
    List<Object> list = new ArrayList<Object>();
    for (int i = 0; i < array.size(); i++) {
      JSONValue v = array.get(i);
      if (v.isObject() != null) {
        list.add(decode(v.isObject()));
      } else if (v.isArray() != null) {
        list.add(decodeToList(v.isArray()));
      } else if (v.isNull() != null) {
        list.add(null);
      } else if (v.isNumber() != null) {
        list.add(v.isNumber().doubleValue());
      } else if (v.isBoolean() != null) {
        list.add(v.isBoolean().booleanValue());
      } else if (v.isString() != null) {
        list.add(decodeValue(v.isString().stringValue()));
      }
    }

    return list;
  }
View Full Code Here

     * field and send the unparsed JSON object onwards.
     *
     */


    JSONValue val = null;

    try {
      val = JSONParser.parseStrict(value);
    }
    catch (ClassCastException e) {
      if (!GWT.isProdMode()) {
        System.out.println("*** working around devmode bug ***");
        val = JSONParser.parseStrict(value);
      }
    }

    if (val == null) {
      return Collections.emptyList();
    }
    JSONArray arr = val.isArray();
    if (arr == null) {
      throw new RuntimeException("unrecognized payload" + val.toString());
    }
    ArrayList<MarshalledMessage> list = new ArrayList<MarshalledMessage>();
    unwrap(list, arr);
    return list;

View Full Code Here

TOP

Related Classes of com.google.gwt.json.client.JSONValue

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.