src/main/java/org/beigesoft/replicator/service/SrvEntityFieldFillerStd.java
@Override
  public final void fill(final Map<String, Object> pAddParam,
    final Object pEntity, final String pFieldName,
      final String pFieldStrValue) throws Exception {
    Field rField = getUtlReflection().retrieveField(pEntity.getClass(),
      pFieldName);
    rField.setAccessible(true);
    if ("NULL".equals(pFieldStrValue)) {
      rField.set(pEntity, null);
      return;
    }
    boolean isFilled = true;
    try {
     if (rField.getType() == Double.class) {
        rField.set(pEntity, Double.valueOf(pFieldStrValue));
      } else if (rField.getType() == Float.class) {
        rField.set(pEntity, Float.valueOf(pFieldStrValue));
      } else if (rField.getType() == BigDecimal.class) {
        rField.set(pEntity, new BigDecimal(pFieldStrValue));
      } else if (rField.getType() == Date.class) {
        rField.set(pEntity, new Date(Long.parseLong(pFieldStrValue)));
      } else if (Enum.class.isAssignableFrom(rField.getType())) {
        Integer intVal = Integer.valueOf(pFieldStrValue);
        Enum val = null;
        if (intVal != null) {
          val = (Enum) rField.getType().getEnumConstants()[intVal];
        }
        rField.set(pEntity, val);
      } else if (rField.getType() == Boolean.class) {
        rField.set(pEntity, Boolean.valueOf(pFieldStrValue));
      } else if (Integer.class == rField.getType()) {
        rField.set(pEntity, Integer.valueOf(pFieldStrValue));
      } else if (Long.class == rField.getType()) {
        rField.set(pEntity, Long.valueOf(pFieldStrValue));
      } else if (String.class == rField.getType()) {
        String unescaped = this.utilXml.unescapeXml(pFieldStrValue);
        rField.set(pEntity, unescaped);
      } else {
        isFilled = false;
      }
    } catch (Exception ex) {
      throw new ExceptionWithCode(ExceptionWithCode
        .WRONG_PARAMETER, "Can not fill field: " + pEntity + "/" + pFieldName
          + "/" + pFieldStrValue + ", " + ex.getMessage(), ex);
    }
    if (!isFilled) {
      throw new ExceptionWithCode(ExceptionWithCode
        .CONFIGURATION_MISTAKE, "There is no rule to fill field: " + pEntity
          + "/" + pFieldName + "/" + pFieldStrValue);
    }
  }
@Override
  public final void fill(final Map<String, Object> pAddParam,
    final Object pEntity, final String pFieldName,
      final String pFieldStrValue) throws Exception {
    Field rField = getUtlReflection().retrieveField(pEntity.getClass(),
      pFieldName);
    rField.setAccessible(true);
    if ("NULL".equals(pFieldStrValue)) {
      rField.set(pEntity, null);
      return;
    }
    boolean isFilled = true;
    try {
     if (rField.getType() == Double.class) {
        rField.set(pEntity, Double.valueOf(pFieldStrValue));
      } else if (rField.getType() == Float.class) {
        rField.set(pEntity, Float.valueOf(pFieldStrValue));
      } else if (rField.getType() == BigDecimal.class) {
        rField.set(pEntity, new BigDecimal(pFieldStrValue));
      } else if (rField.getType() == Date.class) {
        rField.set(pEntity, new Date(Long.parseLong(pFieldStrValue)));
      } else if (Enum.class.isAssignableFrom(rField.getType())) {
        Integer intVal = Integer.valueOf(pFieldStrValue);
        Enum val = null;
        if (intVal != null) {
          val = (Enum) rField.getType().getEnumConstants()[intVal];
        }
        rField.set(pEntity, val);
      } else if (rField.getType() == Boolean.class) {
        rField.set(pEntity, Boolean.valueOf(pFieldStrValue));
      } else if (Integer.class == rField.getType()) {
        rField.set(pEntity, Integer.valueOf(pFieldStrValue));
      } else if (Long.class == rField.getType()) {
        rField.set(pEntity, Long.valueOf(pFieldStrValue));
      } else if (String.class == rField.getType()) {
        String unescaped = this.utilXml.unescapeXml(pFieldStrValue);
        rField.set(pEntity, unescaped);
      } else {
        isFilled = false;
      }
    } catch (Exception ex) {
      throw new ExceptionWithCode(ExceptionWithCode
        .WRONG_PARAMETER, "Can not fill field: " + pEntity + "/" + pFieldName
          + "/" + pFieldStrValue + ", " + ex.getMessage(), ex);
    }
    if (!isFilled) {
      throw new ExceptionWithCode(ExceptionWithCode
        .CONFIGURATION_MISTAKE, "There is no rule to fill field: " + pEntity
          + "/" + pFieldName + "/" + pFieldStrValue);
    }
  }
@ Override public final void fill ( final Map < String , Object > pAddParam , final Object pEntity , final String pFieldName , final String pFieldStrValue ) throws Exception { Field rField = getUtlReflection ( ) . retrieveField ( pEntity . getClass ( ) , pFieldName ) ; rField . setAccessible ( true ) ; if ( "NULL" . equals ( pFieldStrValue ) ) { rField . set ( pEntity , null ) ; return ; } boolean isFilled = true ; try { if ( rField . getType ( ) == Double . class ) { rField . set ( pEntity , Double . valueOf ( pFieldStrValue ) ) ; } else if ( rField . getType ( ) == Float . class ) { rField . set ( pEntity , Float . valueOf ( pFieldStrValue ) ) ; } else if ( rField . getType ( ) == BigDecimal . class ) { rField . set ( pEntity , new BigDecimal ( pFieldStrValue ) ) ; } else if ( rField . getType ( ) == Date . class ) { rField . set ( pEntity , new Date ( Long . parseLong ( pFieldStrValue ) ) ) ; } else if ( Enum . class . isAssignableFrom ( rField . getType ( ) ) ) { Integer intVal = Integer . valueOf ( pFieldStrValue ) ; Enum val = null ; if ( intVal != null ) { val = ( Enum ) rField . getType ( ) . getEnumConstants ( ) [ intVal ] ; } rField . set ( pEntity , val ) ; } else if ( rField . getType ( ) == Boolean . class ) { rField . set ( pEntity , Boolean . valueOf ( pFieldStrValue ) ) ; } else if ( Integer . class == rField . getType ( ) ) { rField . set ( pEntity , Integer . valueOf ( pFieldStrValue ) ) ; } else if ( Long . class == rField . getType ( ) ) { rField . set ( pEntity , Long . valueOf ( pFieldStrValue ) ) ; } else if ( String . class == rField . getType ( ) ) { String unescaped = this . utilXml . unescapeXml ( pFieldStrValue ) ; rField . set ( pEntity , unescaped ) ; } else { isFilled = false ; } } catch ( Exception ex ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "Can not fill field: " + pEntity + "/" + pFieldName + "/" + pFieldStrValue + ", " + ex . getMessage ( ) , ex ) ; } if ( ! isFilled ) { throw new ExceptionWithCode ( ExceptionWithCode . CONFIGURATION_MISTAKE , "There is no rule to fill field: " + pEntity + "/" + pFieldName + "/" + pFieldStrValue ) ; } }
<p>
Fill given field of given entity according value represented as
string.
</p>
@param pAddParam additional params
@param pEntity Entity.
@param pFieldName Field Name
@param pFieldStrValue Field value
@throws Exception - an exception
<p > Fill given field of given entity according value represented as string . < / p >