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;
 }
 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 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();
 }
コード例 #4
0
ファイル: ProductCatalog.java プロジェクト: stefFischer/splar
  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));
    }
  }