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  /*
19   * Project: KernelConfigurator
20   * Created on 30-nov-2004
21   *
22   * Copyright (c)2004 Grid Systems
23   */
24  package com.gridsystems.config.tools;
25  
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import com.gridsystems.config.Configurator;
30  
31  /**
32   * Type description.
33   *
34   * @author <a href="mailto:rruiz@gridsystems.com">Rodrigo Ruiz Aguayo</a>
35   * @version 1.0
36   */
37  public class ErrorSupport {
38    /**
39     * The associated configurator.
40     */
41    private Configurator conf;
42  
43    /**
44     * A map of error messages.
45     */
46    private Map<String, String> msgs = new HashMap<String, String>();
47  
48    /**
49     * Creates a new instance.
50     *
51     * @param conf  The configurator
52     */
53    public ErrorSupport(Configurator conf) {
54      this.conf = conf;
55    }
56  
57    /**
58     * Adds an error message to the messages map.
59     *
60     * @param id       The error identifier
61     * @param message  The error message
62     */
63    public void addError(String id, String message) {
64      msgs.put(id, message);
65    }
66  
67    /**
68     * Notifies the configurator about an error event.
69     *
70     * @param id  The error identifier
71     * @param add The error action
72     */
73    public void updateError(String id, boolean add) {
74      String message = (String)msgs.get(id);
75      if (message == null) {
76        message = "Unknown error: " + id;
77      }
78      conf.updateError(id, message, add);
79    }
80  }