|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.messaging.simp.stomp;
|
18 | 18 |
|
19 |
| -import java.util.Arrays; |
20 |
| -import java.util.Collection; |
21 |
| -import java.util.HashMap; |
22 |
| -import java.util.Map; |
23 |
| - |
24 | 19 | import org.springframework.messaging.simp.SimpMessageType;
|
25 | 20 |
|
26 | 21 | /**
|
27 | 22 | * Represents a STOMP command.
|
28 | 23 | *
|
29 | 24 | * @author Rossen Stoyanchev
|
| 25 | + * @author Juergen Hoeller |
30 | 26 | * @since 4.0
|
31 | 27 | */
|
32 | 28 | public enum StompCommand {
|
33 | 29 |
|
34 | 30 | // client
|
35 |
| - CONNECT, |
36 |
| - STOMP, |
37 |
| - DISCONNECT, |
38 |
| - SUBSCRIBE, |
39 |
| - UNSUBSCRIBE, |
40 |
| - SEND, |
41 |
| - ACK, |
42 |
| - NACK, |
43 |
| - BEGIN, |
44 |
| - COMMIT, |
45 |
| - ABORT, |
| 31 | + STOMP(SimpMessageType.CONNECT), |
| 32 | + CONNECT(SimpMessageType.CONNECT), |
| 33 | + DISCONNECT(SimpMessageType.DISCONNECT), |
| 34 | + SUBSCRIBE(SimpMessageType.SUBSCRIBE, true, true, false), |
| 35 | + UNSUBSCRIBE(SimpMessageType.UNSUBSCRIBE, false, true, false), |
| 36 | + SEND(SimpMessageType.MESSAGE, true, false, true), |
| 37 | + ACK(SimpMessageType.OTHER), |
| 38 | + NACK(SimpMessageType.OTHER), |
| 39 | + BEGIN(SimpMessageType.OTHER), |
| 40 | + COMMIT(SimpMessageType.OTHER), |
| 41 | + ABORT(SimpMessageType.OTHER), |
46 | 42 |
|
47 | 43 | // 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 |
| - } |
| 44 | + CONNECTED(SimpMessageType.OTHER), |
| 45 | + RECEIPT(SimpMessageType.OTHER), |
| 46 | + MESSAGE(SimpMessageType.MESSAGE, true, true, true), |
| 47 | + ERROR(SimpMessageType.OTHER, false, false, true); |
| 48 | + |
64 | 49 |
|
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); |
| 50 | + private final SimpMessageType messageType; |
69 | 51 |
|
| 52 | + private final boolean destination; |
| 53 | + |
| 54 | + private final boolean subscriptionId; |
| 55 | + |
| 56 | + private final boolean body; |
| 57 | + |
| 58 | + |
| 59 | + StompCommand(SimpMessageType messageType) { |
| 60 | + this(messageType, false, false, false); |
| 61 | + } |
| 62 | + |
| 63 | + StompCommand(SimpMessageType messageType, boolean destination, boolean subscriptionId, boolean body) { |
| 64 | + this.messageType = messageType; |
| 65 | + this.destination = destination; |
| 66 | + this.subscriptionId = subscriptionId; |
| 67 | + this.body = body; |
| 68 | + } |
70 | 69 |
|
71 | 70 |
|
72 | 71 | public SimpMessageType getMessageType() {
|
73 |
| - SimpMessageType type = messageTypes.get(this); |
74 |
| - return (type != null) ? type : SimpMessageType.OTHER; |
| 72 | + return this.messageType; |
75 | 73 | }
|
76 | 74 |
|
77 | 75 | public boolean requiresDestination() {
|
78 |
| - return destinationRequired.contains(this); |
| 76 | + return this.destination; |
79 | 77 | }
|
80 | 78 |
|
81 | 79 | public boolean requiresSubscriptionId() {
|
82 |
| - return subscriptionIdRequired.contains(this); |
| 80 | + return this.subscriptionId; |
83 | 81 | }
|
84 | 82 |
|
85 | 83 | public boolean requiresContentLength() {
|
86 |
| - return contentLengthRequired.contains(this); |
| 84 | + return this.body; |
87 | 85 | }
|
88 | 86 |
|
89 | 87 | public boolean isBodyAllowed() {
|
90 |
| - return bodyAllowed.contains(this); |
| 88 | + return this.body; |
91 | 89 | }
|
92 | 90 |
|
93 | 91 | }
|
94 |
| - |
0 commit comments