Пример #1
0
  /**
   * @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;
  }
Пример #2
0
  private Properties createURLSourceConfiguration() {
    final URLResourceModelSource.Configuration build = URLResourceModelSource.Configuration.build();
    build.url(projectConfig.getProperty(PROJECT_RESOURCES_URL_PROPERTY));
    build.project(projectConfig.getName());

    return build.getProperties();
  }
Пример #3
0
 private File getResourceModelSourceFileCacheForType(String ident) {
   String varDir = projectConfig.getProperty("framework.var.dir");
   File file =
       new File(
           varDir, "resourceModelSourceCache/" + projectConfig.getName() + "/" + ident + ".xml");
   if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
     logger.warn("Failed to create cache dirs for source file cache");
   }
   return file;
 }
Пример #4
0
  private Properties generateFileSourceConfigurationProperties(
      String filepath, String format, boolean generate, boolean includeServerNode) {
    final FileResourceModelSource.Configuration build =
        FileResourceModelSource.Configuration.build();
    build.file(filepath);
    if (null != format) {
      build.format(format);
    }
    build.project(projectConfig.getName());
    build.generateFileAutomatically(generate);
    build.includeServerNode(includeServerNode);

    return build.getProperties();
  }
Пример #5
0
  private ResourceModelSource loadResourceModelSource(
      String type, Properties configuration, boolean useCache, String ident)
      throws ExecutionServiceException {

    final ResourceModelSourceService nodesSourceService = getResourceModelSourceService();
    configuration.put("project", projectConfig.getName());
    ResourceModelSource sourceForConfiguration =
        nodesSourceService.getSourceForConfiguration(type, configuration);

    if (useCache) {
      ResourceModelSourceFactory provider = nodesSourceService.providerOfType(type);
      String name = ident;
      if (provider instanceof Describable) {
        Describable desc = (Describable) provider;
        Description description = desc.getDescription();
        name = ident + " (" + description.getTitle() + ")";
      }
      return createCachingSource(sourceForConfiguration, ident, name);
    } else {
      return sourceForConfiguration;
    }
  }