View Javadoc

1   package com.melloware.jukes.gui.view.validation;
2   
3   import com.jgoodies.validation.ValidationResult;
4   import com.jgoodies.validation.Validator;
5   import com.jgoodies.validation.util.PropertyValidationSupport;
6   import com.jgoodies.validation.util.ValidationUtils;
7   import com.melloware.jukes.db.orm.Artist;
8   
9   /**
10   * Validates Artists.
11   * <p>
12   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
13   * @author Emil A. Lefkof III <info@melloware.com>
14   * @version 4.0
15   */
16  public final class ArtistValidator
17      implements Validator {
18  
19      /**
20       * Holds the artist to be validated.
21       */
22      private final Artist artist;
23  
24      /**
25       * Constructs a ArtistValidator on the given Artist.
26       *
27       * @param artist    the artist to be validated
28       */
29      public ArtistValidator(Artist artist) {
30          this.artist = artist;
31      }
32  
33      /**
34       * Validates this Validator's Artist and returns the result
35       * as an instance of {@link ValidationResult}.
36       *
37       * @return the ValidationResult of the artist validation
38       */
39      public ValidationResult validate() {
40          final PropertyValidationSupport support = new PropertyValidationSupport(artist, "Artist");
41  
42          if (ValidationUtils.isBlank(artist.getName())) {
43              support.addError("Name", "is mandatory");
44          }
45          
46          if (!ValidationUtils.hasMaximumLength(artist.getName(), 100)) {
47              support.addError("Name", "length shall be in [0, 100]");
48          }
49          
50          if (!ValidationUtils.hasMaximumLength(artist.getNotes(), 500)) {
51              support.addError("Notes", "length shall be in [0, 500]");
52          }
53  
54          return support.getResult();
55      }
56  
57  }