Java tutorial
/* * Copyright 1999-2004 Alibaba.com All right reserved. This software is the confidential and proprietary information of * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with Alibaba.com. */ package com.alibaba.tamper.process; import org.apache.commons.lang.StringUtils; import com.alibaba.tamper.core.BeanMappingException; import com.alibaba.tamper.core.config.BeanMappingBehavior; import com.alibaba.tamper.core.config.BeanMappingField; import com.alibaba.tamper.core.process.ValueProcess; import com.alibaba.tamper.core.process.ValueProcessInvocation; /** * ?Behavior, ??? {@linkplain BeanMappingBehavior} * * @author jianghang 2011-6-22 ?09:50:16 */ public class BehaviorValueProcess implements ValueProcess { public Object process(Object value, ValueProcessInvocation invocation) throws BeanMappingException { BeanMappingField field = invocation.getContext().getCurrentField(); BeanMappingBehavior behavior = field.getBehavior(); // ?mappingbehavior? // valuenull if (value == null && behavior.isMappingNullValue() == false) { return value; } // trim? if (value instanceof String && behavior.isTrimStrings()) { value = StringUtils.trim((String) value); } // Stringnull / empty if ((value == null || (value instanceof String && StringUtils.isEmpty((String) value))) && behavior.isMappingEmptyStrings() == false) { return value; } return invocation.proceed(value); } }