de.uka.ipd.consensus.impl
Class AssociationImpl

java.lang.Object
  extended byde.uka.ipd.consensus.impl.TM4JObjectWrapper
      extended byde.uka.ipd.consensus.impl.AssociationImpl
All Implemented Interfaces:
Association, Commentatable, Comparable, Concept, Createable, Rateable, Serializable, Versionable

public class AssociationImpl
extends TM4JObjectWrapper
implements Association

This is the TM4J-based implementation of the Association interface.

Version:
2006-06-14
Author:
Thomas Much
See Also:
Serialized Form

Field Summary
 
Fields inherited from class de.uka.ipd.consensus.impl.TM4JObjectWrapper
EMPTY_SCOPE
 
Constructor Summary
protected AssociationImpl(OntologyManagerImpl omi, org.tm4j.topicmap.Association tmAssociation)
           
 
Method Summary
 AssociationRole addAssociationRole(User adder, Topic type)
          Creates an association role of the given type if the role does not exist yet.
 Rating addRating(User rater, double value)
          Adds a rating for the given user to this element.
 void addTopic(User adder, Topic topic, Topic roleType)
          Adds a topic to this association as a player of the given role.
 int compareTo(Object other)
           
 AssociationRole getAssociationRole(Topic type)
          Returns the AssociationRole of a certain type.
 Collection getAssociationRoles(User getter)
          Returns a collection of all AssociationRole objects used by this association.
 double getAverageRatingValue()
          Returns the average value (the arithmetic mean) of all current ratings for this element.
 String getComment()
          Returns the comment of the element.
 User getCreator()
          Returns the user that created this element.
 String getId()
          Returns the concept's unique id that was either computed automatically or given explicitely at creation time.
 String getName()
          Returns the concept's name.
 Rating getRating(User user)
          Returns the rating of the given user for this element.
 Collection getRatings()
          Returns a collection of all current Rating objects (from different users) for this element.
 int getRatingsCount()
          Returns the number of ratings for this element.
 Collection getTopics(User getter, Topic roleType)
          Returns a collection of Topic player objects of the given role.
 Topic getType()
          Returns the type of the association.
 Version getVersion()
          Returns the version of the versionable element.
protected  org.tm4j.topicmap.Association getWrappedAssociation()
           
 boolean hasTopic(Topic topic, Topic roleType)
          Queries if the topic is player of the given role in this association.
 boolean hasTopic(User user, Topic topic)
          Queries if the topic is player of any role (that the user is allowed to see) in this association.
protected  Version incVersion()
           
 boolean isOfType(Topic type)
          Checks if this concept is of the given type.
 void removeAssociationRole(User remover, Topic type)
          Removes the association role of the given type.
 void removeTopic(User remover, Topic topic, Topic roleType)
          Removes a topic from the given role if it is player of the role.
 void setComment(User setter, String comment)
          Changes the element's comment.
 void setName(User setter, String name)
          Changes the concept's name.
 void setType(User setter, Topic type)
          Sets the type of the association.
 String toString()
           
 
Methods inherited from class de.uka.ipd.consensus.impl.TM4JObjectWrapper
equals, getCache, getLoggingManager, getObjectId, getOccurrence, getOntologyManager, getWrappedObject, hashCode, putCache, wrap, wrap, wrap, wrap, wrap, wrap, wrap
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AssociationImpl

protected AssociationImpl(OntologyManagerImpl omi,
                          org.tm4j.topicmap.Association tmAssociation)
Method Detail

getWrappedAssociation

protected org.tm4j.topicmap.Association getWrappedAssociation()

getId

public String getId()
Description copied from interface: Concept
Returns the concept's unique id that was either computed automatically or given explicitely at creation time.

Specified by:
getId in interface Concept
Returns:
the id (never empty, never null)
See Also:
OntologyManager.createTopic(User, String, String, Topic), OntologyManager.createAssociation(User, String, String, Topic), OntologyManager.createAttribute(User, String, String, String, Topic)

getType

public Topic getType()
Description copied from interface: Association
Returns the type of the association.

Specified by:
getType in interface Association
Returns:
the associations's type or null if the association does not have a type

setType

public void setType(User setter,
                    Topic type)
             throws OntologyManagerException,
                    DynamicRightsManagerException
Description copied from interface: Association
Sets the type of the association. If the implementation supports classes, the type must be a class topic.

Specified by:
setType in interface Association
Parameters:
setter - the user who wants to set the type
type - the type topic (or null to remove the type)
Throws:
OntologyManagerException - if the type could not be set
DynamicRightsManagerException - if the user is not allowed to change the type
See Also:
Topic.isClassTopic(), DynamicRightsManager.mayChangeAssociation(User, Association)

isOfType

public boolean isOfType(Topic type)
Description copied from interface: Concept
Checks if this concept is of the given type.

Specified by:
isOfType in interface Concept
Parameters:
type - the type topic, including null for typeless concepts
Returns:
true if the concept is of the specified type, false otherwise

getAssociationRoles

public Collection getAssociationRoles(User getter)
Description copied from interface: Association
Returns a collection of all AssociationRole objects used by this association. This includes the typeless role if this association contains a typeless player topic.

Specified by:
getAssociationRoles in interface Association
Parameters:
getter - the user who wants to see the roles
Returns:
a possibly empty collection, never null
See Also:
AssociationRole, DynamicRightsManager.mayViewTopic(User, Topic)

getAssociationRole

public AssociationRole getAssociationRole(Topic type)
Description copied from interface: Association
Returns the AssociationRole of a certain type.

Specified by:
getAssociationRole in interface Association
Parameters:
type - the type topic of the desired role, null for the typeless role
Returns:
the role object of the given type or null if this association does not contain a player topic of the type

addAssociationRole

public AssociationRole addAssociationRole(User adder,
                                          Topic type)
                                   throws OntologyManagerException,
                                          DynamicRightsManagerException
Description copied from interface: Association
Creates an association role of the given type if the role does not exist yet. The newly created or the already existing role is returned.

Specified by:
addAssociationRole in interface Association
Parameters:
adder - the user who wants to add the role
type - the type topic of the role to be created, including null for the typeless role
Returns:
the role of the given type, never null
Throws:
DynamicRightsManagerException - if the user is not allowed to add the role
OntologyManagerException - if the role could not be created
See Also:
DynamicRightsManager.mayChangeAssociation(User, Association)

removeAssociationRole

public void removeAssociationRole(User remover,
                                  Topic type)
                           throws OntologyManagerException,
                                  DynamicRightsManagerException
Description copied from interface: Association
Removes the association role of the given type. Its player topics are no longer part of this association afterwards (unless they are player of another role in this association).

Specified by:
removeAssociationRole in interface Association
Parameters:
remover - the user who wants to remove the role
type - the type of the role to be removed, including null for the typeless role
Throws:
DynamicRightsManagerException - if the user is not allowed to remove the role
OntologyManagerException - if the role could not be removed
See Also:
DynamicRightsManager.mayChangeAssociation(User, Association)

removeTopic

public void removeTopic(User remover,
                        Topic topic,
                        Topic roleType)
                 throws OntologyManagerException,
                        DynamicRightsManagerException
Description copied from interface: Association
Removes a topic from the given role if it is player of the role. If the topic is no player of the role of the role does not exist, the call is ignored. This is just a convenience method and simply delegates to AssociationRole.removeTopic()!

Specified by:
removeTopic in interface Association
Parameters:
remover - the user who wants to remove the topic
topic - the topic to be removed
roleType - the role that the topic to be removed plays, including null for the typeless role
Throws:
DynamicRightsManagerException - if the user is not allowed to remove the topic
OntologyManagerException - if the topic could not be removed
See Also:
AssociationRole.removeTopic(User, Topic), DynamicRightsManager.mayChangeAssociation(User, Association)

addTopic

public void addTopic(User adder,
                     Topic topic,
                     Topic roleType)
              throws OntologyManagerException,
                     DynamicRightsManagerException
Description copied from interface: Association
Adds a topic to this association as a player of the given role. The AssociationRole is created if it does not exist yet. This is just a convenience method and simply delegates to AssociationRole.addTopic()!

Specified by:
addTopic in interface Association
Parameters:
adder - the user who wants to add the topic
topic - the topic to be added to this association
roleType - the player role of the topic, including null for the typeless role
Throws:
OntologyManagerException - if the topic could not be added
DynamicRightsManagerException - if the user is not allowed to add the topic
See Also:
AssociationRole.addTopic(User, Topic), DynamicRightsManager.mayChangeAssociation(User, Association)

hasTopic

public boolean hasTopic(Topic topic,
                        Topic roleType)
Description copied from interface: Association
Queries if the topic is player of the given role in this association. This is just a convenience method and simply delegates to AssociationRole.hasTopic()!

Specified by:
hasTopic in interface Association
Parameters:
topic - the queried topic
roleType - the role that this topic must play, including null for the typeless role
Returns:
true if the topic is player of the given role in this association, false otherwise
See Also:
AssociationRole.hasTopic(Topic)

hasTopic

public boolean hasTopic(User user,
                        Topic topic)
Description copied from interface: Association
Queries if the topic is player of any role (that the user is allowed to see) in this association.

Specified by:
hasTopic in interface Association
Parameters:
user - the user who does the query
topic - the queried topic
Returns:
true if the topic is player of any role in this association, false otherwise
See Also:
DynamicRightsManager.mayViewTopic(User, Topic), AssociationRole.hasTopic(Topic)

getTopics

public Collection getTopics(User getter,
                            Topic roleType)
Description copied from interface: Association
Returns a collection of Topic player objects of the given role. This is just a convenience method and simply delegates to AssociationRole.getTopics()!

Specified by:
getTopics in interface Association
Parameters:
getter - the user who wants to see the topics
roleType - the role type, ncluding null for the typeless role
Returns:
a possibly empty collection, never null
See Also:
DynamicRightsManager.mayViewTopic(User, Topic), AssociationRole.getTopics(User)

getName

public String getName()
Description copied from interface: Concept
Returns the concept's name.

Specified by:
getName in interface Concept
Returns:
the name of the concept (may be the empty string, but never null)

setName

public void setName(User setter,
                    String name)
             throws OntologyManagerException,
                    DynamicRightsManagerException
Description copied from interface: Concept
Changes the concept's name.

Specified by:
setName in interface Concept
Parameters:
setter - the user who wants to change the name
name - the new name
Throws:
DynamicRightsManagerException - if the user is not allowed to change the name
OntologyManagerException - if the name could not be changed

incVersion

protected Version incVersion()

getVersion

public Version getVersion()
Description copied from interface: Versionable
Returns the version of the versionable element.

Specified by:
getVersion in interface Versionable
Returns:
the Version object or null if no version information is available

getComment

public String getComment()
Description copied from interface: Commentatable
Returns the comment of the element.

Specified by:
getComment in interface Commentatable
Returns:
the comment (may be the empty string, but never null)

setComment

public void setComment(User setter,
                       String comment)
                throws OntologyManagerException,
                       DynamicRightsManagerException
Description copied from interface: Commentatable
Changes the element's comment.

Specified by:
setComment in interface Commentatable
Parameters:
setter - the user who wants to change the comment
comment - the new comment (null is treated as an empty string)
Throws:
DynamicRightsManagerException - if the user is not allowed to change the comment
OntologyManagerException - if the comment could not be changed
See Also:
DynamicRightsManager.mayChangeConceptComment(User, Concept), DynamicRightsManager.mayChangeUserComment(User, User)

getRatings

public Collection getRatings()
Description copied from interface: Rateable
Returns a collection of all current Rating objects (from different users) for this element. This method exists just for convenience and delegates to one of the getRatings() methods of RatingManager.

Specified by:
getRatings in interface Rateable
Returns:
a possibly empty collection, never null
See Also:
Rating, RatingManager

getAverageRatingValue

public double getAverageRatingValue()
Description copied from interface: Rateable
Returns the average value (the arithmetic mean) of all current ratings for this element.

Specified by:
getAverageRatingValue in interface Rateable
Returns:
the arithmetic mean of all ratings for this element

getRatingsCount

public int getRatingsCount()
Description copied from interface: Rateable
Returns the number of ratings for this element. Each user can have only one current rating for each element, i.e. historical ratings do not count.

Specified by:
getRatingsCount in interface Rateable
Returns:
the number of ratings for this element.

getRating

public Rating getRating(User user)
Description copied from interface: Rateable
Returns the rating of the given user for this element. This method exists just for convenience and delegates to one of the getRatings() methods of RatingManager.

Specified by:
getRating in interface Rateable
Parameters:
user - the user who's rating shall be returned
Returns:
the rating of the user or null if the user hasn't rated this element yet
See Also:
RatingManager

addRating

public Rating addRating(User rater,
                        double value)
                 throws RatingManagerException,
                        DynamicRightsManagerException
Description copied from interface: Rateable
Adds a rating for the given user to this element. If the user has rated the element already, only the rating's value is changed. Otherwise, this method creates and adds a new rating using suitable RatingManager methods.

Specified by:
addRating in interface Rateable
Parameters:
rater - the user who wants to add or change the rating
value - the new value
Returns:
the newly created or the existing but changed rating
Throws:
DynamicRightsManagerException - if the user is not allowed to rate this element
RatingManagerException - if the rating could not be created/changed
See Also:
RatingManager, DynamicRightsManager.mayAddRating(Rating, Rateable)

getCreator

public User getCreator()
Description copied from interface: Createable
Returns the user that created this element.

Specified by:
getCreator in interface Createable
Returns:
the User object

compareTo

public int compareTo(Object other)
Specified by:
compareTo in interface Comparable

toString

public String toString()