SearchMethod.java

  1. package gov.usgs.earthquake.indexer;

  2. /**
  3.  * Different types of searches that are supported.
  4.  */
  5. public enum SearchMethod {
  6.     /** Summary for multiple events. */
  7.     EVENTS_SUMMARY("getEventSummary"),

  8.     /** Detail for one event. */
  9.     EVENT_DETAIL("getEvent"),

  10.     /** Summary for multiple products. */
  11.     PRODUCTS_SUMMARY("getProductSummary"),

  12.     /** Detail for one product. */
  13.     PRODUCT_DETAIL("getProduct");

  14.     private String xmlMethodName;

  15.     private SearchMethod(final String xmlMethodName) {
  16.         this.xmlMethodName = xmlMethodName;
  17.     }

  18.     /**
  19.      * @return The XML string used to represent this response type.
  20.      */
  21.     public String getXmlMethodName() {
  22.         return xmlMethodName;
  23.     }

  24.     /**
  25.      * Get the enumerated value for the given xml string.
  26.      *
  27.      * @param xmlMethodName
  28.      *            the xml name.
  29.      * @return null if xmlMethodName is unknown.
  30.      */
  31.     public static SearchMethod fromXmlMethodName(
  32.             final String xmlMethodName) {
  33.         if (xmlMethodName == null) {
  34.             return null;
  35.         }

  36.         if (EVENTS_SUMMARY.getXmlMethodName().equals(xmlMethodName)) {
  37.             return EVENTS_SUMMARY;
  38.         } else if (EVENT_DETAIL.getXmlMethodName().equals(xmlMethodName)) {
  39.             return EVENT_DETAIL;
  40.         } else if (PRODUCTS_SUMMARY.getXmlMethodName().equals(xmlMethodName)) {
  41.             return PRODUCTS_SUMMARY;
  42.         } else if (PRODUCT_DETAIL.getXmlMethodName().equals(xmlMethodName)) {
  43.             return PRODUCT_DETAIL;
  44.         }

  45.         return null;
  46.     }
  47. }