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.vc;
20  
21  import nl.toolforge.karma.core.ErrorCode;
22  
23  /***
24   * Root exception for stuff relating to version control system functionality.
25   *
26   * @author D.A. Smedes
27   * @version $Id: VersionControlException.java,v 1.19 2004/11/02 22:26:44 asmedes Exp $
28   */
29  public abstract class VersionControlException extends Exception {
30  
31    private ErrorCode errorCode = null;
32    private Object[] messageArguments = null;
33  
34    public static String EXCEPTION_PREFIX = "VER-";
35    /*** Version already exists for this module. */
36    public static final ErrorCode DUPLICATE_VERSION = new ErrorCode(EXCEPTION_PREFIX + "00001");
37    /*** The requested module does not exist in the repository */
38    public static final ErrorCode MODULE_NOT_IN_REPOSITORY = new ErrorCode(EXCEPTION_PREFIX + "00002");
39    /*** A <code>Location</code> instance was required, but missing. */
40    public static final ErrorCode MISSING_LOCATION = new ErrorCode(EXCEPTION_PREFIX + "00003");;
41  
42  
43    public VersionControlException(ErrorCode errorCode) {
44      this(errorCode, null);
45    }
46  
47    public VersionControlException(Throwable t, ErrorCode errorCode) {
48      this(t, errorCode, null);
49    }
50  
51    public VersionControlException(ErrorCode errorCode, Object[] messageArguments) {
52      super();
53      this.errorCode = errorCode;
54      this.messageArguments = messageArguments;
55    }
56    
57    public VersionControlException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
58      super(t);
59      this.errorCode = errorCode;
60      this.messageArguments = messageArguments;
61    }
62  
63    public String getMessage() {
64      if (messageArguments != null && messageArguments.length > 0) {
65        errorCode.setMessageArguments(messageArguments);
66      }
67      return getErrorCode().getErrorMessage();
68    }
69  
70    /***
71     * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
72     * @return
73     */
74    public final ErrorCode getErrorCode() {
75      return errorCode;
76    }
77  
78    public final Object[] getMessageArguments() {
79      return messageArguments;
80    }
81  }