pl.edu.agh.cast.data.model.general
Class Entity

java.lang.Object
  extended by pl.edu.agh.cast.data.model.property.PropertyContainer
      extended by pl.edu.agh.cast.data.model.AbstractElement
          extended by pl.edu.agh.cast.data.model.general.Entity
All Implemented Interfaces:
Serializable, Observer, IDisposable, IReplicable, IValidatable, IDomainElement, IEntity, IGeneralElement, Identifiable, IElement, IPropertyContainer

public class Entity
extends AbstractElement
implements IEntity

Default implementation of IEntity interface.

All public constructors set the element type to IEntity.TYPE. Protected constructors should only be used by direct subclasses to provide the concrete type to the super constructor.

Author:
AGH CAST Team
See Also:
IEntity, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface pl.edu.agh.cast.data.model.general.IEntity
IEntity.Properties
 
Field Summary
 
Fields inherited from interface pl.edu.agh.cast.data.model.general.IEntity
TYPE
 
Constructor Summary
  Entity()
          Default constructor.
  Entity(IGeneralDataSet<? extends IGeneralElement> dataSet, String name)
          Creates a new entity with given data set, name and newly-generated ID.
  Entity(String name)
          Creates a new entity with given name and newly-generated ID.
protected Entity(Type type)
          Initializes element with type.
protected Entity(Type type, UUID id, String name)
          Initializes element with type, ID and name.
protected Entity(Type type, UUID id, String name, List<IManyToManyRelation> incomingRelations, List<IManyToManyRelation> outgoingRelations)
          Initializes element with given type, ID, data set, name and incoming and outgoing relations.
  Entity(UUID id, IGeneralDataSet<? extends IGeneralElement> dataSet, String name)
          Creates a new entity with given ID, data set and name.
  Entity(UUID id, IGeneralDataSet<? extends IGeneralElement> dataSet, String name, List<IManyToManyRelation> incomingRelations, List<IManyToManyRelation> outgoingRelations)
          Creates a new entity with given ID, data set, name and incoming and outgoing relations.
  Entity(UUID id, String name)
          Creates a new entity with given ID and name.
  Entity(UUID id, String name, List<IManyToManyRelation> incomingRelations, List<IManyToManyRelation> outgoingRelations)
          Creates a new entity with given ID, data set, name and incoming and outgoing relations.
 
Method Summary
 void addIncomingRelation(IManyToManyRelation relation)
          Adds a new incoming relation to the entity, if not present.
 void addOutgoingRelation(IManyToManyRelation relation)
          Adds a new outgoing relation to the entity, if not present.
protected  String getDescString()
          Returns a string with short description of element.
 List<? extends IManyToManyRelation> getIncomingRelations()
          Returns the list of incoming relations associated with the entity.
 String getName()
          Returns the entity name.
 List<? extends IManyToManyRelation> getOutgoingRelations()
          Returns the list of outgoing relations associated with the entity.
 boolean removeIncomingRelation(IManyToManyRelation relation)
          Removes the specified incoming relation from the entity.
 boolean removeOutgoingRelation(IManyToManyRelation relation)
          Removes the specified outgoing relation from the entity.
 Entity replicate()
          Returns a replicated instance of this instance.
 Entity replicateTo(Object replica)
          Replicates this instance state to given replica object.
 void setIncomingRelations(List<? extends IManyToManyRelation> relations)
          Sets the list of incoming relations associated with the entity.
 void setName(String name)
          Sets the entity name.
 void setOutgoingRelations(List<? extends IManyToManyRelation> relations)
          Sets the list of outgoing relations associated with the entity.
 
Methods inherited from class pl.edu.agh.cast.data.model.AbstractElement
afterSetMetaPropertyManager, canReplicateTo, checkIfValid, equals, getDataSet, getId, getType, hashCode, isValid, setDataSet, setId, setType, 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.IElement
getDataSet
 
Methods inherited from interface pl.edu.agh.cast.data.model.Identifiable
getId, getType
 
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.IValidatable
isValid
 
Methods inherited from interface pl.edu.agh.cast.common.IDisposable
dispose
 

Constructor Detail

Entity

public Entity()
Default constructor.

Usage of this constructor is discouraged, since it does not provide any integrity control. If, however, this constructor is used, the AbstractElement.isValid() method should be called in order to check the integrity.


Entity

public Entity(String name)
Creates a new entity with given name and newly-generated ID.

Parameters:
name - the name of the entity
Throws:
IllegalArgumentException

Entity

public Entity(IGeneralDataSet<? extends IGeneralElement> dataSet,
              String name)
Creates a new entity with given data set, name and newly-generated ID.

Parameters:
dataSet - the data set this element is in
name - the name of the entity
Throws:
IllegalArgumentException

Entity

public Entity(UUID id,
              String name)
Creates a new entity with given ID and name.

Parameters:
id - ID of the element
name - the name of the entity
Throws:
IllegalArgumentException

Entity

public Entity(UUID id,
              IGeneralDataSet<? extends IGeneralElement> dataSet,
              String name)
Creates a new entity with given ID, data set and name.

Parameters:
id - ID of the element
dataSet - the data set this element is in
name - the name of the entity
Throws:
IllegalArgumentException

Entity

public Entity(UUID id,
              String name,
              List<IManyToManyRelation> incomingRelations,
              List<IManyToManyRelation> outgoingRelations)
Creates a new entity with given ID, data set, name and incoming and outgoing relations.

Parameters:
id - ID of the element
name - the name of the entity
incomingRelations - the list of references to incoming relations for this entity - if null, then empty IReferenceList instance is acquired from ReferenceUtil
outgoingRelations - the list of references to outgoing relations for this entity - if null, then empty IReferenceList instance is acquired from ReferenceUtil
Throws:
IllegalArgumentException

Entity

public Entity(UUID id,
              IGeneralDataSet<? extends IGeneralElement> dataSet,
              String name,
              List<IManyToManyRelation> incomingRelations,
              List<IManyToManyRelation> outgoingRelations)
Creates a new entity with given ID, data set, name and incoming and outgoing relations.

Parameters:
id - ID of the element
dataSet - the data set this element is in
name - the name of the entity
incomingRelations - the list of references to incoming relations for this entity - if null, then empty IReferenceList instance is acquired from ReferenceUtil
outgoingRelations - the list of references to outgoing relations for this entity - if null, then empty IReferenceList instance is acquired from ReferenceUtil
Throws:
IllegalArgumentException

Entity

protected Entity(Type type)
Initializes element with type.

This constructor should be used only by extending classes to implement the default constructor.

Parameters:
type - type of the element
See Also:
AbstractElement.AbstractElement(Type)

Entity

protected Entity(Type type,
                 UUID id,
                 String name)
Initializes element with type, ID and name.

Parameters:
type - type of element which extends this one
id - ID of the element
name - the name of the entity
Throws:
IllegalArgumentException

Entity

protected Entity(Type type,
                 UUID id,
                 String name,
                 List<IManyToManyRelation> incomingRelations,
                 List<IManyToManyRelation> outgoingRelations)
Initializes element with given type, ID, data set, name and incoming and outgoing relations.

Parameters:
type - type of element which extends this one
id - ID of the element
dataSet - the data set this element is in
name - the name of the entity
incomingRelations - the list of references to incoming relations for this entity - if null, then empty IReferenceList instance is acquired from ReferenceUtil
outgoingRelations - the list of references to outgoing relations for this entity - if null, then empty IReferenceList instance is acquired from ReferenceUtil
Throws:
IllegalArgumentException
Method Detail

getIncomingRelations

public final List<? extends IManyToManyRelation> getIncomingRelations()
Returns the list of incoming relations associated with the entity.

Specified by:
getIncomingRelations in interface IEntity
Returns:
unmodifiable list of incoming relations; if no incoming relation is associated with an entity an empty but non-null object is returned
See Also:
IEntity.getIncomingRelations()

setIncomingRelations

public final void setIncomingRelations(List<? extends IManyToManyRelation> relations)
Sets the list of incoming relations associated with the entity.

Specified by:
setIncomingRelations in interface IEntity
Parameters:
relations - list of incoming relations to set
See Also:
pl.edu.agh.cast.data.model.general.IEntity#setIncomingRelations(java.lang.Iterable)

addIncomingRelation

public final void addIncomingRelation(IManyToManyRelation relation)
Adds a new incoming relation to the entity, if not present. This method should be called during construction of the new relation.

Specified by:
addIncomingRelation in interface IEntity
Parameters:
relation - incoming relation to be added
See Also:
#addIncomingRelation(pl.edu.agh.cast.data.model.general.IManyToManyRelation)

removeIncomingRelation

public final boolean removeIncomingRelation(IManyToManyRelation relation)
Removes the specified incoming relation from the entity.

Specified by:
removeIncomingRelation in interface IEntity
Parameters:
relation - incoming relation to be removed, if present
Returns:
true if the relation was present and successfully removed
See Also:
#removeIncomingRelation(pl.edu.agh.cast.data.model.general.IManyToManyRelation)

getOutgoingRelations

public final List<? extends IManyToManyRelation> getOutgoingRelations()
Returns the list of outgoing relations associated with the entity.

Specified by:
getOutgoingRelations in interface IEntity
Returns:
unmodifiable list of outgoing relations; if no outgoing relation is associated with an entity an empty but non-null object is returned
See Also:
IEntity.getOutgoingRelations()

setOutgoingRelations

public final void setOutgoingRelations(List<? extends IManyToManyRelation> relations)
Sets the list of outgoing relations associated with the entity.

Specified by:
setOutgoingRelations in interface IEntity
Parameters:
relations - list of outgoing relations to set
See Also:
pl.edu.agh.cast.data.model.general.IEntity#setOutgoingRelations(java.lang.Iterable)

addOutgoingRelation

public final void addOutgoingRelation(IManyToManyRelation relation)
Adds a new outgoing relation to the entity, if not present. This method should be called during construction of the new relation.

Specified by:
addOutgoingRelation in interface IEntity
Parameters:
relation - outgoing relation to be added
See Also:
#addOutgoingRelation(pl.edu.agh.cast.data.model.general.IManyToManyRelation)

removeOutgoingRelation

public final boolean removeOutgoingRelation(IManyToManyRelation relation)
Removes the specified outgoing relation from the entity.

Specified by:
removeOutgoingRelation in interface IEntity
Parameters:
relation - outgoing relation to be removed, if present
Returns:
true if the relation was present and successfully removed
See Also:
#removeOutgoingRelation(pl.edu.agh.cast.data.model.general.IManyToManyRelation)

getName

public final String getName()
Returns the entity name. Name does not have to be unique and can be displayed to user.

Specified by:
getName in interface IEntity
Returns:
entity name
See Also:
IEntity.getName()

setName

public final void setName(String name)
Sets the entity name.

Specified by:
setName in interface IEntity
Parameters:
name - entity name
See Also:
IEntity.setName(java.lang.String)

getDescString

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

Overrides:
getDescString in class AbstractElement
Returns:
a description string
See Also:
AbstractElement.getDescString()

replicateTo

public Entity 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.

Replicates entity name, the lists of outgoing and incoming relations are empty.

Specified by:
replicateTo in interface IReplicable
Overrides:
replicateTo in class AbstractElement
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:
AbstractElement.replicateTo(java.lang.Object)

replicate

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

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


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