summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/InCommand.java
blob: a1564d9ec58e6a8af93761ae2e7f461ae60ce8af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package f00f.net.irc.martyr;

import java.util.Iterator;

import f00f.net.irc.martyr.clientstate.ClientState;

/**
 * Defines commands that come from the server.  Errors and replies are
 * incoming commands.
 *
 * @see f00f.net.irc.martyr.errors.GenericError
 * @see f00f.net.irc.martyr.replies.GenericReply
 */
public interface InCommand extends Command
{

    /**
     * Some commands, when received by the server, can only occur in one
     * state.  Thus, when this command is received, the protocol should
     * assume that it is in that state, and a state change may be
     * triggered.  A command can use the 'unknown' state to indicate it
     * can be received in any state (for example, ping).
     *
     * @return State associated with command
     */
    State getState();

    /**
     * Every incoming command should know how to register itself with the
     * command register.
     *
     * @param commandRegister Command register we want to register with
     */
    void selfRegister( CommandRegister commandRegister );

    /**
     * Parses a string and produces a formed command object, if it can.
     * Should return null if it cannot form the command object.  The
     * identifier is usually ignored, except in the special case where
     * commands can be identified by multiple identifiers.  In that case,
     * the behaviour of the command may change in sublte ways.
     *
     * @param prefix Prefix of the command
     * @param identifier ID of the command
     * @param params Parameters of the command
     * @return InCommand instance for parsed command
     */
    InCommand parse( String prefix, String identifier, String params );

    /**
     * Gives the command a copy of the raw string from the server.  Called
     * by IRCConnection after the command is parsed.
     *
     * @param str Sets the source string to be parsed
     */
    void setSourceString( String str );

    /**
     * Allows a third party to receive a copy of the raw string.
     *
     * @return The original source string from the server
     */
    String getSourceString();

    /**
     * Asks the command to ensure that information it knows about the
     * state the server thinks the client is in matches what we have.
     * Returns true if state changes were made.
     *
     * @param state Client state to be updated
     * @return True or false if changes were made
     */
    boolean updateClientState( ClientState state );


    /**
     * Returns an iterator of String objects over the attribute names
     * for this command.  Warning: Still new, support for this is not
     * yet widespread.  Should return all possible attribute keys, not just
     * those that have a value in the current context.
     *
     * @return Iterator of attribute keys
     */
    Iterator getAttributeKeys();

    /**
     * Returns the attribute, or null if the attribute does not exist,
     * or is not defined.
     *
     * @param key Attribute to get value of
     * @return Attribute value or null if attribute doesn't exist
     */
    String getAttribute( String key );
    
}