Package com.google.gwt.thirdparty.json

Examples of com.google.gwt.thirdparty.json.JSONArray


    try {
      switch (payload.charAt(0)) {
        case '{':
          return new JsonSplittable(new JSONObject(payload));
        case '[':
          return new JsonSplittable(new JSONArray(payload));
        case '"':
          return new JsonSplittable(new JSONArray("[" + payload + "]").getString(0));
        case '-':
        case '0':
        case '1':
        case '2':
        case '3':
View Full Code Here


      throw new RuntimeException("Could not parse payload", e);
    }
  }

  public static Splittable createIndexed() {
    return new JsonSplittable(new JSONArray());
  }
View Full Code Here

    reified.put(key, object);
  }

  public void setSize(int size) {
    // This is terrible, but there's no API support for resizing or splicing
    JSONArray newArray = new JSONArray();
    for (int i = 0; i < size; i++) {
      try {
        newArray.put(i, array.get(i));
      } catch (JSONException e) {
        throw new RuntimeException(e);
      }
    }
    array = newArray;
View Full Code Here

  }

  private void checkSplitPloints(File origSplitPoints, File fragmentsFile)
      throws Exception {
    JSONObject jsPoints = new JSONObject(stringContent(fragmentsFile));
    final JSONArray initSeq = (JSONArray) jsPoints.opt(EntityRecorder.INITIAL_SEQUENCE);
    if (initSeq != null) {
      // Considering stable order on "initial sequence". May be this is too strict, in that case,
      // we need to store the elements in a list and provide a search method
      JSONArray fragments = (JSONArray) jsPoints.get(EntityRecorder.FRAGMENTS);
      final Map<Integer, JSONObject> fragmentById = Maps.newHashMap();
      for (int i = 0; i < fragments.length(); i++) {
        JSONObject spoint = fragments.getJSONObject(i);
        fragmentById.put(spoint.getInt(EntityRecorder.FRAGMENT_ID), spoint);
      }
      SAXParserFactory.newInstance().newSAXParser().parse(
          new GZIPInputStream(new FileInputStream(origSplitPoints)),
          new DefaultHandler() {
            int isIdx = 0;
            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {
              super.startElement(uri, localName, qName, attributes);
              try {
                if (localName.equals("splipoint")) {
                  JSONArray runAsyncs = fragmentById
                      .get(Integer.parseInt(attributes.getValue("id")))
                      .getJSONArray(EntityRecorder.FRAGMENT_POINTS);
                  boolean present = false;
                  String runAsync = attributes.getValue("location");
                  for (int i = 0; i < runAsyncs.length(); i++) {
                    if (runAsyncs.getString(i).equals(runAsync)) {
                      present = true;
                      break;
                    }
                  }
                  assertTrue(present);
View Full Code Here

  public static final String CLASSES           = "classes";
  public static final String PACKAGES          = "packages";

  private static JSONObject writeJsonFromEntity(EntityDescriptor entity) throws JSONException {
    JSONObject json = new JSONObject();
    JSONArray fragments = new JSONArray();
    for (EntityDescriptor.Fragment frg : entity.getFragments()) {
      JSONObject frag = new JSONObject();
      frag.put(EntityRecorder.FRAGMENT_ID, frg.getId());
      frag.put(EntityRecorder.FRAGMENT_SIZE, frg.getSize());

      fragments.put(frag);
    }
    json.put(EntityRecorder.FRAGMENTS, fragments);
    json.put(ENTITY_JS, new JSONArray(entity.getObfuscatedNames()));
    return json;
  }
View Full Code Here

  public static JSONObject writeJson(PackageDescriptor pkg) throws JSONException {
    JSONObject json = new JSONObject();
    json.put(ENTITY_NAME, pkg.getName());
    // classes
    JSONArray classes = new JSONArray();
    for (ClassDescriptor classDescriptor : pkg.getClasses()) {
      JSONObject jsonClass = writeJsonFromEntity(classDescriptor);
      jsonClass.put(ENTITY_NAME, classDescriptor.getName());
      // fields
      JSONArray fields = new JSONArray();
      for (FieldDescriptor fieldDescriptor : classDescriptor.getFields()) {
        fields.put(writeJsonFromMember(fieldDescriptor));
      }
      jsonClass.put(FIELDS, fields);
      // methods
      JSONArray methods = new JSONArray();
      for (MethodDescriptor methodDescriptor : classDescriptor.getMethods()) {
        JSONObject jsonMethod = writeJsonFromMember(methodDescriptor);
        jsonMethod.put(METHOD_ID, methodDescriptor.getUniqueId());
        jsonMethod.put(METHOD_DEPENDENTS, new JSONArray(methodDescriptor.getDependentPointers()));
        methods.put(jsonMethod);
      }
      jsonClass.put(METHODS, methods);

      classes.put(jsonClass);
    }
    json.put(CLASSES, classes);
    // packages
    JSONArray packages = new JSONArray();
    for (PackageDescriptor packageDescriptor : pkg.getPackages()) {
      packages.put(writeJson(packageDescriptor));
    }
    json.put(PACKAGES, packages);

    return json;
  }
View Full Code Here

      return packageDescriptor;
    }

    private void setMethodDependencies() throws JSONException {
      for (MethodDescriptor method : mapDependants.keySet()) {
        JSONArray dependants = mapDependants.get(method);
        for (int i = 0; i < dependants.length(); i++) {
          method.addDependant(mapMethods.get(dependants.getInt(i)));
        }
      }
    }
View Full Code Here

    }

    private PackageDescriptor readJsonPackage(JSONObject jsonObject, String name,
        String longName) throws JSONException {
      PackageDescriptor descriptor = new PackageDescriptor(name, longName);
      JSONArray clss = jsonObject.getJSONArray(CLASSES);
      for (int i = 0; i < clss.length(); i++) {
        descriptor.addClass(readJsonClass(clss.getJSONObject(i), longName));
      }
      JSONArray packages = jsonObject.getJSONArray(PACKAGES);
      for (int i = 0; i < packages.length(); i++) {
        JSONObject subPackage = packages.getJSONObject(i);
        String packageName = subPackage.getString(ENTITY_NAME);
        descriptor.addPackage(readJsonPackage(subPackage, packageName,
            longName + (longName.isEmpty() ? "" : ".") + packageName));
      }
      return descriptor;
View Full Code Here

    private ClassDescriptor readJsonClass(JSONObject jsonObject, String packageName)
        throws JSONException {
      ClassDescriptor descriptor = new ClassDescriptor(jsonObject.getString("name"), packageName);
      updateEntity(descriptor, jsonObject);
      JSONArray fields = jsonObject.getJSONArray(FIELDS);
      for (int i = 0; i < fields.length(); i++) {
        descriptor.addField(readJsonField(fields.getJSONObject(i), descriptor));
      }
      JSONArray methods = jsonObject.getJSONArray(METHODS);
      for (int i = 0; i < methods.length(); i++) {
        descriptor.addMethod(readJsonMethod(methods.getJSONObject(i), descriptor));
      }
      return descriptor;
    }
View Full Code Here

      updateEntity(fieldDescriptor, jsonObject);
      return fieldDescriptor;
    }

    private void updateEntity(EntityDescriptor entity, JSONObject jsonObject) throws JSONException {
      JSONArray jsNames = jsonObject.getJSONArray(ENTITY_JS);
      for (int i = 0; i < jsNames.length(); i++) {
        entity.addObfuscatedName(jsNames.getString(i));
      }
      JSONArray frags = jsonObject.getJSONArray(EntityRecorder.FRAGMENTS);
      for (int i = 0; i < frags.length(); i++) {
        JSONObject frag = frags.getJSONObject(i);
        entity.addFragment(
            new Fragment(frag.getInt(EntityRecorder.FRAGMENT_ID),
                frag.getInt(EntityRecorder.FRAGMENT_SIZE)));
      }
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.thirdparty.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.