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