001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.transport.stomp;
018
019import java.util.Locale;
020
021public interface Stomp {
022    String NULL = "\u0000";
023    String NEWLINE = "\n";
024
025    byte BREAK = '\n';
026    byte COLON = ':';
027    byte ESCAPE = '\\';
028    byte[] ESCAPE_ESCAPE_SEQ = { 92, 92 };
029    byte[] COLON_ESCAPE_SEQ = { 92, 99 };
030    byte[] NEWLINE_ESCAPE_SEQ = { 92, 110 };
031
032    String COMMA = ",";
033    String V1_0 = "1.0";
034    String V1_1 = "1.1";
035    String V1_2 = "1.2";
036    String DEFAULT_HEART_BEAT = "0,0";
037    String DEFAULT_VERSION = "1.0";
038    String EMPTY = "";
039
040    String[] SUPPORTED_PROTOCOL_VERSIONS = {"1.2", "1.1", "1.0"};
041
042    String TEXT_PLAIN = "text/plain";
043    String TRUE = "true";
044    String FALSE = "false";
045    String END = "end";
046
047    public static interface Commands {
048        String STOMP = "STOMP";
049        String CONNECT = "CONNECT";
050        String SEND = "SEND";
051        String DISCONNECT = "DISCONNECT";
052        String SUBSCRIBE = "SUBSCRIBE";
053        String UNSUBSCRIBE = "UNSUBSCRIBE";
054
055        // Preserve legacy incorrect allow shortened names for
056        // subscribe and un-subscribe as it has been there for so
057        // long that someone has undoubtedly come to expect it.
058        String SUBSCRIBE_PREFIX = "SUB";
059        String UNSUBSCRIBE_PREFIX = "UNSUB";
060
061        String BEGIN_TRANSACTION = "BEGIN";
062        String COMMIT_TRANSACTION = "COMMIT";
063        String ABORT_TRANSACTION = "ABORT";
064        String BEGIN = "BEGIN";
065        String COMMIT = "COMMIT";
066        String ABORT = "ABORT";
067        String ACK = "ACK";
068        String NACK = "NACK";
069        String KEEPALIVE = "KEEPALIVE";
070    }
071
072    public interface Responses {
073        String CONNECTED = "CONNECTED";
074        String ERROR = "ERROR";
075        String MESSAGE = "MESSAGE";
076        String RECEIPT = "RECEIPT";
077    }
078
079    public interface Headers {
080        String SEPERATOR = ":";
081        String RECEIPT_REQUESTED = "receipt";
082        String TRANSACTION = "transaction";
083        String CONTENT_LENGTH = "content-length";
084        String CONTENT_TYPE = "content-type";
085        String TRANSFORMATION = "transformation";
086        String TRANSFORMATION_ERROR = "transformation-error";
087
088        /**
089         * This header is used to instruct ActiveMQ to construct the message
090         * based with a specific type.
091         */
092        String AMQ_MESSAGE_TYPE = "amq-msg-type";
093
094        public interface Response {
095            String RECEIPT_ID = "receipt-id";
096        }
097
098        public interface Send {
099            String DESTINATION = "destination";
100            String CORRELATION_ID = "correlation-id";
101            String REPLY_TO = "reply-to";
102            String EXPIRATION_TIME = "expires";
103            String PRIORITY = "priority";
104            String TYPE = "type";
105            String PERSISTENT = "persistent";
106        }
107
108        public interface Message {
109            String MESSAGE_ID = "message-id";
110            String ACK_ID = "ack";
111            String DESTINATION = "destination";
112            String CORRELATION_ID = "correlation-id";
113            String EXPIRATION_TIME = "expires";
114            String REPLY_TO = "reply-to";
115            String PRORITY = "priority";
116            String REDELIVERED = "redelivered";
117            String TIMESTAMP = "timestamp";
118            String TYPE = "type";
119            String SUBSCRIPTION = "subscription";
120            String BROWSER = "browser";
121            String USERID = "JMSXUserID";
122            String ORIGINAL_DESTINATION = "original-destination";
123            String PERSISTENT = "persistent";
124        }
125
126        public interface Subscribe {
127            String DESTINATION = "destination";
128            String ACK_MODE = "ack";
129            String ID = "id";
130            String SELECTOR = "selector";
131            String BROWSER = "browser";
132
133            public interface AckModeValues {
134                String AUTO = "auto";
135                String CLIENT = "client";
136                String INDIVIDUAL = "client-individual";
137            }
138        }
139
140        public interface Unsubscribe {
141            String DESTINATION = "destination";
142            String ID = "id";
143        }
144
145        public interface Connect {
146            String LOGIN = "login";
147            String PASSCODE = "passcode";
148            String CLIENT_ID = "client-id";
149            String REQUEST_ID = "request-id";
150            String ACCEPT_VERSION = "accept-version";
151            String HOST = "host";
152            String HEART_BEAT = "heart-beat";
153        }
154
155        public interface Error {
156            String MESSAGE = "message";
157        }
158
159        public interface Connected {
160            String SESSION = "session";
161            String RESPONSE_ID = "response-id";
162            String SERVER = "server";
163            String VERSION = "version";
164            String HEART_BEAT = "heart-beat";
165        }
166
167        public interface Ack {
168            String MESSAGE_ID = "message-id";
169            String SUBSCRIPTION = "subscription";
170            String ACK_ID = "id";
171        }
172    }
173
174    public enum Transformations {
175        JMS_BYTE,
176        JMS_XML,
177        JMS_JSON,
178        JMS_OBJECT_XML,
179        JMS_OBJECT_JSON,
180        JMS_MAP_XML,
181        JMS_MAP_JSON,
182        JMS_ADVISORY_XML,
183        JMS_ADVISORY_JSON;
184
185        @Override
186        public String toString() {
187            return name().replaceAll("_", "-").toLowerCase(Locale.ENGLISH);
188        }
189
190        public boolean equals(String value) {
191            return toString().equals(value);
192        }
193
194        public static Transformations getValue(String value) {
195            return valueOf(value.replaceAll("-", "_").toUpperCase(Locale.ENGLISH));
196        }
197    }
198}