View Javadoc

1   /*
2   Copyright (C) 2000 - 2007 Grid Systems, S.A.
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2, as
6   published by the Free Software Foundation.
7   
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17  
18  package com.gridsystems.gridexception;
19  
20  /**
21   * Title:        GridException.
22   * Description:  Excepcion que encapsula un mensaje y parametros adicionales del mensaje
23   * Copyright:    Copyright (c) 2003
24   * Company:      GridSystems SA
25   * @author Xmas
26   * @version 1.0
27   */
28  public class GridException extends Exception {
29  
30    /**
31     * Default Serial UID.
32     */
33    private static final long serialVersionUID = 1234523452345L;
34    /**
35     * The exception message.
36     */
37    String message;
38    /**
39     * The exception code.
40     */
41    String code;
42    /**
43     * The exception parameters.
44     */
45    String[] params;
46  
47    /**
48     * Constructor.
49     * @param code the exception code
50     * @param params the exception parameters
51     */
52    public GridException(String code, String[] params) {
53      this.code = code;
54      this.params = params;
55    }
56  
57    /**
58     * Constructor.
59     * @param code the exception code
60     */
61    public GridException(String code) {
62      this.code = code;
63      this.params = null;
64    }
65  
66    /**
67     * @return the exception message
68     */
69    @Override public String getMessage() {
70      return message;
71    }
72  
73    /**
74     * @return the exception parameters.
75     */
76    public String[] getParams() {
77      return params;
78    }
79  
80    /**
81     * @return the exception code.
82     */
83    public String getCode() {
84      return code;
85    }
86  
87    /**
88     * Converts the exception to a string.
89     * @return the string form of the exception
90     */
91    @Override public String toString() {
92      StringBuffer str = new StringBuffer(code);
93      str.append("{");
94      if (params != null) {
95        for (int i = 0; i < params.length; i++) {
96          if (i > 0) {
97            str.append(',');
98          }
99          str.append(params[i]);
100       }
101     }
102     str.append("}");
103     return str.toString();
104   }
105 }