public Element toXml() {
   Element root = new Element(ROOT_ELEMENT);
   root.setAttribute(ATTR_VERSION, Integer.toString(DEPENDENCIES_VERSION));
   if (myModelHash != null) {
     root.setAttribute(ATTR_MODEL_HASH, myModelHash);
   }
   if (myParametersHash != null) {
     root.setAttribute(ATTR_PARAMS_HASH, myParametersHash);
   }
   String[] models = myUsedModelsHashes.keySet().toArray(new String[myUsedModelsHashes.size()]);
   Arrays.sort(models);
   for (String model : models) {
     Element e = new Element(NODE_MODEL);
     e.setAttribute(ATTR_MODEL_ID, model);
     String hash = myUsedModelsHashes.get(model);
     if (hash != null) {
       e.setAttribute(ATTR_HASH, hash);
     }
     root.addContent(e);
   }
   if (myRootDependencies != null) {
     for (GenerationRootDependencies data : myRootDependencies) {
       Element e = new Element(data.getRootId() != null ? NODE_ROOT : NODE_COMMON);
       data.saveTo(e);
       root.addContent(e);
     }
   }
   return root;
 }
  public static GenerationDependencies fromIncremental(
      Map<SNode, SNode> currentToOriginalMap,
      RootDependenciesBuilder[] roots,
      String modelHash,
      String parametersHash,
      IOperationContext operationContext,
      IncrementalGenerationStrategy incrementalStrategy,
      int skippedCount,
      int fromCacheCount) {
    Map<String, List<String>> generatedFiles = getGeneratedFiles(currentToOriginalMap);

    List<GenerationRootDependencies> unchanged = null;
    List<GenerationRootDependencies> rootDependencies =
        new ArrayList<GenerationRootDependencies>(roots.length);
    Map<String, String> externalHashes = new HashMap<String, String>();
    for (RootDependenciesBuilder l : roots) {
      SNode originalRoot = l.getOriginalRoot();
      List<String> files = generatedFiles.get(originalRoot != null ? originalRoot.getId() : "");
      if (files == null) {
        files = Collections.emptyList();
      }
      GenerationRootDependencies dep;
      if (l.isUnchanged()) {
        dep = l.getSavedDependencies();
        if (unchanged == null) {
          unchanged = new ArrayList<GenerationRootDependencies>();
        }
        unchanged.add(dep);
      } else {
        dep = GenerationRootDependencies.fromData(l, files);
      }
      rootDependencies.add(dep);
      for (String modelReference : dep.getExternal()) {
        if (!externalHashes.containsKey(modelReference)) {
          SModelDescriptor sm =
              SModelRepository.getInstance()
                  .getModelDescriptor(SModelReference.fromString(modelReference));
          Map<String, String> hashes = incrementalStrategy.getModelHashes(sm, operationContext);
          String value = hashes != null ? hashes.get(ModelDigestHelper.FILE) : null;
          externalHashes.put(modelReference, value);
        }
      }
    }
    return new GenerationDependencies(
        rootDependencies,
        modelHash,
        parametersHash,
        externalHashes,
        unchanged == null ? Collections.<GenerationRootDependencies>emptyList() : unchanged,
        skippedCount,
        fromCacheCount);
  }
 public static GenerationDependencies fromXml(Element root) {
   String version = GenerationRootDependencies.getValue(root, ATTR_VERSION);
   if (version == null || !version.equals(Integer.toString(DEPENDENCIES_VERSION))) {
     /* regenerate all */
     return null;
   }
   Map<String, String> externalHashes = new HashMap<String, String>();
   for (Element e : ((List<Element>) root.getChildren(NODE_MODEL))) {
     String modelReference = GenerationRootDependencies.getValue(e, ATTR_MODEL_ID);
     String rootHash = GenerationRootDependencies.getValue(e, ATTR_HASH);
     if (modelReference != null) {
       externalHashes.put(modelReference, rootHash);
     }
   }
   List<GenerationRootDependencies> data = new ArrayList<GenerationRootDependencies>();
   for (Element e : ((List<Element>) root.getChildren(NODE_COMMON))) {
     data.add(GenerationRootDependencies.fromXml(e, true));
   }
   for (Element e : ((List<Element>) root.getChildren(NODE_ROOT))) {
     data.add(GenerationRootDependencies.fromXml(e, false));
   }
   String modelHash = GenerationRootDependencies.getValue(root, ATTR_MODEL_HASH);
   String paramsHash = GenerationRootDependencies.getValue(root, ATTR_PARAMS_HASH);
   if (externalHashes.isEmpty() && data.isEmpty()) {
     return new GenerationDependencies(modelHash, paramsHash);
   }
   return new GenerationDependencies(
       data,
       modelHash,
       paramsHash,
       externalHashes,
       Collections.<GenerationRootDependencies>emptyList(),
       0,
       0);
 }
 private GenerationDependencies(
     List<GenerationRootDependencies> data,
     String modelHash,
     String parametersHash,
     Map<String, String> externalHashes,
     List<GenerationRootDependencies> unchanged,
     int skippedCount,
     int fromCacheCount) {
   this.containsIncrementalInfo = true;
   this.myRootDependencies = data;
   this.mySkippedCount = skippedCount;
   this.myFromCacheCount = fromCacheCount;
   this.myRootDependenciesMap = new HashMap<String, GenerationRootDependencies>(data.size());
   this.myModelHash = modelHash;
   this.myParametersHash = parametersHash;
   this.myUnchanged = unchanged;
   this.myUsedModelsHashes = externalHashes;
   for (GenerationRootDependencies rd : data) {
     String id = rd.getRootId();
     myRootDependenciesMap.put(id == null ? ModelDigestHelper.HEADER : id, rd);
   }
 }