Salome HOME
Copyrights update 2015.
[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-2015
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       }
93     }
94 //  Database fetch constructor
95     protected SimulationContext () {            
96     }
97 //  Internal constructor
98     public SimulationContext (Properties kprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
99       super(kprop);   // Throws one of the above exception if not valid
100       type    = kprop.type;
101       step    = kprop.step.getNumber();
102       value   = kprop.value;
103       counter = 0;
104       state   = kprop.state;
105       if (state == null) state = ProgressState.inCHECK;
106     }
107     
108 //  ==============================================================================================================================
109 //  Public member functions
110 //  ==============================================================================================================================
111
112     public boolean equals (SimulationContext given) {
113 //  -----------------------------------------------
114       if (isSaved()) return (this.getIndex() == given.getIndex());
115       if (!this.getType().getName().equals(given.getType().getName())) return false;
116       if (this.getValue().equals(given.getValue())) return true;
117       return false;      
118     }
119
120     public String getValue () {
121 //  -------------------------
122       return value;
123     }
124
125     public ProgressState getProgressState () {
126 //  ----------------------------------------
127       return state;
128     }
129
130     /**
131          * Set the state.
132          * @param state the state to set
133          */
134         public void setProgressState(ProgressState state) {
135                 this.state = state;
136         }
137         
138     public SimulationContextType getType () {
139 //  ---------------------------------------
140       return type;
141     }
142
143     public boolean isInto (Step container) {
144 //  --------------------------------------
145       return (step == container.getNumber());
146     }
147
148     public boolean isShared () {
149 //  --------------------------
150       return (counter > 1);
151     }
152         /**
153          * Get counter.
154          * @return counter
155          */
156         public int getCounter() {
157                 return counter;
158         }
159         /**
160          * Set counter.
161          * @param aValue a counter value to set
162          */
163         public void setCounter(int aValue) {
164                 counter = aValue;
165         }
166 }