1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.policy;
20
21 import org.apache.neethi.Assertion;
22
23 public class AssertionState {
24
25 public enum State {
26 INIT,
27 HARD_FAILURE,
28 }
29
30 private State state = State.INIT;
31 private boolean asserted;
32 private boolean logged;
33 private Assertion assertion;
34 private StringBuilder errorMessage = new StringBuilder();
35
36 public AssertionState(Assertion assertion, boolean initialAssertionState) {
37 this.assertion = assertion;
38 this.asserted = initialAssertionState;
39 }
40
41 public Assertion getAssertion() {
42 return assertion;
43 }
44
45 public boolean isHardFailure() {
46 return this.state == State.HARD_FAILURE;
47 }
48
49 public synchronized void setAsserted(boolean asserted) {
50
51 if (this.state == State.HARD_FAILURE) {
52 return;
53 }
54 if (!asserted) {
55 this.state = State.HARD_FAILURE;
56 }
57 this.asserted = asserted;
58 }
59
60 public boolean isAsserted() {
61 return asserted;
62 }
63
64 public void setErrorMessage(String errorMessage) {
65 if (this.errorMessage.length() > 0) {
66 this.errorMessage.append("\n");
67 }
68 this.errorMessage.append(errorMessage);
69 }
70
71 public String getErrorMessage() {
72 if (errorMessage.length() == 0) {
73 return "Assertion " + assertion.getName() + " not satisfied";
74 } else {
75 return errorMessage.toString();
76 }
77 }
78
79 protected void clearErrorMessage() {
80 this.errorMessage.delete(0, this.errorMessage.length());
81 }
82
83 public boolean isLogged() {
84 return logged;
85 }
86
87 public void setLogged(boolean logged) {
88 this.logged = logged;
89 }
90 }