001    /*
002     * Copyright (c) 2011, Cloudera, Inc. All Rights Reserved.
003     *
004     * Cloudera, Inc. licenses this file to you under the Apache License,
005     * Version 2.0 (the "License"). You may not use this file except in
006     * compliance with the License. You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
011     * CONDITIONS OF ANY KIND, either express or implied. See the License for
012     * the specific language governing permissions and limitations under the
013     * License.
014     */
015    package com.cloudera.lib.wsrs;
016    
017    import com.cloudera.lib.lang.StringUtils;
018    
019    import java.util.Arrays;
020    
021    public abstract class EnumParam<E extends Enum<E>> extends Param<E> {
022      Class<E> klass;
023    
024      public EnumParam(String label, String str, Class<E> e) {
025        klass = e;
026        value = parseParam(label, str);
027      }
028    
029      protected E parse(String str) throws Exception {
030        return Enum.valueOf(klass, str.toUpperCase());
031      }
032    
033      @Override
034      protected String getDomain() {
035        return StringUtils.toString(Arrays.asList(klass.getEnumConstants()), ",");
036      }
037    
038    }