1 package org.lsst.ccs.config;
2
3 import javax.persistence.*;
4 import java.util.ArrayList;
5 import java.util.List;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 @Entity
24
25
26 class AParameterConfiguration extends ParameterConfiguration implements Cloneable{
27 private static final long serialVersionUID = 8134633715625475333L;
28 @Id
29 @GeneratedValue
30 private long id ;
31
32
33
34
35
36 @ManyToOne (fetch=FetchType.EAGER)
37
38 private
39
40 private boolean copy ;
41
42 @OneToMany (cascade = CascadeType.ALL, fetch=FetchType.EAGER)
43 List<AValueEvent> valueEvents ;
44
45
46
47
48 AParameterConfiguration() {
49
50 }
51
52
53
54
55
56 public AParameterConfiguration(AParameterDescription parameterDescription) {
57 super(parameterDescription.getParameterBase().getDefaultValue()) ;
58 this.parameterDescription = parameterDescription;
59 }
60
61
62
63
64
65
66
67 public AParameterConfiguration(AParameterDescription parameterDescription, String value) {
68 super();
69 this.parameterDescription = parameterDescription;
70 modifyValue(value);
71 }
72
73 public static AParameterConfiguration copyWithoutEvents(ParameterConfiguration other) {
74
75
76
77 throw new UnsupportedOperationException("copy without events (general)") ;
78 }
79
80 public static AParameterConfiguration copyWithoutEvents(AParameterConfiguration another) {
81
82 AParameterDescription descr = another.getParameterDescription() ;
83 AParameterConfiguration res = new AParameterConfiguration(descr, another.getValue()) ;
84 return res ;
85 }
86
87
88 @Override
89 public long getId() {
90 return id;
91 }
92
93 @Override
94 protected void setId(long id) {
95 this.id = id ;
96 }
97
98 @Override
99 public ParameterDescription getDescription() {
100 return parameterDescription;
101 }
102
103 @Override
104 public List<? extends ValueEvent> getValueEvents() {
105 return this.valueEvents ;
106 }
107
108 void setValueEvents(List<AValueEvent> valueEventsList) {
109 this.valueEvents = valueEventsList ;
110 }
111
112
113
114
115
116
117
118 public void addValueEvent(ValueEvent event) {
119 if(! (event instanceof AValueEvent)) {
120 throw new IllegalArgumentException("trying to add a deprecated ValueEvent");
121 }
122 AValueEvent anEvent = (AValueEvent) event ;
123 if(valueEvents == null) {
124 valueEvents = new ArrayList<AValueEvent>() ;
125 }
126 if(checkValue(event.getValue()) != null) {
127 valueEvents.add(anEvent) ;
128 } else {
129 throw new IllegalArgumentException("non compatible value :" + value) ;
130 }
131 }
132
133
134 AParameterDescription getParameterDescription() {
135 return parameterDescription;
136 }
137
138 void setParameterDescription(AParameterDescription parameterDescription) {
139 this.parameterDescription = parameterDescription;
140 }
141
142 public boolean isCopy() {
143 return copy;
144 }
145
146 void setCopy(boolean copy) {
147 this.copy = copy;
148 }
149
150 public AParameterConfiguration clone() {
151 AParameterConfiguration res = null ;
152 try {
153 res = (AParameterConfiguration) super.clone();
154 } catch (CloneNotSupportedException e) {
155 return res ;
156 }
157 }