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 = new HashSet<Attribute>();
26 // ==============================================================================================================================
28 // ==============================================================================================================================
30 // Database fetch constructor.
33 // Initialization constructors
34 protected Any (ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
35 // --------------------------------------
38 protected Any (Attribute... field) {
39 for (int i=0; i<field.length; i++) {
40 if (field[i] == null) continue; // Happen when newing an Any object without property
41 if (field[i].getFrom().equals(this)) getAttributes().add(field[i]);
45 // ==============================================================================================================================
46 // Public member functions
47 // ==============================================================================================================================
49 public Attribute getAttribute (Class<? extends Attribute> type) {
50 for (Iterator<Attribute> i=getAttributes().iterator(); i.hasNext(); ) {
51 Attribute field = i.next();
52 if (field.getClass().equals(type)) return field;
57 // ==============================================================================================================================
59 // ==============================================================================================================================
61 protected boolean removeAttribute (Attribute field) {
62 for (Iterator<Attribute> i=getAttributes().iterator(); i.hasNext(); ) {
63 if (!i.next().equals(field)) continue;
70 public boolean setAttribute (Attribute field) {
71 Class<?> type = field.getClass();
73 if (!field.getFrom().equals(this)) return false;
74 for (Iterator<Attribute> i=getAttributes().iterator(); i.hasNext(); ) {
75 if (!i.next().getClass().equals(type)) continue;
79 getAttributes().add(field);
84 * @return the attributes
86 protected Set<Attribute> getAttributes() {