コード例 #1
0
 public Object get(OgnlContext context, Object target, String propertyName) {
   try {
     return OgnlRuntime.getMethodValue(context, target, propertyName, true);
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
コード例 #2
0
  /** Returns OgnlRuntime.NotFound if the property does not exist. */
  public Object getPossibleProperty(Map context, Object target, String name) throws OgnlException {
    Object result;
    OgnlContext ognlContext = (OgnlContext) context;

    if (context.get("_compile") != null) {
      Getter getter = getGetter(ognlContext, target, name);

      if (getter != NotFoundGetter) {
        result = getter.get(ognlContext, target, name);
      } else {
        try {
          result = OgnlRuntime.getFieldValue(ognlContext, target, name, true);
        } catch (Exception ex) {
          throw new OgnlException(name, ex);
        }
      }
    } else {
      result = super.getPossibleProperty(context, target, name);
    }
    return result;
  }
コード例 #3
0
  private Getter getGetter(OgnlContext context, Object target, String propertyName)
      throws OgnlException {
    Getter result;
    Class targetClass = target.getClass();
    Map propertyMap;

    if ((propertyMap = (Map) seenGetMethods.get(targetClass)) == null) {
      propertyMap = new HashMap(101);
      seenGetMethods.put(targetClass, propertyMap);
    }
    if ((result = (Getter) propertyMap.get(propertyName)) == null) {
      try {
        Method method = OgnlRuntime.getGetMethod(context, targetClass, propertyName);

        if (method != null) {
          if (Modifier.isPublic(method.getModifiers())) {
            if (method.getReturnType().isPrimitive()) {
              propertyMap.put(
                  propertyName,
                  result =
                      generateGetter(
                          context,
                          "java.lang.Object\t\tresult;\n"
                              + targetClass.getName()
                              + "\t"
                              + "t0 = ("
                              + targetClass.getName()
                              + ")$2;\n"
                              + "\n"
                              + "try {\n"
                              + "   result = new "
                              + getPrimitiveWrapperClass(method.getReturnType()).getName()
                              + "(t0."
                              + method.getName()
                              + "());\n"
                              + "} catch (java.lang.Exception ex) {\n"
                              + "    throw new java.lang.RuntimeException(ex);\n"
                              + "}\n"
                              + "return result;"));
            } else {
              propertyMap.put(
                  propertyName,
                  result =
                      generateGetter(
                          context,
                          "java.lang.Object\t\tresult;\n"
                              + targetClass.getName()
                              + "\t"
                              + "t0 = ("
                              + targetClass.getName()
                              + ")$2;\n"
                              + "\n"
                              + "try {\n"
                              + "   result = t0."
                              + method.getName()
                              + "();\n"
                              + "} catch (java.lang.Exception ex) {\n"
                              + "    throw new java.lang.RuntimeException(ex);\n"
                              + "}\n"
                              + "return result;"));
            }
          } else {
            propertyMap.put(propertyName, result = DefaultGetter);
          }
        } else {
          propertyMap.put(propertyName, result = NotFoundGetter);
        }
      } catch (Exception ex) {
        throw new OgnlException("getting getter", ex);
      }
    }
    return result;
  }