1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
28
29
30
31
32 public enum StompCommand {
33
34
35 CONNECT,
36 STOMP,
37 DISCONNECT,
38 SUBSCRIBE,
39 UNSUBSCRIBE,
40 SEND,
41 ACK,
42 NACK,
43 BEGIN,
44 COMMIT,
45 ABORT,
46
47
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