예제 #1
0
파일: VMReader.java 프로젝트: FMTools/AFM
  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);
      }
    }
  }
예제 #2
0
파일: VMReader.java 프로젝트: FMTools/AFM
  private void visitAttributes(EList<AttrDef> att, AttributedFeatureModel fm) {

    for (AttrDef atdef : att) {
      GenericAttribute attribute = new GenericAttribute("");

      attribute.nonTranstalable = atdef.isNotTranslatable();
      attribute.runTime = atdef.isRunTime();
      attribute.nonDesicion = atdef.isNotDecidable();

      BasicAttrDef at = atdef.getBasicAttrDef();
      if (at instanceof BooleanAttrDef) {

        String name = ((BooleanAttrDef) at).getName().getName();

        Boolean val = Boolean.parseBoolean(((BooleanAttrDef) at).getValue());
        if (((BooleanAttrDef) at).getDefault() != null) {
          Boolean defaultvalue =
              Boolean.parseBoolean(((BooleanAttrDef) at).getDefault().getValue());
          attribute.setDefaultValue(defaultvalue);
        }

        if (val != null) {
          // tiene 2 valores
          attribute.setDomain(new Domain(new BooleanRange()));
        }
        // }else{
        // Collection<Integer> values= new LinkedList<Integer>();
        // if(val==true){values.add(1);}else{values.add(0);}
        // Domain domain = new Domain(new IntegerRange(values));
        //
        // }
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((BooleanAttrDef) at).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (at instanceof StringAttrDef) {
        String name = ((StringAttrDef) at).getName().getName();
        String val = ((StringAttrDef) at).getValue();
        if (((StringAttrDef) at).getDefault() != null) {
          String defaultvalue = ((StringAttrDef) at).getDefault().getValue();
          attribute.setDefaultValue(defaultvalue);
        }
        StringRange rang = new StringRange();
        rang.add(val);
        Domain domain = new Domain(rang);
        attribute.setDomain(domain);
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((StringAttrDef) at).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (at instanceof IntegerAttrDefBounded) {
        // bounded can have deltas and multiples ranges, thus, will
        // always use a set integerDomain

        String name = ((IntegerAttrDefBounded) at).getName().getName();
        if (((IntegerAttrDefBounded) at).getDefault() != null) {
          Integer defaultvalue = ((IntegerAttrDefBounded) at).getDefault().getValue();
          attribute.setDefaultValue(defaultvalue);
        }

        // Set<Integer> vals= new HashSet<Integer>();
        EList<IntegerAttrDefComplement> complements = ((IntegerAttrDefBounded) at).getComplements();
        Range range = new IntegerRange();
        for (IntegerAttrDefComplement complement : complements) {
          int delta = 1;
          if (complement.getDelta() != null) {
            delta = complement.getDelta().getValue();
          }
          Integer max = Integer.parseInt(complement.getMax());
          Integer min = Integer.parseInt(complement.getMin());
          // Add the values to the set
          for (int i = min; i <= max; i += delta) {
            range.getItems().add(new Integer(i));
          }
        }

        // Domain domain= new SetIntegerDomain(vals);
        Domain domain = new Domain(range);
        attribute.setDomain(domain);
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((IntegerAttrDefBounded) at).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (at instanceof IntegerAttrDefUnbounded) {

        String name = ((IntegerAttrDefUnbounded) at).getName().getName();
        // Integer val =Integer.parseInt(((IntegerAttrDefUnbounded)
        // at).getValue());
        if (((IntegerAttrDefUnbounded) at).getDefault() != null) {
          Integer defaultvalue = ((IntegerAttrDefUnbounded) at).getDefault().getValue();
          attribute.setDefaultValue(defaultvalue);
        }

        Range range = new IntegerRange();
        range.getItems().add(Integer.MIN_VALUE);
        range.getItems().add(Integer.MAX_VALUE);
        Domain domain = new Domain(range);
        attribute.setDomain(domain);
        // attribute.setValue(val);
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((IntegerAttrDefUnbounded) at).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (at instanceof RealAttrDefBounded) {
        String name = ((RealAttrDefBounded) at).getName().getName();
        if (((RealAttrDefBounded) at).getDefault() != null) {
          Float defaultvalue = Float.parseFloat(((RealAttrDefBounded) at).getDefault().getValue());
          attribute.setDefaultValue(defaultvalue);
        }

        // Set<Float> vals= new HashSet<Float>();
        Collection<Range> ranges = new LinkedList<Range>();
        EList<RealAttrDefComplement> complements = ((RealAttrDefBounded) at).getComplement();
        if (!fakeRealSupport) {

          for (RealAttrDefComplement complement : complements) {
            Float max = Float.parseFloat(complement.getMax());
            Float min = Float.parseFloat(complement.getMin());
            // Range r= null;
            Collection<Float> floats = new LinkedList<Float>();
            if (complement.getDelta() != null) {
              float delta = Float.parseFloat(complement.getDelta().getValue());
              // a set of values
              // Add the values to the set

              for (float i = min; i <= max; i += delta) {
                floats.add(i);
              }
            } else {
              // max min
              floats.add(max);
              floats.add(min);
            }

            ranges.add(new RealRange(floats));
          }

          // Domain domain= new SetRealDomain(vals);
        } else {
          // we create a huge single integer range
          ArrayList<Object> realToInteger = new ArrayList<Object>();
          int intIndex = 0;

          for (RealAttrDefComplement complement : complements) {
            Float max = Float.parseFloat(complement.getMax());
            Float min = Float.parseFloat(complement.getMin());
            // Collection<Float> floats = new LinkedList<Float>();
            if (complement.getDelta() != null) {
              float delta = Float.parseFloat(complement.getDelta().getValue());
              // a set of values
              // Add the values to the set

              for (float i = min; i <= max; i += delta) {
                // floats.add(i);
                realToInteger.add(i);
                intIndex++;
              }
            } else {
              // max min
              // floats.add(max);
              realToInteger.add(max);
              // floats.add(min);
              realToInteger.add(min);
              intIndex++;
              intIndex++;
            }

            // ranges.add(new RealRange(floats));
          }
          Collection<Integer> integerCol = new ArrayList<Integer>();
          for (int i = 0; i < intIndex; i++) {
            integerCol.add(i);
          }
          ranges.add(new IntegerRange(integerCol));
          fakingRealValues.put(name, realToInteger);
        }

        Domain domain = new Domain();
        domain.setRanges(ranges);
        attribute.setDomain(domain);
        attribute.setName(name);

        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((RealAttrDefBounded) at).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (at instanceof RealAttrDefUnbounded) {

        String name = ((RealAttrDefUnbounded) at).getName().getName();
        Float val = Float.parseFloat(((RealAttrDefUnbounded) at).getValue());
        if (((RealAttrDefUnbounded) at).getDefault() != null) {
          Float defaultvalue =
              Float.parseFloat(((RealAttrDefUnbounded) at).getDefault().getValue());
          attribute.setDefaultValue(defaultvalue);
        }
        Collection<Float> floats = new LinkedList<Float>();
        floats.add(val);
        floats.add(Float.MAX_VALUE);
        floats.add(Float.MAX_VALUE);
        RealRange range = new RealRange(floats);
        Domain domain = new Domain();
        domain.addRange(range);
        attribute.setDomain(domain);
        // attribute.setValue(val);
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((RealAttrDefUnbounded) at).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      }

      EnumAttrDef enumAttrDef = atdef.getEnumAttrDef();
      if (enumAttrDef instanceof EnumStringDef) {
        // tratar el caso de emulacion de enteros

        String name = ((EnumStringDef) enumAttrDef).getName().getName();
        if (((EnumStringDef) enumAttrDef).getDefault() != null) {
          String defaultvalue = ((EnumStringDef) enumAttrDef).getDefault().getValue();
          attribute.setDefaultValue(defaultvalue);
        }

        ArrayList<Object> vals = new ArrayList<Object>();
        EList<String> values = ((EnumStringDef) enumAttrDef).getValue();
        for (String value : values) {
          vals.add(value);
        }
        Range range = null;
        if (fakeRealSupport) {
          Collection<Integer> integerCol = new ArrayList<Integer>();
          for (int i = 0; i < vals.size(); i++) {
            integerCol.add(i);
          }
          range = new IntegerRange(integerCol);
          fakingRealValues.put(name, vals);
        } else {
          range = new StringRange(vals);
        }
        attribute.setDomain(new Domain(range));
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((EnumStringDef) enumAttrDef).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (enumAttrDef instanceof EnumIntegerDef) {
        String name = ((EnumIntegerDef) enumAttrDef).getName().getName();
        if (((EnumIntegerDef) enumAttrDef).getDefault() != null) {
          Integer defaultvalue = ((EnumIntegerDef) enumAttrDef).getDefault().getValue();
          attribute.setDefaultValue(defaultvalue);
        }

        Set<Integer> vals = new HashSet<Integer>();
        EList<String> values = ((EnumIntegerDef) enumAttrDef).getValue();
        for (String value : values) {
          vals.add(Integer.parseInt(value));
        }

        Range range = new IntegerRange(vals);
        attribute.setDomain(new Domain(range));
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((EnumIntegerDef) enumAttrDef).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      } else if (enumAttrDef instanceof EnumRealDef) {
        String name = ((EnumRealDef) enumAttrDef).getName().getName();
        if (((EnumRealDef) enumAttrDef).getDefault() != null) {
          Float defaultvalue =
              Float.parseFloat(((EnumRealDef) enumAttrDef).getDefault().getValue());
          attribute.setDefaultValue(defaultvalue);
        }

        Set<Float> vals = new HashSet<Float>();
        EList<String> values = ((EnumIntegerDef) enumAttrDef).getValue();
        for (String value : values) {
          vals.add(Float.parseFloat(value));
        }

        Range range = new RealRange(vals);
        attribute.setDomain(new Domain(range));
        attribute.setName(name);
        fr.familiar.attributedfm.Feature searchFeatureByName =
            fm.searchFeatureByName(
                ((EnumRealDef) enumAttrDef).getName().getHead().getOwnedFeature().getName());
        searchFeatureByName.addAttribute(attribute);
      }
    }
  }