Package com.google.gwt.json.client

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


    }
    return value.isArray();
  }

  protected JSONObject getObject(String key) {
    JSONValue value = get(key);
    if (value == null) {
      return null;
    }
    return value.isObject();
  }
View Full Code Here


     * cannot be sure the destination endpoint exists within this Errai bundle.  So we extract the ToSubject
     * field and send the unparsed JSON object onwards.
     *
     */
    try {
      JSONValue val = JSONParser.parseStrict(value);
      if (val == null) {
        return EMPTYLIST;
      }
      JSONArray arr = val.isArray();
      if (arr == null) {
        throw new RuntimeException("unrecognized payload" + val.toString());
      }
      ArrayList<MarshalledMessage> list = new ArrayList<MarshalledMessage>(arr.size());
      for (int i = 0; i < arr.size(); i++) {
        list.add(new MarshalledMessageImpl((JSONObject) arr.get(i)));
      }
View Full Code Here

               public void onFailure(ServerError error)
               {
                  String message = error.getUserMessage();
                 
                  // see if a special message was provided
                  JSONValue errValue = error.getClientInfo();
                  if (errValue != null)
                  {
                     JSONString errMsg = errValue.isString();
                     if (errMsg != null)
                        message = errMsg.stringValue();
                  }
                 
                  globalDisplay_.showMessage(GlobalDisplay.MSG_ERROR,
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());

        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

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

    if (attrJsonValue == null || attrJsonValue.isNull() != null) return;

    Class<Y> attributeType = attr.getJavaType();
    ErraiEntityType<Y> attrEntityType = eem.getMetamodel().entity(attributeType);

    JSONValue idJson = attrJsonValue.isObject().get("entityReference");
    Class<?> idType = attrEntityType.getId(Object.class).getJavaType();
    Object id = JsonUtil.basicValueFromJson(idJson, idType);

    System.out.println("   looking for " + attrEntityType.getJavaType() + " with id " + id);
    Y value = eem.find(attrEntityType.getJavaType(), id);
View Full Code Here

    // FIXME this is broken for Map attributes
    // TODO when we support Map attributes, we should get the attribute with getCollection()/getMap() to fix this warning
    Collection<E> collection = (Collection<E>) attr.createEmptyCollection();

    for (int i = 0; i < attrJsonValues.size(); i++) {
      JSONValue idJson = attrJsonValues.get(i).isObject().get("entityReference");
      Class<?> idType = attrEntityType.getId(Object.class).getJavaType();
      Object id = JsonUtil.basicValueFromJson(idJson, idType);

      System.out.println("   looking for " + attrEntityType.getJavaType() + " with id " + id);
      E value = eem.getPartiallyConstructedEntity(Key.get(eem, attrEntityType.getJavaType(), id));
View Full Code Here

    attr.set(targetEntity, (C) collection);
  }

  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

    return ("{\"entityType\":\"" + entityType.getJavaType().getName()
            + "\",\"id\":" + JsonUtil.basicValueToJson(id) + "}");
  }

  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);
    }

    String entityClassName = k.isObject().get("entityType").isString().stringValue();
    ErraiEntityType<Object> et = em.getMetamodel().entity(entityClassName, failIfNotFound);
    if (et == null) {
      return null;
    }
    ErraiSingularAttribute<?, Object> idAttr = et.getId(Object.class);
    Object id = JsonUtil.basicValueFromJson(k.isObject().get("id"), idAttr.getJavaType());

    return new Key<Object, Object>(et, id);
  }
View Full Code Here

  @Override
  public <X> void put(Key<X,?> key, X value) {
    ErraiEntityType<X> entityType = key.getEntityType();
    String keyJson = key.toJson();
    JSONValue valueJson = entityType.toJson(em, value);
    System.out.println(">>>put '" + keyJson + "'");
    putImpl(keyJson, valueJson.toString());
  }
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.