2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.vaadin
.data
.validator
;
11 import com
.vaadin
.data
.Validator
;
13 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
14 import eu
.etaxonomy
.cdm
.vaadin
.model
.name
.NameRelationshipDTO
;
17 * Validates a {@link TaxonName} for existence of the nomenclatural reference.
19 * Compatible with fields operating on {@link TaxonName}, {@link NameRelationshipDTO},
21 * @author a.kohlbecker
25 public class NomenclaturalReferenceExistsValidator
implements Validator
{
28 private static final long serialVersionUID
= -7750232876262922982L;
30 private String userHint
= "";
32 public NomenclaturalReferenceExistsValidator(String userHint
){
33 this.userHint
= userHint
;
40 public void validate(Object value
) throws InvalidValueException
{
42 if(value
instanceof TaxonName
){
43 TaxonName name
= (TaxonName
)value
;
46 if(value
instanceof NameRelationshipDTO
){
47 NameRelationshipDTO nameRelDto
= (NameRelationshipDTO
)value
;
48 validateName(nameRelDto
.getOtherName());
57 public void validateName(TaxonName name
) {
58 if(name
.getNomenclaturalReference() == null) {
59 throw new InvalidValueException("The taxon name must have a nomenclatural reference. " + userHint
);