Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sample/griffin/validation/SampleErrorHandler.java


1   /*
2    * SampleErrorHandler.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    */
7   
8   package com.sample.griffin.validation;
9   
10  import com.aendvari.griffin.validation.*;
11  import com.aendvari.common.notices.*;
12  
13  
14  /**
15   * A sample error handler class for managing validation failures.
16   *
17   * @author Scott Milne
18   *
19   */
20  
21  public class SampleErrorHandler
22  {
23    /** A {@link Notice} instance for holding all notices for later retrieval. */
24    private Notices errors;
25  
26  
27    /* Constructors */
28  
29  
30    public SampleErrorHandler()
31    {
32      errors = new Notices();
33    }
34  
35    /**
36     * Adds an error to the messages list.
37     *
38     * @param    propertyName        The name of the property that failed validation.
39     * @param    propertyValue        The value of the property.
40     * @param    resourceKey          The resource key to use for the error message.
41     *
42     */
43  
44    public void addError( String propertyName, String propertyValue, String resourceKey )
45      throws Exception
46    {
47      Notice msg = new Notice(resourceKey, propertyName, propertyValue);
48  
49      try
50      {
51        errors.addNotice( resourceKey, msg );
52      }
53      catch( Exception exception )
54      {
55        throw exception;
56      }
57    }
58  
59    /**
60     * Retrieve the error messages.
61     *
62     * @return                  A {@link Notices} instance of all messages collected.
63     *
64     */
65  
66    public Notices getErrorMessages()
67    {
68      return errors;
69    }
70  }
71