/** * Test whether there is a translation relationship between a scenario and a responsibility * * @param scenario The source scenario * @param resp The target responsibility */ public boolean existTranslation(ArchEScenarioVO scenario, ArchEResponsibilityVO resp) { ArchETranslationRelationVO rel = null; for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) { rel = it.next(); // TODO: Check if an equal 'by name' is needed below ArchEScenarioVO parent = rel.getParent(); ArchEResponsibilityVO child = rel.getChild(); if ((parent != null) && (child != null) && parent.equals(scenario) && child.equals(resp)) return (true); } return (false); }
/** * Return those responsibilities that are linked to a particular scenario (via translation * relations) * * @param scenario The parent scenario */ public List<ArchEResponsibility> getResponsibilitiesByScenario(ArchEScenario scenario) { List<ArchEResponsibility> responsibilitiesOfInterest = new ArrayList<ArchEResponsibility>(); ArchETranslationRelationVO item = null; for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) { item = it.next(); // TODO: Check if an equal 'by name' works better here ArchEScenarioVO parent = item.getParent(); ArchEResponsibility child = item.getChild(); if ((parent != null) && parent.equals((ArchEScenarioVO) scenario) && child != null) responsibilitiesOfInterest.add(child); } return (responsibilitiesOfInterest); }
/** * Establish a refinement relation between two existing responsibilities * * @param parent The source responsibility * @param child The target responsibility */ public boolean refineResponsibility(ArchEResponsibilityVO parent, ArchEResponsibilityVO child) { ArchERelation rel = this.getRelation(parent, child, ArchERefinementRelationVO.class.getName()); if (rel == null) { // There's no previous refinement between the two responsibilities ArchERefinementRelationVO refinement = new ArchERefinementRelationVO(this.version); refinement.setParent(parent); refinement.setChild(child); refVOs.add(refinement); // The child in the refinement relation "inherits" the scenario // translations from its parent responsibility ArchETranslationRelationVO translation = null; ArchETranslationRelationVO newTranslation = null; ArchEScenarioVO baseScenario = null; List<ArchETranslationRelationVO> derivedTranslations = new ArrayList<ArchETranslationRelationVO>(); for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) { translation = it.next(); baseScenario = translation.getParent(); if (parent.equals(translation.getChild()) && !this.existTranslation(baseScenario, child)) { // A translation relation exists for the parent responsibility newTranslation = new ArchETranslationRelationVO(this.version); newTranslation.setParent(baseScenario); newTranslation.setChild(child); derivedTranslations.add(newTranslation); } } for (Iterator<ArchETranslationRelationVO> it = derivedTranslations.iterator(); it.hasNext(); ) trVOs.add(it.next()); return (true); } return (false); }