View Javadoc

1   package fr.gedeon.telnetservice.coreexample1;
2   
3   import fr.gedeon.telnetservice.ActionListener;
4   import fr.gedeon.telnetservice.ActionListenerCreateException;
5   import fr.gedeon.telnetservice.OutputFormatSpi;
6   import fr.gedeon.telnetservice.Prompt;
7   import fr.gedeon.telnetservice.PromptDecorator;
8   import fr.gedeon.telnetservice.PromptDecoratorCreateException;
9   import fr.gedeon.telnetservice.PromptDecoratorInitializationException;
10  import fr.gedeon.telnetservice.SessionState;
11  import fr.gedeon.telnetservice.TelnetServiceExtension;
12  import fr.gedeon.telnetservice.TelnetServiceExtensionAbstractImpl;
13  import fr.gedeon.telnetservice.coreexample1.Example1.ServiceState;
14  
15  public class TelnetServiceExtensionExample1Impl
16      extends TelnetServiceExtensionAbstractImpl
17      implements TelnetServiceExtension
18  {
19      ServiceState serviceState;
20      OutputFormatSpi[] outputFormats;
21      
22      public TelnetServiceExtensionExample1Impl(ServiceState serviceState) {
23          this.serviceState = serviceState;
24          this.outputFormats = new OutputFormatSpi[] { new OutputFormatExample1Impl() };
25      }
26      
27      public String getName() {
28          return "Example1-Extension";
29      }
30  
31      public String getDescription() {
32          return "Extends the telnet service with basic demonstration functionality (Example 1)";
33      }
34  
35      public boolean providesActionListener() {
36          return true;
37      }
38  
39      public ActionListener getActionListener()
40          throws ActionListenerCreateException {
41          return new ActionListenerExample1Impl(this.serviceState);
42      }
43  
44      public boolean providesPromptDecorator() {
45          return true;
46      }
47  
48      public PromptDecorator getPromptDecorator()
49          throws PromptDecoratorCreateException {
50          return new PromptDecorator() {
51              public void initialize(SessionState sessionState)
52                  throws PromptDecoratorInitializationException {
53              }
54  
55              public boolean decoratePrompt(SessionState sessionState, Prompt prompt) {
56                  prompt.append("> ");
57                  return true;
58              }
59          };
60      }
61  
62      public boolean providesOutputFormats() {
63          return true;
64      }
65  
66      public OutputFormatSpi[] getOutputFormats() {
67          return this.outputFormats;
68      }
69  }