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   import com.melloware.jukes.gui.tool.Resources;
9   
10  /**
11   * Validates Artists.
12   * <p>
13   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
14   * @author Emil A. Lefkof III <info@melloware.com>
15   * @version 4.0
16   */
17  public final class ArtistValidator 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      * @param artist the artist to be validated
27      */
28     public ArtistValidator(Artist artist) {
29        this.artist = artist;
30     }
31  
32     /**
33      * Validates this Validator's Artist and returns the result as an instance of
34      * {@link ValidationResult}.
35      * @return the ValidationResult of the artist validation
36      */
37     @Override
38     public ValidationResult validate(Object validationTarget) {
39        final PropertyValidationSupport support = new PropertyValidationSupport(artist, "Artist");
40        if (ValidationUtils.isBlank(artist.getName())) {
41           support.addError("Name", Resources.getString("messages.isMandatory"));
42        }
43  
44        if (!ValidationUtils.hasMaximumLength(artist.getName(), 100)) {
45           support.addError("Name", Resources.getString("messages.Length100"));
46        }
47  
48        if (!ValidationUtils.hasMaximumLength(artist.getNotes(), 500)) {
49           support.addError("Notes", Resources.getString("messages.Length500"));
50        }
51  
52        return support.getResult();
53     }
54  
55  }