View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  package nl.toolforge.karma.core.cmd;
20  
21  import nl.toolforge.karma.core.ErrorCode;
22  
23  /***
24   * Thrown when command loading failed.
25   *
26   * @author D.A. Smedes
27   * @version $Id: CommandLoadException.java,v 1.8 2004/11/02 23:57:05 asmedes Exp $
28   */
29  public class CommandLoadException extends Exception {
30  
31    private ErrorCode errorCode = null;
32    private Object[] messageArguments = null;
33  
34    public static final String EXCEPTION_PREFIX = "CML-";
35  
36    public static final ErrorCode LOAD_FAILURE_FOR_DEFAULT_COMMANDS = new ErrorCode(EXCEPTION_PREFIX + "00001");
37  
38    public static final ErrorCode LOAD_FAILURE_FOR_PLUGIN_COMMANDS_FILE = new ErrorCode(EXCEPTION_PREFIX + "00002");
39    
40    public static final ErrorCode DUPLICATE_COMMAND = new ErrorCode(EXCEPTION_PREFIX + "00003");
41  
42    public CommandLoadException(ErrorCode errorCode) {
43      this(errorCode, null);
44    }
45  
46    public CommandLoadException(ErrorCode errorCode, Object[] messageArguments) {
47      super();
48      this.errorCode = errorCode;
49      this.messageArguments = messageArguments;
50    }
51  
52    public CommandLoadException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
53      super(t);
54      this.errorCode = errorCode;
55      this.messageArguments = messageArguments;
56    }
57  
58    public String getMessage() {
59      if (messageArguments != null && messageArguments.length > 0) {
60        errorCode.setMessageArguments(messageArguments);
61      }
62      return errorCode.getErrorMessage();
63    }
64  
65    /***
66     * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
67     * @return
68     */
69    public final ErrorCode getErrorCode() {
70      return errorCode;
71    }
72  
73    public final Object[] getMessageArguments() {
74      return messageArguments;
75    }
76  
77  
78  
79  }