View Javadoc
1   /*
2    * Copyright 2002-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.messaging.simp.stomp;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.springframework.messaging.simp.SimpMessageType;
25  
26  /**
27   * Represents a STOMP command.
28   *
29   * @author Rossen Stoyanchev
30   * @since 4.0
31   */
32  public enum StompCommand {
33  
34  	// client
35  	CONNECT,
36  	STOMP,
37  	DISCONNECT,
38  	SUBSCRIBE,
39  	UNSUBSCRIBE,
40  	SEND,
41  	ACK,
42  	NACK,
43  	BEGIN,
44  	COMMIT,
45  	ABORT,
46  
47  	// server
48  	CONNECTED,
49  	MESSAGE,
50  	RECEIPT,
51  	ERROR;
52  
53  
54  	private static Map<StompCommand, SimpMessageType> messageTypes = new HashMap<StompCommand, SimpMessageType>();
55  	static {
56  		messageTypes.put(StompCommand.CONNECT, SimpMessageType.CONNECT);
57  		messageTypes.put(StompCommand.STOMP, SimpMessageType.CONNECT);
58  		messageTypes.put(StompCommand.SEND, SimpMessageType.MESSAGE);
59  		messageTypes.put(StompCommand.MESSAGE, SimpMessageType.MESSAGE);
60  		messageTypes.put(StompCommand.SUBSCRIBE, SimpMessageType.SUBSCRIBE);
61  		messageTypes.put(StompCommand.UNSUBSCRIBE, SimpMessageType.UNSUBSCRIBE);
62  		messageTypes.put(StompCommand.DISCONNECT, SimpMessageType.DISCONNECT);
63  	}
64  
65  	private static Collection<StompCommand> destinationRequired = Arrays.asList(SEND, SUBSCRIBE, MESSAGE);
66  	private static Collection<StompCommand> subscriptionIdRequired = Arrays.asList(SUBSCRIBE, UNSUBSCRIBE, MESSAGE);
67  	private static Collection<StompCommand> contentLengthRequired = Arrays.asList(SEND, MESSAGE, ERROR);
68  	private static Collection<StompCommand> bodyAllowed = Arrays.asList(SEND, MESSAGE, ERROR);
69  
70  
71  
72  	public SimpMessageType getMessageType() {
73  		SimpMessageType type = messageTypes.get(this);
74  		return (type != null) ? type : SimpMessageType.OTHER;
75  	}
76  
77  	public boolean requiresDestination() {
78  		return destinationRequired.contains(this);
79  	}
80  
81  	public boolean requiresSubscriptionId() {
82  		return subscriptionIdRequired.contains(this);
83  	}
84  
85  	public boolean requiresContentLength() {
86  		return contentLengthRequired.contains(this);
87  	}
88  
89  	public boolean isBodyAllowed() {
90  		return bodyAllowed.contains(this);
91  	}
92  
93  }
94