1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.isenshi.util.converter.function;
17
18 import org.seasar.tuigwaa.model.common.EntityUtils;
19 import org.seasar.tuigwaa.model.core.TgwAttribute;
20 import org.seasar.tuigwaa.model.core.TgwEntity;
21 import org.seasar.tuigwaa.model.core.impl.FkAttribute;
22 import org.seasar.tuigwaa.model.core.impl.SelfAttribute;
23
24
25 public class Id2ObjConverterFunction extends ConverterFunction {
26
27 private TgwEntity getRefEntity() {
28 TgwAttribute attr = getAttribute();
29 if(attr instanceof FkAttribute){
30 return ((FkAttribute)attr).getRefEntity();
31 }else if(attr instanceof SelfAttribute){
32 return getEntity();
33 }
34 return null;
35 }
36
37 public Object evaluate(Object obj) {
38 String src = getSourceField();
39 String target = getTargetField();
40
41 Long id = (Long) EntityUtils.getProperty(obj, src);
42 if (id != null && id.longValue() >= 0l) {
43 Object targetObj = EntityUtils.newInstanceById(getRefEntity(), id);
44 EntityUtils.setProperty(obj, target, targetObj);
45 } else {
46 EntityUtils.setProperty(obj, target, null);
47 }
48 return obj;
49 }
50 }