X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Workspace%2FSiman-Common%2Fsrc%2Forg%2Fsplat%2Fdal%2Fbo%2Fkernel%2FAny.java;h=e131b6a62a32a8ff58b418397112133f3284c303;hb=d0f7e95389f08ff3dfec5961d9f19866e0ee956b;hp=c84935c09a2ef227b0d3e07d9174097d38acfeb4;hpb=feec9d8014747ccdea7d5c5cdb8607d5b1f6caf5;p=tools%2Fsiman.git
diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java
index c84935c..e131b6a 100644
--- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java
+++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java
@@ -1,4 +1,5 @@
package org.splat.dal.bo.kernel;
+
/**
* Abstract root class of persistent objects supporting dynamic attributes.
* 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 attributes = new HashSet();
-
-// ==============================================================================================================================
-// 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 type) {
- for (Iterator 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 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 i=getAttributes().iterator(); i.hasNext(); ) {
- if (!i.next().getClass().equals(type)) continue;
- i.remove();
- break;
- }
- getAttributes().add(field);
- return true;
- }
+ private final Set attributes = new HashSet();
+
+ // ==============================================================================================================================
+ // 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 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 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 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 tmpSet = new HashSet();
+ 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