001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.messaging.simp.stomp;
018
019import org.springframework.messaging.simp.SimpMessageType;
020
021/**
022 * Represents a STOMP command.
023 *
024 * @author Rossen Stoyanchev
025 * @author Juergen Hoeller
026 * @since 4.0
027 */
028public enum StompCommand {
029
030        // client
031        STOMP(SimpMessageType.CONNECT),
032        CONNECT(SimpMessageType.CONNECT),
033        DISCONNECT(SimpMessageType.DISCONNECT),
034        SUBSCRIBE(SimpMessageType.SUBSCRIBE, true, true, false),
035        UNSUBSCRIBE(SimpMessageType.UNSUBSCRIBE, false, true, false),
036        SEND(SimpMessageType.MESSAGE, true, false, true),
037        ACK(SimpMessageType.OTHER),
038        NACK(SimpMessageType.OTHER),
039        BEGIN(SimpMessageType.OTHER),
040        COMMIT(SimpMessageType.OTHER),
041        ABORT(SimpMessageType.OTHER),
042
043        // server
044        CONNECTED(SimpMessageType.OTHER),
045        RECEIPT(SimpMessageType.OTHER),
046        MESSAGE(SimpMessageType.MESSAGE, true, true, true),
047        ERROR(SimpMessageType.OTHER, false, false, true);
048
049
050        private final SimpMessageType messageType;
051
052        private final boolean destination;
053
054        private final boolean subscriptionId;
055
056        private final boolean body;
057
058
059        StompCommand(SimpMessageType messageType) {
060                this(messageType, false, false, false);
061        }
062
063        StompCommand(SimpMessageType messageType, boolean destination, boolean subscriptionId, boolean body) {
064                this.messageType = messageType;
065                this.destination = destination;
066                this.subscriptionId = subscriptionId;
067                this.body = body;
068        }
069
070
071        public SimpMessageType getMessageType() {
072                return this.messageType;
073        }
074
075        public boolean requiresDestination() {
076                return this.destination;
077        }
078
079        public boolean requiresSubscriptionId() {
080                return this.subscriptionId;
081        }
082
083        public boolean requiresContentLength() {
084                return this.body;
085        }
086
087        public boolean isBodyAllowed() {
088                return this.body;
089        }
090
091}