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.location;
20  
21  import nl.toolforge.karma.core.ErrorCode;
22  
23  /***
24   * <p>Exceptions relating to <code>Location</code>s. As with all other <code>KarmaExceptions</code>, exceptions can
25   * only be thrown with a certain <code>ErrorCode</code>.
26   *
27   * @author D.A. Smedes
28   * @version $Id: LocationException.java,v 1.23 2004/11/02 23:57:06 asmedes Exp $
29   */
30  public final class LocationException extends Exception {
31  
32    private ErrorCode errorCode = null;
33    private Object[] messageArguments = null;
34  
35    /***
36     * This is the prefix that is shown when displaying the error.
37     */
38    public static final String EXCEPTION_PREFIX = "LOC-";
39  
40    /***
41     * Location descriptor does not exist. This happens when a module's 'location'-attribute cannot be found by the
42     * <code>LocationFactory</code>, which contains references to all <code>Location</code> objects mapped in
43     * <code>locations.xml</code>.
44     */
45    public static final ErrorCode LOCATION_NOT_FOUND = new ErrorCode(EXCEPTION_PREFIX + "00005");
46    /***
47     * No location files were found. Karma filters all <code>*.xml</code>-files from
48     * {@link nl.toolforge.karma.core.boot.WorkingContext#getLocationStore()}.
49     */
50    public static final ErrorCode NO_LOCATION_DATA_FOUND = new ErrorCode(EXCEPTION_PREFIX + "00006");
51  
52    /*** Missing location property */
53    public static final ErrorCode MISSING_LOCATION_PROPERTY = new ErrorCode(EXCEPTION_PREFIX + "00010");
54    /***
55     * The manifest-store is configured based on properties in <code>karma.properties</code>. This error code is
56     * created when the <code>Location</code> for the manifest-store could not be created succesfully.
57     */
58    public static final ErrorCode INVALID_MANIFEST_STORE_LOCATION = new ErrorCode(EXCEPTION_PREFIX + "00011");
59    /***
60     * The location-store is configured based on properties in <code>karma.properties</code>. This error code is
61     * created when the <code>Location</code> for the location-store could not be created succesfully.
62     */
63    public static final ErrorCode INVALID_LOCATION_STORE_LOCATION = new ErrorCode(EXCEPTION_PREFIX + "00012");
64  
65    public static final ErrorCode DUPLICATE_LOCATION_KEY = new ErrorCode(EXCEPTION_PREFIX + "00013");
66  
67    /***
68     * An xml file with locations could not be loaded.
69     */
70    public static final ErrorCode LOCATION_LOAD_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00017");
71  
72    /***
73     * A <code>LOCATION_MISMATCH</code> occurs when a module is locally available and an update is requested from
74     * another location. A version control system generally gives an error for this.
75     */
76    public static final ErrorCode LOCATION_MISMATCH = new ErrorCode(EXCEPTION_PREFIX + "00018");
77  
78    /***
79     * A connection to the location could not be made.
80     */
81    public static final ErrorCode CONNECTION_EXCEPTION = new ErrorCode(EXCEPTION_PREFIX + "00019");
82  
83  
84    /*** The location was configured incorrectly. */
85  //  public static final ErrorCode LOCATION_CONFIGURATION_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00007");
86  
87    // Location configuration error codes. Used when the locations xml are misconfigured.
88    //
89  
90    public static final ErrorCode INVALID_LOCATION_TYPE = new ErrorCode(EXCEPTION_PREFIX + "00020");
91    
92    public static final ErrorCode INVALID_ELEMENT_VALUE = new ErrorCode(EXCEPTION_PREFIX + "00021");
93  
94  
95    public LocationException(ErrorCode errorCode) {
96      this(errorCode, null);
97    }
98  
99    public LocationException(Throwable t, ErrorCode errorCode) {
100     this(t, errorCode, null);
101   }
102 
103   public LocationException(ErrorCode errorCode, Object[] messageArguments) {
104     super();
105     this.errorCode = errorCode;
106     this.messageArguments = messageArguments;
107   }
108 
109   public LocationException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
110     super(t);
111     this.errorCode = errorCode;
112     this.messageArguments = messageArguments;
113   }
114 
115   /***
116    * Helper method to get the localized error message based on the {@link nl.toolforge.karma.core.ErrorCode}.
117    */
118 //  public final String getErrorMessage() {
119 //    if (messageArguments != null && messageArguments.length > 0) {
120 //      errorCode.setMessageArguments(messageArguments);
121 //    }
122 //    return errorCode.getErrorMessage();
123 //  }
124 
125   public String getMessage() {
126     if (messageArguments != null && messageArguments.length > 0) {
127       errorCode.setMessageArguments(messageArguments);
128     }
129     return errorCode.getErrorMessage();
130   }
131 
132   /***
133    * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
134    */
135   public final ErrorCode getErrorCode() {
136     return errorCode;
137   }
138 
139   /***
140    * Retrieves the message arguments for this exception.
141    */
142   public final Object[] getMessageArguments() {
143     return messageArguments;
144   }
145 }