View Javadoc

1   /*
2    * BetweenConstraint.java
3    * Created on 17 Октябрь 2006 г., 2:14
4    */
5   
6   package org.weda.property.impl;
7   
8   import org.weda.enhance.InjectMessages;
9   import org.weda.message.Messages;
10  import org.weda.property.ConstraintCheck;
11  import org.weda.property.ConstraintException;
12  import org.weda.property.ConstraintIdentificatorHolder;
13  
14  /**
15   *
16   * @author Mikhail Titov
17   */
18  public class BetweenConstraint implements ConstraintIdentificatorHolder {
19      private String id;
20      @InjectMessages()
21      private Messages messages;
22  
23      public String getId() {
24          return id;
25      }
26  
27      public void setId(String id) {
28          this.id = id;
29      }
30      
31      @ConstraintCheck(defaultMethod=true)
32      public void check(Double value, Double leftBorder, Double rightBorder)
33          throws ConstraintException
34      {
35          if (value < leftBorder || value > rightBorder)
36              throw new ConstraintException(
37                      messages.format("errorMessage", leftBorder, rightBorder));
38      }
39  }