1 package org.splat.dal.bo.kernel;
4 * Abstract root class of persistent objects supporting dynamic attributes.<br/>
5 * Dynamic attributes are instances of concrete subclasses of Attribute that are assigned to Any objects at run time.
6 * The attributes of a given Any object must all be of different types.
9 * @author Daniel Brunier-Coulin
10 * @copyright OPEN CASCADE 2012
13 import java.util.HashSet;
14 import java.util.Iterator;
17 import org.splat.kernel.InvalidPropertyException;
18 import org.splat.kernel.MissedPropertyException;
19 import org.splat.kernel.MultiplyDefinedException;
20 import org.splat.kernel.ObjectProperties;
22 public abstract class Any extends Persistent {
24 private final Set<Attribute> attributes = new HashSet<Attribute>();
26 // ==============================================================================================================================
28 // ==============================================================================================================================
30 // Database fetch constructor.
35 // Initialization constructors
36 protected Any(final ObjectProperties oprop) throws MissedPropertyException,
37 InvalidPropertyException, MultiplyDefinedException {
38 // --------------------------------------
42 protected Any(final Attribute... field) {
43 for (int i = 0; i < field.length; i++) {
44 if (field[i] == null) {
45 continue; // Happen when newing an Any object without property
47 if (field[i].getFrom().equals(this)) {
48 getAttributes().add(field[i]);
53 // ==============================================================================================================================
54 // Public member functions
55 // ==============================================================================================================================
57 public Attribute getAttribute(final Class<? extends Attribute> type) {
58 Attribute found = null;
59 for (Attribute field : getAttributes()) {
60 if (field.getClass().equals(type)) {
68 // ==============================================================================================================================
70 // ==============================================================================================================================
72 public boolean removeAttribute(final Attribute field) {
74 for (Iterator<Attribute> i = getAttributes().iterator(); i.hasNext();) {
75 if (i.next().equals(field)) {
84 public boolean setAttribute(final Attribute field) {
85 Class<?> type = field.getClass();
87 if (!field.getFrom().equals(this)) {
90 for (Iterator<Attribute> i = getAttributes().iterator(); i.hasNext();) {
91 if (i.next().getClass().equals(type)) {
96 getAttributes().add(field);
101 * Get the attributes.
103 * @return the attributes
105 protected Set<Attribute> getAttributes() {
112 * @see org.splat.dal.bo.kernel.Persistent#evict()
115 public void evict() {
117 // Evict all attributes of the persistent object
118 Set<Attribute> tmpSet = new HashSet<Attribute>();
119 tmpSet.addAll(attributes);
121 for (Attribute field : tmpSet) {
122 if (field.isSaved()) { // to avoid recursive evict
125 attributes.add(field);