JingleAction.java

  1. /**
  2.  *
  3.  * Copyright © 2014-2017 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.jingle.element;

  18. import java.util.HashMap;
  19. import java.util.Map;

  20. /**
  21.  * The "action" in the jingle packet, as an enum.
  22.  *
  23.  *
  24.  * @author Florian Schmaus
  25.  */
  26. public enum JingleAction {

  27.     content_accept,
  28.     content_add,
  29.     content_modify,
  30.     content_reject,
  31.     content_remove,
  32.     description_info,
  33.     security_info,
  34.     session_accept,
  35.     session_info,
  36.     session_initiate,
  37.     session_terminate,
  38.     transport_accept,
  39.     transport_info,
  40.     transport_reject,
  41.     transport_replace,
  42.     ;

  43.     private static final Map<String, JingleAction> map = new HashMap<>(
  44.                     JingleAction.values().length);
  45.     static {
  46.         for (JingleAction jingleAction : JingleAction.values()) {
  47.             map.put(jingleAction.toString(), jingleAction);
  48.         }
  49.     }

  50.     private final String asString;

  51.     JingleAction() {
  52.         asString = this.name().replace('_', '-');
  53.     }

  54.     @Override
  55.     public String toString() {
  56.         return asString;
  57.     }

  58.     public static JingleAction fromString(String string) {
  59.         JingleAction jingleAction = map.get(string);
  60.         if (jingleAction == null) {
  61.             throw new IllegalArgumentException("Unknown jingle action: " + string);
  62.         }
  63.         return jingleAction;
  64.     }
  65. }