1 package org.splat.dal.bo.kernel;
5 * Base implementation of relations between entities.<br/> A relation makes a typed link from an entity to any kind persistent object. The
6 * relations are typed by subclasses of this abstract class which define the actual object referenced by the relation.<br/> This Relation
7 * base class implements unidirectional relations. The bidirectionality must be implemented in concrete subclasses by:
9 * <li>overriding the isBidirectional() and getReverseClass() methods,</li>
10 * <li>creating the reverse relation in constructors.</li>
12 * Relation objects also support dynamic attributes provided by the Any class.
15 * @author Daniel Brunier-Coulin
16 * @copyright OPEN CASCADE 2012
18 public abstract class Relation extends Any {
21 protected Entity owner; // Study or Document
24 protected Relation reverse;
26 // ==============================================================================================================================
28 // ==============================================================================================================================
30 // Database fetch constructor
31 protected Relation() {
35 // Initialization constructor
36 protected Relation(final Entity from) {
38 this.reverse = null; // Initialized by subclasses
41 // ==============================================================================================================================
42 // Public member functions
43 // ==============================================================================================================================
45 public Entity getFrom() {
49 public Relation getReverse() {
50 if (this.isBidirectional() && reverse == null) {
51 Class<? extends Relation> type = this.getReverseClass();
52 Entity to = (Entity) this.getTo(); // Bidirectional relations are necessarily between Entities
54 for (Relation asked : to.getAllRelations()) {
55 if (asked.getClass().equals(type)
56 && asked.getTo().equals(owner)) {
58 reverse.reverse = this; // For benefiting from this execution
66 public Class<? extends Relation> getReverseClass() {
70 public boolean isBidirectional() {
75 * Moves this relation from its current owner entity to the given one.
78 * the document to which this relation is moved
80 public void moveTo(final Entity nowner) {
82 Entity oldOwner = this.owner;
84 nowner.getAllRelations().add(this);
85 oldOwner.getAllRelations().remove(this);
87 if (this.isBidirectional()) {
88 Relation link = this.getReverse();
93 // ==============================================================================================================================
95 // ==============================================================================================================================
97 public abstract Persistent getTo();
99 public abstract void setTo(Persistent to); // For the need of the moveTo() method