Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / SimulationContextType.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.dal.dao.som.Database;
12 import org.splat.kernel.InvalidPropertyException;
13 import org.splat.service.technical.ProjectSettingsService;
14 import org.splat.service.technical.ProjectSettingsService.Step;
15 import org.splat.service.technical.ProjectSettingsServiceImpl;
16
17
18 public class SimulationContextType extends Persistent implements Serializable {
19         
20 //  Persistent fields
21     private String         name;
22     private ProgressState  state;
23     private int            step;
24
25 //  Required by the serialization
26         private static final long serialVersionUID = 4819425038576161242L;
27
28 //  ==============================================================================================================================
29 //  Constructors
30 //  ==============================================================================================================================
31
32 //  Search properties class
33     public static class Properties {
34 //  ------------------------------
35       private ProgressState         state = null;
36       private ProjectSettingsService.Step  step  = null;
37
38       public ProgressState getProgressState () {
39         return state;
40       }
41       public ProjectSettingsService.Step getStep () {
42         return step;
43       }
44       public Properties setState (ProgressState state) {
45         this.state = state;
46         return this;
47       }
48       public Properties setStep (ProjectSettingsService.Step  step) {
49         this.step = step;
50         return this;
51       }
52     }
53 //  Database fetch constructor
54     protected SimulationContextType () {
55     }
56 //  Initialization constructor
57     public SimulationContextType (String name, ProjectSettingsService.Step step) throws InvalidPropertyException {
58 //  ------------------------------------------------------------------------
59       super();
60       this.name  = name;
61       this.state = ProgressState.inCHECK;
62       this.step  = step.getNumber();
63     }
64
65 //  ==============================================================================================================================
66 //  Public member functions
67 //  ==============================================================================================================================
68
69     public boolean approve () {
70 //  -------------------------
71       if  (state != ProgressState.inCHECK) return false;      
72       this.state =  ProgressState.APPROVED;     // The type name is supposed being localized
73       Database.getSession().update(this);
74           return true;
75     }
76
77     public boolean equals(Object entity) {
78 //  ------------------------------------
79       if (entity == null) return false;
80       if (entity instanceof String) {
81         return this.name.equals((String)entity);   // Names are unique
82       } else
83       if (entity instanceof SimulationContextType) {
84           SimulationContextType object = (SimulationContextType)entity;
85         long   he = object.getIndex();
86         long   me = this.getIndex();
87         if (me*he != 0) return (he == me);
88         else            return this.getName().equals(object.getName());
89       } else {
90         return false;
91       }
92     }
93
94     public ProjectSettingsService.Step getAttachedStep () {
95 //  ----------------------------------------------
96       return ProjectSettingsServiceImpl.getStep(step);
97     }
98
99     public String getName () {
100 //  ------------------------
101       return name;
102     }
103
104     public boolean isAttachedTo (ProjectSettingsService.Step step) {
105 //  -------------------------------------------------------
106       if (this.step == step.getNumber()) return true;
107       return false;
108     }
109
110     public boolean isApproved () {
111 //  ----------------------------
112       return (state == ProgressState.APPROVED);
113     }
114 }