1 package org.lsst.ccs.config;
2
3 import javax.persistence.MappedSuperclass;
4 import java.io.Serializable;
5 import java.util.List;
6
7
8
9
10
11
12
13 @MappedSuperclass
14 public abstract class ParameterConfiguration implements Serializable, PathObject{
15
16 protected String value ;
17
18
19
20
21 protected ParameterConfiguration() {
22
23 }
24 protected ParameterConfiguration(String value) {
25 this.value = value;
26 }
27
28
29
30
31 public abstract long getId() ;
32 protected abstract void setId(long id) ;
33
34 public boolean isReadOnly() {
35 return getId() != 0L ;
36 }
37
38 public abstract ParameterDescription getDescription() ;
39
40 public abstract List<? extends ValueEvent> getValueEvents() ;
41
42
43
44 public String getValue() {
45 return value;
46 }
47 void setValue(String value) {
48
49
50
51 this.value = value;
52 }
53
54 public Object checkValue(String value) throws IllegalArgumentException{
55 ParameterDescription description = this.getDescription();
56 return description.checkValue(value) ;
57
58
59
60
61 }
62
63
64
65
66
67
68
69 public void modifyValue(String value) {
70 if( isReadOnly()) {
71 throw new ImmutableStateException("read only value") ;
72 }
73 if(checkValue(value) != null) {
74 setValue(value);
75 }
76 }
77
78
79
80
81
82 public void modifyValueAfterCheck(String value) {
83 if( isReadOnly()) {
84 throw new ImmutableStateException("read only value") ;
85 }
86 setValue(value);
87 }
88
89
90
91 @Override
92 public boolean equals(Object o) {
93 if (this == o) return true;
94 if (!(o instanceof PathObject)) return false;
95
96 PathObject that = (PathObject) o;
97 ParameterDescription description = getDescription();
98 if (!description.getPath().equals(that.getPath())) return false;
99
100 return true;
101 }
102
103 @Override
104 public String toString() {
105 return this.getId() + "{" + getId() +
106 ": description=" + getDescription() +
107 ", value='" + value + '\'' +
108 '}';
109 }
110
111 @Override
112 public int hashCode() {
113 return getDescription().hashCode();
114 }
115
116 @Override
117 public ParameterPath getPath() {
118 return getDescription().getPath();
119 }
120 }