177391c2a01ce1fed085906743cc240a4d58edd92chrismair/*
277391c2a01ce1fed085906743cc240a4d58edd92chrismair * Copyright 2007 the original author or authors.
377391c2a01ce1fed085906743cc240a4d58edd92chrismair *
477391c2a01ce1fed085906743cc240a4d58edd92chrismair * Licensed under the Apache License, Version 2.0 (the "License");
577391c2a01ce1fed085906743cc240a4d58edd92chrismair * you may not use this file except in compliance with the License.
677391c2a01ce1fed085906743cc240a4d58edd92chrismair * You may obtain a copy of the License at
777391c2a01ce1fed085906743cc240a4d58edd92chrismair *
877391c2a01ce1fed085906743cc240a4d58edd92chrismair *      http://www.apache.org/licenses/LICENSE-2.0
977391c2a01ce1fed085906743cc240a4d58edd92chrismair *
1077391c2a01ce1fed085906743cc240a4d58edd92chrismair * Unless required by applicable law or agreed to in writing, software
1177391c2a01ce1fed085906743cc240a4d58edd92chrismair * distributed under the License is distributed on an "AS IS" BASIS,
1277391c2a01ce1fed085906743cc240a4d58edd92chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1377391c2a01ce1fed085906743cc240a4d58edd92chrismair * See the License for the specific language governing permissions and
1477391c2a01ce1fed085906743cc240a4d58edd92chrismair * limitations under the License.
1577391c2a01ce1fed085906743cc240a4d58edd92chrismair */
1677391c2a01ce1fed085906743cc240a4d58edd92chrismairpackage org.mockftpserver.core.command;
1777391c2a01ce1fed085906743cc240a4d58edd92chrismair
1877391c2a01ce1fed085906743cc240a4d58edd92chrismairimport java.util.ResourceBundle;
1977391c2a01ce1fed085906743cc240a4d58edd92chrismair
2077391c2a01ce1fed085906743cc240a4d58edd92chrismairimport org.mockftpserver.core.util.Assert;
2177391c2a01ce1fed085906743cc240a4d58edd92chrismair
2277391c2a01ce1fed085906743cc240a4d58edd92chrismair/**
2377391c2a01ce1fed085906743cc240a4d58edd92chrismair * Contains common utility method to conditionally set the reply text ResourceBundle on a
2477391c2a01ce1fed085906743cc240a4d58edd92chrismair * CommandHandler instance.
2577391c2a01ce1fed085906743cc240a4d58edd92chrismair *
2677391c2a01ce1fed085906743cc240a4d58edd92chrismair * @version $Revision$ - $Date$
2777391c2a01ce1fed085906743cc240a4d58edd92chrismair *
2877391c2a01ce1fed085906743cc240a4d58edd92chrismair * @author Chris Mair
2977391c2a01ce1fed085906743cc240a4d58edd92chrismair */
3077391c2a01ce1fed085906743cc240a4d58edd92chrismairpublic final class ReplyTextBundleUtil {
3177391c2a01ce1fed085906743cc240a4d58edd92chrismair
3277391c2a01ce1fed085906743cc240a4d58edd92chrismair    /**
3377391c2a01ce1fed085906743cc240a4d58edd92chrismair     * Set the <code>replyTextBundle</code> property of the specified CommandHandler to the
3477391c2a01ce1fed085906743cc240a4d58edd92chrismair     * <code>ResourceBundle</code> if and only if the <code>commandHandler</code> implements the
3577391c2a01ce1fed085906743cc240a4d58edd92chrismair     * {@link ReplyTextBundleAware} interface AND its <code>replyTextBundle</code> property
3677391c2a01ce1fed085906743cc240a4d58edd92chrismair     * has not been set (is null).
3777391c2a01ce1fed085906743cc240a4d58edd92chrismair     *
3877391c2a01ce1fed085906743cc240a4d58edd92chrismair     * @param commandHandler - the CommandHandler instance
3977391c2a01ce1fed085906743cc240a4d58edd92chrismair     * @param replyTextBundle - the ResourceBundle to use for localizing reply text
4077391c2a01ce1fed085906743cc240a4d58edd92chrismair     *
4177391c2a01ce1fed085906743cc240a4d58edd92chrismair     * @throws AssertFailedException - if the commandHandler is null
4277391c2a01ce1fed085906743cc240a4d58edd92chrismair     */
4377391c2a01ce1fed085906743cc240a4d58edd92chrismair    public static void setReplyTextBundleIfAppropriate(CommandHandler commandHandler, ResourceBundle replyTextBundle) {
4477391c2a01ce1fed085906743cc240a4d58edd92chrismair        Assert.notNull(commandHandler, "commandHandler");
4577391c2a01ce1fed085906743cc240a4d58edd92chrismair        if (commandHandler instanceof ReplyTextBundleAware) {
4677391c2a01ce1fed085906743cc240a4d58edd92chrismair            ReplyTextBundleAware replyTextBundleAware = (ReplyTextBundleAware) commandHandler;
4777391c2a01ce1fed085906743cc240a4d58edd92chrismair            if (replyTextBundleAware.getReplyTextBundle() == null) {
4877391c2a01ce1fed085906743cc240a4d58edd92chrismair                replyTextBundleAware.setReplyTextBundle(replyTextBundle);
4977391c2a01ce1fed085906743cc240a4d58edd92chrismair            }
5077391c2a01ce1fed085906743cc240a4d58edd92chrismair        }
5177391c2a01ce1fed085906743cc240a4d58edd92chrismair    }
5277391c2a01ce1fed085906743cc240a4d58edd92chrismair
5377391c2a01ce1fed085906743cc240a4d58edd92chrismair}
54