1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.example.stomp.websocket;
17
18 import io.netty.util.AttributeKey;
19 import io.netty.util.internal.StringUtil;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 public enum StompVersion {
25
26 STOMP_V11("1.1", "v11.stomp"),
27
28 STOMP_V12("1.2", "v12.stomp");
29
30 public static final AttributeKey<StompVersion> CHANNEL_ATTRIBUTE_KEY = AttributeKey.valueOf("stomp_version");
31 public static final String SUB_PROTOCOLS;
32
33 static {
34 List<String> subProtocols = new ArrayList<String>(values().length);
35 for (StompVersion stompVersion : values()) {
36 subProtocols.add(stompVersion.subProtocol);
37 }
38
39 SUB_PROTOCOLS = StringUtil.join(",", subProtocols).toString();
40 }
41
42 private final String version;
43 private final String subProtocol;
44
45 StompVersion(String version, String subProtocol) {
46 this.version = version;
47 this.subProtocol = subProtocol;
48 }
49
50 public String version() {
51 return version;
52 }
53
54 public String subProtocol() {
55 return subProtocol;
56 }
57
58 public static StompVersion findBySubProtocol(String subProtocol) {
59 if (subProtocol != null) {
60 for (StompVersion stompVersion : values()) {
61 if (stompVersion.subProtocol().equals(subProtocol)) {
62 return stompVersion;
63 }
64 }
65 }
66
67 throw new IllegalArgumentException("Not found StompVersion for '" + subProtocol + "'");
68 }
69 }