pl.edu.agh.cast.data.model
Class AbstractElement

java.lang.Object
  extended by pl.edu.agh.cast.data.model.property.PropertyContainer
      extended by pl.edu.agh.cast.data.model.AbstractElement
All Implemented Interfaces:
Serializable, Observer, IDisposable, IReplicable, IValidatable, Identifiable, IElement, IPropertyContainer
Direct Known Subclasses:
Entity, ManyToManyRelation, PresentationElement, VisualElement

public abstract class AbstractElement
extends PropertyContainer
implements IElement

Abstract implementation of IElement.

Author:
AGH CAST Team
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface pl.edu.agh.cast.data.model.Identifiable
Identifiable.Properties
 
Field Summary
 
Fields inherited from interface pl.edu.agh.cast.data.model.IElement
TYPE
 
Constructor Summary
protected AbstractElement(Type type)
          Initializes element with type.
protected AbstractElement(Type type, UUID id)
          Initializes element with type and ID.
protected AbstractElement(Type type, UUID id, IDataSet<? extends IElement> dataSet)
          Initializes element with ID and type.
 
Method Summary
protected  void afterSetMetaPropertyManager()
          Adds all PermanentProperty'ies and TransientProperty'ies defined this container's meta-property manager.
protected  void canReplicateTo(Object replica, Class<?> clazz)
           
protected  boolean checkIfValid()
          Checks if the element is valid.
 boolean equals(Object other)
          Compares two elements.
 IDataSet<? extends IElement> getDataSet()
          Returns the data set this element is in.
protected  String getDescString()
          Returns a string with short description of element.
 UUID getId()
          Returns object's globally unique ID.
 Type getType()
          Returns object's type.
 int hashCode()
          Returns the hash code of the element.
 boolean isValid()
          Checks if the state of implementing object is valid.
 AbstractElement replicate()
          Returns a replicated instance of this instance.
 AbstractElement replicateTo(Object replica)
          Replicates this instance state to given replica object.
 void setDataSet(IDataSet<? extends IElement> dataSet)
          Sets the data set of the element.
 void setId(UUID id)
          Sets the ID of the element.
 void setType(Type type)
          Sets the type of the element.
 String toString()
          
 
Methods inherited from class pl.edu.agh.cast.data.model.property.PropertyContainer
addProperty, createProperty, dispose, getCustomProperties, getMetaPropertyManager, getPermanentProperties, getProperties, getProperty, getTransientProperties, initializeProperties, matches, removeProperty, setMetaPropertyManager, setProperty, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface pl.edu.agh.cast.data.model.property.IPropertyContainer
addProperty, getCustomProperties, getMetaPropertyManager, getPermanentProperties, getProperties, getProperty, getTransientProperties, matches, removeProperty, setProperty
 
Methods inherited from interface java.util.Observer
update
 
Methods inherited from interface pl.edu.agh.cast.common.IDisposable
dispose
 

Constructor Detail

AbstractElement

protected AbstractElement(Type type)
Initializes element with type. The ID and data set have to be set manually - until then the element is invalid.

Parameters:
type - type of the element
Throws:
IllegalArgumentException - if the argument is null

AbstractElement

protected AbstractElement(Type type,
                          UUID id)
Initializes element with type and ID. The data set has to be set manually - until then the element is invalid.

Parameters:
type - type of the element
id - ID of the element
Throws:
IllegalArgumentException - if any of the arguments is null

AbstractElement

protected AbstractElement(Type type,
                          UUID id,
                          IDataSet<? extends IElement> dataSet)
Initializes element with ID and type.

Parameters:
type - type of the element
id - ID of the element
dataSet - the IDataSet this element is in
Throws:
IllegalArgumentException - if any of the arguments is null or dataSet.getMetaPropertyManager(type) returns null
Method Detail

isValid

public final boolean isValid()
Checks if the state of implementing object is valid.

Specified by:
isValid in interface IValidatable
Overrides:
isValid in class PropertyContainer
Returns:
true if object's state is valid, false otherwise
See Also:
pl.edu.agh.cast.data.model.AbstractInitializable#doInitialize()

checkIfValid

protected boolean checkIfValid()
Checks if the element is valid.

This method is called by the isValid() method. By default it always returns true, however it can be overridden in order to define new validation rules. In such case the implementation from base class should be called inside the overridden method in order to preserve data consistency.

Returns:
true if the element is valid, false otherwise

getId

public final UUID getId()
Returns object's globally unique ID.

Specified by:
getId in interface Identifiable
Returns:
globally unique ID
See Also:
Identifiable.getId()

setId

public final void setId(UUID id)
Sets the ID of the element. The ID cannot be changed.

Parameters:
id - the element ID
Throws:
ModelException - if the ID is already set and it is not equal to given one
IllegalArgumentException - if the given ID is null

getType

public final Type getType()
Returns object's type.

Specified by:
getType in interface Identifiable
Returns:
type
See Also:
Identifiable.getType()

setType

public final void setType(Type type)
Sets the type of the element. This method may be called only once, if the type is not set yet.

Parameters:
type - the element type
Throws:
ModelException - if the type is already set
IllegalArgumentException - if the given type is null or is not a type of element

getDataSet

public final IDataSet<? extends IElement> getDataSet()
Returns the data set this element is in.

Specified by:
getDataSet in interface IElement
Returns:
the data set this element is in
See Also:
IElement.getDataSet()

setDataSet

public final void setDataSet(IDataSet<? extends IElement> dataSet)
Sets the data set of the element. This method may be called only once, if the data set is not set yet.

This method cannot be called before the type and ID are defined.

Parameters:
dataSet - the element's data set
Throws:
ModelException - if the data set is already set or element is not ready for it (the type or ID is not defined)
IllegalArgumentException - if the given data set is null
See Also:
setType(Type), setId(UUID)

afterSetMetaPropertyManager

protected final void afterSetMetaPropertyManager()
Adds all PermanentProperty'ies and TransientProperty'ies defined this container's meta-property manager. Called right after setting the MPM. May be overridden.

Overrides:
afterSetMetaPropertyManager in class PropertyContainer
See Also:
PropertyContainer.afterSetMetaPropertyManager()

equals

public final boolean equals(Object other)
Compares two elements. Two elements are equal if they have equal ids. To compare domain semantic of two elements use IPropertyContainer#match(IPropertyContainer) method.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object), IPropertyContainer#match(IPropertyContainer)

hashCode

public final int hashCode()
Returns the hash code of the element.

This method will throw NullPointerException if the ID is not set.

Overrides:
hashCode in class Object
See Also:
getId(), Object.hashCode()

toString

public final String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

getDescString

protected String getDescString()
Returns a string with short description of element. This method is used by toString() and may be overridden in order to customize its results.

Returns:
a description string

canReplicateTo

protected final void canReplicateTo(Object replica,
                                    Class<?> clazz)

replicateTo

public AbstractElement replicateTo(Object replica)
                            throws IllegalArgumentException,
                                   ReplicationException
Replicates this instance state to given replica object. The replica should be an instance of replicated instance's class (same class or subclass).

Replicates element type and ID.

Specified by:
replicateTo in interface IReplicable
Parameters:
replica - the object to replicate to
Returns:
the replica object (the same instance as given)
Throws:
IllegalArgumentException - if given object is null or of invalid type
ReplicationException - if replication fails
See Also:
IReplicable.replicateTo(java.lang.Object)

replicate

public AbstractElement replicate()
                          throws ReplicationException
Returns a replicated instance of this instance.

Specified by:
replicate in interface IReplicable
Returns:
replicated instance
Throws:
ReplicationException - if replication fails
See Also:
IReplicable.replicate()


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.