Package org.eweb4j.util

Examples of org.eweb4j.util.ReflectUtil


          for (int i = 0; i < fList.size(); i++) {
            Object tarObj = fList.get(i);
            if (tarObj == null)
              continue;

            ReflectUtil tarRu = new ReflectUtil(tarObj);
            String mappedBy = oneToMany.mappedBy();
            if (mappedBy != null && mappedBy.trim().length() > 0) {
              Method ownFieldSetter = tarRu.getSetter(mappedBy);
              if (ownFieldSetter == null)
                continue;

              // finished
              ownFieldSetter.invoke(tarObj,ru.getObject());
              DAOFactory.getInsertDAO(dsName).insert(tarObj);
            } else {
              JoinTable joinTable = null;
              if (f.isAnnotationPresent(JoinTable.class)) {
                joinTable = f.getAnnotation(JoinTable.class);
              } else if (fGetter.isAnnotationPresent(JoinTable.class)) {
                joinTable = fGetter.getAnnotation(JoinTable.class);
              } else {
                // find ownclass in tarObj fields
                for (Field tarObjField : tarRu.getFields()) {
                  if (tarObjField.getType().getName().equals(ownClass.getName())) {
                    Method ownFieldSetter = tarRu.getSetter(tarObjField.getName());
                    if (ownFieldSetter == null)
                      continue;

                    // finished
                    ownFieldSetter.invoke(tarObj,ru.getObject());
View Full Code Here


                tarGetter + " invoke exception ", e);
          }
         
          if (tarList == null || tarList.size() == 0) {
            // 当关联对象为空的时候,删除所有关联对象
            ReflectUtil tarRu = new ReflectUtil(tarClass);
            if (mappedBy == null || mappedBy.trim().length() == 0) {
              for (Field tarObjField : tarRu.getFields()) {
                if (tarObjField.getType().getName().equals(ownClass.getName())) {
                  if (!tarObjField.getType().getName().equals(ownClass.getName()))
                    continue;
                 
                  Method tarObjFieldGetter = tarRu.getGetter(tarObjField.getName());
                  if (tarObjFieldGetter == null)
                    continue;
                 
                  ManyToOne manyToOne = tarObjField.getAnnotation(ManyToOne.class);
                  if (manyToOne == null)
                    manyToOne = tarObjFieldGetter.getAnnotation(ManyToOne.class);
                  if (manyToOne == null)
                    continue;
                 
                  JoinColumn joinCol = tarObjField.getAnnotation(JoinColumn.class);
                  if (joinCol == null)
                    joinCol = tarObjFieldGetter.getAnnotation(JoinColumn.class);
                 
                  if (joinCol != null){
                    String referencedColumn = joinCol.referencedColumnName();
                    if (referencedColumn == null || referencedColumn.trim().length() == 0)
                      referencedColumn = idColumn;
                   
                    referencedField = ORMConfigBeanUtil.getField(ownClass, referencedColumn);
                    Method referencedFieldGetter = ru.getGetter(referencedField);
                    if (referencedFieldGetter != null)
                      referencedFieldVal = referencedFieldGetter.invoke(t);
                  }
                 
                  // finished
                  mappedBy = tarObjField.getName();
                 
                  DAOFactory.getDeleteDAO(dsName).deleteByFieldIsValue(tarClass, new String[]{tarObjField.getName()}, new String[]{String.valueOf(referencedFieldVal)});
                  break;
                }
              }
            }

          } else {
            for (int i = 0; i < tarList.size(); i++) {
              Object tarObj = tarList.get(i);
              if (tarObj == null)
                continue;
             
              Object tarObjIdVal = ORMConfigBeanUtil.getIdVal(tarObj);
              if (tarObjIdVal == null)
                continue;
             
              ReflectUtil tarRu = new ReflectUtil(tarObj);

              if (mappedBy != null && mappedBy.trim().length() > 0) {
                Method ownFieldSetter = tarRu.getSetter(mappedBy);
                if (ownFieldSetter == null)
                  continue;

                // finished
                DAOFactory.getDeleteDAO(dsName).deleteById(tarObj);
              } else {
                JoinTable joinTable = null;
                if (f.isAnnotationPresent(JoinTable.class)) {
                  joinTable = f.getAnnotation(JoinTable.class);
                } else if (tarGetter.isAnnotationPresent(JoinTable.class)) {
                  joinTable = tarGetter.getAnnotation(JoinTable.class);
                } else {
                  // find ownclass in tarObj fields
                  for (Field tarObjField : tarRu.getFields()) {
                    if (!tarObjField.getType().getName().equals(ownClass.getName()))
                      continue;
                   
                    Method tarObjFieldGetter = tarRu.getGetter(tarObjField.getName());
                    if (tarObjFieldGetter == null)
                      continue;
                   
                    ManyToOne manyToOne = tarObjField.getAnnotation(ManyToOne.class);
                    if (manyToOne == null)
View Full Code Here

     
      Class<?> tarClass = ann.targetEntity();
      if (void.class.isAssignableFrom(tarClass))
        tarClass = ClassUtil.getGenericType(f);
      try {
        ReflectUtil tarRu = new ReflectUtil(tarClass);
       
        List<?> tarList = null;
       
        String mappedBy = ann.mappedBy();
        if (mappedBy != null && mappedBy.trim().length() > 0) {
          Method ownFieldSetter = tarRu.getSetter(mappedBy);
          if (ownFieldSetter == null)
            continue;
        } else {
          JoinTable joinTable = null;
          if (f.isAnnotationPresent(JoinTable.class)) {
            joinTable = f.getAnnotation(JoinTable.class);
          } else if (tarGetter.isAnnotationPresent(JoinTable.class)) {
            joinTable = tarGetter.getAnnotation(JoinTable.class);
          } else {
            // find ownclass in tarObj fields
            for (Field tarObjField : tarRu.getFields()) {
              if (!tarObjField.getType().getName().equals(ownClass.getName()))
                continue;
             
              Method tarObjFieldGetter = tarRu.getGetter(tarObjField.getName());
              if (tarObjFieldGetter == null)
                continue;
             
              ManyToOne manyToOne = tarObjField.getAnnotation(ManyToOne.class);
              if (manyToOne == null)
View Full Code Here

            if (void.class.isAssignableFrom(tarClass))
              tarClass = ClassUtil.getGenericType(f);
     
            String mappedBy = ann.mappedBy();
     
            ReflectUtil tarRu = new ReflectUtil(tarClass);
            if (mappedBy != null && mappedBy.trim().length() > 0) {
              Method ownFieldSetter = tarRu.getSetter(mappedBy);
              if (ownFieldSetter == null)
                continue;
            } else {
              JoinTable joinTable = null;
              if (f.isAnnotationPresent(JoinTable.class)) {
                joinTable = f.getAnnotation(JoinTable.class);
              } else if (tarGetter.isAnnotationPresent(JoinTable.class)) {
                joinTable = tarGetter.getAnnotation(JoinTable.class);
              } else {
                // find ownclass in tarObj fields
                for (Field tarObjField : tarRu.getFields()) {
                  if (tarObjField.getType().getName().equals(ownClass.getName())) {
                    // finished
                    mappedBy = tarObjField.getName();
                    break;
                  }
View Full Code Here

            scopeName = scopeName+"."+f.getName();
          else
            scopeName = f.getName();
         
          try {
            readValidator(params,excepts, scopeName, new ReflectUtil(f.getType()),vList, hasCls);
            scopeName = null;
          } catch (Exception e) {
            continue;
          }
        }
View Full Code Here

      interceptor = Class.forName(inter.getClazz()).newInstance();
      if ("singleton".equalsIgnoreCase(inter.getScope()))
        SingleBeanCache.add(inter.getClazz(), interceptor);
    }
   
    ReflectUtil ru = new ReflectUtil(interceptor);
    Method intercept = ru.getMethod(inter.getMethod());
    if (intercept == null){
      this.error = null ;
      return ;
    }
   
    Method setter = ru.getSetter("Context");
    if (setter != null)
      setter.invoke(interceptor, this.context);
   
    Object err = null;
   
View Full Code Here

  private static <T> TRData getData(ListPage listPage,
      Map<String, String> prop, TRData data, String scope, T pojo,
      boolean flag) throws IllegalAccessException,
      InvocationTargetException, Exception {
    ReflectUtil ru = new ReflectUtil(pojo);
    Field[] fields = ru.getFields();

    if (data == null)
      data = new TRData();

    for (Field field : fields) {
      String _name = field.getName();
      Method getter = ru.getGetter(_name);

      if (getter == null)
        continue;

      Object getterVal = getter.invoke(pojo);
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

  public Model load() {
    Long id = getId();
    if (id == null || id <= 0)
      return this;

    ReflectUtil ru = new ReflectUtil(this);
    Model _model = DAOFactory.getSelectDAO(dsName).selectOneById(this);
    if (_model == null)
      return this;

    ReflectUtil _ru = new ReflectUtil(_model);
    for (String field : ru.getFieldsName()) {
      Method setter = ru.getSetter(field);
      if (setter == null)
        continue;

      Method _getter = _ru.getGetter(field);
      if (_getter == null)
        continue;

      try {
        setter.invoke(this, _getter.invoke(_model));
View Full Code Here

      this.id = id;
      return ;
    }

    try {
      new ReflectUtil(this).getSetter(idField).invoke(this, id);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
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.