001 // SECTION-START[License Header]
002 // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003 /*
004 * Copyright (c) 2009 The JOMC Project
005 * Copyright (c) 2005 Christian Schulte <cs@jomc.org>
006 * All rights reserved.
007 *
008 * Redistribution and use in source and binary forms, with or without
009 * modification, are permitted provided that the following conditions
010 * are met:
011 *
012 * o Redistributions of source code must retain the above copyright
013 * notice, this list of conditions and the following disclaimer.
014 *
015 * o Redistributions in binary form must reproduce the above copyright
016 * notice, this list of conditions and the following disclaimer in
017 * the documentation and/or other materials provided with the
018 * distribution.
019 *
020 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 *
032 * $Id: Command.java 1102 2009-12-07 03:01:58Z schulte2005 $
033 *
034 */
035 // </editor-fold>
036 // SECTION-END
037 package org.jomc.cli;
038
039 import java.util.List;
040 import java.util.Locale;
041 import java.util.logging.Level;
042 import org.apache.commons.cli.CommandLine;
043 import org.apache.commons.cli.Options;
044
045 // SECTION-START[Documentation]
046 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
047 /**
048 * Command.
049 * <p>This specification declares a multiplicity of {@code Many}.
050 * An application assembler may provide multiple implementations of this specification (including none).
051 * Use of class {@link org.jomc.ObjectManager ObjectManager} is supported for getting these implementations or for
052 * selecting a single implementation.<pre>
053 * Command[] objects = (Command[]) ObjectManagerFactory.getObjectManager( getClassLoader() ).getObject( Command.class );
054 * Command object = ObjectManagerFactory.getObjectManager( getClassLoader() ).getObject( Command.class, "<i>implementation name</i>" );
055 * </pre>
056 * </p>
057 *
058 * <p>This specification does not apply to any scope. A new object is returned whenever requested.</p>
059 *
060 * @author <a href="mailto:cs@jomc.org">Christian Schulte</a> 1.0
061 * @version $Id: Command.java 1102 2009-12-07 03:01:58Z schulte2005 $
062 */
063 // </editor-fold>
064 // SECTION-END
065 // SECTION-START[Annotations]
066 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
067 @javax.annotation.Generated( value = "org.jomc.tools.JavaSources",
068 comments = "See http://jomc.sourceforge.net/jomc/1.0-alpha-11/jomc-tools" )
069 // </editor-fold>
070 // SECTION-END
071 public interface Command
072 {
073 // SECTION-START[Command]
074
075 /** Listener interface. */
076 public interface Listener
077 {
078
079 /**
080 * Get called on logging.
081 *
082 * @param level The level of the event.
083 * @param message The message of the event or {@code null}.
084 * @param t The throwable of the event or {@code null}.
085 *
086 * @throws NullPointerException if {@code level} is {@code null}.
087 */
088 void onLog( Level level, String message, Throwable t );
089
090 }
091
092 /** Status code when the command completed successfully. */
093 int STATUS_SUCCESS = 0;
094
095 /** Status code when the command failed. */
096 int STATUS_FAILURE = 1;
097
098 /**
099 * Gets the list of registered listeners.
100 *
101 * @return The list of registered listeners.
102 */
103 List<Listener> getListeners();
104
105 /**
106 * Gets the log level of the instance.
107 *
108 * @return The log level of the instance.
109 *
110 * @see #setLogLevel(java.util.logging.Level)
111 */
112 Level getLogLevel();
113
114 /**
115 * Sets the log level of the instance.
116 *
117 * @param value The new log level of the instance or {@code null}.
118 *
119 * @see #getLogLevel()
120 */
121 void setLogLevel( Level value );
122
123 /**
124 * Gets the name of the command.
125 *
126 * @return The name of the command.
127 */
128 String getName();
129
130 /**
131 * Gets the abbreviated name of the command.
132 *
133 * @return The abbreviated name of the command.
134 */
135 String getAbbreviatedName();
136
137 /**
138 * Gets the short description of the command.
139 *
140 * @param locale The locale of the short description to return.
141 *
142 * @return The short description of the command.
143 *
144 * @throws NullPointerException if {@code locale} is {@code null}.
145 */
146 String getShortDescription( Locale locale ) throws NullPointerException;
147
148 /**
149 * Gets the long description of the command.
150 *
151 * @param locale The locale of the long description to return.
152 *
153 * @return The long description of the command.
154 *
155 * @throws NullPointerException if {@code locale} is {@code null}.
156 */
157 String getLongDescription( Locale locale ) throws NullPointerException;
158
159 /**
160 * Gets the options of the command.
161 *
162 * @return The options of the command.
163 */
164 Options getOptions();
165
166 /**
167 * Executes the command.
168 *
169 * @param commandLine Command line to execute.
170 *
171 * @return The status code of the command.
172 *
173 * @throws NullPointerException if {@code commandLine} is {@code null}.
174 *
175 * @see #STATUS_SUCCESS
176 * @see #STATUS_FAILURE
177 */
178 int execute( CommandLine commandLine ) throws NullPointerException;
179
180 // SECTION-END
181 }