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   * @author D.A. Smedes
25   * @version $Id: AuthenticationException.java,v 1.7 2004/11/02 22:26:44 asmedes Exp $
26   */
27  public class AuthenticationException extends Exception {
28  
29    private ErrorCode errorCode = null;
30    private Object[] messageArguments = null;
31  
32    /***
33     * This is the prefix that is shown when displaying the error.
34     */
35    public static final String EXCEPTION_PREFIX = "AUT-";
36    /***
37     * When the authenticator configuration is invalid. This is due to functional errors in the content of the
38     * <code>&lt;&authenticator&gt;</code>-element. Some locations require certain data to be available (username and
39     * password for a <code>pserver</code> location for instance).
40     */
41    public static final ErrorCode INVALID_AUTHENTICATOR_CONFIGURATION = new ErrorCode(EXCEPTION_PREFIX + "00001");
42    /***
43     * When the location-type requires authentication configuration to be present.
44     */
45    public static final ErrorCode MISSING_AUTHENTICATOR_CONFIGURATION = new ErrorCode(EXCEPTION_PREFIX + "00002");
46    /***
47     * No authenticator entry is configured that matches the location alias (the <code>id</code>-attribute).
48     */
49    public static final ErrorCode DUPLICATE_AUTHENTICATOR_KEY = new ErrorCode(EXCEPTION_PREFIX + "00003");
50    /***
51     * When the <code>authenticators.xml</code> file could not be read properly.
52     */
53    public static final ErrorCode AUTHENTICATOR_LOAD_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00004");
54    /***
55     * No authenticator entry is configured that matches the location alias (the <code>id</code>-attribute).
56     */
57    public static final ErrorCode AUTHENTICATOR_NOT_FOUND = new ErrorCode(EXCEPTION_PREFIX + "00005");
58    /*** Could not write <code>authenticators.xml</code> */
59    public static final ErrorCode AUTHENTICATOR_WRITE_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00006");
60    /*** Username is missing while configuring a new authenticator. */
61    public static final ErrorCode MISSING_USERNAME = new ErrorCode(EXCEPTION_PREFIX + "00007");
62  
63    public AuthenticationException(ErrorCode errorCode) {
64      this(errorCode, null);
65    }
66  
67    public AuthenticationException(Throwable t, ErrorCode errorCode) {
68      this(t, errorCode, null);
69    }
70  
71    public AuthenticationException(ErrorCode errorCode, Object[] messageArguments) {
72      super();
73      this.errorCode = errorCode;
74      this.messageArguments = messageArguments;
75    }
76  
77    public AuthenticationException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
78      super(t);
79      this.errorCode = errorCode;
80      this.messageArguments = messageArguments;
81    }
82  
83    public String getMessage() {
84      if (messageArguments != null && messageArguments.length > 0) {
85        errorCode.setMessageArguments(messageArguments);
86      }
87      return errorCode.getErrorMessage();
88    }
89  
90    /***
91     * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
92     */
93    public final ErrorCode getErrorCode() {
94      return errorCode;
95    }
96  
97    /***
98     * Retrieves the message arguments for this exception.
99     */
100   public final Object[] getMessageArguments() {
101     return messageArguments;
102   }
103 }