public void produceStepTemplateElement(ConfigurationStep step, Map stepData) {
   String output = "";
   try {
     stepData.put("step_id", step.getId());
     List stepManualDecisionsList = new LinkedList();
     if (step.getDecisions().isEmpty()) {
       Map tempMap = new HashMap();
       tempMap.put("featureName", "auto-completion");
       tempMap.put("featureId", "auto-completion");
       tempMap.put("featureValue", "");
       stepManualDecisionsList.add(tempMap);
     } else {
       for (FeatureTreeNode manualDecisionFeature : step.getDecisions()) {
         Map tempMap = new HashMap();
         tempMap.put("featureName", manualDecisionFeature.getName());
         tempMap.put("featureId", manualDecisionFeature.getID());
         tempMap.put("featureValue", manualDecisionFeature.getValue());
         stepManualDecisionsList.add(tempMap);
       }
     }
     stepData.put("step_manualDecisions", stepManualDecisionsList);
     stepData.put("step_countDecisions", step.countDecisions());
     stepData.put("step_countPropagations", step.countPropagations());
     // Step attributes
     stepData.putAll(step.getAttributesMap());
   } catch (Exception e) {
   }
 }
 public Map produceBasicFeatureData(FeatureTreeNode feature) {
   Map basicDataMap = new HashMap();
   basicDataMap.put("feature_id", feature.getID());
   basicDataMap.put("feature_name", getFeatureName(feature));
   basicDataMap.put("feature_type", getFeatureType(feature));
   basicDataMap.put("feature_level", feature.getLevel());
   basicDataMap.put("feature_parentid", getFeatureParent(feature));
   basicDataMap.put("feature_decision", "" + feature.getValue());
   basicDataMap.put(
       "feature_decisionType",
       feature.getValue() == -1
           ? ""
           : (String) feature.getProperty("decisionType")); // manual, propagated, auto-completion
   basicDataMap.put(
       "feature_decisionStep",
       feature.getValue() == -1 ? "" : (String) feature.getProperty("decisionStep"));
   basicDataMap.put(
       "feature_previousDecisionStep",
       feature.getValue() == -1
           ? ""
           : "" + (Integer.valueOf((String) feature.getProperty("decisionStep")) - 1));
   basicDataMap.put("feature_has_children", feature.getChildCount() > 0);
   basicDataMap.put("feature_group_min", -1);
   basicDataMap.put("feature_group_max", -1);
   if (feature instanceof FeatureGroup) {
     FeatureGroup group = (FeatureGroup) feature;
     int min = group.getMin();
     int max = group.getMax();
     basicDataMap.put("feature_group_min", min);
     basicDataMap.put("feature_group_max", max == -1 ? group.getChildCount() : max);
   }
   return basicDataMap;
 }
 protected String getFeatureParent(FeatureTreeNode feature) {
   FeatureTreeNode parent = (FeatureTreeNode) feature.getParent();
   if (parent == null) {
     return "";
   }
   return parent.getID();
 }
Ejemplo n.º 4
0
  protected FeatureTreeNode createNodes() throws FeatureModelException {

    int countFeatures = 1;
    Vector<FeatureTreeNode> fmNodes = new Vector<FeatureTreeNode>();

    String featureName = "R";
    countFeatures++;

    RootNode root = new RootNode(featureName, featureName);
    fmNodes.add(root);
    FeatureTreeNode parentNode = null;

    while (countFeatures <= numberOfFeatures) {

      parentNode = fmNodes.firstElement();
      fmNodes.removeElement(parentNode);

      int numberOfChildNodesToCreate =
          Math.min(
              numberOfFeatures - countFeatures + 1,
              (Math.abs(new Random().nextInt()) % (childFeaturesOdds - minChildFeature + 1))
                  + minChildFeature);

      // prevents an early end of the recursion when all nodes happen to have no children
      if (numberOfChildNodesToCreate == 0) {
        if (fmNodes.size() == 0) {
          numberOfChildNodesToCreate = 1;
        }
      }

      if (numberOfChildNodesToCreate > 0) {
        for (int i = 0; i < numberOfChildNodesToCreate && countFeatures <= numberOfFeatures; i++) {
          String childFeatureName = parentNode.getID().substring(1) + (i + 1);
          FeatureTreeNode randomNode =
              createRandomNode(
                  childFeatureName, solitaireOdds, groupOdds, minGroupCard, maxGroupCard);
          parentNode.add(randomNode);
          if (randomNode instanceof FeatureGroup) {
            FeatureGroup groupRandomNode = (FeatureGroup) randomNode;
            int countGroupedNodes = groupRandomNode.getChildCount();
            for (int j = 0; j < countGroupedNodes; j++) {
              fmNodes.add((FeatureTreeNode) groupRandomNode.getChildAt(j));
            }
            countFeatures += (countGroupedNodes);
          } else {
            fmNodes.add(randomNode);
            countFeatures++;
          }
        }
      }
    }

    return root;
  }
Ejemplo n.º 5
0
  protected void extractComponentsFromFeatureModel(FeatureTreeNode featureNode) {

    if (featureNode.isLeaf()) {
      if (getParentNode(featureNode) != null) {
        String componentKey = getParentNode(featureNode).getID();
        String componentName = getParentNode(featureNode).getName();
        ProductComponent component = concreteComponents.get(componentKey);
        if (component == null) {
          component = new ProductComponent(componentKey, componentName);
          concreteComponents.put(componentKey, component);
        }
        component.addComponentType(featureNode.getID());
      }
    }

    for (int i = 0; i < featureNode.getChildCount(); i++) {
      extractComponentsFromFeatureModel((FeatureTreeNode) featureNode.getChildAt(i));
    }
  }
 public String produceStepElement(ConfigurationStep step, Map stepData) {
   String output = "";
   try {
     if (stepElementTemplate == null) {
       stepElementTemplate = cfg.getTemplate("interactive_configuration_element_step.ftl");
     }
     stepData.put("step_id", step.getId());
     List stepManualDecisionsList = new LinkedList();
     if (step.getDecisions().isEmpty()) {
       Map tempMap = new HashMap();
       tempMap.put("featureName", "auto-completion");
       tempMap.put("featureId", "auto-completion");
       tempMap.put("featureValue", "");
       stepManualDecisionsList.add(tempMap);
     } else {
       for (FeatureTreeNode manualDecisionFeature : step.getDecisions()) {
         Map tempMap = new HashMap();
         tempMap.put("featureName", manualDecisionFeature.getName());
         tempMap.put("featureId", manualDecisionFeature.getID());
         tempMap.put("featureValue", manualDecisionFeature.getValue());
         stepManualDecisionsList.add(tempMap);
       }
     }
     stepData.put("step_manualDecisions", stepManualDecisionsList);
     stepData.put("step_countDecisions", step.countDecisions());
     stepData.put("step_countPropagations", step.countPropagations());
     // Step attributes
     stepData.putAll(step.getAttributesMap());
     StringWriter outputWriter = new StringWriter();
     stepElementTemplate.process(stepData, outputWriter);
     output = outputWriter.toString();
   } catch (Exception e) {
     output = e.getMessage();
   }
   return output;
 }