01: /*
02: * User: Michael Rettig
03: * Date: Sep 1, 2002
04: * Time: 10:43:09 PM
05: */
06: package net.sourceforge.jaxor.example.mappers;
07:
08: import net.sourceforge.jaxor.api.FieldAdapter;
09: import net.sourceforge.jaxor.example.Money;
10: import net.sourceforge.jaxor.example.MoneyWithCurrency;
11:
12: import java.math.BigDecimal;
13:
14: /**
15: * This class provides a way to map money and currency values with one
16: * attribute.
17: */
18:
19: public class MoneyWithCurrencyMapper implements java.io.Serializable {
20:
21: private final FieldAdapter _moneyMapper;
22: private final FieldAdapter _stringMapper;
23:
24: public MoneyWithCurrencyMapper(FieldAdapter _moneyMapper,
25: FieldAdapter _stringMapper) {
26: this ._moneyMapper = _moneyMapper;
27: this ._stringMapper = _stringMapper;
28: }
29:
30: public MoneyWithCurrency getValue() {
31: Money money = (Money) _moneyMapper.getValue();
32: BigDecimal amount = null;
33:
34: if (money == null && _stringMapper.getValue() == null)
35: return null;
36:
37: if (money != null)
38: amount = money.getAmount();
39:
40: return new MoneyWithCurrency(amount, (String) _stringMapper
41: .getValue());
42: }
43:
44: public void setValue(MoneyWithCurrency curr) {
45: _moneyMapper.setValue(curr);
46: if (curr != null)
47: _stringMapper.setValue(curr.getCurrency());
48: else
49: _stringMapper.setValue(null);
50: }
51: }
|