01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.generator.postchecks;
21:
22: import java.util.StringTokenizer;
23:
24: import de.schlund.pfixcore.generator.IWrapperParamPostCheck;
25: import de.schlund.pfixcore.generator.SimpleCheck;
26: import de.schlund.util.statuscodes.StatusCode;
27: import de.schlund.util.statuscodes.StatusCodeLib;
28:
29: /**
30: * IntegerRange.java
31: *
32: *
33: * Created: Thu Aug 16 17:18:57 2001
34: *
35: * @author <a href="mailto: "Jens Lautenbacher</a>
36: *
37: *
38: */
39:
40: public class IntegerRange extends SimpleCheck implements
41: IWrapperParamPostCheck {
42: private int lower;
43: private int upper;
44: private StatusCode scode_small;
45: private StatusCode scode_big;
46:
47: public IntegerRange() {
48: scode_small = StatusCodeLib.PFIXCORE_GENERATOR_POSTCHECK_INTEGER_TOO_SMALL;
49: scode_big = StatusCodeLib.PFIXCORE_GENERATOR_POSTCHECK_INTEGER_TOO_BIG;
50: }
51:
52: public void put_scode_too_small(String fqscode) {
53: scode_small = StatusCodeLib.getStatusCodeByName(fqscode);
54: }
55:
56: public void put_scode_too_big(String fqscode) {
57: scode_big = StatusCodeLib.getStatusCodeByName(fqscode);
58: }
59:
60: public void put_range(String param) {
61: param = param.trim();
62:
63: StringTokenizer tok = new StringTokenizer(param, " :", false);
64: if (tok.countTokens() == 2) {
65: Integer thelower = new Integer(tok.nextToken());
66: Integer theupper = new Integer(tok.nextToken());
67: lower = thelower.intValue();
68: upper = theupper.intValue();
69: } else {
70: throw new RuntimeException("Range spec '" + param
71: + "' isn't correct");
72: }
73: }
74:
75: public void check(Object[] obj) {
76: reset();
77: for (int i = 0; i < obj.length; i++) {
78: int value = ((Integer) obj[i]).intValue();
79: if (lower > value) {
80: addSCode(scode_small);
81: break;
82: } else if (upper < value) {
83: addSCode(scode_big);
84: break;
85: }
86: }
87: }
88:
89: }// IntegerRange
|