001/**
002 *
003 * Copyright © 2014-2017 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.jingle.element;
018
019import java.util.HashMap;
020import java.util.Map;
021
022/**
023 * The "action" in the jingle packet, as an enum.
024 *
025 *
026 * @author Florian Schmaus
027 */
028public enum JingleAction {
029
030    content_accept,
031    content_add,
032    content_modify,
033    content_reject,
034    content_remove,
035    description_info,
036    security_info,
037    session_accept,
038    session_info,
039    session_initiate,
040    session_terminate,
041    transport_accept,
042    transport_info,
043    transport_reject,
044    transport_replace,
045    ;
046
047    private static final Map<String, JingleAction> map = new HashMap<>(
048                    JingleAction.values().length);
049    static {
050        for (JingleAction jingleAction : JingleAction.values()) {
051            map.put(jingleAction.toString(), jingleAction);
052        }
053    }
054
055    private final String asString;
056
057    JingleAction() {
058        asString = this.name().replace('_', '-');
059    }
060
061    @Override
062    public String toString() {
063        return asString;
064    }
065
066    public static JingleAction fromString(String string) {
067        JingleAction jingleAction = map.get(string);
068        if (jingleAction == null) {
069            throw new IllegalArgumentException("Unknown jingle action: " + string);
070        }
071        return jingleAction;
072    }
073}