X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=Workspace%2FSiman-Common%2Fsrc%2Forg%2Fsplat%2Fdal%2Fbo%2Fkernel%2FRelation.java;h=c5bc21ef8338955fca60bd11ce2749555a21306f;hb=b6343a018a953ae4bf5b843ae62aa0a30e2abb22;hp=b176ad0d0d2464d694763053959cb39879e5be70;hpb=a4ac35ce8653ea88a4b81a445c5de72411f10c85;p=tools%2Fsiman.git
diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java
index b176ad0..c5bc21e 100644
--- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java
+++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java
@@ -1,10 +1,10 @@
package org.splat.dal.bo.kernel;
+
+
/**
- * Base implementation of relations between entities.
- * A relation makes a typed link from an entity to any kind persistent object. The relations are typed by subclasses of this
- * abstract class which define the actual object referenced by the relation.
- * This Relation base class implements unidirectional relations. The bidirectionality must be implemented in concrete subclasses
- * by:
+ * Base implementation of relations between entities.
A relation makes a typed link from an entity to any kind persistent object. The
+ * relations are typed by subclasses of this abstract class which define the actual object referenced by the relation.
This Relation
+ * base class implements unidirectional relations. The bidirectionality must be implemented in concrete subclasses by:
*
* - overriding the isBidirectional() and getReverseClass() methods,
* - creating the reverse relation in constructors.
@@ -12,100 +12,89 @@ package org.splat.dal.bo.kernel;
* Relation objects also support dynamic attributes provided by the Any class.
*
* @see Entity
- * @author Daniel Brunier-Coulin
+ * @author Daniel Brunier-Coulin
* @copyright OPEN CASCADE 2012
*/
-
-import java.util.Iterator;
-
public abstract class Relation extends Any {
-// Persistent fields
- protected Entity owner; // Study or Document
-
-// Transient field
- protected Relation reverse;
-
-// ==============================================================================================================================
-// Constructors
-// ==============================================================================================================================
-
-// Database fetch constructor
- protected Relation () {
-// ---------------------
- reverse = null;
- }
-// Initialization constructor
- protected Relation (Entity from) {
-// --------------------------------
- this.owner = from;
- this.reverse = null; // Initialized by subclasses
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- public Entity getFrom () {
-// ------------------------
- return owner;
- }
-
- public Relation getReverse () {
-// -----------------------------
- if (!this.isBidirectional() || reverse != null) return reverse;
-
- Class extends Relation> type = this.getReverseClass();
- Entity to = (Entity)this.getTo(); // Bidirectional relations are necessarily between Entities
-
- for (Iterator i=to.getAllRelations().iterator(); i.hasNext(); ) {
- Relation asked = i.next();
- if (!asked.getClass().equals(type)) continue;
- if (!asked.getTo().equals(owner)) continue;
- reverse = asked;
- reverse.reverse = this; // For benefiting from this execution
- return reverse;
- }
- return null;
- }
-
- public Class extends Relation> getReverseClass () {
-// ---------------------------------------------------
- return null;
- }
-
- public boolean isBidirectional () {
-// ---------------------------------
- return false;
- }
-
-/**
- * Moves this relation from its current owner entity to the given one.
- *
- * @param nowner the document to which this relation is moved
- * */
- public void moveTo (Entity nowner) {
- //RKV Session session = Database.getCurSession();
-
- Entity oldOwner = this.owner;
- this.owner = nowner;
- nowner.getAllRelations().add(this);
- oldOwner.getAllRelations().remove(this);
-// myold.getAllRelations().remove(this); Harmful as it leads to remove this relation from the database (!?)
- //RKV session.update(this);
- //RKV session.update(nowner);
-
- if (this.isBidirectional()) {
- Relation link = this.getReverse();
- link.setTo(nowner);
- //RKV session.update(link);
- }
- }
-
-// ==============================================================================================================================
-// Abstract functions
-// ==============================================================================================================================
-
- public abstract Persistent getTo ();
- protected abstract void setTo (Persistent to); // For the need of the moveTo() method
+ // Persistent fields
+ protected Entity owner; // Study or Document
+
+ // Transient field
+ protected Relation reverse;
+
+ // ==============================================================================================================================
+ // Constructors
+ // ==============================================================================================================================
+
+ // Database fetch constructor
+ protected Relation() {
+ reverse = null;
+ }
+
+ // Initialization constructor
+ protected Relation(final Entity from) {
+ this.owner = from;
+ this.reverse = null; // Initialized by subclasses
+ }
+
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ public Entity getFrom() {
+ return owner;
+ }
+
+ public Relation getReverse() {
+ if (this.isBidirectional() && reverse == null) {
+ Class extends Relation> type = this.getReverseClass();
+ Entity to = (Entity) this.getTo(); // Bidirectional relations are necessarily between Entities
+
+ for (Relation asked : to.getAllRelations()) {
+ if (asked.getClass().equals(type)
+ && asked.getTo().equals(owner)) {
+ reverse = asked;
+ reverse.reverse = this; // For benefiting from this execution
+ break;
+ }
+ }
+ }
+ return reverse;
+ }
+
+ public Class extends Relation> getReverseClass() {
+ return null;
+ }
+
+ public boolean isBidirectional() {
+ return false;
+ }
+
+ /**
+ * Moves this relation from its current owner entity to the given one.
+ *
+ * @param nowner
+ * the document to which this relation is moved
+ */
+ public void moveTo(final Entity nowner) {
+
+ Entity oldOwner = this.owner;
+ this.owner = nowner;
+ nowner.getAllRelations().add(this);
+ oldOwner.getAllRelations().remove(this);
+
+ if (this.isBidirectional()) {
+ Relation link = this.getReverse();
+ link.setTo(nowner);
+ }
+ }
+
+ // ==============================================================================================================================
+ // Abstract functions
+ // ==============================================================================================================================
+
+ public abstract Persistent getTo();
+
+ public abstract void setTo(Persistent to); // For the need of the moveTo() method
}
\ No newline at end of file