1 package org.splat.dal.bo.kernel;
3 * Abstract root class of persistent objects supporting relations to other persistent objects.<br/>
4 * Relations are instances of concrete subclasses of Relation that are assigned to Entity objects at run time.<br/>
6 * Entity objects also support dynamic attributes provided by the Any class.
9 * @author Daniel Brunier-Coulin
10 * @copyright OPEN CASCADE 2012
13 import java.util.HashSet;
14 import java.util.Iterator;
15 import java.util.List;
17 import java.util.Vector;
19 import org.splat.kernel.InvalidPropertyException;
20 import org.splat.kernel.MissedPropertyException;
21 import org.splat.kernel.MultiplyDefinedException;
22 import org.splat.kernel.ObjectProperties;
25 public abstract class Entity extends Any {
27 private Set<Relation> relations = new HashSet<Relation>();
29 // ==============================================================================================================================
31 // ==============================================================================================================================
33 // Database fetch constructor
36 // Initialization constructor
37 protected Entity (ObjectProperties prop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
41 // ==============================================================================================================================
42 // Public member functions
43 // ==============================================================================================================================
45 public Relation getFirstRelation (Class<? extends Relation> type) {
46 // -----------------------------------------------------------------
47 for (Iterator<Relation> i=relations.iterator(); i.hasNext();) {
48 Relation link = i.next();
49 if (link.getClass().equals(type)) return link;
54 public List<Relation> getRelations (Class<? extends Relation> type) {
55 List<Relation> result = new Vector<Relation>();
57 for (Iterator<Relation> i=relations.iterator(); i.hasNext();) {
58 Relation link = i.next();
59 if (link.getClass().equals(type)) result.add(link);
64 // ==============================================================================================================================
66 // ==============================================================================================================================
68 protected Set<Relation> getAllRelations () {
72 protected Relation addRelation (Relation link) {
76 if (link.isBidirectional()) {
77 Entity to = (Entity)link.getTo(); // Bidirectional relation are necessarily between entities
79 link = link.getReverse();
80 to.relations.add(link);
85 protected void removeRelation (Class<? extends Relation> type, Persistent to) {
86 for (Iterator<Relation> i=relations.iterator(); i.hasNext();) {
87 Relation link = i.next();
88 if (!link.getClass().equals(type)) continue;
89 if (!link.getTo().equals(to)) continue;