/**
   * @param logging
   * @param origin origin source
   * @param ident unique identity for this cached source, used in filename
   * @param descr description of the source, used in logging
   * @param logging if true, log cache access
   * @return new source
   */
  public ResourceModelSource createCachingSource(
      ResourceModelSource origin,
      String ident,
      String descr,
      SourceFactory.CacheType type,
      final boolean logging) {
    final File file = getResourceModelSourceFileCacheForType(ident);
    final ResourceModelSourceService nodesSourceService = getResourceModelSourceService();
    final ResourceFormatGeneratorService resourceFormatGeneratorService =
        getResourceFormatGeneratorService();
    final Properties fileSourceConfig =
        generateFileSourceConfigurationProperties(
            file.getAbsolutePath(), ResourceXMLFormatGenerator.SERVICE_PROVIDER_TYPE, false, false);
    try {
      ResourceModelSource fileSource =
          nodesSourceService.getSourceForConfiguration("file", fileSourceConfig);

      ResourceFormatGenerator generatorForFormat =
          resourceFormatGeneratorService.getGeneratorForFormat(
              ResourceXMLFormatGenerator.SERVICE_PROVIDER_TYPE);

      String ident1 =
          "[ResourceModelSource: " + descr + ", project: " + projectConfig.getName() + "]";
      StoreExceptionHandler handler = new StoreExceptionHandler(ident);
      ResourceModelSourceCache cache =
          new FileResourceModelSourceCache(file, generatorForFormat, fileSource);
      if (logging) {
        cache = new LoggingResourceModelSourceCache(cache, ident1);
      }
      return SourceFactory.cachedSource(origin, ident1, handler, cache, type);
    } catch (UnsupportedFormatException | ExecutionServiceException e) {
      e.printStackTrace();
    }
    return null;
  }
  /**
   * Update the resources file given an input Nodes set
   *
   * @param nodeset nodes
   * @throws UpdateUtils.UpdateException if an error occurs while trying to update the resources
   *     file or generate nodes
   */
  @Override
  public void updateNodesResourceFile(final INodeSet nodeset, final String nodesResourceFilePath)
      throws UpdateUtils.UpdateException {
    final ResourceFormatGenerator generator;
    File destfile = new File(nodesResourceFilePath);
    try {
      generator = resourceFormatGeneratorService.getGeneratorForFileExtension(destfile);
    } catch (UnsupportedFormatException e) {
      throw new UpdateUtils.UpdateException(
          "Unable to determine file format for file: " + nodesResourceFilePath, e);
    }
    File resfile = null;
    try {
      resfile = File.createTempFile("resource-temp", destfile.getName());
      resfile.deleteOnExit();
    } catch (IOException e) {
      throw new UpdateUtils.UpdateException("Unable to create temp file: " + e.getMessage(), e);
    }
    // serialize nodes and replace the nodes resource file

    try {
      final FileOutputStream stream = new FileOutputStream(resfile);
      try {
        generator.generateDocument(nodeset, stream);
      } finally {
        stream.close();
      }
    } catch (IOException e) {
      throw new UpdateUtils.UpdateException(
          "Unable to generate resources file: " + e.getMessage(), e);
    } catch (ResourceFormatGeneratorException e) {
      throw new UpdateUtils.UpdateException(
          "Unable to generate resources file: " + e.getMessage(), e);
    }

    updateNodesResourceFile(resfile, nodesResourceFilePath);
    if (!resfile.delete()) {
      logger.warn("failed to remove temp file: " + resfile);
    }
    logger.debug("generated resources file: " + resfile.getAbsolutePath());
  }