Salome HOME
Update copyrights 2014.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / SimulationContextType.java
index 881d086a9bbb732157785ae64ea0191d5992f46b..f735da29430d0478aac935964589c57ca73ea164 100644 (file)
 package org.splat.dal.bo.som;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
- * @copyright OPEN CASCADE 2012
+ * @copyright OPEN CASCADE 2012-2014
  */
 
 import java.io.Serializable;
 
 import org.splat.dal.bo.kernel.Persistent;
-import org.splat.dal.dao.som.Database;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.ProjectSettingsService.Step;
-import org.splat.service.technical.ProjectSettingsServiceImpl;
-
 
+/**
+ * Persistent simulation context type.
+ */
 public class SimulationContextType extends Persistent implements Serializable {
-       
-//  Persistent fields
-    private String         name;
-    private ProgressState  state;
-    private int            step;
 
-//  Required by the serialization
+       /**
+        * Serialization version id.
+        */
        private static final long serialVersionUID = 4819425038576161242L;
 
-//  ==============================================================================================================================
-//  Constructors
-//  ==============================================================================================================================
-
-//  Search properties class
-    public static class Properties {
-//  ------------------------------
-      private ProgressState         state = null;
-      private ProjectSettingsService.Step  step  = null;
-
-      protected ProgressState getProgressState () {
-       return state;
-      }
-      protected ProjectSettingsService.Step getStep () {
-       return step;
-      }
-      public Properties setState (ProgressState state) {
-       this.state = state;
-       return this;
-      }
-      public Properties setStep (ProjectSettingsService.Step  step) {
-       this.step = step;
-       return this;
-      }
-    }
-//  Database fetch constructor
-    protected SimulationContextType () {
-    }
-//  Initialization constructor
-    protected SimulationContextType (String name, ProjectSettingsService.Step step) throws InvalidPropertyException {
-//  ------------------------------------------------------------------------
-      super();
-      this.name  = name;
-      this.state = ProgressState.inCHECK;
-      this.step  = step.getNumber();
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public boolean approve () {
-//  -------------------------
-      if  (state != ProgressState.inCHECK) return false;      
-      this.state =  ProgressState.APPROVED;     // The type name is supposed being localized
-      Database.getSession().update(this);
-         return true;
-    }
-
-    public boolean equals(Object entity) {
-//  ------------------------------------
-      if (entity == null) return false;
-      if (entity instanceof String) {
-        return this.name.equals((String)entity);   // Names are unique
-      } else
-      if (entity instanceof SimulationContextType) {
-         SimulationContextType object = (SimulationContextType)entity;
-        long   he = object.getIndex();
-        long   me = this.getIndex();
-        if (me*he != 0) return (he == me);
-        else            return this.getName().equals(object.getName());
-      } else {
-        return false;
-      }
-    }
-
-    public ProjectSettingsService.Step getAttachedStep () {
-//  ----------------------------------------------
-      return ProjectSettingsServiceImpl.getStep(step);
-    }
-
-    public String getName () {
-//  ------------------------
-      return name;
-    }
-
-    public boolean isAttachedTo (ProjectSettingsService.Step step) {
-//  -------------------------------------------------------
-      if (this.step == step.getNumber()) return true;
-      return false;
-    }
-
-    public boolean isApproved () {
-//  ----------------------------
-      return (state == ProgressState.APPROVED);
-    }
+       // Persistent fields
+       /**
+        * Context type name.
+        */
+       private String name;
+       /**
+        * Context progress state.
+        */
+       private ProgressState state;
+       /**
+        * Context type first applicable step.
+        */
+       private int step;
+
+       // ==============================================================================================================================
+       // Constructors
+       // ==============================================================================================================================
+
+       /**
+        * Search properties class.
+        */
+       public static class Properties {
+               private ProgressState state = null;
+               private ProjectSettingsService.Step step = null;
+
+               public ProgressState getProgressState() {
+                       return state;
+               }
+
+               public ProjectSettingsService.Step getStep() {
+                       return step;
+               }
+
+               public Properties setProgressState(final ProgressState state) {
+                       this.state = state;
+                       return this;
+               }
+
+               public Properties setStep(final ProjectSettingsService.Step step) {
+                       this.step = step;
+                       return this;
+               }
+       }
+
+       /**
+        * Database fetch constructor.
+        */
+       protected SimulationContextType() {
+               super();
+       }
+
+       /**
+        * Initialization constructor.
+        * 
+        * @param name
+        *            context type name
+        * @param step
+        *            first applicable step for this type of context
+        * @throws InvalidPropertyException
+        *             from constructor of parent class
+        */
+       public SimulationContextType(final String name,
+                       final ProjectSettingsService.Step step)
+                       throws InvalidPropertyException {
+               super();
+               this.name = name;
+               this.state = ProgressState.inCHECK;
+               this.step = step.getNumber();
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       /**
+        * Saved context types are equal if their persistent ids are equal. <BR>
+        * Before becoming persistent context types are compared by their names.
+        * 
+        * @param entity
+        *            object to compare with
+        * @return true if this context type equals to the given object
+        * @see org.splat.dal.bo.kernel.Persistent#equals(java.lang.Object)
+        */
+       @Override
+       public boolean equals(final Object entity) {
+
+               if (entity == null) {
+                       return false;
+               }
+               if (entity instanceof String) {
+                       return this.name.equals(entity); // Names are unique
+               } else if (entity instanceof SimulationContextType) {
+                       SimulationContextType object = (SimulationContextType) entity;
+                       long he = object.getIndex();
+                       long me = this.getIndex();
+                       if (me * he == 0) {
+                               return this.getName().equals(object.getName());
+                       } else {
+                               return (he == me);
+                       }
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * Get context type name.
+        * 
+        * @return context type name
+        */
+       public String getName() {
+               return name;
+       }
+
+       /**
+        * Check if contexts of this type are attached to the given study step.
+        * 
+        * @param step
+        *            the study step
+        * @return true if contexts of this type are attached to the given study step
+        */
+       public boolean isAttachedTo(final ProjectSettingsService.Step step) {
+               return (this.step == step.getNumber());
+       }
+
+       /**
+        * Check if the context is approved.
+        * 
+        * @return true if the context is approved
+        */
+       public boolean isApproved() {
+               return (state == ProgressState.APPROVED);
+       }
+
+       /**
+        * Get the state.
+        * 
+        * @return the state
+        */
+       public ProgressState getState() {
+               return state;
+       }
+
+       /**
+        * Set the state.
+        * 
+        * @param state
+        *            the state to set
+        */
+       public void setState(final ProgressState state) {
+               this.state = state;
+       }
+
+       /**
+        * Get the step.
+        * 
+        * @return the step
+        */
+       public int getStep() {
+               return step;
+       }
+
+       /**
+        * Set the step.
+        * 
+        * @param step
+        *            the step to set
+        */
+       public void setStep(final int step) {
+               this.step = step;
+       }
+
 }
\ No newline at end of file