| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractCommandHandler |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2007 the original author or authors. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.mockftpserver.core.command; | |
| 17 | ||
| 18 | import org.slf4j.Logger; | |
| 19 | import org.slf4j.LoggerFactory; | |
| 20 | import org.mockftpserver.core.util.Assert; | |
| 21 | ||
| 22 | import java.util.ResourceBundle; | |
| 23 | ||
| 24 | /** | |
| 25 | * The abstract superclass for CommandHandler classes. | |
| 26 | * | |
| 27 | * @author Chris Mair | |
| 28 | * @version $Revision: 264 $ - $Date: 2012-07-17 21:19:23 -0400 (Tue, 17 Jul 2012) $ | |
| 29 | */ | |
| 30 | 5346 | public abstract class AbstractCommandHandler implements CommandHandler, ReplyTextBundleAware { |
| 31 | ||
| 32 | 5346 | protected final Logger LOG = LoggerFactory.getLogger(getClass()); |
| 33 | ||
| 34 | private ResourceBundle replyTextBundle; | |
| 35 | ||
| 36 | //------------------------------------------------------------------------- | |
| 37 | // Support for reply text ResourceBundle | |
| 38 | //------------------------------------------------------------------------- | |
| 39 | ||
| 40 | /** | |
| 41 | * Return the ResourceBundle containing the reply text messages | |
| 42 | * | |
| 43 | * @return the replyTextBundle | |
| 44 | * @see ReplyTextBundleAware#getReplyTextBundle() | |
| 45 | */ | |
| 46 | public ResourceBundle getReplyTextBundle() { | |
| 47 | 5582 | return replyTextBundle; |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Set the ResourceBundle containing the reply text messages | |
| 52 | * | |
| 53 | * @param replyTextBundle - the replyTextBundle to set | |
| 54 | * @see ReplyTextBundleAware#setReplyTextBundle(java.util.ResourceBundle) | |
| 55 | */ | |
| 56 | public void setReplyTextBundle(ResourceBundle replyTextBundle) { | |
| 57 | 5255 | this.replyTextBundle = replyTextBundle; |
| 58 | 5255 | } |
| 59 | ||
| 60 | // ------------------------------------------------------------------------- | |
| 61 | // Utility methods for subclasses | |
| 62 | // ------------------------------------------------------------------------- | |
| 63 | ||
| 64 | /** | |
| 65 | * Return the specified text surrounded with double quotes | |
| 66 | * | |
| 67 | * @param text - the text to surround with quotes | |
| 68 | * @return the text with leading and trailing double quotes | |
| 69 | * @throws org.mockftpserver.core.util.AssertFailedException | |
| 70 | * - if text is null | |
| 71 | */ | |
| 72 | protected static String quotes(String text) { | |
| 73 | 18 | Assert.notNull(text, "text"); |
| 74 | 17 | final String QUOTES = "\""; |
| 75 | 17 | return QUOTES + text + QUOTES; |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * Assert that the specified number is a valid reply code | |
| 80 | * | |
| 81 | * @param replyCode - the reply code to check | |
| 82 | * @throws org.mockftpserver.core.util.AssertFailedException | |
| 83 | * - if the replyCode is invalid | |
| 84 | */ | |
| 85 | protected void assertValidReplyCode(int replyCode) { | |
| 86 | 3365 | Assert.isTrue(replyCode > 0, "The number [" + replyCode + "] is not a valid reply code"); |
| 87 | 3351 | } |
| 88 | ||
| 89 | } |