1f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair/*
2f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * Copyright 2007 the original author or authors.
3f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair *
4f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * you may not use this file except in compliance with the License.
6f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * You may obtain a copy of the License at
7f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair *
8f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair *
10f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * Unless required by applicable law or agreed to in writing, software
11f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * See the License for the specific language governing permissions and
14f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * limitations under the License.
15f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair */
16f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismairpackage org.mockftpserver.core.command;
17f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
18f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismairimport org.mockftpserver.core.session.Session;
19f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismairimport org.mockftpserver.core.util.AssertFailedException;
20f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismairimport org.mockftpserver.stub.command.AbstractStubCommandHandler;
21f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
22f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair/**
23f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * CommandHandler that sends back the configured reply code and text. You can customize the
24f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * returned reply code by setting the required <code>replyCode</code> property. If only the
25f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * <code>replyCode</code> property is set, then the default reply text corresponding to that
26f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * reply code is used in the response. You can optionally configure the reply text by setting
27f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * the <code>replyMessageKey</code> or <code>replyText</code> property.
28f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * <p>
29f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * Each invocation record stored by this CommandHandler contains no data elements.
30f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair *
31f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * @version $Revision$ - $Date$
32f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair *
33f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair * @author Chris Mair
34f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair */
35f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismairpublic final class StaticReplyCommandHandler extends AbstractStubCommandHandler implements CommandHandler {
36f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
37f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    /**
38f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * Create a new uninitialized instance
39f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     */
40f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    public StaticReplyCommandHandler() {
41f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    }
42f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
43f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    /**
44f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * Create a new instance with the specified replyCode
45f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * @param replyCode - the replyCode to use
46f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * @throws AssertFailedException - if the replyCode is null
47f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     */
48f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    public StaticReplyCommandHandler(int replyCode) {
49f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair        setReplyCode(replyCode);
50f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    }
51f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
52f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    /**
53f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * Create a new instance with the specified replyCode and replyText
54f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * @param replyCode - the replyCode to use
55f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * @param replyText - the replyText
56f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * @throws AssertFailedException - if the replyCode is null
57f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     */
58f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    public StaticReplyCommandHandler(int replyCode, String replyText) {
59f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair        setReplyCode(replyCode);
60f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair        setReplyText(replyText);
61f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    }
62f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
63f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    /**
64f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     * @see org.mockftpserver.core.command.CommandHandler#handleCommand(Command, Session, InvocationRecord)
65f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair     */
66f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) {
67f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair        sendReply(session);
68f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair    }
69f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair
70f688bc4bc07500f1548006ebbc4a0bd95f46b106chrismair}
71