Ejemplo n.º 1
0
 private void guessClassReference(TypedValues list, String name) {
   try {
     Class<?> type = Class.forName(fixPotentialArrayName(name));
     list.add(new TypedValue(type.getClass(), type));
   } catch (ClassNotFoundException y) {
     _logger.fine(name + " looked like a class reference but is not");
   }
 }
Ejemplo n.º 2
0
  private TypedValues guessUntypedValue(String name, String value) {
    TypedValues list = new TypedValues(name);

    if (value.startsWith("java:")) { // possible java static reference
      int dot;
      if (value.equals("java:null")) {
        list.add(new TypedValue(Object.class, null));
      } else if (value.charAt(5) == '$') { // reference to a local object (assemble @id)
        ElementInfo element = _local.get(value.substring(6));
        if (element != null) {
          list.add(new TypedValue(element.type, element.data));
        }
      } else if ((dot = value.lastIndexOf('.')) > 5) {
        try {
          // public static refernce? (don't override access control)
          _logger.fine("public static refernce? " + value);
          Object object =
              Class.forName(value.substring(5, dot)).getField(value.substring(dot + 1)).get(null);
          Class<?> type = object.getClass();
          list.add(new TypedValue(type, object));
          // automatic upscaling to larger types
          if (type == Byte.class) {
            object = new Short(((Byte) object).byteValue());
            list.add(new TypedValue(Short.class, object));
            type = Short.class;
          }
          if (type == Short.class) {
            object = new Integer(((Short) object).shortValue());
            list.add(new TypedValue(Integer.class, object));
            type = Integer.class;
          }
          if (type == Integer.class) {
            object = new Long(((Integer) object).intValue());
            list.add(new TypedValue(Long.class, object));
            type = Long.class;
          }
          if (type == Long.class) {
            object = new Float(((Long) object).longValue());
            list.add(new TypedValue(Float.class, object));
            type = Float.class;
          }
          if (type == Float.class) {
            object = new Double(((Float) object).floatValue());
            list.add(new TypedValue(Double.class, object));
          }
        } catch (Exception x) {
          _logger.fine(value + " looked like a static reference but is not: " + x.getMessage());
          // class reference?
          guessClassReference(list, value.substring(5));
        }
      } else { // no '.' at all
        // class reference?
        guessClassReference(list, value.substring(5));
      }
    } else if (value.equals("true")) {
      list.add(new TypedValue(Boolean.class, Boolean.TRUE));
    } else if (value.equals("false")) {
      list.add(new TypedValue(Boolean.class, Boolean.FALSE));
    } else {
      // numbers? multiple possibilities
      try {
        list.add(new TypedValue(Integer.class, Integer.valueOf(value)));
      } catch (Exception x) {
      }
      try {
        list.add(new TypedValue(Long.class, Long.valueOf(value)));
      } catch (Exception x) {
      }
      try {
        list.add(new TypedValue(Float.class, Float.valueOf(value)));
      } catch (Exception x) {
      }
      try {
        list.add(new TypedValue(Double.class, Double.valueOf(value)));
      } catch (Exception x) {
      }
    }

    // always try String as the last resort
    list.add(new TypedValue(String.class, value));

    return list;
  }