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

Quick Search    Search Deep

Source code: com/aendvari/griffin/validation/handlers/simple/SimpleErrorHandler.java


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