View Javadoc

    1   /*******************************************************************************
    2    * Copyright (c) 2011 Michael Mimo Moratti.
    3    *
    4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
    5    * (the "License"); you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at:
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    * Unless required by applicable law or agreed to in writing, software
    9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    11   * License for the specific language governing permissions and limitations
    12   * under the License.
    13   *******************************************************************************/
    14  package ch.mimo.netty.handler.codec.icap;
    15
    16  import java.util.HashMap;
    17  import java.util.Map;
    18
    19  /**
    20   * ICAP methods that are valid to use in messages.
    21   *
    22   * @author Michael Mimo Moratti (mimo@mimo.ch)
    23   *
    24   */
    25  public final class IcapMethod {
    26
    27  	/**
    28  	 * Request Modification
    29  	 */
    30  	public static final IcapMethod REQMOD = new IcapMethod("REQMOD");
    31
    32  	/**
    33  	 * Response Modification
    34  	 */
    35  	public static final IcapMethod RESPMOD = new IcapMethod("RESPMOD");
    36
    37  	/**
    38  	 * learn about configuration
    39  	 */
    40  	public static final IcapMethod OPTIONS = new IcapMethod("OPTIONS");
    41
    42      private static final Map<String, IcapMethod> METHOD_MAP =
    43          new HashMap<String, IcapMethod>();
    44
    45  	static {
    46  		METHOD_MAP.put(REQMOD.toString(),REQMOD);
    47  		METHOD_MAP.put(RESPMOD.toString(),RESPMOD);
    48  	    METHOD_MAP.put(OPTIONS.toString(),OPTIONS);
    49  	}
    50
    51  	private String name;
    52
    53  	IcapMethod(String name) {
    54  		this.name = name;
    55  	}
    56
    57      /**
    58       * Returns the {@link IcapMethod} represented by the specified name.
    59       * If the specified name is a standard RTSP method name, a cached instance
    60       * will be returned.  Otherwise, a new instance will be returned.
    61       */
    62      public static IcapMethod valueOf(String name) {
    63          if (name == null) {
    64              throw new NullPointerException("name");
    65          }
    66
    67          name = name.trim().toUpperCase();
    68          if (name.length() == 0) {
    69              throw new IllegalArgumentException("empty name");
    70          }
    71
    72          IcapMethod result = METHOD_MAP.get(name);
    73          if (result != null) {
    74              return result;
    75          } else {
    76              return new IcapMethod(name);
    77          }
    78      }
    79
    80      @Override
    81      public String toString() {
    82      	return name;
    83      }
    84  }