1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package it.jnrpe.utils.thresholds;
17
18
19
20
21
22
23 class StartStage extends Stage {
24
25
26
27
28 protected StartStage() {
29 super("root");
30 }
31
32 @Override
33 public boolean canParse(final String threshold) {
34 return false;
35 }
36
37 @Override
38 public String parse(final String threshold, final RangeConfig tc)
39 throws RangeException {
40
41 if (threshold == null) {
42 throw new RangeException("Range can't be null");
43 }
44
45 Stage currentStage = this;
46
47 String parsedThreshold = threshold;
48
49 boolean stageParsed;
50
51 while (parsedThreshold.length() != 0) {
52 stageParsed = false;
53 for (String transitionName : currentStage.getTransitionNames()) {
54 Stage transition = currentStage.getTransition(transitionName);
55 if (transition.canParse(parsedThreshold)) {
56 parsedThreshold = transition.parse(parsedThreshold, tc);
57 currentStage = transition;
58 stageParsed = true;
59 break;
60 }
61 }
62
63 if (!stageParsed) {
64 throw new InvalidRangeSyntaxException(currentStage,
65 parsedThreshold, threshold);
66 }
67 }
68
69 if (!currentStage.isLeaf()) {
70 throw new PrematureEndOfRangeException(currentStage, threshold);
71 }
72
73 return parsedThreshold;
74 }
75
76 @Override
77 public String expects() {
78 return null;
79 }
80 }