1 package org.apache.commons.net;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Commons" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.util.EventObject;
58
59 /****
60 * There exists a large class of IETF protocols that work by sending an
61 * ASCII text command and arguments to a server, and then receiving an
62 * ASCII text reply. For debugging and other purposes, it is extremely
63 * useful to log or keep track of the contents of the protocol messages.
64 * The ProtocolCommandEvent class coupled with the
65 * <a href="org.apache.commons.net.ProtocolCommandListener.html">
66 * ProtocolCommandListener </a> interface facilitate this process.
67 * <p>
68 * <p>
69 * @see ProtocolCommandListener
70 * @see ProtocolCommandSupport
71 * @author Daniel F. Savarese
72 ***/
73
74 public class ProtocolCommandEvent extends EventObject
75 {
76 private int __replyCode;
77 private boolean __isCommand;
78 private String __message, __command;
79
80 /****
81 * Creates a ProtocolCommandEvent signalling a command was sent to
82 * the server. ProtocolCommandEvents created with this constructor
83 * should only be sent after a command has been sent, but before the
84 * reply has been received.
85 * <p>
86 * @param source The source of the event.
87 * @param command The string representation of the command type sent, not
88 * including the arguments (e.g., "STAT" or "GET").
89 * @param message The entire command string verbatim as sent to the server,
90 * including all arguments.
91 ***/
92 public ProtocolCommandEvent(Object source, String command, String message)
93 {
94 super(source);
95 __replyCode = 0;
96 __message = message;
97 __isCommand = true;
98 __command = command;
99 }
100
101
102 /****
103 * Creates a ProtocolCommandEvent signalling a reply to a command was
104 * received. ProtocolCommandEvents created with this constructor
105 * should only be sent after a complete command reply has been received
106 * fromt a server.
107 * <p>
108 * @param source The source of the event.
109 * @param replyCode The integer code indicating the natureof the reply.
110 * This will be the protocol integer value for protocols
111 * that use integer reply codes, or the reply class constant
112 * corresponding to the reply for protocols like POP3 that use
113 * strings like OK rather than integer codes (i.e., POP3Repy.OK).
114 * @param message The entire reply as received from the server.
115 ***/
116 public ProtocolCommandEvent(Object source, int replyCode, String message)
117 {
118 super(source);
119 __replyCode = replyCode;
120 __message = message;
121 __isCommand = false;
122 __command = null;
123 }
124
125 /****
126 * Returns the string representation of the command type sent (e.g., "STAT"
127 * or "GET"). If the ProtocolCommandEvent is a reply event, then null
128 * is returned.
129 * <p>
130 * @return The string representation of the command type sent, or null
131 * if this is a reply event.
132 ***/
133 public String getCommand()
134 {
135 return __command;
136 }
137
138
139 /****
140 * Returns the reply code of the received server reply. Undefined if
141 * this is not a reply event.
142 * <p>
143 * @return The reply code of the received server reply. Undefined if
144 * not a reply event.
145 ***/
146 public int getReplyCode()
147 {
148 return __replyCode;
149 }
150
151 /****
152 * Returns true if the ProtocolCommandEvent was generated as a result
153 * of sending a command.
154 * <p>
155 * @return true If the ProtocolCommandEvent was generated as a result
156 * of sending a command. False otherwise.
157 ***/
158 public boolean isCommand()
159 {
160 return __isCommand;
161 }
162
163 /****
164 * Returns true if the ProtocolCommandEvent was generated as a result
165 * of receiving a reply.
166 * <p>
167 * @return true If the ProtocolCommandEvent was generated as a result
168 * of receiving a reply. False otherwise.
169 ***/
170 public boolean isReply()
171 {
172 return !isCommand();
173 }
174
175 /****
176 * Returns the entire message sent to or received from the server.
177 * <p>
178 * @return The entire message sent to or received from the server.
179 ***/
180 public String getMessage()
181 {
182 return __message;
183 }
184 }
This page was automatically generated by Maven