Salome HOME
The draft of the "Copy from existing study" action is added. The YACS step is introdu...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / kernel / Any.java
index c84935c09a2ef227b0d3e07d9174097d38acfeb4..e131b6a62a32a8ff58b418397112133f3284c303 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.dal.bo.kernel;
+
 /**
  * Abstract root class of persistent objects supporting dynamic attributes.<br/>
  * Dynamic attributes are instances of concrete subclasses of Attribute that are assigned to Any objects at run time.
@@ -18,72 +19,110 @@ import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.ObjectProperties;
 
-
 public abstract class Any extends Persistent {
 
-    private  Set<Attribute> attributes = new HashSet<Attribute>();
-
-//  ==============================================================================================================================
-//  Constructors
-//  ==============================================================================================================================
-
-//  Database fetch constructor.
-    protected Any () {
-    }
-//  Initialization constructors
-    protected Any (ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-//  --------------------------------------
-      super(oprop);
-    }
-    protected Any (Attribute... field) {
-      for (int i=0; i<field.length; i++) {
-       if (field[i] == null) continue;     // Happen when newing an Any object without property 
-        if (field[i].getFrom().equals(this)) getAttributes().add(field[i]);
-      }
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public Attribute getAttribute (Class<? extends Attribute> type) {
-      for (Iterator<Attribute> i=getAttributes().iterator(); i.hasNext(); ) {
-       Attribute field = i.next();
-        if (field.getClass().equals(type)) return field;
-      }
-      return null;
-    }
-
-//  ==============================================================================================================================
-//  Protected services
-//  ==============================================================================================================================
-
-    public boolean removeAttribute (Attribute field) {
-      for (Iterator<Attribute> i=getAttributes().iterator(); i.hasNext(); ) {
-        if (!i.next().equals(field)) continue;
-       i.remove();
-       return true;
-      }
-      return false;
-    }
-
-    public boolean setAttribute (Attribute field) {
-      Class<?> type    = field.getClass();
-
-      if (!field.getFrom().equals(this)) return false;
-      for (Iterator<Attribute> i=getAttributes().iterator(); i.hasNext(); ) {
-        if (!i.next().getClass().equals(type)) continue;
-        i.remove();
-       break;
-      }
-      getAttributes().add(field);
-      return true;
-    }
+       private final Set<Attribute> attributes = new HashSet<Attribute>();
+
+       // ==============================================================================================================================
+       // Constructors
+       // ==============================================================================================================================
+
+       // Database fetch constructor.
+       protected Any() {
+               super();
+       }
+
+       // Initialization constructors
+       protected Any(final ObjectProperties oprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException {
+               // --------------------------------------
+               super(oprop);
+       }
+
+       protected Any(final Attribute... field) {
+               for (int i = 0; i < field.length; i++) {
+                       if (field[i] == null) {
+                               continue; // Happen when newing an Any object without property
+                       }
+                       if (field[i].getFrom().equals(this)) {
+                               getAttributes().add(field[i]);
+                       }
+               }
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       public Attribute getAttribute(final Class<? extends Attribute> type) {
+               Attribute found = null;
+               for (Attribute field : getAttributes()) {
+                       if (field.getClass().equals(type)) {
+                               found = field;
+                               break;
+                       }
+               }
+               return found;
+       }
+
+       // ==============================================================================================================================
+       // Protected services
+       // ==============================================================================================================================
+
+       public boolean removeAttribute(final Attribute field) {
+               boolean res = false;
+               for (Iterator<Attribute> i = getAttributes().iterator(); i.hasNext();) {
+                       if (i.next().equals(field)) {
+                               i.remove();
+                               res = true;
+                               break;
+                       }
+               }
+               return res;
+       }
+
+       public boolean setAttribute(final Attribute field) {
+               Class<?> type = field.getClass();
+
+               if (!field.getFrom().equals(this)) {
+                       return false;
+               }
+               for (Iterator<Attribute> i = getAttributes().iterator(); i.hasNext();) {
+                       if (i.next().getClass().equals(type)) {
+                               i.remove();
+                               break;
+                       }
+               }
+               getAttributes().add(field);
+               return true;
+       }
+
        /**
         * Get the attributes.
+        * 
         * @return the attributes
         */
        protected Set<Attribute> getAttributes() {
                return attributes;
        }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.dal.bo.kernel.Persistent#evict()
+        */
+       @Override
+       public void evict() {
+               super.evict();
+               // Evict all attributes of the persistent object
+               Set<Attribute> tmpSet = new HashSet<Attribute>();
+               tmpSet.addAll(attributes);
+               attributes.clear();
+               for (Attribute field : tmpSet) {
+                       if (field.isSaved()) { // to avoid recursive evict
+                               field.evict();
+                       }
+                       attributes.add(field);
+               }
+       }
 }
\ No newline at end of file