1 package org.splat.dal.bo.som;
4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
8 import java.io.Serializable;
11 import org.hibernate.Session;
13 import org.splat.dal.bo.kernel.Persistent;
14 import org.splat.dal.dao.som.Database;
15 import org.splat.kernel.InvalidPropertyException;
16 import org.splat.kernel.MissedPropertyException;
17 import org.splat.kernel.MultiplyDefinedException;
18 import org.splat.service.technical.ProjectSettingsService;
19 import org.splat.som.Step;
22 public class SimulationContext extends Persistent implements Serializable {
24 private SimulationContextType type; // User extendable types
26 private ProgressState state;
30 private static final long serialVersionUID = 422889133378471949L;
32 // ==============================================================================================================================
34 // ==============================================================================================================================
36 // Fields initialization class
37 public static class Properties extends Persistent.Properties {
38 // ------------------------------------------------------------
39 private SimulationContextType type = null;
40 private ProjectSettingsService.Step step = null;
41 private ProgressState state = null;
42 private String value = null;
46 public void clear () {
53 public ProgressState getProgressState () {
56 public SimulationContextType getType () {
59 public String getValue () {
63 // - Setters of SimulationContext properties
65 public Properties setState (ProgressState state) throws InvalidPropertyException
67 if (state != ProgressState.inCHECK && state != ProgressState.APPROVED) {
68 throw new InvalidPropertyException("state");
73 public Properties setStep (ProjectSettingsService.Step step) throws InvalidPropertyException
78 public Properties setValue (String value) throws InvalidPropertyException
80 if (value.length() == 0) throw new InvalidPropertyException("value");
84 public Properties setType (SimulationContextType type)
89 // - Global validity check
91 public void checkValidity () throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
93 if (type == null) throw new MissedPropertyException("type");
94 if (step == null) throw new MissedPropertyException("step");
95 if (value == null) throw new MissedPropertyException("value");
96 if (!type.isAttachedTo(step)) throw new InvalidPropertyException("step");
99 // Database fetch constructor
100 protected SimulationContext () {
102 // Internal constructor
103 public SimulationContext (Properties kprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
104 super(kprop); // Throws one of the above exception if not valid
106 step = kprop.step.getNumber();
110 if (state == null) state = ProgressState.inCHECK;
113 // ==============================================================================================================================
114 // Public member functions
115 // ==============================================================================================================================
117 public boolean approve () {
118 // -------------------------
119 if (state != ProgressState.inCHECK) return false;
120 this.state = ProgressState.APPROVED; // The type name is supposed being localized
121 Database.getSession().update(this);
125 public boolean equals (SimulationContext given) {
126 // -----------------------------------------------
127 if (isSaved()) return (this.getIndex() == given.getIndex());
128 if (!this.getType().getName().equals(given.getType().getName())) return false;
129 if (this.getValue().equals(given.getValue())) return true;
133 public String getValue () {
134 // -------------------------
138 public ProgressState getProgressState () {
139 // ----------------------------------------
143 public SimulationContextType getType () {
144 // ---------------------------------------
148 public boolean isInto (Step container) {
149 // --------------------------------------
150 return (step == container.getNumber());
153 public boolean isShared () {
154 // --------------------------
155 return (counter > 1);
161 public int getCounter() {
166 * @param aValue a counter value to set
168 public void setCounter(int aValue) {