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-2014
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 {
41 protected Any(final Attribute... field) {
42 for (int i = 0; i < field.length; i++) {
43 if (field[i] == null) {
44 continue; // Happen when newing an Any object without property
46 if (field[i].getFrom().equals(this)) {
47 getAttributes().add(field[i]);
52 // ==============================================================================================================================
53 // Public member functions
54 // ==============================================================================================================================
56 public Attribute getAttribute(final Class<? extends Attribute> type) {
57 Attribute found = null;
58 for (Attribute field : getAttributes()) {
59 if (field.getClass().equals(type)) {
67 // ==============================================================================================================================
69 // ==============================================================================================================================
71 public boolean removeAttribute(final Attribute field) {
73 for (Iterator<Attribute> i = getAttributes().iterator(); i.hasNext();) {
74 if (i.next().equals(field)) {
83 public boolean setAttribute(final Attribute field) {
84 Class<?> type = field.getClass();
86 if (!field.getFrom().equals(this)) {
89 for (Iterator<Attribute> i = getAttributes().iterator(); i.hasNext();) {
90 if (i.next().getClass().equals(type)) {
95 getAttributes().add(field);
100 * Get the attributes.
102 * @return the attributes
104 protected Set<Attribute> getAttributes() {
111 * @see org.splat.dal.bo.kernel.Persistent#evict()
114 public void evict() {
116 // Evict all attributes of the persistent object
117 Set<Attribute> tmpSet = new HashSet<Attribute>();
118 tmpSet.addAll(attributes);
120 for (Attribute field : tmpSet) {
121 if (field.isSaved()) { // to avoid recursive evict
124 attributes.add(field);