Home | History | Annotate | Download | only in command
      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.mockftpserver.core.util.Assert;
     19 
     20 import java.util.ResourceBundle;
     21 
     22 /**
     23  * Contains common utility method to conditionally set the reply text ResourceBundle on a
     24  * CommandHandler instance.
     25  *
     26  * @version $Revision$ - $Date$
     27  *
     28  * @author Chris Mair
     29  */
     30 public final class ReplyTextBundleUtil {
     31 
     32     /**
     33      * Set the <code>replyTextBundle</code> property of the specified CommandHandler to the
     34      * <code>ResourceBundle</code> if and only if the <code>commandHandler</code> implements the
     35      * {@link ReplyTextBundleAware} interface AND its <code>replyTextBundle</code> property
     36      * has not been set (is null).
     37      *
     38      * @param commandHandler - the CommandHandler instance
     39      * @param replyTextBundle - the ResourceBundle to use for localizing reply text
     40      *
     41      * @throws org.mockftpserver.core.util.AssertFailedException - if the commandHandler is null
     42      */
     43     public static void setReplyTextBundleIfAppropriate(CommandHandler commandHandler, ResourceBundle replyTextBundle) {
     44         Assert.notNull(commandHandler, "commandHandler");
     45         if (commandHandler instanceof ReplyTextBundleAware) {
     46             ReplyTextBundleAware replyTextBundleAware = (ReplyTextBundleAware) commandHandler;
     47             if (replyTextBundleAware.getReplyTextBundle() == null) {
     48                 replyTextBundleAware.setReplyTextBundle(replyTextBundle);
     49             }
     50         }
     51     }
     52 
     53 }
     54