/** * 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; }