Examples of RePresentationException


Examples of ru.yandex.strictweb.ajaxtools.exception.RePresentationException

    return result;
  }

  private Collection parseListOrSet(Class clazz, Type type) throws Exception {
    if(type==null || !(type instanceof ParameterizedType))
      throw new RePresentationException(clazz);

    boolean isList = List.class.isAssignableFrom(clazz);
   
    if(isList) {
        if(lexer.type != Yytoken.TYPE_LEFT_SQUARE) new RePresentationException("Bad json: list is not list");
    } else if(lexer.type != Yytoken.TYPE_LEFT_BRACE && lexer.type != Yytoken.TYPE_LEFT_SQUARE) {
        new RePresentationException("Bad json: set is not map or list");
    }
   
    Collection<Object> col = isList ? new ArrayList<Object>() :
      (SortedSet.class.isAssignableFrom(clazz) ? new TreeSet<Object>(): new LinkedHashSet<Object>());
   
    ParameterizedType pType = (ParameterizedType) type;
    Type valType = pType.getActualTypeArguments()[0];
    Class valClass = null;
    if(valType instanceof Class) valClass = (Class)valType;
    if(valType instanceof ParameterizedType) valClass = (Class)((ParameterizedType)valType).getRawType();
    if(valClass==null) throw new RePresentationException("Cant find parameter for Collection : " + valType.toString());
   
    if(lexer.type == Yytoken.TYPE_LEFT_BRACE) {
      // это мапа {}
      for(;;) {
        lexer.yylex();
        if(lexer.type == Yytoken.TYPE_COMMA) continue;
        if(lexer.type == Yytoken.TYPE_RIGHT_BRACE) break;
        if(lexer.type != Yytoken.TYPE_VALUE) throw new RePresentationException("Bad json: map key expected");
        Object key = getObjectSimple(valClass);
        lexer.yylex();
        if(lexer.type != Yytoken.TYPE_COLON) throw new RePresentationException("Bad json: key:value separator expected");
        lexer.yylex();
        if(Boolean.TRUE == getObjectSimple(Boolean.class)) {
          col.add(key);
        }
      }
    } else {
      // это маccив []
      for(;;) {
          col.add(getObject(valClass, valType));
          lexer.yylex();
          if(lexer.type == Yytoken.TYPE_COMMA) continue;
          if(lexer.type == Yytoken.TYPE_RIGHT_SQUARE) break;
          throw new RePresentationException("Bad json: expected , or ]");
      }     
    }
   
    return col;
  }
View Full Code Here

Examples of ru.yandex.strictweb.ajaxtools.exception.RePresentationException

   
    return col;
  }

  private Map parseMap(Class clazz, Type type) throws IOException, ParseException, Exception {
    if(lexer.type != Yytoken.TYPE_LEFT_BRACE) throw new RePresentationException("Bad json: map is not map");
   
    final Map map = SortedMap.class.isAssignableFrom(clazz) ? new TreeMap() : new LinkedHashMap();
   
    ParameterizedType pType = (ParameterizedType) type;
    Type keyType = pType.getActualTypeArguments()[0];
    Class keyClass = null;
    if(keyType instanceof Class) keyClass = (Class)keyType;
    if(keyType instanceof ParameterizedType) keyClass = (Class)((ParameterizedType)keyType).getRawType();
    if(keyClass==null) throw new RePresentationException("Cant find key parameter for Map : " + keyType.toString());     
    Type valType = pType.getActualTypeArguments()[1];
    Class valClass = null;
    if(valType instanceof Class) valClass = (Class)valType;
    if(valType instanceof ParameterizedType) valClass = (Class)((ParameterizedType)valType).getRawType();
    if(valClass==null) throw new RePresentationException("Cant find value parameter for Map : " + valType.toString());     
   
    for(;;) {
      lexer.yylex();
      if(lexer.type == Yytoken.TYPE_COMMA) continue;
      if(lexer.type == Yytoken.TYPE_RIGHT_BRACE) break;
      if(lexer.type != Yytoken.TYPE_VALUE) throw new RePresentationException("Bad json: map key expected");
      Object key = getObjectSimple(keyClass);
      lexer.yylex();
      if(lexer.type != Yytoken.TYPE_COLON) throw new RePresentationException("Bad json: key:value separator expected");
      map.put(key, getObject(valClass, valType));
    }
   
    return map;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.