Ejemplo n.º 1
0
  @Override
  public AttributedFeatureModel parseFile(String fileName) throws Exception {
    Injector injector = new VMStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
    resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    if (models != null) {
      for (String s : models) {
        resourceSet.getResource(URI.createURI(s), true);
      }
    }

    Resource resource = resourceSet.getResource(URI.createURI(fileName), true);

    Model model = (Model) resource.getContents().get(0);

    fm = new AttributedFeatureModel();

    VmBlock relationships = null;
    VmBlock attsblock = null;
    VmBlock constratins = null;

    EList<VmBlock> bl = model.getBlocks();
    for (VmBlock block : bl) {
      if (block instanceof Relationships) {
        relationships = block;
      } else if (block instanceof Attributes) {
        attsblock = block;
      } else if (block instanceof Constraints) {
        constratins = block;
      } else if (block instanceof PackageDeclaration) {
        for (VmBlock blockinpkg : ((PackageDeclaration) block).getBlocks()) {
          if (blockinpkg instanceof Relationships) {
            relationships = blockinpkg;
          } else if (blockinpkg instanceof Attributes) {
            attsblock = blockinpkg;

          } else if (blockinpkg instanceof Constraints) {
            constratins = blockinpkg;
          }
        }
      }
    }
    if (((Relationships) relationships) != null) {
      FeatureHierarchy fhs = ((Relationships) relationships).getRoot();
      fr.familiar.attributedfm.Feature ffeat =
          new fr.familiar.attributedfm.Feature(fhs.getParent().getName());
      visitFeatureHierarchy(ffeat, fhs);
      fm.setRoot(ffeat);
    }
    if ((Attributes) attsblock != null) {
      visitAttributes(((Attributes) attsblock).getAttrDefs(), fm);
    }
    if ((Constraints) constratins != null) {
      visitConstraints(((Constraints) constratins).getConstraints(), fm);
    }
    return fm;
  }
Ejemplo n.º 2
0
  private void visitFeatureHierarchy(
      fr.familiar.attributedfm.Feature ffeatroot, FeatureHierarchy fh) {
    EList<FeatureDefinition> fhchildren = fh.getChildren();
    for (FeatureDefinition fd : fhchildren) {

      fr.familiar.attributedfm.Relation frel = new fr.familiar.attributedfm.Relation();

      if (fd instanceof Feature) {
        fr.inria.lang.vM.Feature f = (fr.inria.lang.vM.Feature) fd;
        if (f.isOptional()) {
          frel.addCardinality(new Cardinality(0, 1));
        } else if (!f.isOptional()) { // isMandatory
          frel.addCardinality(new Cardinality(1, 1));
        }
        frel.addDestination(new fr.familiar.attributedfm.Feature(f.getName()));
        ffeatroot.addRelation(frel);

      } else if (fd instanceof FeaturesGroup) {
        frel.addCardinality(new Cardinality(1, 1));

        FeaturesGroup group = (FeaturesGroup) fd;
        EList<FeatureDefinition> groupedFeatures = group.getGroupedFeatures();
        int maxCard = 0;
        for (FeatureDefinition fdef : groupedFeatures) {
          maxCard++;

          if (fdef instanceof Feature) {
            Feature vmfeature = (Feature) fdef;
            fr.familiar.attributedfm.Feature feat =
                new fr.familiar.attributedfm.Feature(vmfeature.getName());
            // Adding translation info
            feat.nonTranstalable = vmfeature.isNotTranslatable();
            feat.runTime = vmfeature.isRunTime();
            feat.nonDecision = vmfeature.isNotDecidable();
            // addding range (if not specified =1,1)
            if (vmfeature.getMin() != null && vmfeature.getMax() != null) {
              IntegerRange r = new IntegerRange();
              r.add(vmfeature.getMin());
              r.add(vmfeature.getMax());

              feat.clone.add(r);
            } else {
              IntegerRange r = new IntegerRange();
              r.getItems().add(1);
              feat.clone.add(r);
            }
            frel.addDestination(feat);
          } else if (fdef instanceof FeatureHierarchy) {
            Feature vmfeature = ((FeatureHierarchy) fdef).getParent();
            fr.familiar.attributedfm.Feature feat =
                new fr.familiar.attributedfm.Feature(vmfeature.getName());
            // adding translation info
            feat.nonTranstalable = vmfeature.isNotTranslatable();
            feat.runTime = vmfeature.isRunTime();
            if (vmfeature.getMin() != null && vmfeature.getMax() != null) {
              IntegerRange r = new IntegerRange();
              r.add(vmfeature.getMin());
              r.add(vmfeature.getMax());

              feat.clone.add(r);
            } else {
              IntegerRange r = new IntegerRange();
              r.getItems().add(1);
              feat.clone.add(r);
            }
            frel.addDestination(feat);
            visitFeatureHierarchy(feat, (FeatureHierarchy) fdef);
          }
        }
        if (fd instanceof Xorgroup) {
          frel.addCardinality(new Cardinality(1, 1));
        } else if (fd instanceof Orgroup) {
          frel.addCardinality(new Cardinality(1, maxCard));
        }
        ffeatroot.addRelation(frel);

      } else if (fd instanceof FeatureHierarchy) {
        String dest = ((FeatureHierarchy) fd).getParent().getName();
        fr.familiar.attributedfm.Feature fdest = new fr.familiar.attributedfm.Feature(dest);

        frel.addDestination(fdest);
        ffeatroot.addRelation(frel);

        if (((FeatureHierarchy) fd).getParent().isOptional()) {
          frel.addCardinality(new Cardinality(0, 1));

        } else if (!((FeatureHierarchy) fd).getParent().isOptional()) {
          frel.addCardinality(new Cardinality(1, 1));
        }
        visitFeatureHierarchy(fdest, (FeatureHierarchy) fd);
      }
    }
  }