Esempio n. 1
0
 public static HGHandle getHandle(String name) {
   HGHandle result = syntacticPredicates.get(name);
   if (result == null) {
     String s = relationNames.getX(name);
     if (s != null) result = syntacticPredicates.get(s);
   }
   return result;
 }
 @SuppressWarnings({"unchecked", "rawtypes"})
 public <T> T value(Json x) {
   if (x == null || x.isNull()) return null;
   else if (x.isPrimitive()) return (T) x.getValue();
   else if (x.isArray())
     // what to do here ... this is some sort of collection??
     return (T) x.getValue();
   else if (x.has("java.lang.Enum")) {
     try {
       return (T)
           Enum.valueOf(
               (Class<Enum>) Class.forName(x.at("java.lang.Enum").asString()),
               x.at("value").asString());
     } catch (Exception t) {
       throw new RuntimeException(t);
     }
   } else if (x.has("javaArrayType")) {
     String fullName = shortNameMap.getX(x.at("javaArrayType").asString());
     if (fullName == null) fullName = x.at("javaArrayType").asString();
     try {
       Class<?> cl = Class.forName(fullName);
       JsonConverter converter = converterMap.get(fullName);
       Object A = Array.newInstance(cl, x.at("array").asJsonList().size());
       for (int i = 0; i < x.at("array").asJsonList().size(); i++) {
         Json j = x.at("array").at(i);
         Array.set(A, i, j.isNull() ? null : converter != null ? converter.from(j) : value(j));
       }
       return (T) A;
     } catch (Exception ex) {
       throw new RuntimeException(ex);
     }
   } else if (x.has("javaType")) {
     String fullName = shortNameMap.getX(x.at("javaType").asString());
     if (fullName == null) fullName = x.at("javaType").asString();
     JsonConverter converter = converterMap.get(fullName);
     if (converter != null)
       return (T) converter.from(converter instanceof BeanJsonConverter ? x : x.at("value"));
     else return (T) beanConverter.from(x); // .at("value"));
   } else return (T) x.getValue();
 }
Esempio n. 3
0
 public static String relexToIdFriendly(String relexName) {
   String x = relationNames.getX(relexName);
   return x != null ? x : relexName;
 }