/** Save all the VOs related to this core responsibility structure */
  public void save() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Save or update the raw responsibility structure
        //				openSession.saveOrUpdate(rawRSVO);

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); ) {
          ArchEResponsibilityVO resp = itResps.next();
          String name = resp.getName();
          openSession.saveOrUpdate(resp);
          this.saveParametersForResponsibility(resp, openSession);
        }

        // Save or update the translation relations
        for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); )
          openSession.saveOrUpdate(it.next());

        // Save or update the refinement relations
        for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); )
          openSession.saveOrUpdate(it.next());

        // It deletes the list of 'removed' VOs
        for (Iterator it = removedRelationVOs.iterator(); it.hasNext(); )
          openSession.delete(it.next());

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
 /**
  * Test whether there is a refinement relationship between a pair of responsibilities
  *
  * @param resp The source responsibility
  * @param leaf The target responsibility
  */
 public boolean existRefinement(ArchEResponsibilityVO resp, ArchEResponsibilityVO leaf) {
   ArchERefinementRelationVO rel = null;
   for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); ) {
     rel = it.next(); // TODO: Check if an equal 'by name' is needed below
     ArchEResponsibilityVO parent = rel.getParent();
     ArchEResponsibilityVO child = rel.getChild();
     if ((parent != null) && (child != null) && parent.equals(resp) && child.equals(leaf))
       return (true);
   }
   return (false);
 }
 /**
  * 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);
 }
  /**
   * Save AS all the VOs related to this core responsibility structure
   *
   * @param newVersion The version for the new VOs
   * @throws ArchEException
   */
  public void saveAs(ArchEVersionVO newVersion) throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {

        // Save the newly-created raw responsibility structure
        rawRSVO.setId(newVersion.getId());

        ArchEResponsibilityVO itemResp = null;
        for (Iterator<ArchEResponsibilityVO> it = rawRSVO.getResponsibilities().iterator();
            it.hasNext(); ) {
          itemResp = it.next();
          itemResp.setVersion(newVersion);
          openSession.save(itemResp);
          this.saveParametersForResponsibilityAs(newVersion, itemResp, openSession);
        }

        // Create a copy of the existing translation relations
        ArchETranslationRelationVO itemTr = null;
        for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) {
          itemTr = it.next();
          itemTr.setVersion(newVersion);
          openSession.save(itemTr);
        }

        // Create a copy of the existing refinement relations
        ArchERefinementRelationVO itemRef = null;
        for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); ) {
          itemRef = it.next();
          itemRef.setVersion(newVersion);
          openSession.save(itemRef);
        }

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
  /**
   * 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);
  }