1 package org.splat.dal.bo.kernel;
3 * Abstract root class of persistent objects supporting dynamic attributes.<br/>
4 * Dynamic attributes are instances of concrete subclasses of Attribute that are assigned to Any objects at run time.
5 * The attributes of a given Any object must all be of different types.
8 * @author Daniel Brunier-Coulin
9 * @copyright OPEN CASCADE 2012
12 import java.util.HashSet;
13 import java.util.Iterator;
16 import org.splat.kernel.InvalidPropertyException;
17 import org.splat.kernel.MissedPropertyException;
18 import org.splat.kernel.MultiplyDefinedException;
19 import org.splat.kernel.ObjectProperties;
22 public abstract class Any extends Persistent {
24 private Set<Attribute> attributes;
26 // ==============================================================================================================================
28 // ==============================================================================================================================
30 // Database fetch constructor.
33 // Initialization constructors
34 protected Any (ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
35 // --------------------------------------
37 attributes = new HashSet<Attribute>();
39 protected Any (Attribute... field) {
40 // ----------------------------------
41 attributes = new HashSet<Attribute>();
42 for (int i=0; i<field.length; i++) {
43 if (field[i] == null) continue; // Happen when newing an Any object without property
44 if (field[i].getFrom().equals(this)) attributes.add(field[i]);
48 // ==============================================================================================================================
49 // Public member functions
50 // ==============================================================================================================================
52 public Attribute getAttribute (Class<? extends Attribute> type) {
53 // ---------------------------------------------------------------
54 for (Iterator<Attribute> i=attributes.iterator(); i.hasNext(); ) {
55 Attribute field = i.next();
56 if (field.getClass().equals(type)) return field;
61 // ==============================================================================================================================
63 // ==============================================================================================================================
65 protected boolean removeAttribute (Attribute field) {
66 // ---------------------------------------------------
67 for (Iterator<Attribute> i=attributes.iterator(); i.hasNext(); ) {
68 if (!i.next().equals(field)) continue;
70 //RKV if (this.isSaved()) Database.getCurSession().update(this);
76 public boolean setAttribute (Attribute field) {
77 // ------------------------------------------------
78 Class<?> type = field.getClass();
79 //RKV Session session = Database.getCurSession();
81 if (!field.getFrom().equals(this)) return false;
82 for (Iterator<Attribute> i=attributes.iterator(); i.hasNext(); ) {
83 if (!i.next().getClass().equals(type)) continue;
87 attributes.add(field);
89 //RKV if (!field.isSaved()) session.save(field);
90 //RKV session.update(this);
91 } // Else, when saving this, Hibernate will propagate the operation