Esempio n. 1
0
 public void callModelValidator(final AQuery $, final Ajax ajax) throws VolleyError {
   Map<Annotation, java.lang.reflect.Method> methodMap =
       ReflectUtils.getMethodsByAnnotation(Handler.class, getClass());
   for (Map.Entry<Annotation, java.lang.reflect.Method> entry : methodMap.entrySet()) {
     java.lang.reflect.Method method = entry.getValue();
     for (int i = 0; i < method.getParameterTypes().length; i++) {
       Class type = method.getParameterTypes()[i];
       if (method.getParameterAnnotations()[i][0] instanceof ResponseBody
           && type != String.class
           && type != byte[].class
           && Checker.class.isAssignableFrom(type)) {
         try {
           Checker checker =
               (Checker) new Gson().fromJson(new String(ajax.getResponseBody(), "utf-8"), type);
           if (checker.getValidator().validate()) {
             $.log.i("has warning");
           }
         } catch (UnsupportedEncodingException e) {
           $.log.i(e);
           throw new IllegalDataError("Unsupported encoding bytes");
         }
       }
     }
   }
 }
Esempio n. 2
0
 private Object scanAnnotation(AQuery $, Class<?> type, Annotation annotation, Ajax ajax)
     throws Exception {
   if (annotation instanceof Header) {
     return ajax.getHeaders().get(((Header) annotation).value());
   } else if (annotation instanceof Headers) {
     return ajax.getHeaders();
   } else if (annotation instanceof Method) {
     return ajax.getMethod();
   } else if (annotation instanceof NetError) {
     if (type == int.class || type == Integer.class) {
       return getVolleyErrorType(ajax.getResponseError());
     }
     return ajax.getResponseError();
   } else if (annotation instanceof Param) {
     return ajax.getParams().get(((Param) annotation).value());
   } else if (annotation instanceof Params) {
     return ajax.getParams();
   } else if (annotation instanceof RequestBody) {
     return antiSerialize($, type, ajax.getRequestBody());
   } else if (annotation instanceof RequestEntity) {
     if (type == Request.class) return ajax.getRequestEntity();
     if (type == Ajax.class) return ajax;
   } else if (annotation instanceof RequestID) {
     return ajax.hashCode();
   } else if (annotation instanceof ResponseBody) {
     return antiSerialize($, type, ajax.getResponseBody());
   } else if (annotation instanceof URL) {
     return ajax.getURL();
   }
   return null;
 }