01: /*
02: * Created on Dec 2, 2006
03: */
04: package uk.org.ponder.rsf.state.entity;
05:
06: import java.io.Serializable;
07:
08: import uk.org.ponder.conversion.StaticLeafParser;
09: import uk.org.ponder.reflect.ReflectiveCache;
10: import uk.org.ponder.saxalizer.SAXalizerMappingContext;
11: import uk.org.ponder.util.ObjectFactory;
12: import uk.org.ponder.util.UniversalRuntimeException;
13:
14: public class DefaultEntityMapper implements EntityMapper {
15: private Class idclazz;
16: private ReflectiveCache reflectivecache;
17: private StaticLeafParser parser;
18: private Class entityclazz;
19: private ObjectFactory objectFactory;
20:
21: public void setEntityClass(Class entityclazz) {
22: this .entityclazz = entityclazz;
23: }
24:
25: public void setIDClass(Class idclazz) {
26: this .idclazz = idclazz;
27: }
28:
29: public void setObjectFactory(ObjectFactory objectFactory) {
30: this .objectFactory = objectFactory;
31: }
32:
33: public void setMappingContext(SAXalizerMappingContext mappingcontext) {
34: this .reflectivecache = mappingcontext.getReflectiveCache();
35: this .parser = mappingcontext.saxleafparser;
36: }
37:
38: public Object instantiate() {
39: if (objectFactory == null) {
40: return reflectivecache.construct(entityclazz);
41: } else {
42: return objectFactory.getObject();
43: }
44: }
45:
46: public Object parseID(String IDString) {
47: try {
48: Serializable beanid = (Serializable) parser.parse(idclazz,
49: IDString);
50: return beanid;
51: } catch (Exception e) {
52: throw UniversalRuntimeException.accumulate(e,
53: "Error parsing ID " + IDString + " as " + idclazz);
54: }
55: }
56:
57: public Class getEntityClass() {
58: return entityclazz;
59: }
60: }
|