01: /*
02: * Created on Dec 14, 2004
03: */
04: package uk.org.ponder.rsf.viewstate;
05:
06: import uk.org.ponder.beanutil.BeanGetter;
07: import uk.org.ponder.beanutil.PathUtil;
08: import uk.org.ponder.beanutil.entity.EntityID;
09:
10: /**
11: * View parameters, which as well as defining the core viewID, are centred
12: * upon a particular entity, defined by Java class and entity ID. The parseSpec
13: * supplied here will create URLs of the form
14: * /servlet-path/view-id/entity-id?mode=edit
15: * @author Antranig Basman (antranig@caret.cam.ac.uk)
16: *
17: */
18: public class EntityCentredViewParameters extends ViewParameters {
19: public static final String MODE_NEW = "new";
20: public static final String MODE_EDIT = "edit";
21:
22: public String getParseSpec() {
23: return ViewParameters.BASE_PARSE_SPEC + ", @1:entity.ID, mode";
24: }
25:
26: public EntityCentredViewParameters(String viewid, EntityID entity,
27: String mode) {
28: this .viewID = viewid;
29: this .entity = entity;
30: this .mode = mode;
31: }
32:
33: public EntityCentredViewParameters(String viewid, EntityID entity) {
34: this (viewid, entity, null);
35: }
36:
37: public EntityCentredViewParameters() {
38: }
39:
40: public EntityID entity;
41: public String mode;
42:
43: /** Build an EL path which locates the referred-to entity **/
44: public String getELPath() {
45: return PathUtil.buildPath(entity.entityname, entity.ID);
46: }
47:
48: /** Fetch the referenced entity from the supplied beangetter */
49: public Object fetch(BeanGetter beangetter) {
50: return beangetter.getBean(getELPath());
51: }
52:
53: }
|