FilterProductHandler.java

  1. /*
  2.  * FilterProductHandler
  3.  */
  4. package gov.usgs.earthquake.product.io;

  5. import gov.usgs.earthquake.product.Content;
  6. import gov.usgs.earthquake.product.ProductId;
  7. import gov.usgs.util.CryptoUtils.Version;

  8. import java.net.URI;
  9. import java.net.URL;

  10. /**
  11.  * Filter calls to another ProductHandler.
  12.  *
  13.  * By default, calls are passed directly on to the wrapped ProductOutput.
  14.  */
  15. public class FilterProductHandler implements ProductHandler {

  16.     /** The product output being filtered. */
  17.     private ProductHandler output;

  18.     /**
  19.      * Create a new FilterProductHandler.
  20.      *
  21.      * A ProductOutput should be set using setProductOutput before any calls to
  22.      * other methods.
  23.      */
  24.     public FilterProductHandler() {
  25.     }

  26.     /**
  27.      * Create a new FilterProductHandler using and existing ProductOutput.
  28.      *
  29.      * @param output
  30.      *            the ProductOutput to wrap.
  31.      */
  32.     public FilterProductHandler(final ProductHandler output) {
  33.         setProductOutput(output);
  34.     }

  35.     /**
  36.      * Set the wrapped ProductOutput.
  37.      *
  38.      * @param output
  39.      *            the ProductOutput being wrapped.
  40.      */
  41.     public void setProductOutput(final ProductHandler output) {
  42.         this.output = output;
  43.     }

  44.     /**
  45.      * Calls the wrapped ProductOutput onBeginProduct method.
  46.      */
  47.     public void onBeginProduct(ProductId id, String status, URL trackerURL)
  48.             throws Exception {
  49.         output.onBeginProduct(id, status, trackerURL);
  50.     }

  51.     /**
  52.      * Calls the wrapped ProductOutput onContent method.
  53.      */
  54.     public void onContent(ProductId id, String path, Content content)
  55.             throws Exception {
  56.         output.onContent(id, path, content);
  57.     }

  58.     /**
  59.      * Calls the wrapped ProductOutput onEndProduct method.
  60.      */
  61.     public void onEndProduct(ProductId id) throws Exception {
  62.         output.onEndProduct(id);
  63.     }

  64.     /**
  65.      * Calls the wrapped ProductOutput onLink method.
  66.      */
  67.     public void onLink(ProductId id, String relation, URI href)
  68.             throws Exception {
  69.         output.onLink(id, relation, href);
  70.     }

  71.     /**
  72.      * Calls the wrapped ProductOutput onProperty method.
  73.      */
  74.     public void onProperty(ProductId id, String name, String value)
  75.             throws Exception {
  76.         output.onProperty(id, name, value);
  77.     }

  78.     @Override
  79.     public void onSignatureVersion(ProductId id, Version version) throws Exception {
  80.         output.onSignatureVersion(id, version);
  81.     }

  82.     /**
  83.      * Calls the wrapped ProductOutput onSignature method.
  84.      */
  85.     public void onSignature(ProductId id, String signature) throws Exception {
  86.         output.onSignature(id, signature);
  87.     }


  88.     /**
  89.      * Free any resources associated with this source.
  90.      */
  91.     @Override
  92.     public void close() {
  93.         if (output != null) {
  94.             output.close();
  95.         }
  96.     }

  97. }