Example #1
0
  public void setAttrByFieldName(String fieldName, String newValue) {
    Field field = null;
    try {
      field = this.getClass().getDeclaredField(fieldName);
    } catch (SecurityException e) {
      ErrorLogger.log(e.getMessage());
    } catch (NoSuchFieldException e) {
      ErrorLogger.log(e.getMessage());
    }

    if (null != field) {
      try {
        field.set(this, newValue);
      } catch (IllegalArgumentException e) {
        ErrorLogger.log(e.getMessage());
      } catch (IllegalAccessException e) {
        ErrorLogger.log(e.getMessage());
      }
    }
  }
Example #2
0
 public String getAttrByFieldName(String fieldName) {
   Field field = null;
   try {
     field = this.getClass().getDeclaredField(fieldName);
   } catch (SecurityException e) {
     ErrorLogger.log(e.getMessage());
   } catch (NoSuchFieldException e) {
     ErrorLogger.log(e.getMessage());
   }
   String attr = null;
   if (null != field) {
     try {
       attr = (String) field.get(this);
     } catch (IllegalArgumentException e) {
       ErrorLogger.log(e.getMessage());
     } catch (IllegalAccessException e) {
       ErrorLogger.log(e.getMessage());
     }
   }
   return attr;
 }