Examples of RePresentationException


Examples of jp.ac.kobe_u.cs.prolog.lang.RepresentationException

      } else if (!a2.isInteger()) {
        throw new IllegalTypeException(this, 2, "integer", a2);
      }
      int i = ((IntegerTerm) a2).intValue();
      if (!Character.isDefined(i)) {
        throw new RepresentationException(this, 2, "character_code");
      }
      if (!a1.unify(SymbolTerm.makeSymbol(String.valueOf((char) i)),
          engine.trail)) {
        return engine.fail();
      }
View Full Code Here

Examples of jp.ac.kobe_u.cs.prolog.lang.RepresentationException

        throw e;
      }
    }
    n = ((NumberTerm) a2).intValue();
    if (!Character.isDefined(n)) {
      throw new RepresentationException(this, 2, "character_code");
    }
    // S_or_a
    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    } else if (a1.isSymbol()) {
      if (!engine.getStreamManager().containsKey(a1)) {
        throw new ExistenceException(this, 1, "stream", a1, "");
      }
      stream = ((JavaObjectTerm) engine.getStreamManager().get(a1))
          .object();
    } else if (a1.isJavaObject()) {
      stream = ((JavaObjectTerm) a1).object();
    } else {
      throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
    }
    if (!(stream instanceof PushbackReader)) {
      throw new PermissionException(this, "input", "stream", a1, "");
    }
    // skip
    try {
      PushbackReader in = (PushbackReader) stream;
      int c = in.read();
      while (c != n) {
        c = in.read();
        if (c == -1) {
          return cont;
        }
        if (!Character.isDefined(c)) {
          throw new RepresentationException(this, 0, "character");
        }
      }
      return cont;
    } catch (IOException e) {
      throw new TermException(new JavaObjectTerm(e));
View Full Code Here

Examples of jp.ac.kobe_u.cs.prolog.lang.RepresentationException

          return engine.fail();
        }
        return cont;
      }
      if (!Character.isDefined(c)) {
        throw new RepresentationException(this, 0, "character");
      }
      if (!a2.unify(SymbolTerm.makeSymbol(String.valueOf((char) c)),
          engine.trail)) {
        return engine.fail();
      }
View Full Code Here

Examples of jp.ac.kobe_u.cs.prolog.lang.RepresentationException

          return engine.fail();
        }
        return cont;
      }
      if (!Character.isDefined(c)) {
        throw new RepresentationException(this, 0, "character");
      }
      ((PushbackReader) stream).unread(c);
      if (!a2.unify(SymbolTerm.makeSymbol(String.valueOf((char) c)),
          engine.trail)) {
        return engine.fail();
View Full Code Here

Examples of jp.ac.kobe_u.cs.prolog.lang.RepresentationException

      if (!a2.isInteger()) {
        throw new IllegalTypeException(this, 2, "integer", a2);
      }
      int n = ((IntegerTerm) a2).intValue();
      if (n != -1 && !Character.isDefined(n)) {
        throw new RepresentationException(this, 2, "in_character_code");
      }
    }
    // S_or_a
    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    } else if (a1.isSymbol()) {
      if (!engine.getStreamManager().containsKey(a1)) {
        throw new ExistenceException(this, 1, "stream", a1, "");
      }
      stream = ((JavaObjectTerm) engine.getStreamManager().get(a1))
          .object();
    } else if (a1.isJavaObject()) {
      stream = ((JavaObjectTerm) a1).object();
    } else {
      throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
    }
    if (!(stream instanceof PushbackReader)) {
      throw new PermissionException(this, "input", "stream", a1, "");
    }
    // read single character
    try {
      int c = ((PushbackReader) stream).read();
      if (c < 0) { // EOF
        if (!a2.unify(INT_EOF, engine.trail)) {
          return engine.fail();
        }
        return cont;
      }
      if (!Character.isDefined(c)) {
        throw new RepresentationException(this, 0, "character");
      }
      if (!a2.unify(new IntegerTerm(c), engine.trail)) {
        return engine.fail();
      }
      return cont;
View Full Code Here

Examples of jp.ac.kobe_u.cs.prolog.lang.RepresentationException

        Term car = ((ListTerm) x).car().dereference();
        if (car.isVariable()) {
          throw new PInstantiationException(this, 2);
        }
        if (!car.isInteger()) {
          throw new RepresentationException(this, 2, "character_code");
        }
        // car is an integer
        int i = ((IntegerTerm) car).intValue();
        if (!Character.isDefined((char) i)) {
          throw new RepresentationException(this, 2, "character_code");
        }
        sb.append((char) i);
        x = ((ListTerm) x).cdr().dereference();
      }
      try {
View Full Code Here

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

  public static Object getObjectSimple(String value, Class clazz) {
    if(clazz.equals(Integer.class) || clazz.equals(int.class)) {
      try {
        return Integer.parseInt(value);
      } catch (RuntimeException e) {
        throw new RePresentationException("Invalid int: " + value);
      }
    } else if(clazz.equals(Long.class) || clazz.equals(long.class)) {
      try {
        return Long.parseLong(value);
      } catch (RuntimeException e) {
        throw new RePresentationException("Invalid long: " + value);
      }     
    } else if(clazz.equals(Double.class) || clazz.equals(double.class)) {
      try {
        return Double.parseDouble(value);
      } catch (RuntimeException e) {
        throw new RePresentationException("Invalid double: " + value);
      }
        } else if(clazz.equals(Byte.class) || clazz.equals(byte.class)) {
            try {
                return Byte.parseByte(value);
            } catch (RuntimeException e) {
                throw new RePresentationException("Invalid byte: " + value);
            }
    } else if(clazz.equals(String.class)) {
      return value;
    } else if(clazz.isEnum()) {
        return Enum.valueOf(clazz, value);
    } else if(clazz.equals(Timestamp.class)) {
      long ts = parseDate(value);
            return ts==-1 ? null : new Timestamp(ts);
        } else if(clazz.equals(Date.class)) {
            long ts = parseDate(value);
            return ts==-1 ? null : new Date(ts);
    } else if(clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
      return (boolean)(null!=value && (value.equals("1") || value.equals("true")));
    }
    throw new RePresentationException(clazz);
  }
View Full Code Here

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

      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(int i=0; i<node.getChildNodes().getLength(); i++) {
        Node n = node.getChildNodes().item(i);
        String id = n.getAttributes().getNamedItem("id").getNodeValue();
        if(n.getNodeType()==Node.ELEMENT_NODE) map.put(getObjectSimple(id, keyClass), getObject(n, valClass, valType));
      }
      return map;
    } else if(Set.class.isAssignableFrom(clazz) || List.class.isAssignableFrom(clazz)) {
      if(type==null || !(type instanceof ParameterizedType))
        throw new RePresentationException(clazz);

      boolean isList = List.class.isAssignableFrom(clazz);
      Collection<Object> col = isList ? new ArrayList<Object>() :
        (HashSet.class.isAssignableFrom(clazz) ? new HashSet<Object>() : new TreeSet<Object>());
     
      ParameterizedType pType = (ParameterizedType) type;
      Type t = pType.getActualTypeArguments()[0];
      Class c = null;
      if(t instanceof Class) c = (Class)t;
      if(t instanceof ParameterizedType) c = (Class)((ParameterizedType)t).getRawType();
      if(c==null) throw new RePresentationException("Cant find parameter for Collection : " + t.toString());
     
      for(int i=0; i<node.getChildNodes().getLength(); i++) {
        Node n = node.getChildNodes().item(i);
        if(n.getNodeType()==Node.ELEMENT_NODE) {
            Node id = isList ? null : n.getAttributes().getNamedItem("id");
            
            col.add(getObject(id!=null ? id : n, c, t));
        }
      }
      return col;
    } else if(ClassMethodsInfo.isPresentableOrEntity(clazz)) {
      if(null == node.getFirstChild()) return null;
     
      boolean isEntity = ClassMethodsInfo.isEntity(clazz);
//      System.out.println("isEntity " +clazz+ " :: " + isEntity);
     
     
      if(node.getFirstChild().getNodeType() == Node.TEXT_NODE) {
        String text = node.getFirstChild().getNodeValue();
        if("new".equals(text)) return clazz.newInstance();
       
        if(clazz.isEnum()) {
            return Enum.valueOf(clazz, text);
        }
     
        if(!isEntity) throw new RePresentationException("Cant create new instance of Presentable " + clazz.getCanonicalName()+"("+text+")");

        return ef.find(clazz, getObjectSimple(text, ClassMethodsInfo.getEntityIdClass(clazz)));
      }
     
      Object result = null;
     
      if(isEntity) {
        ClassMethodsInfo.Property idInfo = ClassMethodsInfo.getEntityIdProperty(clazz);
        Class idClass = ClassMethodsInfo.getEntityIdClass(clazz);
       
        for(int i=0; i<node.getChildNodes().getLength(); i++) {
          Node n = node.getChildNodes().item(i);
          String id = n.getAttributes().getNamedItem("id").getNodeValue();
          if(idInfo.getName().equals(id)) {
            if(null == n.getFirstChild()) break;
            result = ef.find(clazz, getObjectSimple(n.getFirstChild().getNodeValue(), idClass));
            break;
          }
        }       
      }     
     
      if(null == result) result = clazz.newInstance();
     
      boolean skipIncoming = ClassMethodsInfo.getSkipIncoming(clazz);
     
      for(int i=0; i<node.getChildNodes().getLength(); i++) {
        Node n = node.getChildNodes().item(i);
        String mName = n.getAttributes().getNamedItem("id").getNodeValue();
       
        ClassMethodsInfo.Property mInfo = ClassMethodsInfo.getProperty(clazz, mName);
        if(mInfo == null) {
          if(skipIncoming) continue;
          throw new RePresentationException("Unknown property `"+mName+"` in class " + clazz);
        }
        if(!mInfo.canSet()) {
          if(skipIncoming) continue;
          throw new RePresentationException("Unknown setter property `"+mName+"` in class " + clazz);
        }
       
        Object value = getObject(n, mInfo.getReturnType(), mInfo.getGenericReturnType());
        //System.out.println("CALL SETTER: " + setMethod.getName()+"("+getMethod.getGenericReturnType()+") - "+value);
        if(Collection.class.isAssignableFrom(mInfo.getReturnType())) {
View Full Code Here

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

    return this;
  }
 
  public Object getObjectSimple(Class clazz) {
      if(lexer.type == Yytoken.TYPE_EOF) {
        throw new RePresentationException("Bad json: eof instead of object " + clazz.getCanonicalName());
      }
     
      if(lexer.type != Yytoken.TYPE_VALUE) {
        throw new RePresentationException("Bad json: not simple value for object " + clazz.getCanonicalName() + " : " + lexer.type);
      }
     
      if(lexer.value == null) return null;
     
    if(clazz.equals(Integer.class) || clazz.equals(int.class)) {
      try {
        return Integer.parseInt(lexer.value);
      } catch (RuntimeException e) {
        throw new RePresentationException("Invalid int: " + lexer.value);
      }
    } else if(clazz.equals(Long.class) || clazz.equals(long.class)) {
      try {
        return Long.parseLong(lexer.value);
      } catch (RuntimeException e) {
        throw new RePresentationException("Invalid long: " + lexer.value);
      }     
    } else if(clazz.equals(Double.class) || clazz.equals(double.class)) {
      try {
        return Double.parseDouble(lexer.value);
      } catch (RuntimeException e) {
        throw new RePresentationException("Invalid double: " + lexer.value);
      }
        } else if(clazz.equals(Byte.class) || clazz.equals(byte.class)) {
            try {
                return Byte.parseByte(lexer.value);
            } catch (RuntimeException e) {
                throw new RePresentationException("Invalid byte: " + lexer.value);
            }
        } else if(clazz.equals(Short.class) || clazz.equals(short.class)) {
            try {
                return Short.parseShort(lexer.value);
            } catch (RuntimeException e) {
                throw new RePresentationException("Invalid short: " + lexer.value);
            }
    } else if(clazz.equals(String.class)) {
      return lexer.value;
    } else if(clazz.isEnum()) {
        return Enum.valueOf(clazz, lexer.value);
    } else if(clazz.equals(Timestamp.class) || clazz.equals(Date.class)) {
      long ts = XmlRePresentation.parseDate(lexer.value);
            return ts==-1 ? null : (clazz.equals(Date.class) ? new Date(ts) : new Timestamp(ts));
    } else if(clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
      String v = lexer.value;
        return v.equals("1") || v.equalsIgnoreCase("y") || v.equalsIgnoreCase("true");
    }
    throw new RePresentationException(clazz);
  }
View Full Code Here

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

     
      if(clazz.isEnum()) {
          return Enum.valueOf(clazz, lexer.value);
      }
   
      if(!isEntity) throw new RePresentationException("Cant create new instance of Presentable " + clazz.getCanonicalName()+"("+lexer.value+")");

      Class<?> entityIdClass = ClassMethodsInfo.getEntityIdClass(clazz);
      if(entityIdClass == null) throw new RePresentationException("Unknown @Id for Entity " + clazz.getCanonicalName());
     
      return ef.find(clazz, getObjectSimple(entityIdClass));
    }
   
    if(lexer.type != Yytoken.TYPE_LEFT_BRACE) throw new RePresentationException("Bad json: object is not map");
   
    Object result = null;
    List propertiesAndValues = new ArrayList(ClassMethodsInfo.getPresentableProperties(clazz).size());
    boolean skipIncoming = ClassMethodsInfo.getSkipIncoming(clazz);

    ClassMethodsInfo.Property idInfo = null;
    Class idClass = null;
   
    if(isEntity) {
      idInfo = ClassMethodsInfo.getEntityIdProperty(clazz);
      idClass = ClassMethodsInfo.getEntityIdClass(clazz);
    }
   
    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 " + lexer.type);
      String mName = getObjectSimple(String.class).toString();
            lexer.yylex();
            if(lexer.type != Yytoken.TYPE_COLON) throw new RePresentationException("Bad json: key:value separator expected");

      ClassMethodsInfo.Property mInfo = ClassMethodsInfo.getProperty(clazz, mName);
      if(mInfo == null) {
        if(skipIncoming) {lexer.yylex();continue;}
        throw new RePresentationException("Unknown property `"+mName+"` in class " + clazz);
      }
      if(!mInfo.canSet()) {
                if(skipIncoming) {lexer.yylex();continue;}
        throw new RePresentationException("Unknown setter property `"+mName+"` in class " + clazz);
      }

      Object value = getObject(mInfo.getReturnType(), mInfo.getGenericReturnType());
      propertiesAndValues.add(mInfo);
      propertiesAndValues.add(value);
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.