View Javadoc
1   // SECTION-START[License Header]
2   // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3   /*
4    * Java Object Management and Configuration
5    * Copyright (C) Christian Schulte <cs@schulte.it>, 2005-206
6    * All rights reserved.
7    *
8    * Redistribution and use in source and binary forms, with or without
9    * modification, are permitted provided that the following conditions
10   * are met:
11   *
12   *   o Redistributions of source code must retain the above copyright
13   *     notice, this list of conditions and the following disclaimer.
14   *
15   *   o Redistributions in binary form must reproduce the above copyright
16   *     notice, this list of conditions and the following disclaimer in
17   *     the documentation and/or other materials provided with the
18   *     distribution.
19   *
20   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22   * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23   * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
24   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   * $JOMC: Command.java 5061 2015-05-31 13:20:40Z schulte $
32   *
33   */
34  // </editor-fold>
35  // SECTION-END
36  package org.jomc.cli;
37  
38  import java.util.List;
39  import java.util.Locale;
40  import java.util.logging.Level;
41  import org.apache.commons.cli.CommandLine;
42  import org.apache.commons.cli.Options;
43  
44  // SECTION-START[Documentation]
45  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
46  /**
47   * Command.
48   *
49   * <dl>
50   *   <dt><b>Identifier:</b></dt><dd>JOMC ⁑ CLI ⁑ Command</dd>
51   *   <dt><b>Multiplicity:</b></dt><dd>Many</dd>
52   *   <dt><b>Scope:</b></dt><dd>None</dd>
53   * </dl>
54   *
55   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
56   * @version 1.0
57   * @see org.jomc.ObjectManager#getObject(java.lang.Class) getObject(Command[].class)
58   * @see org.jomc.ObjectManager#getObject(java.lang.Class,java.lang.String) getObject(Command.class, "<i>implementation name</i>")
59   * @see org.jomc.ObjectManagerFactory
60   */
61  // </editor-fold>
62  // SECTION-END
63  // SECTION-START[Annotations]
64  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
65  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
66  // </editor-fold>
67  // SECTION-END
68  public interface Command
69  {
70      // SECTION-START[Command]
71  
72      /**
73       * Listener interface.
74       */
75      public interface Listener
76      {
77  
78          /**
79           * Gets called on logging.
80           *
81           * @param level The level of the event.
82           * @param message The message of the event or {@code null}.
83           * @param t The throwable of the event or {@code null}.
84           *
85           * @throws NullPointerException if {@code level} is {@code null}.
86           */
87          void onLog( Level level, String message, Throwable t );
88  
89      }
90  
91      /**
92       * Status code when the command completed successfully.
93       */
94      int STATUS_SUCCESS = 0;
95  
96      /**
97       * Status code when the command failed.
98       */
99      int STATUS_FAILURE = 1;
100 
101     /**
102      * Gets the list of registered listeners.
103      *
104      * @return The list of registered listeners.
105      */
106     List<Listener> getListeners();
107 
108     /**
109      * Gets the log level of the instance.
110      *
111      * @return The log level of the instance.
112      *
113      * @see #setLogLevel(java.util.logging.Level)
114      */
115     Level getLogLevel();
116 
117     /**
118      * Sets the log level of the instance.
119      *
120      * @param value The new log level of the instance or {@code null}.
121      *
122      * @see #getLogLevel()
123      */
124     void setLogLevel( Level value );
125 
126     /**
127      * Gets the name of the command.
128      *
129      * @return The name of the command.
130      */
131     String getName();
132 
133     /**
134      * Gets the abbreviated name of the command.
135      *
136      * @return The abbreviated name of the command.
137      */
138     String getAbbreviatedName();
139 
140     /**
141      * Gets the short description of the command.
142      *
143      * @param locale The locale of the short description to return.
144      *
145      * @return The short description of the command.
146      *
147      * @throws NullPointerException if {@code locale} is {@code null}.
148      */
149     String getShortDescription( Locale locale ) throws NullPointerException;
150 
151     /**
152      * Gets the long description of the command.
153      *
154      * @param locale The locale of the long description to return.
155      *
156      * @return The long description of the command.
157      *
158      * @throws NullPointerException if {@code locale} is {@code null}.
159      */
160     String getLongDescription( Locale locale ) throws NullPointerException;
161 
162     /**
163      * Gets the options of the command.
164      *
165      * @return The options of the command.
166      */
167     Options getOptions();
168 
169     /**
170      * Executes the command.
171      *
172      * @param commandLine Command line to execute.
173      *
174      * @return The status code to report.
175      *
176      * @throws NullPointerException if {@code commandLine} is {@code null}.
177      *
178      * @see #STATUS_SUCCESS
179      * @see #STATUS_FAILURE
180      */
181     int execute( CommandLine commandLine ) throws NullPointerException;
182 
183     // SECTION-END
184 }