class ViewRegistry {

  protected static boolean extractViewArchive(String archivePath, ViewModule viewModule, boolean systemOnly)
      throws Exception {
    Injector injector = Guice.createInjector(viewModule);

    ViewExtractor extractor = injector.getInstance(ViewExtractor.class);
    ViewArchiveUtility archiveUtility = injector.getInstance(ViewArchiveUtility.class);
    Configuration configuration = injector.getInstance(Configuration.class);

    File viewDir = configuration.getViewsDir();

    String extractedArchivesPath = viewDir.getAbsolutePath() +
        File.separator + EXTRACTED_ARCHIVES_DIR;

    if (extractor.ensureExtractedArchiveDirectory(extractedArchivesPath)) {

      File archiveFile = archiveUtility.getFile(archivePath);

      ViewConfig viewConfig = archiveUtility.getViewConfigFromArchive(archiveFile);

      String commonName = viewConfig.getName();
      String version = viewConfig.getVersion();
      String viewName = ViewEntity.getViewName(commonName, version);

      String extractedArchiveDirPath = extractedArchivesPath + File.separator + viewName;
      File extractedArchiveDirFile = archiveUtility.getFile(extractedArchiveDirPath);

      if (!extractedArchiveDirFile.exists()) {
        ViewEntity viewDefinition = new ViewEntity(viewConfig, configuration, extractedArchiveDirPath);

        if (!systemOnly || viewDefinition.isSystem()) {
          ClassLoader classLoader = null;
          try {
            List<File> additionalPaths = getViewsAdditionalClasspath(configuration);
            classLoader = extractor.extractViewArchive(viewDefinition, archiveFile, extractedArchiveDirFile, additionalPaths);
            return true;
          } finally {
            if (classLoader instanceof Closeable) {
              Closeables.closeSilently((Closeable) classLoader);
            }
          }
        }
      }
    }
    return false;
  }

  @Inject public  ViewRegistry(AmbariEventPublisher publisher);

}