01: package net.javacoding.jspider.core.model;
02:
03: import net.javacoding.jspider.api.model.Decision;
04: import net.javacoding.jspider.api.model.DecisionStep;
05:
06: import java.util.ArrayList;
07:
08: /**
09: *
10: * $Id: DecisionInternal.java,v 1.1 2003/03/09 09:25:22 vanrogu Exp $
11: *
12: * @author Günther Van Roey
13: */
14: public class DecisionInternal implements Decision {
15:
16: protected int type;
17: protected String comment;
18: protected ArrayList history;
19:
20: public DecisionInternal() {
21: this (Decision.RULE_DONTCARE);
22: }
23:
24: public DecisionInternal(int type) {
25: this (type, "(no comment given)");
26: }
27:
28: public DecisionInternal(int type, String comment) {
29: this .type = type;
30: this .comment = comment;
31: this .history = new ArrayList();
32: }
33:
34: public int getDecision() {
35: return type;
36: }
37:
38: public String getComment() {
39: return comment;
40: }
41:
42: public boolean isVetoable() {
43: if (type == Decision.RULE_ACCEPT
44: || type == Decision.RULE_DONTCARE) {
45: return true;
46: } else {
47: return false;
48: }
49: }
50:
51: public void change(Decision other) {
52: this .type = other.getDecision();
53: this .comment = other.getComment();
54: }
55:
56: public void merge(Decision other) {
57: if (other.getDecision() > this .getDecision()) {
58: this .change(other);
59: }
60: }
61:
62: public void addStep(String rule, int ruleType, int type,
63: String comment) {
64: history.add(new DecisionStepInternal(rule, ruleType, type,
65: comment));
66: }
67:
68: public DecisionStep[] getSteps() {
69: return (DecisionStep[]) history
70: .toArray(new DecisionStep[history.size()]);
71: }
72:
73: public String toString() {
74: return "decision : " + translate(type) + " - " + getComment();
75: }
76:
77: public static String translate(int type) {
78: switch (type) {
79: case Decision.RULE_ACCEPT:
80: return "ACCEPT";
81: case Decision.RULE_FORBIDDEN:
82: return "FORBIDDEN";
83: case Decision.RULE_IGNORE:
84: return "IGNORE";
85: case Decision.RULE_DONTCARE:
86: return "DON'T CARE";
87: }
88: return "ERROR!!!";
89: }
90:
91: }
|