예제 #1
0
 /**
  * Returns the destination of a relation. The destination of a relation is defined as the
  * modelelement that receives this relation. If there are more then 1 destinations, only the first
  * is returned. If there is no destination, null is returned. Examples of sources include
  * classifiers that are types to associationends, usecases that are bases to extend and include
  * relations and so on. In the case of an association, the destination is defined as the type of
  * the second element in the connections list.
  *
  * @param relation
  * @return MModelElement
  */
 public MModelElement getDestination(MRelationship relation) {
   if (relation instanceof MAssociation) {
     MAssociation assoc = (MAssociation) relation;
     List conns = assoc.getConnections();
     if (conns.size() <= 1) return null;
     return ((MAssociationEnd) conns.get(1)).getType();
   }
   if (relation instanceof MGeneralization) {
     MGeneralization gen = (MGeneralization) relation;
     return gen.getChild();
   }
   if (relation instanceof MDependency) {
     MDependency dep = (MDependency) relation;
     Collection col = dep.getClients();
     if (col.isEmpty()) return null;
     return (MModelElement) (col.toArray())[0];
   }
   if (relation instanceof MFlow) {
     MFlow flow = (MFlow) relation;
     Collection col = flow.getTargets();
     if (col.isEmpty()) return null;
     return (MModelElement) (col.toArray())[0];
   }
   if (relation instanceof MExtend) {
     MExtend extend = (MExtend) relation;
     return extend.getBase();
   }
   if (relation instanceof MInclude) {
     MInclude include = (MInclude) relation;
     return include.getAddition();
   }
   return null;
 }
예제 #2
0
 /**
  * Returns the source of a relation. The source of a relation is defined as the modelelement that
  * propagates this relation. If there are more then 1 sources, only the first is returned. If
  * there is no source, null is returned. Examples of sources include classifiers that are types to
  * associationends, usecases that are bases to extend and include relations and so on.
  *
  * @param relation
  * @return MModelElement
  */
 public MModelElement getSource(MRelationship relation) {
   if (relation instanceof MAssociation) {
     MAssociation assoc = (MAssociation) relation;
     List conns = assoc.getConnections();
     if (conns.isEmpty()) return null;
     return ((MAssociationEnd) conns.get(0)).getType();
   }
   if (relation instanceof MGeneralization) {
     MGeneralization gen = (MGeneralization) relation;
     return gen.getParent();
   }
   if (relation instanceof MDependency) {
     MDependency dep = (MDependency) relation;
     Collection col = dep.getSuppliers();
     if (col.isEmpty()) return null;
     return (MModelElement) (col.toArray())[0];
   }
   if (relation instanceof MFlow) {
     MFlow flow = (MFlow) relation;
     Collection col = flow.getSources();
     if (col.isEmpty()) return null;
     return (MModelElement) (col.toArray())[0];
   }
   if (relation instanceof MExtend) {
     MExtend extend = (MExtend) relation;
     return extend.getExtension(); // we have to follow the arrows..
   }
   if (relation instanceof MInclude) {
     MInclude include = (MInclude) relation;
     return include.getBase();
   }
   return null;
 }