Пример #1
0
 private static final boolean validArgumentTypes(Object[] args) {
   for (Object arg : args) {
     if (!Types.isValidGreqlValue(arg)) {
       throw new GreqlException(
           "Type unknown to GReQL: " + arg.getClass().getName() + ", value: " + arg);
     }
   }
   return true;
 }
Пример #2
0
 public static final Object apply(FunctionInfo fi, Object... args) {
   assert fi != null;
   if (!fi.acceptsUndefinedValues) {
     for (Object arg : args) {
       if ((arg == null) || (arg == Undefined.UNDEFINED)) {
         return Undefined.UNDEFINED;
       }
     }
   }
   for (Signature sig : fi.signatures) {
     if (sig.matches(args)) {
       try {
         Object result = sig.evaluateMethod.invoke(fi.function, args);
         assert Types.isValidGreqlValue(result);
         return result == null ? Undefined.UNDEFINED : result;
       } catch (IllegalArgumentException e) {
         if (e.getCause() instanceof GreqlException) {
           throw (GreqlException) e.getCause();
         } else {
           throw new GreqlException(
               "When applying function " + fi.name + ": " + e.getMessage(), e.getCause());
         }
       } catch (IllegalAccessException e) {
         if (e.getCause() instanceof GreqlException) {
           throw (GreqlException) e.getCause();
         } else {
           throw new GreqlException(
               "When applying function " + fi.name + ": " + e.getMessage(), e.getCause());
         }
       } catch (InvocationTargetException e) {
         if (e.getCause() instanceof GreqlException) {
           throw (GreqlException) e.getCause();
         } else {
           throw new GreqlException(
               "When applying function " + fi.name + ": " + e.getMessage(), e.getCause());
         }
       }
     }
   }
   StringBuilder sb = new StringBuilder();
   sb.append("Function '").append(fi.name).append("' not defined for argument types (");
   String delim = "";
   for (Object arg : args) {
     sb.append(delim).append(Types.getGreqlTypeName(arg));
     delim = ", ";
   }
   sb.append(")");
   throw new GreqlException(sb.toString());
 }