177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/* 277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Copyright 2007 the original author or authors. 377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * you may not use this file except in compliance with the License. 677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * You may obtain a copy of the License at 777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * http://www.apache.org/licenses/LICENSE-2.0 977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 1077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Unless required by applicable law or agreed to in writing, software 1177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * distributed under the License is distributed on an "AS IS" BASIS, 1277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * See the License for the specific language governing permissions and 1477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * limitations under the License. 1577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 1677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairpackage org.mockftpserver.core.command; 1777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 1877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.session.Session; 1977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 2077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/** 2177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * The abstract superclass for CommandHandler classes that default to sending 2277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * back a configured reply code and text. You can customize the returned reply 2377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * code by setting the required <code>replyCode</code> property. If only the 2477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * <code>replyCode</code> property is set, then the default reply text corresponding to that 2577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * reply code is used in the response. You can optionally configure the reply text by setting 2677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * the <code>replyMessageKey</code> or <code>replyText</code> property. 2777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * <p> 2877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Subclasses can optionally override the reply code and/or text for the reply by calling 2977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * {@link #setReplyCode(int)}, {@link #setReplyMessageKey(String)} and {@link #setReplyText(String)}. 3077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 3177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @version $Revision$ - $Date$ 3277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 3377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @author Chris Mair 3477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 3577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairpublic abstract class AbstractStaticReplyCommandHandler extends AbstractTrackingCommandHandler { 3677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 3777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // Defaults to zero; must be set to non-zero 3877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected int replyCode = 0; 3977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 4077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // Defaults to null; if set to non-null, this value will override the default reply text associated with 4177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // the replyCode. 4277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected String replyText = null; 4377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 4477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // The message key for the reply text. Defaults to null. If null, use the default message associated 4577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // with the reply code 4677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected String replyMessageKey = null; 4777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 4877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 4977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Set the reply code. 5077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 5177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @param replyCode - the replyCode 5277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 5377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @throws org.mockftpserver.core.util.AssertFailedException - if the replyCode is not valid 5477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 5577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair public void setReplyCode(int replyCode) { 5677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair assertValidReplyCode(replyCode); 5777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair this.replyCode = replyCode; 5877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 5977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 6177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Set the reply text. If null, then use the (default) message key for the replyCode. 6277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 6377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @param replyText - the replyText 6477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 6577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair public void setReplyText(String replyText) { 6677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair this.replyText = replyText; 6777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 6877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 7077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Set the message key for the reply text. If null, then use the default message key. 7177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 7277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @param replyMessageKey - the replyMessageKey to set 7377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 7477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair public void setReplyMessageKey(String replyMessageKey) { 7577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair this.replyMessageKey = replyMessageKey; 7677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 7777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 7877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // ------------------------------------------------------------------------- 7977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // Utility methods for subclasses 8077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // ------------------------------------------------------------------------- 8177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 8277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 8377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Send the reply using the replyCode and message key/text configured for this command handler. 8477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @param session - the Session 8577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 8677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @throws org.mockftpserver.core.util.AssertFailedException if the replyCode is not valid 8777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 8877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected void sendReply(Session session) { 8977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair sendReply(session, null); 9077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 9177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 9277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 9377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Send the reply using the replyCode and message key/text configured for this command handler. 9477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @param session - the Session 9577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @param messageParameter - message parameter; may be null 9677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 9777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @throws org.mockftpserver.core.util.AssertFailedException if the replyCode is not valid 9877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 9977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected void sendReply(Session session, Object messageParameter) { 10077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair Object[] parameters = (messageParameter == null) ? null : new Object[] { messageParameter }; 10177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair sendReply(session, replyCode, replyMessageKey, replyText, parameters); 10277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 10377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 10477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair}