package org.splat.dal.bo.kernel;
+
+
/**
- * Base implementation of relations between entities.<br/>
- * 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.<br/>
- * This Relation base class implements unidirectional relations. The bidirectionality must be implemented in concrete subclasses
- * by:
+ * Base implementation of relations between entities.<br/> 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.<br/> This Relation
+ * base class implements unidirectional relations. The bidirectionality must be implemented in concrete subclasses by:
* <ul>
* <li>overriding the isBidirectional() and getReverseClass() methods,</li>
* <li>creating the reverse relation in constructors.</li>
* 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<Relation> 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) {
-
- 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 ();
- 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