]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java
Salome HOME
74c5a59596119deb8e23673c6399089cae9112d4
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / ProjectElement.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.util.Collections;
9 import java.util.Date;
10 import java.util.Iterator;
11 import java.util.LinkedHashSet;
12 import java.util.List;
13 import java.util.Set;
14 import java.util.Vector;
15
16 import org.apache.log4j.Logger;
17 import org.splat.dal.bo.kernel.Entity;
18 import org.splat.dal.bo.kernel.User;
19 import org.splat.kernel.InvalidPropertyException;
20 import org.splat.kernel.MissedPropertyException;
21 import org.splat.kernel.MultiplyDefinedException;
22 import org.splat.kernel.ObjectProperties;
23 import org.splat.som.Step;
24
25
26 public abstract class ProjectElement extends Entity {
27
28 //  Persistent fields
29     protected  String                   title;
30     protected  User                     manager;
31     protected  Date                     credate;    // Object creation date
32     protected  Date                     lasdate;    // Object Last modification date
33     private final    List<SimulationContext>  contex = new Vector<SimulationContext>();     // Structured by the Step transient class
34     private final    Set<Publication>         docums = new LinkedHashSet<Publication>();     // Structured by the Step transient class
35
36 //  Transient field
37     private    Step[]                   folders;
38
39     /**
40          * Set the folders.
41          * @param folders the folders to set
42          */
43         public void setFolders(final Step[] folders) {
44                 this.folders = folders;
45         }
46         /**
47          * Get the folders.
48          * @return the folders
49          */
50         public Step[] getFolders() {
51                 return folders;
52         }
53
54         protected final static Logger       LOGGER = Logger.getLogger(ProjectElement.class);
55
56 //  ==============================================================================================================================
57 //  Constructors
58 //  ==============================================================================================================================
59
60 //  Database fetch constructor
61     protected ProjectElement () {
62 //  ---------------------------
63       folders  = null;
64     }
65 //  Initialization constructor
66     protected ProjectElement (final ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
67 //  -------------------------------------------------           
68       super(oprop);       // Throws one of the above exception if not valid
69       title    = null;     // Initialized by subclasses
70       credate  = null;     // Initialized by subclasses
71       lasdate  = null;     // Initialized by subclasses
72 //RKV      docums   = new LinkedHashSet<Publication>();
73 //RKV      contex   = new Vector<SimulationContext>();
74       
75       folders  = null;
76     }
77
78 //  ==============================================================================================================================
79 //  Public member functions
80 //  ==============================================================================================================================
81
82     public User getAuthor () {
83 //  ------------------------
84       return manager;
85     }
86
87 /**
88  * Returns the creation date of this Project Element.
89  */
90     public Date getDate () {
91 //  ----------------------
92       return credate;
93     }
94
95     public String getDescription () {
96 //  -------------------------------
97       String               summary = null;
98       DescriptionAttribute field   = (DescriptionAttribute)this.getAttribute(DescriptionAttribute.class);
99       if (field != null) {
100                 summary = field.getValue();
101         }
102       return summary;               // May be null
103     }
104
105     public Date getLastModificationDate () {
106       return lasdate;
107     }
108
109     public void setLastModificationDate (final Date aDate) {
110       lasdate = aDate;
111     }
112
113     /**
114  * Returns the publication into this Project Element of the given document version, if exists.
115  * If exists, a document publication id unique in a given ProjectElement.
116  * 
117  * @param doc a document version published into this Project Element
118  * @return the publication of the document version, or null if the given document version is not published into this Project Element
119  */
120     public Publication getPublication (final Document doc) {
121 //  ------------------------------------------------
122       long  index = doc.getIndex();
123       for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
124         Publication  found = i.next();
125         if (found.value().getIndex() == index) {
126                         return found;   // A document publication is unique in a given ProjectElement
127                 }
128       }
129       return null;
130     }
131
132     public String getTitle () {
133 //  -------------------------
134       return title;
135     }
136
137     public void setTitle (final String aTitle) {
138       title = aTitle;
139     }
140
141     public boolean publishes (final Document doc) {
142 //  ---------------------------------------
143       long  index = doc.getIndex();
144       for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
145         Document  found = i.next().value();
146         if (found.getIndex() == index) {
147                         return true;
148                 }
149       }
150       return false;
151     }
152
153     public Iterator<Publication> PublicationIterator () {
154 //  ---------------------------------------------------
155       return  Collections.unmodifiableSet(docums).iterator();
156     }
157
158     public Iterator<SimulationContext> SimulationContextIterator () {
159 //  ---------------------------------------------------------------
160       return  Collections.unmodifiableList(contex).iterator();
161     }
162
163 //  ==============================================================================================================================
164 //  Protected member functions
165 //  ==============================================================================================================================
166
167     public boolean add (final Publication newdoc) {
168 //  ------------------------------------------
169       return  docums.add(newdoc);
170     }
171
172     public boolean add (final SimulationContext newdoc) {
173 //  ------------------------------------------------
174       return  contex.add(newdoc);
175     }
176
177     public boolean remove (final Publication oldoc) {
178 //  --------------------------------------------
179       return  docums.remove(oldoc);   // The removed tag becoming orphan, it is supposed automatically deleted from the data store
180     }
181
182     public boolean remove (final SimulationContext oldoc) {
183 //  --------------------------------------------------
184       return  contex.remove(oldoc);
185     }
186         /**
187          * Get the docums.
188          * @return the docums
189          */
190         public Set<Publication> getDocums() {
191                 return docums;
192         }
193 }