Package org.eweb4j.util

Examples of org.eweb4j.util.ReflectUtil


   * @throws DAOException
   */
  public void init(Object t, List<Field> fields) throws DAOException {
    this.t = t;
    this.fields = fields;
    this.ru = new ReflectUtil(this.t);
    this.table = ORMConfigBeanUtil.getTable(t.getClass());
    // 主类的ID属性名
    this.idField = ORMConfigBeanUtil.getIdField(this.t.getClass());
    this.idColumn = ORMConfigBeanUtil.getIdColumn(this.t.getClass());
    this.idGetter = ru.getGetter(idField);
View Full Code Here


      try {
        Object tarObj = tarGetter.invoke(t);
        if (tarObj == null)
          continue;

        ReflectUtil tarRu = new ReflectUtil(tarObj);
        Method tarIdGetter = tarRu.getGetter(tarIdField);
        Object tarIdValObj = tarIdGetter.invoke(tarObj);
        if (tarIdValObj == null)
          continue;

        String column = ann.mappedBy();
View Full Code Here

      try {
        Object _tarObj = tarGetter.invoke(t);
        Object tarObj = null;
        boolean flag = false;
        if (_tarObj != null) {
          Method tarFKFieldGetter = new ReflectUtil(_tarObj)
              .getGetter(tarFKField);
          if (tarFKFieldGetter != null
              && tarFKFieldGetter.invoke(_tarObj) != null)
            tarObj = DAOFactory.getSelectDAO(dsName).selectOne(
                _tarObj, tarFKField);
View Full Code Here

    if (Map.class.isAssignableFrom(clazz)) {
      HashMap<String, Object> map = (HashMap<String, Object>) _t;
      return map.get("idValue");
    }
    String _idField = ORMConfigBeanUtil.getIdField(_t.getClass());
    ReflectUtil _ru = new ReflectUtil(_t);
    Method _idGetter = _ru.getGetter(_idField);
    return _idGetter.invoke(_t);
  }
View Full Code Here

      return (String[]) map.get("values");
    }

    String[] fields = ORMConfigBeanUtil.getFields(t.getClass());
    String[] values = new String[fields.length];
    ReflectUtil _ru = new ReflectUtil(t);
    for (int i = 0; i < fields.length; i++) {
      Method getter = _ru.getGetter(fields[i]);
      Object val = getter.invoke(t);
      if (val == null)
        continue;
      values[i] = String.valueOf(val);
    }
View Full Code Here

    return values;
  }

  public static <T> Object getValue(T _t, String field) throws Exception {

    ReflectUtil _ru = new ReflectUtil(_t);
    Method getter = _ru.getGetter(field);
    Object val = getter.invoke(_t);
    if (val == null)
      return null;

    Object value = String.valueOf(val);
View Full Code Here

      else
        clazz = (Class<T>) this.classes.get(bean.getName());
    }

    T o = clazz.newInstance();
    ReflectUtil ru = new ReflectUtil(o);
    Field[] fields = ru.getFields();
    for (Field f : fields) {
      String n = f.getName();
      Method m = ru.getMethod("set" + StringUtil.toUpCaseFirst(n));
      if (m != null) {
        Annotation[] annotation = f.getAnnotations();
        if (annotation != null && annotation.length > 0) {
          for (Annotation anno : annotation) {
            XmlTag tag = (XmlTag) anno;
View Full Code Here

              // 如果属性名字不为空,说明使用的是setter注入方式
              // 使用setter注入的时候,需要提供一个无参构造方法
              if (t == null)
                t = clazz.newInstance();
             
              ReflectUtil ru = new ReflectUtil(t);
              Method m = ru.getSetter(name);
              if (m != null)
                m.invoke(t, getBean(ref));
             
            } else {
              // 如果属性名字为空,说明使用的是构造器注入方式
              // 使用构造器注入的时候,需要按照构造器参数列表顺序实例化
              t = (T)getBean(ref);
              argList.add(t.getClass());
              initargList.add(t);
            }
          } else {
            // 注入基本类型
            String type = inj.getType();
            String value = inj.getValue();
            if (value == null) {
              value = "";
            }
            String name = inj.getName();
            if (name != null && !"".equals(name)) {
              // 如果属性名字不为空,说明使用的是setter注入方式
              // 使用setter注入的时候,需要提供一个无参构造方法
              if (t == null)
                t = clazz.newInstance();
             
              ReflectUtil ru = new ReflectUtil(t);
              Method m = ru.getMethod("set"
                  + StringUtil.toUpCaseFirst(name));
              if (m != null) {
                if (IOCConfigConstant.INT_ARGTYPE
                    .equalsIgnoreCase(type)
                    || "java.lang.Integer"
View Full Code Here

   * @throws DAOException
   */
  public void init(Object t, List<Field> fields) throws DAOException {
    this.t = t;
    this.fields = fields;
    this.ru = new ReflectUtil(this.t);
    // 主类的ID属性名
    this.idField = ORMConfigBeanUtil.getIdField(this.t.getClass());
    this.idGetter = ru.getGetter(idField);
    if (idGetter == null)
      throw new DAOException("can not find idGetter.", null);
View Full Code Here

          // 检查是否该对象真的与主对象有关联且存在数据库
          // select * from {tarTable} where {tarIdColumn} =
          // {tarIdVal} and {column} = {idVal}
          String format = "select * from %s where %s = ? and %s = ? ";

          ReflectUtil tarRu = new ReflectUtil(tarObj);
          String tarIdColumn = ORMConfigBeanUtil
              .getIdColumn(tarClass);
          String tarIdField = ORMConfigBeanUtil.getIdField(tarClass);
          Method tarIdGetter = tarRu.getGetter(tarIdField);

          if (tarIdGetter == null)
            throw new DAOException("can not find tarIdGetter.",
                null);

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.