1 /***
2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.codestreet.messageforge;
19
20 /***
21 * Class to represent a constraint on a numeric <tt>byte</tt> message
22 * field.
23 * @author Jawaid Hakim.
24 */
25 public abstract class RFldConstraintI8 implements RFldConstraintNumeric
26 {
27 /***
28 * Ctor.
29 */
30 protected RFldConstraintI8()
31 {
32 }
33
34 /***
35 * Get error description.
36 * @param fldName Field name.
37 * @return Error description.
38 */
39 public abstract String errDesc(String fldName);
40
41 /***
42 * Check if a message field satisfies the constraint.
43 * @param fld Field to validate.
44 */
45 public void validate(RFld fld) throws FieldValidationException
46 {
47 if (fld instanceof RFldI8)
48 {
49 RFldI8 numericFld = (RFldI8)fld;
50 if (! isValid(numericFld.getValue()))
51 throw new FieldValidationException(errDesc(fld.getName()));
52 }
53 else
54 throw new FieldValidationException("Invalid field type: " + fld.getName());
55 }
56
57 /***
58 * Check if a value satisfies the constraint.
59 * @param fld Field.
60 * @param val Value to validate.
61 */
62 public void validate(RFld fld, byte val) throws FieldValidationException
63 {
64 if (! isValid(val))
65 throw new FieldValidationException(errDesc(fld.getName()));
66 }
67
68 /***
69 * Check if a message field satisfies the constraint.
70 * @param fld Field to validate.
71 * @return <tt>true</tt> if the field satisfies the
72 * constraint. Otherwise, <tt>false</tt> is returned.
73 * @see RFld
74 */
75 public boolean isValid(RFld fld)
76 {
77 if (fld instanceof RFldI8)
78 return isValid(((RFldI8)fld).getValue());
79 else
80 return false;
81 }
82
83 /***
84 * Check if a message field satisfies the constraint.
85 * @param val Field value to validate.
86 * @return <tt>true</tt> if the field satisfies the
87 * constraint. Otherwise, <tt>false</tt> is returned.
88 * @see RFld
89 */
90 public abstract boolean isValid(byte val);
91 }
This page was automatically generated by Maven