01: package com.completex.objective.components.persistency.mapper.impl;
02:
03: import com.completex.objective.components.persistency.PersistentObject;
04: import com.completex.objective.components.persistency.mapper.Mapper;
05: import com.completex.objective.components.persistency.mapper.OdalMappingRuntimeException;
06: import com.completex.objective.components.persistency.mapper.ThreadSession;
07:
08: /**
09: * @author Gennady Krizhevsky
10: */
11: public class DynamicPoToBeanMapperImpl extends BasicDynamicMapperImpl {
12:
13: private boolean tolerateNonMappedBean = true;
14:
15: public DynamicPoToBeanMapperImpl(Mapper mapper) {
16: super (mapper);
17: }
18:
19: protected Class getBeanClassSafe(Class poClass) {
20: Class beanClass = getDirectBeanClass(poClass);
21: if (beanClass == null) {
22: if (tolerateNonMappedBean) {
23: beanClass = poClass;
24: } else {
25: throw new OdalMappingRuntimeException(
26: "Cannot find mapped bean class by PersistentObject class "
27: + poClass);
28: }
29: }
30: return beanClass;
31: }
32:
33: protected Object objectNewInstance(Class beanClass,
34: Object fromObject, boolean forModification) {
35: PersistentObject po = (PersistentObject) fromObject;
36: Object bean;
37: if (ThreadSession.containsPo(getMapper(), po)) {
38: bean = ThreadSession.getBean(getMapper(), po);
39: } else {
40: po.flatten();
41: bean = super .objectNewInstance(beanClass);
42: }
43: if (forModification) {
44: ThreadSession.set(getMapper(), bean, fromObject);
45: }
46: return bean;
47: }
48:
49: public boolean isTolerateNonMappedBean() {
50: return tolerateNonMappedBean;
51: }
52:
53: public void setTolerateNonMappedBean(boolean tolerateNonMappedBean) {
54: this.tolerateNonMappedBean = tolerateNonMappedBean;
55: }
56:
57: }
|