All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cedarsoft.couchdb.test.utils.FileBasedDesignDocumentsProvider Maven / Gradle / Ivy

package com.cedarsoft.couchdb.test.utils;

import com.cedarsoft.couchdb.core.DesignDocument;
import com.cedarsoft.couchdb.core.DesignDocuments;
import com.cedarsoft.couchdb.update.DesignDocumentsProvider;
import com.cedarsoft.version.Version;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.net.URL;
import java.util.List;

/**
 * Attention: The resource must be a file!
 *
 * @author Johannes Schneider ([email protected])
 */
public class FileBasedDesignDocumentsProvider implements DesignDocumentsProvider {
  @Nonnull
  public static final String FILE_PROTOCOL = "file";

  @Nonnull
  private final URL resource;
  @Nonnull
  private final Version version;

  /**
   * Attention: The resource must be a file!
   *
   * @param resource the resource (must be a file!)
   * @param version the version
   */
  public FileBasedDesignDocumentsProvider( @Nonnull URL resource, @Nonnull Version version ) {
    this.resource = resource;
    this.version = version;

    if ( !resource.getProtocol().equals( FILE_PROTOCOL ) ) {
      throw new IllegalArgumentException( "Invalid protocol <" + resource.getProtocol() + "> for resource <" + resource + ">" );
    }
  }

  @Override
  @Nonnull
  public List getDesignDocuments() throws IOException {
    return DesignDocuments.createDesignDocuments( resource );
  }

  @Nonnull
  @Override
  public Version getVersion() {
    return version;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy