01: package com.completex.objective.components.persistency.mapper;
02:
03: /**
04: * Establishes map between Persistent Objects and Domain Objects that can be POJOs.
05: * Inability to map the value should normally be tolerated.
06: *
07: * @author Gennady Krizhevsky
08: */
09: public interface Mapper {
10:
11: public static final NullMapper NULL_MAPPER = new NullMapper();
12:
13: /**
14: * Converts Persistent Object to POJO bean. If the mapping not found it should normally return
15: * unconverted Persistent Object.
16: *
17: * @param po Persistent Object
18: * @param forModification if true, indicates to cache Persistent Object in Thread Session
19: * @return POJO bean
20: */
21: Object convertPoToBean(Object po, boolean forModification);
22:
23: /**
24: * Converts POJO bean to Persistent Object.
25: *
26: * @param bean POJO bean
27: * @param forModification if true, indicates to cache Persistent Object in Thread Session
28: * @return Persistent Object
29: * @throws OdalMappingRuntimeException if the mapping is not found
30: */
31: Object convertBeanToPo(Object bean, boolean forModification);
32:
33: /**
34: * Returns true is the mapping found. At least one of the arguments should not be null.
35: *
36: * @param beanClass bean class
37: * @param poClass persistent object class
38: * @return true is the mapping found
39: */
40: boolean mappingExists(Class beanClass, Class poClass);
41:
42: /**
43: * Null implementation of Mapper
44: */
45: static class NullMapper implements Mapper {
46:
47: protected NullMapper() {
48: }
49:
50: public Object convertPoToBean(Object po, boolean forModification) {
51: return po;
52: }
53:
54: public Object convertBeanToPo(Object bean,
55: boolean forModification) {
56: return bean;
57: }
58:
59: public boolean mappingExists(Class beanClass, Class poClass) {
60: return false;
61: }
62: }
63: }
|