Package com.google.gwt.json.client

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


   * @param json JSON object to extract the value from.
   * @param key key of the value to extract.
   * @return the JSONObject if it exists.
   */
  private static JSONObject getJsonObjectValue(JSONObject json, String key) {
    JSONValue value = json.get(key);
    return (value != null) ? value.isObject() : null;
  }
View Full Code Here


   * @param jsonValue
   * @return
   */
  public static <T extends JavaScriptObject> T fromJSONValue(String encodedObject)
  {
    JSONValue jsonValue = JSONParser.parseStrict(encodedObject);
    return fromJSONValue(jsonValue).cast();
  }
View Full Code Here

  @Override
  public <X> void put(Key<X,?> key, X value) {
    ErraiManagedType<X> entityType = key.getEntityType();
    String keyJson = namespace + key.toJson();
    JSONValue valueJson = entityType.toJson(em, value);
    logger.trace(">>>put '" + keyJson + "'");
    LocalStorage.put(keyJson, valueJson.toString());
  }
View Full Code Here

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

    entity = newInstance();
    try {
      eem.putPartiallyConstructedEntity(key, entity);
      for (Attribute<? super X, ?> a : getAttributes()) {
        ErraiAttribute<? super X, ?> attr = (ErraiAttribute<? super X, ?>) a;
        JSONValue attrJsonValue = jsonValue.isObject().get(attr.getName());

        // this attribute did not exist when the entity was originally persisted; skip it.
        if (attrJsonValue == null) continue;

        switch (attr.getPersistentAttributeType()) {
        case ELEMENT_COLLECTION:
        case EMBEDDED:
        case BASIC:
          parseInlineJson(entity, attr, attrJsonValue, eem);
          break;

        case MANY_TO_MANY:
        case MANY_TO_ONE:
        case ONE_TO_MANY:
        case ONE_TO_ONE:
          if (attr instanceof ErraiSingularAttribute) {
            parseSingularJsonReference(entity, (ErraiSingularAttribute<? super X, ?>) attr, attrJsonValue, eem);
          }
          else if (attr instanceof ErraiPluralAttribute) {
            parsePluralJsonReference(entity, (ErraiPluralAttribute<? super X, ?, ?>) attr, attrJsonValue.isArray(), eem);
          }
          else {
            throw new PersistenceException("Unknown attribute type " + attr);
          }
        }
View Full Code Here

      eem.removePartiallyConstructedEntity(key);
    }
  }

  private Key<X, ?> keyFromJson(JSONValue json) {
    JSONValue keyJson = json.isObject().get(id.getName());
    Object idValue = JsonUtil.basicValueFromJson(keyJson, id.getJavaType());
    return new Key<X, Object>(this, idValue);
  }
View Full Code Here

      case MANY_TO_MANY:
      case MANY_TO_ONE:
      case ONE_TO_MANY:
      case ONE_TO_ONE:
        JSONValue attributeValue;
        if (attr instanceof ErraiSingularAttribute) {
          attributeValue = makeJsonReference(sourceEntity, (ErraiSingularAttribute<? super X, ?>) attr, eem);
        }
        else if (attr instanceof ErraiPluralAttribute) {
          attributeValue = makeJsonReference(sourceEntity, (ErraiPluralAttribute<? super X, ?, ?>) attr, eem);
View Full Code Here

    if (attrEntityType == null) {
      throw new IllegalArgumentException("Can't make a reference to non-entity-typed attribute " + attr);
    }

    Object idToReference = attrEntityType.getId(Object.class).get(entityToReference);
    JSONValue ref;
    if (idToReference == null) {
      ref = JSONNull.getInstance();
    }
    else {
      // XXX attrEntityType is incorrect entityToReference is a subtype of attr.getJavaType()
View Full Code Here

    JSONArray array = new JSONArray();
    int index = 0;
    for (E element : (Iterable<E>) attrValue) {
      Object idToReference = attrEntityType.getId(Object.class).get(element);
      JSONValue ref;
      if (idToReference == null) {
        ref = JSONNull.getInstance();
      }
      else {
        // XXX attrEntityType is incorrect for collection elements that are subtypes of the attrEntityType
View Full Code Here

   *          {@code em}, an IllegalArgumentException will be thrown.
   * @return An instance of Key that corresponds with the entity type and ID of
   *         the given JSON string.
   */
  public static Key<?, ?> fromJson(ErraiEntityManager em, String key, boolean failIfNotFound) {
    JSONValue k;
    try {
      k = JSONParser.parseStrict(key);

    } catch (JSONException e) {
      throw new JSONException("Input: " + key, e);
    }
    return fromJsonObject(em, k.isObject(), failIfNotFound);
  }
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.