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;
 }
 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) {
   }
 }
 protected String getFeatureParent(FeatureTreeNode feature) {
   FeatureTreeNode parent = (FeatureTreeNode) feature.getParent();
   if (parent == null) {
     return "";
   }
   return parent.getID();
 }
 protected String getFeatureName(FeatureTreeNode feature) {
   if (feature instanceof FeatureGroup) {
     int min = ((FeatureGroup) feature).getMin();
     int max = ((FeatureGroup) feature).getMax();
     max = (max == -1) ? feature.getChildCount() : max;
     return "[" + min + ".." + max + "]";
   }
   return feature.getName();
 }
  private FeatureTreeNode createRandomNode(
      String childFeatureName,
      int solitaireOdds,
      int groupOdds,
      int minGroupCard,
      int maxGroupCard) {

    int solitaireOrGroupRandom = (new Random().nextInt() % childFeaturesOdds) + 1;

    FeatureTreeNode node = null;
    String featureName = "";

    // should create a solitaire feature (optional/mandatory)?
    if (solitaireOrGroupRandom <= solitaireOdds) {
      featureName = "S" + childFeatureName;
      // 50% odds for mandatory and optional features
      //			int solitaireOptorMandRandom = (new Random().nextInt()%2);
      // should create an optional feature?
      //			if ( solitaireOptorMandRandom == 0 ) {
      node = new SolitaireFeature(true, featureName, featureName);
      //			}
      //			 should create a mandatory feature?
      //			else  {
      //		        node = new SolitaireFeature( true, featureName, featureName,
      // TreeNodeRendererFactory.createMandatoryRenderer());
      //			}
    }
    // should create a feature group?
    else {
      // number of grouped features
      int groupSize =
          (Math.abs(new Random().nextInt()) % (maxGroupCard - minGroupCard + 1)) + minGroupCard;
      // 50% odds for [1..*] and [1] group cardinality
      int groupTypeOdds = (new Random().nextInt() % 2);
      // [1..*] or [1] cardinality
      int lower = 1;
      int upper = 1;
      if (groupTypeOdds == 0) { // [1..*] = [1,-1]
        upper = -1;
      }

      String groupName = "_G" + childFeatureName;
      ;
      // create group parent node
      node = new FeatureGroup(groupName, groupName, lower, upper);

      // create grouped feature nodes
      for (int i = 0; i < groupSize; i++) {
        featureName = "g" + childFeatureName + (i + 1);
        node.add(new GroupedFeature(featureName, featureName));
      }
    }

    return node;
  }
  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;
  }
 public String produceFeatureElement(
     FeatureTreeNode feature, Map featureData, String templateFileName) {
   String output = "";
   try {
     if (featureElementTemplate == null) {
       featureElementTemplate = cfg.getTemplate(templateFileName);
     }
     featureData.putAll(produceBasicFeatureData(feature));
     FeatureTreeNode parentNode =
         (FeatureTreeNode) ((feature instanceof FeatureGroup) ? feature.getParent() : feature);
     List children = new ArrayList(parentNode.getChildCount());
     for (int i = 0; i < parentNode.getChildCount(); i++) {
       FeatureTreeNode childNode = (FeatureTreeNode) parentNode.getChildAt(i);
       if (childNode instanceof FeatureGroup) {
         for (int j = 0; j < childNode.getChildCount(); j++) {
           FeatureTreeNode groupedNode = (FeatureTreeNode) childNode.getChildAt(j);
           children.add(produceBasicFeatureData(groupedNode));
         }
       } else {
         children.add(produceBasicFeatureData(childNode));
       }
     }
     featureData.put("children", children);
     StringWriter outputWriter = new StringWriter();
     featureElementTemplate.process(featureData, outputWriter);
     output = outputWriter.toString();
   } catch (Exception e) {
     output = e.getMessage();
   }
   return output;
 }
示例#8
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));
    }
  }
示例#9
0
 public List<Product> filterProductsBasedOnFeatureModelSelection() {
   List<Product> filteredProducts = new LinkedList<Product>();
   filteredProducts.addAll(products.values());
   // for each component
   for (ProductComponent component : concreteComponents.values()) {
     // for each component type
     for (String componentType : component.getTypes()) {
       FeatureTreeNode featureNode = featureModel.getNodeByID(componentType);
       // if the component type is selected/deselected in the feature model
       if (featureNode.isInstantiated()) {
         // for each product
         for (Iterator<Product> it = filteredProducts.iterator(); it.hasNext(); ) {
           Product product = it.next();
           String productComponentType = product.getComponent(component.getID());
           // component type is selected in the feature model but is NOT part of the product -
           // remove product from filter list
           try {
             if (featureNode.getValue() == 1
                 && componentType.compareToIgnoreCase(productComponentType) != 0) {
               it.remove();
             }
             // or if component type is DEselected in the feature model but IS part of the product
             // - remove product from filter list
             else if (featureNode.getValue() == 0
                 && componentType.compareToIgnoreCase(productComponentType) == 0) {
               it.remove();
             }
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       }
     }
   }
   return filteredProducts;
 }
 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;
 }
 protected String getFeatureType(FeatureTreeNode feature) {
   if (feature.isRoot()) {
     return "root";
   } else if (feature instanceof SolitaireFeature) {
     if (((SolitaireFeature) feature).isOptional()) {
       return "optional";
     } else {
       return "mandatory";
     }
   } else if (feature instanceof FeatureGroup) {
     return "group";
   } else if (feature instanceof GroupedFeature) {
     return "grouped";
   }
   return "error";
 }
示例#12
0
 protected FeatureTreeNode getParentNode(FeatureTreeNode featureNode) {
   if (featureNode instanceof GroupedFeature) {
     return (FeatureTreeNode) featureNode.getParent().getParent();
   }
   return (FeatureTreeNode) featureNode.getParent();
 }