i3.dragos.gm.core.proxy
Class RelationProxy

java.lang.Object
  extended by i3.dragos.gm.core.proxy.GraphEntityProxy
      extended by i3.dragos.gm.core.proxy.RelationProxy
All Implemented Interfaces:
GraphEntity, Relation, ExistenceCheckable, MetaAttributable

public class RelationProxy
extends GraphEntityProxy
implements Relation

A RelationProxy delegates all method calls to the underlying relation except for those that access fields which are used after a relation has been deleted.

Author:
Boris Boehlen <boehlen@cs.rwth-aachen.de>

Field Summary
 
Fields inherited from class i3.dragos.gm.core.proxy.GraphEntityProxy
proxiedEntity
 
Constructor Summary
RelationProxy(Relation r)
          Constructs a new wrapper for a relation.
 
Method Summary
 RelationEnd createRelationEnd(GraphEntity target, RelationEndClass type)
          Creates a relation end.
 java.util.Collection<? extends RelationEnd> getAllRelationEndsOfRelation()
          Returns a collection of all relation ends of this relation.
 java.util.Collection<? extends GraphEntity> getRelatedGraphEntitiesOfRelationEndsOfRelation(RelationEndClass type, boolean includeSubClasses, boolean set)
          Returns a collection of entities referenced by this relation through relation ends.
 RelationClass getRelationClass()
          Returns the relation's type.
 java.util.Collection<? extends RelationEnd> getRelationEndsOfRelation(RelationEndClass type, boolean includeSubClasses)
          Returns a collection of all relation ends of the specified type belonging to this relation.
 boolean isDirected()
          Returns true if the relation is directed and false otherwise.
 void removeAllRelationEndsOfRelation()
          Removes all relation ends belonging to this relation from it.
 void removeRelationEnd(RelationEnd relationEndId)
          Removes a relation end belonging to this relation from it.
 
Methods inherited from class i3.dragos.gm.core.proxy.GraphEntityProxy
checkExistence, checkExistenceOptional, equals, getAdjacentGraphEntities, getAdjacentRelations, getAdjacentRelations, getAllMetaAttributes, getAllValidAttributeValues, getAttributeValue, getDataSourceURL, getEdges, getEdges, getGraphEntityClass, getInternalIdentifier, getMetaAttribute, getParent, getProxyGraphEntity, getRelationEnds, getRelationEnds, getRelationEnds, getWrappedGraphEntity, hashCode, isAttributeValid, isIncident, isIncident, isMetaAttributeKeyReserved, isMetaAttributeSet, putAttributeValue, setAttributeInvalid, setMetaAttribute, toString, unsetMetaAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface i3.dragos.gm.core.GraphEntity
equals, getAdjacentGraphEntities, getAdjacentRelations, getAdjacentRelations, getAllValidAttributeValues, getAttributeValue, getDataSourceURL, getEdges, getEdges, getGraphEntityClass, getInternalIdentifier, getParent, getRelationEnds, getRelationEnds, getRelationEnds, getWrappedGraphEntity, hashCode, isAttributeValid, isIncident, isIncident, putAttributeValue, setAttributeInvalid
 
Methods inherited from interface i3.dragos.gm.core.schema.MetaAttributable
getAllMetaAttributes, getMetaAttribute, isMetaAttributeKeyReserved, isMetaAttributeSet, setMetaAttribute, unsetMetaAttribute
 
Methods inherited from interface i3.dragos.gm.core.schema.ExistenceCheckable
checkExistence, checkExistenceOptional
 

Constructor Detail

RelationProxy

public RelationProxy(Relation r)
Constructs a new wrapper for a relation.

Parameters:
r - The relation to wrap.
Method Detail

getRelationClass

public RelationClass getRelationClass()
                               throws DragosException
Returns the relation's type.

Specified by:
getRelationClass in interface Relation
Returns:
the relation's type.
Throws:
DragosException - if something went wrong.

isDirected

public boolean isDirected()
                   throws DragosException
Returns true if the relation is directed and false otherwise.

A relation is directed if it contains at least one directed relation end. If all contained relation ends are undirected the relation is undirected, too.

Specified by:
isDirected in interface Relation
Returns:
true if the relation is directed and false otherwise.
Throws:
DragosException - if something went wrong.

createRelationEnd

public RelationEnd createRelationEnd(GraphEntity target,
                                     RelationEndClass type)
                              throws DragosException
Creates a relation end.

The target (if not null)) has to be in the same graph pool as this relation, otherwise an exception is thrown.

Specified by:
createRelationEnd in interface Relation
Parameters:
target - The graph element the relation end is connected to (may be null).
type - The type of the new relation end (must not be null).
Returns:
the new relation end.
Throws:
EntityNotFoundException - if the target was not null and could not be found, or if the type for the relation end could not be found.
DragosException - if something else went wrong.

removeRelationEnd

public void removeRelationEnd(RelationEnd relationEndId)
                       throws EntityNotFoundException,
                              DragosException
Removes a relation end belonging to this relation from it.

It simply performs an additional check whether the RelationEnd to remove really belongs to this Relation, throwing an EntityNotFoundException if not. Afterwards, it follows the same procedure as Graph.removeGraphEntity(GraphEntity).

This method could/should be implemented roughly as follows:

 if (! this.equals(relationEnd.getRelation())) {
     throw new EntityNotFoundException("RelationEnd " + relationEnd + " does not belong to " + toString());
 }
 getParent().removeGraphEntity(relationEnd);
 

Specified by:
removeRelationEnd in interface Relation
Parameters:
relationEndId - the relation end which is removed.
Throws:
EntityNotFoundException - if the relation end couldn't be found or does not belong to this relation.
DragosException - if something went wrong.

removeAllRelationEndsOfRelation

public void removeAllRelationEndsOfRelation()
                                     throws DragosException
Removes all relation ends belonging to this relation from it. It follows the same rules as Graph.removeGraphEntity(GraphEntity), and could / should be implemented using that method.

Relation ends connected to the relation, but not belongig to it, are not affected.

Specified by:
removeAllRelationEndsOfRelation in interface Relation
Throws:
DragosException - if something went wrong .

getAllRelationEndsOfRelation

public java.util.Collection<? extends RelationEnd> getAllRelationEndsOfRelation()
                                                                         throws DragosException
Returns a collection of all relation ends of this relation. The contents of the returned collection will be of type RelationEnd.

Specified by:
getAllRelationEndsOfRelation in interface Relation
Returns:
A collection of all relation ends.
Throws:
DragosException - if anything went wrong.

getRelationEndsOfRelation

public java.util.Collection<? extends RelationEnd> getRelationEndsOfRelation(RelationEndClass type,
                                                                             boolean includeSubClasses)
                                                                      throws DragosException
Returns a collection of all relation ends of the specified type belonging to this relation.

If type == null, this method is equivalent to Relation.getAllRelationEndsOfRelation().

Specified by:
getRelationEndsOfRelation in interface Relation
Parameters:
type - The type of the relation ends to return (null means "any type").
includeSubClasses - Whether instances of subclasses of type should also be returned (has no effect if type == null).
Returns:
A collection of all relation ends.
Throws:
EntityNotFoundException - if type != null and type is not a dependent relation end class of relation's class.
DragosException - if anything went wrong.

getRelatedGraphEntitiesOfRelationEndsOfRelation

public java.util.Collection<? extends GraphEntity> getRelatedGraphEntitiesOfRelationEndsOfRelation(RelationEndClass type,
                                                                                                   boolean includeSubClasses,
                                                                                                   boolean set)
                                                                                            throws DragosException
Returns a collection of entities referenced by this relation through relation ends.

In contrast to Relation.getRelationEndsOfRelation(RelationEndClass, boolean), this method does not return the relation ends themselves, but rather the related elements of each of these relation ends.

If type == null, this method will follow all relation ends belonging to this relation.

Specified by:
getRelatedGraphEntitiesOfRelationEndsOfRelation in interface Relation
Parameters:
type - The type of the relation ends to follow (null means "any type").
includeSubClasses - Whether instances of subclasses of type should also be followed (has no effect if type == null).
set - If true, each entity is contained at most once in the returned collection, even if multiple relation ends lead to it.
Returns:
A collection of all relation ends.
Throws:
EntityNotFoundException - if type != null and type is not a dependent relation end class of relation's class.
DanglingReferenceException - if this method would have to traverse a dangling relation end.
DragosException - if anything went wrong.


Copyright © 2002-2008 RWTH Aachen, Department of Computer Science 3 (Software Engineering). All Rights Reserved.