Package org.json

Examples of org.json.JSONException


   */
  private Object next(Object prev, int idx) throws JSONException
  {
    if (prev==null)
    {
      throw new JSONException("cannot traverse- missing object encountered");
    }

    if (prev instanceof JSONArray)
    {
      return ((JSONArray)prev).get(idx);
    }
    throw new JSONException("not an array");
  }
View Full Code Here


   */
  private Object next(Object prev, String ref) throws JSONException
  {
    if (prev==null)
    {
      throw new JSONException("cannot traverse- missing object encountered");
    }
    if (prev instanceof JSONObject)
    {
      return ((JSONObject)prev).get(ref);
    }
    throw new JSONException("not an object");
  }
View Full Code Here

    }
  }
  public static class test1JsonError extends MapReduceAdapter {
    @Override
    public void init(JSONObject params) {
      throw new RuntimeException("JsonException", new JSONException("JsonException"));
    }
View Full Code Here

    return new ArrayList(java.util.Arrays.asList(new NonSerializable()));
  }}
    public static class test7ResponseJsonError extends MapReduceAdapter {
    @Override
    public JSONObject render(Serializable reduceResult) {
      throw new RuntimeException(new JSONException("renderError"));
    }
View Full Code Here

          typeNum <= RelevanceJSONConstants.TYPENUMBER_SET_STRING)
      {
        Set hs = null;
        JSONArray values = jsonValues.optJSONArray(symbol);
        if (values == null)
          throw new JSONException("Variable "+ symbol + " does not have value.");

        switch (typeNum)
        {
        case RelevanceJSONConstants.TYPENUMBER_SET_INT:
          hs = new IntOpenHashSet();
          for (int k = 0; k < values.length(); k++)
          {
            hs.add(values.getInt(k));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_SET_DOUBLE:
          hs = new DoubleOpenHashSet();
          for (int k = 0; k < values.length(); k++)
          {
            hs.add(values.getDouble(k));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_SET_FLOAT:
          hs = new FloatOpenHashSet();
          for (int k = 0; k < values.length(); k++)
          {
            hs.add((float) values.getDouble(k));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_SET_LONG:
          hs = new LongOpenHashSet();
          for (int k = 0; k < values.length(); k++)
          {
            hs.add(values.getLong(k));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_SET_STRING:
          hs = new ObjectOpenHashSet();
          for (int k = 0; k < values.length(); k++)
          {
            hs.add(values.getString(k));
          }
          break;
        }
        dataTable.hm_var.put(symbol, hs);
      }
      else if (typeNum >= RelevanceJSONConstants.TYPENUMBER_MAP_INT_INT &&
               typeNum <= RelevanceJSONConstants.TYPENUMBER_MAP_STRING_STRING)
      {
        JSONObject values = jsonValues.optJSONObject(symbol);
        if (values == null)
          throw new JSONException("Variable "+ symbol + " does not have value.");

        JSONArray keysList = values.names();
        int keySize = keysList == null ? 0 : keysList.length();
       
        // denote if the map is represented in a way of combination of key jsonarray and value jsonarray;
        boolean isKeyValue = isKeyValueArrayMethod(values);
        JSONArray keysArrayList = null, valuesArrayList = null;
        int keyArraySize, valueArraySize;
        if(isKeyValue)
        {
          keysArrayList = values.optJSONArray(RelevanceJSONConstants.KW_KEY);
          valuesArrayList = values.optJSONArray(RelevanceJSONConstants.KW_VALUE);
         
          if (keysArrayList == null)
            throw new JSONException("Variable " + symbol + " is a map, but does not have a key list.");

          if (valuesArrayList == null)
            throw new JSONException("Variable " + symbol + "is a map, but does not have a value list.");

          keyArraySize = keysArrayList.length();
          valueArraySize = valuesArrayList.length();
          if (keyArraySize != valueArraySize)
            throw new JSONException("Variable " + symbol + ": key size is different from value size, can not convert to a map." );
         
          keySize = keysArrayList.length();
        }

        Map hm = null;
        switch (typeNum)
        {
        case RelevanceJSONConstants.TYPENUMBER_MAP_INT_INT:
          hm = new Int2IntOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Int2IntOpenHashMap) hm).put(keysArrayList.getInt(j), valuesArrayList.getInt(j));
            else
              ((Int2IntOpenHashMap) hm).put(keysList.getInt(j), values.getInt(keysList.getString(j)));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_INT_DOUBLE:
          hm = new Int2DoubleOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Int2DoubleOpenHashMap) hm).put(keysArrayList.getInt(j), valuesArrayList.getDouble(j));
            else
              ((Int2DoubleOpenHashMap) hm).put(keysList.getInt(j), values.getDouble(keysList.getString(j)));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_INT_FLOAT:
          hm = new Int2FloatOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Int2FloatOpenHashMap) hm).put(keysArrayList.getInt(j), (float) valuesArrayList.getDouble(j));
            else
              ((Int2FloatOpenHashMap) hm).put(keysList.getInt(j), (float) values.getDouble(keysList.getString(j)));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_INT_LONG:
          hm = new Int2LongOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Int2LongOpenHashMap) hm).put(keysArrayList.getInt(j), Long.parseLong(valuesArrayList.getString(j)));
            else
              ((Int2LongOpenHashMap) hm).put(keysList.getInt(j), Long.parseLong(values.getString(keysList.getString(j))));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_INT_STRING:
          hm = new Int2ObjectOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Int2ObjectOpenHashMap) hm).put(keysArrayList.getInt(j), valuesArrayList.getString(j));
            else
              ((Int2ObjectOpenHashMap) hm).put(keysList.getInt(j), values.getString(keysList.getString(j)));
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_STRING_INT:
          hm = new Object2IntOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Object2IntOpenHashMap) hm).put(keysArrayList.getString(j), valuesArrayList.getInt(j));
            else
            {
              String key = keysList.getString(j);
              ((Object2IntOpenHashMap) hm).put(key, values.getInt(key));
            }
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_STRING_DOUBLE:
          hm = new Object2DoubleOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Object2DoubleOpenHashMap) hm).put(keysArrayList.getString(j), valuesArrayList.getDouble(j));
            else
            {
            String key = keysList.getString(j);
            ((Object2DoubleOpenHashMap) hm).put(key, values.getDouble(key));
            }
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_STRING_FLOAT:
          hm = new Object2FloatOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Object2FloatOpenHashMap) hm).put(keysArrayList.getString(j), (float) valuesArrayList.getDouble(j));
            else
            {
              String key = keysList.getString(j);
              ((Object2FloatOpenHashMap) hm).put(key, (float) values.getDouble(key));
            }
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_STRING_LONG:
          hm = new Object2LongOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Object2LongOpenHashMap) hm).put(keysArrayList.getString(j), Long.parseLong(valuesArrayList.getString(j)));
            else
            {
              String key = keysList.getString(j);
              ((Object2LongOpenHashMap) hm).put(key, Long.parseLong(values.getString(keysList.getString(j))));
            }
          }
          break;
        case RelevanceJSONConstants.TYPENUMBER_MAP_STRING_STRING:
          hm = new Object2ObjectOpenHashMap();
          for (int j = 0; j < keySize; j++)
          {
            if(isKeyValue)
              ((Object2ObjectOpenHashMap) hm).put(keysArrayList.getString(j), valuesArrayList.getString(j));
            else
            {
              String key = keysList.getString(j);
              ((Object2ObjectOpenHashMap) hm).put(key, values.getString(key));
            }
          }
          break;
        }
        dataTable.hm_var.put(symbol, hm);
      }
      else if (typeNum >= RelevanceJSONConstants.TYPENUMBER_INT &&
               typeNum <= RelevanceJSONConstants.TYPENUMBER_STRING)
      {
        if (!jsonValues.has(symbol))
          throw new JSONException("Symbol " + symbol + " was not assigned with a value." );

        switch (typeNum)
        {
        case RelevanceJSONConstants.TYPENUMBER_INT:
          dataTable.hm_var.put(symbol, jsonValues.getInt(symbol));
          break;
        case RelevanceJSONConstants.TYPENUMBER_DOUBLE:
          dataTable.hm_var.put(symbol, jsonValues.getDouble(symbol));
          break;
        case RelevanceJSONConstants.TYPENUMBER_FLOAT:
          dataTable.hm_var.put(symbol, (float) jsonValues.getDouble(symbol));
          break;
        case RelevanceJSONConstants.TYPENUMBER_LONG:
          dataTable.hm_var.put(symbol, Long.parseLong(jsonValues.getString(symbol)));
          break;
        case RelevanceJSONConstants.TYPENUMBER_STRING:
          dataTable.hm_var.put(symbol, jsonValues.getString(symbol));
          break;
        case RelevanceJSONConstants.TYPENUMBER_BOOLEAN:
          dataTable.hm_var.put(symbol, jsonValues.getBoolean(symbol));
          break;
        }
      }
      else if (typeNum == RelevanceJSONConstants.TYPENUMBER_CUSTOM_OBJ)
      {
        Object obj = ExternalRelevanceDataStorage.getObj(symbol);
        if(obj != null)
          dataTable.hm_var.put(symbol, obj);
        else
          throw new JSONException("function parameter: " + symbol + " can not be initialized as a custom Object.");
      }
    }

    // Check if all the parameters have been initialized
    for(int i=0; i< dataTable.lls_params.size(); i++)
    {
      String symbol = dataTable.lls_params.get(i);
      Integer typeNum = dataTable.hm_type.get(symbol);
      if (typeNum < RelevanceJSONConstants.TYPENUMBER_FACET_INT ||
          typeNum > RelevanceJSONConstants.TYPENUMBER_FACET_A_INT)
      {
        if(!dataTable.hm_var.containsKey(symbol))
          throw new JSONException("function parameter: " + symbol + " was not initialized.");
      }
    }
  } // End of initializeValues()
View Full Code Here

      ch.addField(f);
    }
    catch (CannotCompileException e)
    {
      logger.info(e.getMessage());
      throw new JSONException(e);
    }
  }
View Full Code Here

      ch.addMethod(m_exp);
    }
    catch (CannotCompileException e)
    {
      logger.info(e.getMessage());
      throw new JSONException(e);
    }
  }
View Full Code Here

    {
       String errorString = String.format("Wrong facet type in facet variable definition json: %s. Map contents are %s. Facet array is %s.",
         facetType, mkString(RelevanceJSONConstants.FACET_INFO_MAP), facetArray);


       throw new JSONException(errorString);
    }

    Integer type = facetInfo[0];

    for(int i=0; i < facetArray.length(); i++)
    {
      String facetName = facetArray.getString(i);
      String symbol = facetName;

      if(dataTable.hm_symbol_facet.containsKey(symbol) || dataTable.hm_symbol_mfacet.containsKey(symbol) || dataTable.hm_symbol_afacet.containsKey(symbol))
        throw new JSONException("facet Symbol "+ symbol + " already defined." );

      if(dataTable.hm_facet_index.containsKey(facetName) || dataTable.hm_mfacet_index.containsKey(facetName) || dataTable.hm_afacet_index.containsKey(facetName))
        throw new JSONException("facet name "+ facetName + " already assigned to a symbol." );

      if (facetInfo[1] == 0)
      {
        // This facet is a normal facet;
        dataTable.hm_symbol_facet.put(symbol, facetName);
View Full Code Here

    for(int i=0; i< dataTable.lls_params.size();i++)
    {
      String paramName = dataTable.lls_params.get(i);

      if(!dataTable.hm_type.containsKey(paramName) || (dataTable.hm_type.get(paramName) == null))
        throw new JSONException("function parameter " + paramName + " is not defined.");

      Integer paramType = dataTable.hm_type.get(paramName);
      int[] paramInfo = PARAM_INIT_MAP.get(paramType);
      if(paramType.intValue() == RelevanceJSONConstants.TYPENUMBER_CUSTOM_OBJ)
      {
        String className = ExternalRelevanceDataStorage.getObjClsName(paramName);
        if(className == null)
          throw new JSONException("Custom external object " + paramName + " is not found.");
       
        String className2 = className.replace('$', '.');
       
        hs_safe.add(className);
        pool.importPackage(className);
View Full Code Here

    JSONObject jsonRelevance = null;
    if(jsonValue.has(RELEVANCE))
    {
      jsonRelevance = jsonValue.optJSONObject(RELEVANCE);
      if(jsonRelevance == null)
        throw new JSONException("relevance part of the query json can not be parsed.");
    }
    if(jsonRelevance == null)
    {
      return baseQuery;
    }
    else
    {
        // the olde code path, now turned off;
//      return new RelevanceQuery(baseQuery, jsonRelevance);
     
      ScoreAugmentFunction func = RelevanceFunctionBuilder.build(jsonRelevance);
      JSONObject valuesJson = jsonRelevance.optJSONObject(RelevanceJSONConstants.KW_VALUES);
      if(func == null)
        throw new JSONException("Can not create the score function;");
     
      return new ScoreAugmentQuery(baseQuery, func, valuesJson);
    }
  }
View Full Code Here

TOP

Related Classes of org.json.JSONException

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.