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, 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 4795 2013-04-21 09:09:02Z 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.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
66  // </editor-fold>
67  // SECTION-END
68  public interface Command
69  {
70      // SECTION-START[Command]
71  
72      /** Listener interface. */
73      public interface Listener
74      {
75  
76          /**
77           * Gets called on logging.
78           *
79           * @param level The level of the event.
80           * @param message The message of the event or {@code null}.
81           * @param t The throwable of the event or {@code null}.
82           *
83           * @throws NullPointerException if {@code level} is {@code null}.
84           */
85          void onLog( Level level, String message, Throwable t );
86  
87      }
88  
89      /** Status code when the command completed successfully. */
90      int STATUS_SUCCESS = 0;
91  
92      /** Status code when the command failed. */
93      int STATUS_FAILURE = 1;
94  
95      /**
96       * Gets the list of registered listeners.
97       *
98       * @return The list of registered listeners.
99       */
100     List<Listener> getListeners();
101 
102     /**
103      * Gets the log level of the instance.
104      *
105      * @return The log level of the instance.
106      *
107      * @see #setLogLevel(java.util.logging.Level)
108      */
109     Level getLogLevel();
110 
111     /**
112      * Sets the log level of the instance.
113      *
114      * @param value The new log level of the instance or {@code null}.
115      *
116      * @see #getLogLevel()
117      */
118     void setLogLevel( Level value );
119 
120     /**
121      * Gets the name of the command.
122      *
123      * @return The name of the command.
124      */
125     String getName();
126 
127     /**
128      * Gets the abbreviated name of the command.
129      *
130      * @return The abbreviated  name of the command.
131      */
132     String getAbbreviatedName();
133 
134     /**
135      * Gets the short description of the command.
136      *
137      * @param locale The locale of the short description to return.
138      *
139      * @return The short description of the command.
140      *
141      * @throws NullPointerException if {@code locale} is {@code null}.
142      */
143     String getShortDescription( Locale locale ) throws NullPointerException;
144 
145     /**
146      * Gets the long description of the command.
147      *
148      * @param locale The locale of the long description to return.
149      *
150      * @return The long description of the command.
151      *
152      * @throws NullPointerException if {@code locale} is {@code null}.
153      */
154     String getLongDescription( Locale locale ) throws NullPointerException;
155 
156     /**
157      * Gets the options of the command.
158      *
159      * @return The options of the command.
160      */
161     Options getOptions();
162 
163     /**
164      * Executes the command.
165      *
166      * @param commandLine Command line to execute.
167      *
168      * @return The status code to report.
169      *
170      * @throws NullPointerException if {@code commandLine} is {@code null}.
171      *
172      * @see #STATUS_SUCCESS
173      * @see #STATUS_FAILURE
174      */
175     int execute( CommandLine commandLine ) throws NullPointerException;
176 
177     // SECTION-END
178 }