1 /**
2 This file is part of GoldenGate Project (named also GoldenGate or GG).
3
4 Copyright 2009, Frederic Bregier, and individual contributors by the @author
5 tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 individual contributors.
7
8 All GoldenGate Project is free software: you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published
10 by the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GoldenGate is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>.
20 */
21 package openr66.protocol.localhandler.packet;
22
23 import openr66.protocol.exception.OpenR66ProtocolPacketException;
24
25 import org.jboss.netty.buffer.ChannelBuffer;
26 import org.jboss.netty.buffer.ChannelBuffers;
27
28 /**
29 * Connection Error Message class for packet
30 *
31 * 2 strings: sheader,smiddle
32 *
33 * @author frederic bregier
34 */
35 public class ConnectionErrorPacket extends AbstractLocalPacket {
36
37 private final String sheader;
38
39 private final String smiddle;
40
41 /**
42 * @param headerLength
43 * @param middleLength
44 * @param endLength
45 * @param buf
46 * @return the new ErrorPacket from buffer
47 * @throws OpenR66ProtocolPacketException
48 */
49 public static ConnectionErrorPacket createFromBuffer(int headerLength,
50 int middleLength, int endLength, ChannelBuffer buf)
51 throws OpenR66ProtocolPacketException {
52 final byte[] bheader = new byte[headerLength - 1];
53 final byte[] bmiddle = new byte[middleLength];
54 if (headerLength - 1 > 0) {
55 buf.readBytes(bheader);
56 }
57 if (middleLength > 0) {
58 buf.readBytes(bmiddle);
59 }
60 return new ConnectionErrorPacket(new String(bheader), new String(
61 bmiddle));
62 }
63
64 /**
65 * @param header
66 * @param middle
67 */
68 public ConnectionErrorPacket(String header, String middle) {
69 sheader = header;
70 smiddle = middle;
71 }
72
73 /*
74 * (non-Javadoc)
75 *
76 * @see openr66.protocol.localhandler.packet.AbstractLocalPacket#createEnd()
77 */
78 @Override
79 public void createEnd() throws OpenR66ProtocolPacketException {
80 end = ChannelBuffers.EMPTY_BUFFER;
81 }
82
83 /*
84 * (non-Javadoc)
85 *
86 * @see
87 * openr66.protocol.localhandler.packet.AbstractLocalPacket#createHeader()
88 */
89 @Override
90 public void createHeader() throws OpenR66ProtocolPacketException {
91 if (sheader != null) {
92 header = ChannelBuffers.wrappedBuffer(sheader.getBytes());
93 }
94 }
95
96 /*
97 * (non-Javadoc)
98 *
99 * @see
100 * openr66.protocol.localhandler.packet.AbstractLocalPacket#createMiddle()
101 */
102 @Override
103 public void createMiddle() throws OpenR66ProtocolPacketException {
104 if (smiddle != null) {
105 middle = ChannelBuffers.wrappedBuffer(smiddle.getBytes());
106 }
107 }
108
109 /*
110 * (non-Javadoc)
111 *
112 * @see openr66.protocol.localhandler.packet.AbstractLocalPacket#toString()
113 */
114 @Override
115 public String toString() {
116 return "ConnectionErrorPacket: " + sheader + ":" + smiddle;
117 }
118
119 @Override
120 public byte getType() {
121 return LocalPacketFactory.CONNECTERRORPACKET;
122 }
123
124 /**
125 * @return the sheader
126 */
127 public String getSheader() {
128 return sheader;
129 }
130
131 /**
132 * @return the smiddle
133 */
134 public String getSmiddle() {
135 return smiddle;
136 }
137 }