Package org.eweb4j.util

Examples of org.eweb4j.util.ReflectUtil


        return (List<T>) (_list.isEmpty() ? null : _list);
      } else {
        while (rs.next()) {
          t = cls.newInstance();
          ReflectUtil ru = new ReflectUtil(t);
          ORMConfigBean ormBean = ORMConfigBeanCache.get(cls);

          for (Iterator<Property> it = ormBean.getProperty()
              .iterator(); it.hasNext();) {
            Property p = it.next();
            String type = p.getType();
            if (type == null)
              continue;

            // 如果查询出来的字段名字没有,则不进行值注入
            boolean flag = false;
            for (String col : columns) {
              if (col.equalsIgnoreCase(p.getColumn())) {
                flag = true;
                continue;
              }
            }

            if (!flag)
              continue;

            Method m = ru.getSetter(p.getName());
            if (m == null)
              continue;

            Object value = rs.getObject(p.getColumn());
            if (value == null)
              continue;

            String v = String.valueOf(value);
            if (v == null) {
              v = "";
            }

            if ("int".equalsIgnoreCase(type)
                || "java.lang.Integer".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0";
              }
              m.invoke(t, Integer.parseInt(v));
            } else if ("long".equalsIgnoreCase(type)
                || "java.lang.Long".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0";
              }
              m.invoke(t, Long.parseLong(v));
            } else if ("float".equalsIgnoreCase(type)
                || "java.lang.Float".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0.0";
              }
              m.invoke(t, Float.parseFloat(v));
            } else if ("double".equalsIgnoreCase(type)
                || "java.lang.Double".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0.0";
              }

              m.invoke(t, Float.parseFloat(v));
            } else if ("string".equalsIgnoreCase(type)
                || "java.lang.String".equalsIgnoreCase(type)) {
              m.invoke(t, v);
            } else if ("date".equalsIgnoreCase(type)
                || "java.sql.Date".equalsIgnoreCase(type)
                || "java.util.Date".equalsIgnoreCase(type)) {
              m.invoke(t, value);
            } else if (PropType.ONE.equalsIgnoreCase(type)) {
              if ("".equals(v))
                continue;

              Field field = ru.getField(p.getName());
              Class<?> tarClass = field.getType();

              String tarFKField = null;

              tarFKField = ORMConfigBeanUtil.getIdField(tarClass);
View Full Code Here


      IllegalAccessException, IllegalArgumentException,
      InvocationTargetException {
    if (parentPojo == null)
      return null;

    ReflectUtil _ru = new ReflectUtil(parentPojo);

    Method pojoSetter = _ru.getSetter(pojoParamName);
    if (pojoSetter == null)
      return parentPojo;

    Class<?> pojoClass = pojoSetter.getParameterTypes()[0];
View Full Code Here

  }

  public static void injectParam(Map<String, String[]> paramMap,
      Object actionObject) throws IllegalAccessException,
      InvocationTargetException, InstantiationException {
    ReflectUtil ru = new ReflectUtil(actionObject);
    Hashtable<String, Object> hasPojo = new Hashtable<String, Object>();

    paramForeach: for (Entry<String, String[]> entry : paramMap.entrySet()) {
      String paramName = entry.getKey();
      String[] paramValue = entry.getValue();

      if (paramValue == null || paramValue.length == 0)
        continue;
      // System.out.println("paramName-->" + paramName);
      // System.out.println(paramValue[0]);
      Method setter = null;

      String[] pojoParamNames = paramName.split("\\.");
      if (pojoParamNames.length > 1) {
        Object lastPojo = actionObject;
        int lastIndex = pojoParamNames.length - 1;
        for (int i = 0; i < lastIndex; i++) {
          lastPojo = getLastPojo(lastPojo, pojoParamNames[i], hasPojo);
          if (lastPojo == null)
            continue paramForeach;
        }

        String _paramName = pojoParamNames[lastIndex];
        ReflectUtil lpRu = new ReflectUtil(lastPojo);

        setter = lpRu.getSetter(_paramName);
        if (setter == null)
          continue;

        invokeSetter(lastPojo, paramValue, setter);
View Full Code Here

            sb.append("当前您填写的( class=").append(mvc.getClazz())
                .append(" )是错误的!它必须是一个有效的类 ;\n");
          } else {
            if (mvc.getMethod() != null
                && !"".equals(mvc.getMethod())) {
              Method m = new ReflectUtil(clazz.newInstance())
                  .getMethod(mvc.getMethod());
              if (m == null) {
                sb.append("当前您填写的( method=")
                    .append(mvc.getMethod())
                    .append(" )是错误的!它必须是一个有效的方法 ;\n");
View Full Code Here

        SingleBeanCache.add(clazz, this.actionObject);
      }
    } else
      this.actionObject = clazz.newInstance();

    ru = new ReflectUtil(this.actionObject);

    return this.actionObject;
  }
View Full Code Here

  }

  private Object injectParam2Pojo(Class<?> paramClass, String startName)
      throws Exception {
    Object paramObj = paramClass.newInstance();
    ReflectUtil ru = new ReflectUtil(paramObj);
    this.injectActionCxt2Pojo(ru);
    // 注入mvc action 请求参数
    ParamUtil.injectParam(this.context, ru, startName);

    return paramObj;
View Full Code Here

    return paramObj;
  }

  private Object injectParam2Map(String startName) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    ReflectUtil ru = new ReflectUtil(map);
    this.injectActionCxt2Pojo(ru);
    // 注入mvc action 请求参数
    ParamUtil.injectParam(this.context, ru, startName);

    return map;
View Full Code Here

        SingleBeanCache.add(clazz, this.actionObject);
      }
    } else
      this.actionObject = clazz.newInstance();

    ru = new ReflectUtil(this.actionObject);

    return this.actionObject;
  }
View Full Code Here

    // 带参数运行方法
    return m.invoke(actionObject, params);
  }

  private void injectActionCxt2Pojo(Object pojo) throws Exception {
    ReflectUtil ru = new ReflectUtil(pojo);
    HttpServletRequest req = this.context.getRequest();
    HttpServletResponse res = this.context.getResponse();
    PrintWriter out = this.context.getWriter();
    // ServletOutputStream sos = this.context.getOut();
    HttpSession session = this.context.getSession();
    ActionProp actionProp = this.context.getActionProp();
    QueryParams queryParams = this.context.getQueryParams();
    for (String n : ru.getFieldsName()) {
      Method m = ru.getSetter(n);
      if (m == null)
        continue;

      Class<?> clazz = m.getParameterTypes()[0];
      if (HttpServletRequest.class.isAssignableFrom(clazz)) {
View Full Code Here

      } catch (Exception e) {
        LogFactory.getMVCLogger("WARRING").write(
            "the action class new instance failued -> " + clsName);
      }

      ReflectUtil ru = new ReflectUtil(obj);
      Method[] ms = ru.getMethods();
      if (ms == null)
        return;

      // 扫描方法的注解信息
      for (Method m : ms) {
        if (m.getModifiers() != 1)
          continue;

        Path path = m.getAnnotation(Path.class);

        if (path == null) {
          String methodName = m.getName();
          Method getter = ru.getGetter(methodName.replace("get", ""));
          Method setter = ru.getSetter(methodName.replace("set", ""));
          // 默认下setter和getter不作为action方法
          if (getter != null || setter != null)
            continue;
        }
View Full Code Here

TOP

Related Classes of org.eweb4j.util.ReflectUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.