KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > stomp > StompFrame


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport.stomp;
19
20 import java.util.Arrays JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.activemq.command.Command;
27 import org.apache.activemq.command.Endpoint;
28 import org.apache.activemq.command.Response;
29 import org.apache.activemq.state.CommandVisitor;
30
31 /**
32  * Represents all the data in a STOMP frame.
33  *
34  * @author <a HREF="http://hiramchirino.com">chirino</a>
35  */

36 public class StompFrame implements Command {
37
38     private static final byte[] NO_DATA = new byte[]{};
39
40     private String JavaDoc action;
41     private Map JavaDoc headers = Collections.EMPTY_MAP;
42     private byte[] content = NO_DATA;
43
44     public StompFrame(String JavaDoc command, HashMap JavaDoc headers, byte[] data) {
45         this.action = command;
46         this.headers = headers;
47         this.content = data;
48     }
49
50     public StompFrame() {
51     }
52
53     public String JavaDoc getAction() {
54         return action;
55     }
56
57     public void setAction(String JavaDoc command) {
58         this.action = command;
59     }
60
61     public byte[] getContent() {
62         return content;
63     }
64
65     public void setContent(byte[] data) {
66         this.content = data;
67     }
68
69     public Map JavaDoc getHeaders() {
70         return headers;
71     }
72
73     public void setHeaders(Map JavaDoc headers) {
74         this.headers = headers;
75     }
76
77     //
78
// Methods in the Command interface
79
//
80
public int getCommandId() {
81         return 0;
82     }
83
84     public Endpoint getFrom() {
85         return null;
86     }
87
88     public Endpoint getTo() {
89         return null;
90     }
91
92     public boolean isBrokerInfo() {
93         return false;
94     }
95
96     public boolean isMessage() {
97         return false;
98     }
99
100     public boolean isMessageAck() {
101         return false;
102     }
103
104     public boolean isMessageDispatch() {
105         return false;
106     }
107
108     public boolean isMessageDispatchNotification() {
109         return false;
110     }
111
112     public boolean isResponse() {
113         return false;
114     }
115
116     public boolean isResponseRequired() {
117         return false;
118     }
119
120     public boolean isShutdownInfo() {
121         return false;
122     }
123
124     public boolean isWireFormatInfo() {
125         return false;
126     }
127
128     public void setCommandId(int value) {
129     }
130
131     public void setFrom(Endpoint from) {
132     }
133
134     public void setResponseRequired(boolean responseRequired) {
135     }
136
137     public void setTo(Endpoint to) {
138     }
139
140     public Response visit(CommandVisitor visitor) throws Exception JavaDoc {
141         return null;
142     }
143
144     public byte getDataStructureType() {
145         return 0;
146     }
147
148     public boolean isMarshallAware() {
149         return false;
150     }
151
152     public String JavaDoc toString() {
153         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
154         buffer.append(getAction());
155         buffer.append("\n");
156         Map JavaDoc headers = getHeaders();
157         for (Iterator JavaDoc iter = headers.entrySet().iterator(); iter.hasNext();) {
158             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
159             buffer.append(entry.getKey());
160             buffer.append(":");
161             buffer.append(entry.getValue());
162             buffer.append("\n");
163         }
164         buffer.append("\n");
165         if( getContent()!=null ) {
166             try {
167                 buffer.append(new String JavaDoc(getContent()));
168             } catch (Throwable JavaDoc e) {
169                 buffer.append(Arrays.toString(getContent()));
170             }
171         }
172         return buffer.toString();
173     }
174 }
175
Popular Tags