001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.mina.http.api;
021
022/**
023 * Type safe enumeration representing HTTP protocol version
024 * 
025 * @author The Apache MINA Project (dev@mina.apache.org)
026 */
027public enum HttpVersion {
028    /**
029     * HTTP 1/1
030     */
031    HTTP_1_1("HTTP/1.1"),
032
033    /**
034     * HTTP 1/0
035     */
036    HTTP_1_0("HTTP/1.0");
037
038    private final String value;
039
040    private HttpVersion(String value) {
041        this.value = value;
042    }
043
044    /**
045     * Returns the {@link HttpVersion} instance from the specified string.
046     * 
047     * @param string The String contaoning the HTTP version
048     * @return The version, or <code>null</code> if no version is found
049     */
050    public static HttpVersion fromString(String string) {
051        if (HTTP_1_1.toString().equalsIgnoreCase(string)) {
052            return HTTP_1_1;
053        }
054
055        if (HTTP_1_0.toString().equalsIgnoreCase(string)) {
056            return HTTP_1_0;
057        }
058
059        return null;
060    }
061
062    /**
063     * @return A String representation of this version
064     */
065    @Override
066    public String toString() {
067        return value;
068    }
069
070}