1 package org.whatsitcalled.webflange.webapp.model;
2
3 import org.apache.wicket.markup.repeater.IItemReuseStrategy;
4 import org.apache.wicket.model.LoadableDetachableModel;
5 import org.whatsitcalled.webflange.ResourceFactory;
6 import org.whatsitcalled.webflange.model.Script;
7 import org.whatsitcalled.webflange.model.ScriptDAO;
8
9 public class ScriptDetachableModel extends LoadableDetachableModel {
10 private transient Script script;
11 private Long id;
12 public ScriptDetachableModel(Script p) {
13 this(p.getId());
14 this.script = p;
15 }
16
17 public ScriptDetachableModel(Long id) {
18 this.id = id;
19 }
20
21 protected ScriptDAO getDAO() {
22 return ResourceFactory.getScriptDAO();
23 }
24
25 @Override
26 protected Object load() {
27 script = getDAO().getScript(id);
28 return script;
29 }
30
31 @Override
32 public Object getObject() {
33 return script;
34 }
35
36 @Override
37 protected void onAttach() {
38 if (script == null) {
39 script = getDAO().getScript(id);
40 }
41 }
42
43 @Override
44 protected void onDetach() {
45 script=null;
46 }
47
48
49
50
51 public int hashCode()
52 {
53 return id.hashCode();
54 }
55
56
57
58
59
60
61
62
63 public boolean equals(Object obj)
64 {
65 if (obj instanceof ScriptDetachableModel)
66 {
67 ScriptDetachableModel other = (ScriptDetachableModel)obj;
68 return other.id.equals(this.id);
69 }
70 return false;
71 }
72
73
74 }