Salome HOME
Refactoring: configuration files are moved into Siman web project.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / KnowledgeElementType.java
1 package org.splat.som;
2 /**
3  * 
4  * @author    Daniel Brunier-Coulin
5  * @copyright OPEN CASCADE 2012
6  */
7
8 import org.splat.kernel.Persistent;
9
10
11 public class KnowledgeElementType extends Persistent {
12         
13     private String         name;
14     private ProgressState  state;
15
16 //  ==============================================================================================================================
17 //  Constructors
18 //  ==============================================================================================================================
19
20 //  Database fetch constructor
21     protected KnowledgeElementType () {
22     }
23 //  Initialization constructor
24     protected KnowledgeElementType (String name) {
25 //  --------------------------------------------
26       super();
27       this.name  = name;
28       this.state = ProgressState.inCHECK;
29     }
30
31 //  ==============================================================================================================================
32 //  Public member functions
33 //  ==============================================================================================================================
34
35     public boolean approve () {
36 //  -------------------------
37       if  (state != ProgressState.inCHECK) return false;      
38       this.state =  ProgressState.APPROVED;     // The type name is supposed being localized
39       if (this.isSaved()) Database.getSession().update(this);
40           return true;
41     }
42
43     public boolean equals(Object entity) {
44 //  ------------------------------------
45       if (entity == null) return false;
46       if (entity instanceof String) {
47         return this.name.equals((String)entity);   // Names are unique
48       } else
49       if (entity instanceof KnowledgeElementType) {
50         KnowledgeElementType object = (KnowledgeElementType)entity;
51         int   he = object.getIndex();
52         int   me = this.getIndex();
53         if (me*he != 0) return (he == me);
54         else            return this.getName().equals(object.getName());
55       } else {
56         return false;
57       }
58     }
59
60     public String getName () {
61 //  ------------------------
62       return name;
63     }
64
65     public boolean isApproved () {
66 //  ----------------------------
67       return (state == ProgressState.APPROVED);
68     }
69
70     public boolean isReserved () {
71 //  ----------------------------
72       return (state == ProgressState.inWORK);
73     }
74
75 //  ==============================================================================================================================
76 //  Protected service
77 //  ==============================================================================================================================
78 /**
79  * Reserves this type for the management of simulation contexts.
80  * For being able to get the studies in which simulation contexts are used, all study scenarios are indexed through this
81  * knowledge element type, whether they include knowledge elements or not.
82  */
83     protected boolean reserve () {
84 //  ----------------------------
85       if  (state != ProgressState.inCHECK) return false;      
86       this.state =  ProgressState.inWORK;
87       if (this.isSaved()) Database.getSession().update(this);
88       return true;
89     }
90 }