Salome HOME
ab900bd0660bf2b122c4f95e7fc4d5bdeb682fc6
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / SimulationContext.java
1 package org.splat.dal.bo.som;
2 /**
3  * 
4  * @author    Daniel Brunier-Coulin
5  * @copyright OPEN CASCADE 2012
6  */
7
8 import java.io.Serializable;
9
10 import org.splat.dal.bo.kernel.Persistent;
11 import org.splat.kernel.InvalidPropertyException;
12 import org.splat.kernel.MissedPropertyException;
13 import org.splat.kernel.MultiplyDefinedException;
14 import org.splat.service.technical.ProjectSettingsService;
15 import org.splat.som.Step;
16
17
18 public class SimulationContext extends Persistent implements Serializable {
19
20         private SimulationContextType  type;     // User extendable types
21     private int                    step;
22     private ProgressState          state;
23         private String                 value;
24     private int                    counter;
25
26     private static final long serialVersionUID = 422889133378471949L;
27
28 //  ==============================================================================================================================
29 //  Construction
30 //  ==============================================================================================================================
31
32 //  Fields initialization class
33     public static class Properties extends Persistent.Properties {
34 //  ------------------------------------------------------------
35       private SimulationContextType  type  = null;
36       private ProjectSettingsService.Step   step  = null;
37       private ProgressState          state = null;
38       private String                 value = null;
39
40 //  - Public services
41
42       public void clear () {
43         super.clear();
44         type  = null;
45         step  = null;
46         state = null;
47         value = null;
48       }
49           public ProgressState getProgressState () {
50         return state;
51       }
52       public SimulationContextType getType () {
53         return type;
54       }
55       public String getValue () {
56         return value;
57       }
58       
59 //  - Setters of SimulationContext properties
60
61       public Properties setState (ProgressState state) throws InvalidPropertyException
62       {
63         if (state != ProgressState.inCHECK && state != ProgressState.APPROVED) {
64           throw new InvalidPropertyException("state");
65         }
66         this.state = state;
67         return this;
68       }
69       public Properties setStep (ProjectSettingsService.Step step) throws InvalidPropertyException
70       {
71         this.step = step;
72         return this;
73       }
74       public Properties setValue (String value) throws InvalidPropertyException
75       {
76         if (value.length() == 0) throw new InvalidPropertyException("value");
77         this.value = value;
78         return this;
79       }
80       public Properties setType (SimulationContextType type)
81       {
82         this.type = type;
83         return this;
84       }
85 //  - Global validity check
86         
87       public void checkValidity () throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
88       {
89         if (type == null)  throw new MissedPropertyException("type");
90         if (step == null)  throw new MissedPropertyException("step");
91         if (value == null) throw new MissedPropertyException("value");        
92         if (!type.isAttachedTo(step)) throw new InvalidPropertyException("step");
93       }
94     }
95 //  Database fetch constructor
96     protected SimulationContext () {            
97     }
98 //  Internal constructor
99     public SimulationContext (Properties kprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
100       super(kprop);   // Throws one of the above exception if not valid
101       type    = kprop.type;
102       step    = kprop.step.getNumber();
103       value   = kprop.value;
104       counter = 0;
105       state   = kprop.state;
106       if (state == null) state = ProgressState.inCHECK;
107     }
108     
109 //  ==============================================================================================================================
110 //  Public member functions
111 //  ==============================================================================================================================
112
113     public boolean equals (SimulationContext given) {
114 //  -----------------------------------------------
115       if (isSaved()) return (this.getIndex() == given.getIndex());
116       if (!this.getType().getName().equals(given.getType().getName())) return false;
117       if (this.getValue().equals(given.getValue())) return true;
118       return false;      
119     }
120
121     public String getValue () {
122 //  -------------------------
123       return value;
124     }
125
126     public ProgressState getProgressState () {
127 //  ----------------------------------------
128       return state;
129     }
130
131     /**
132          * Set the state.
133          * @param state the state to set
134          */
135         public void setProgressState(ProgressState state) {
136                 this.state = state;
137         }
138         
139     public SimulationContextType getType () {
140 //  ---------------------------------------
141       return type;
142     }
143
144     public boolean isInto (Step container) {
145 //  --------------------------------------
146       return (step == container.getNumber());
147     }
148
149     public boolean isShared () {
150 //  --------------------------
151       return (counter > 1);
152     }
153         /**
154          * Get counter.
155          * @return counter
156          */
157         public int getCounter() {
158                 return counter;
159         }
160         /**
161          * Set counter.
162          * @param aValue a counter value to set
163          */
164         public void setCounter(int aValue) {
165                 counter = aValue;
166         }
167 }