100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair/* 200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Copyright 2007 the original author or authors. 300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * you may not use this file except in compliance with the License. 600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * You may obtain a copy of the License at 700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * http://www.apache.org/licenses/LICENSE-2.0 900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 1000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Unless required by applicable law or agreed to in writing, software 1100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * distributed under the License is distributed on an "AS IS" BASIS, 1200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * See the License for the specific language governing permissions and 1400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * limitations under the License. 1500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 1600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismairpackage org.mockftpserver.core.command; 1700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 1800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismairimport org.mockftpserver.core.session.Session; 1900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 2000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair/** 2100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * The abstract superclass for CommandHandler classes that default to sending 2200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * back a configured reply code and text. You can customize the returned reply 2300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * code by setting the required <code>replyCode</code> property. If only the 2400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * <code>replyCode</code> property is set, then the default reply text corresponding to that 2500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * reply code is used in the response. You can optionally configure the reply text by setting 2600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * the <code>replyMessageKey</code> or <code>replyText</code> property. 2700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * <p> 2800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Subclasses can optionally override the reply code and/or text for the reply by calling 2900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * {@link #setReplyCode(int)}, {@link #setReplyMessageKey(String)} and {@link #setReplyText(String)}. 3000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 3100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @version $Revision$ - $Date$ 3200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 3300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @author Chris Mair 3400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 3500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismairpublic abstract class AbstractStaticReplyCommandHandler extends AbstractTrackingCommandHandler { 3600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 3700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // Defaults to zero; must be set to non-zero 3800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair protected int replyCode = 0; 3900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 4000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // Defaults to null; if set to non-null, this value will override the default reply text associated with 4100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // the replyCode. 4200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair protected String replyText = null; 4300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 4400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // The message key for the reply text. Defaults to null. If null, use the default message associated 4500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // with the reply code 4600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair protected String replyMessageKey = null; 4700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 4800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair /** 4900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Set the reply code. 5000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 5100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @param replyCode - the replyCode 5200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 5300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @throws org.mockftpserver.core.util.AssertFailedException - if the replyCode is not valid 5400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 5500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair public void setReplyCode(int replyCode) { 5600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair assertValidReplyCode(replyCode); 5700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair this.replyCode = replyCode; 5800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair } 5900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 6000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair /** 6100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Set the reply text. If null, then use the (default) message key for the replyCode. 6200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 6300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @param replyText - the replyText 6400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 6500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair public void setReplyText(String replyText) { 6600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair this.replyText = replyText; 6700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair } 6800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 6900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair /** 7000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Set the message key for the reply text. If null, then use the default message key. 7100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 7200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @param replyMessageKey - the replyMessageKey to set 7300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 7400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair public void setReplyMessageKey(String replyMessageKey) { 7500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair this.replyMessageKey = replyMessageKey; 7600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair } 7700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 7800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // ------------------------------------------------------------------------- 7900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // Utility methods for subclasses 8000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair // ------------------------------------------------------------------------- 8100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 8200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair /** 8300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Send the reply using the replyCode and message key/text configured for this command handler. 8400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @param session - the Session 8500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 8600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @throws org.mockftpserver.core.util.AssertFailedException if the replyCode is not valid 8700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 8800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair protected void sendReply(Session session) { 8900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair sendReply(session, null); 9000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair } 9100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 9200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair /** 9300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * Send the reply using the replyCode and message key/text configured for this command handler. 9400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @param session - the Session 9500dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @param messageParameter - message parameter; may be null 9600dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * 9700dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair * @throws org.mockftpserver.core.util.AssertFailedException if the replyCode is not valid 9800dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair */ 9900dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair protected void sendReply(Session session, Object messageParameter) { 10000dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair Object[] parameters = (messageParameter == null) ? null : new Object[] { messageParameter }; 10100dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair sendReply(session, replyCode, replyMessageKey, replyText, parameters); 10200dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair } 10300dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair 10400dc7bdcf1df9e86789d963984dfc6912a8854c6chrismair}