01: package org.concern.controller;
02:
03: import org.hibernate.LockMode;
04: import org.hibernate.HibernateException;
05: import org.concern.*;
06:
07: import java.util.*;
08:
09: public class DummyCondition extends AbstractCondition {
10: String depends = "";
11:
12: public DummyCondition() {
13: }
14:
15: public DummyCondition(String name) {
16: super (name);
17: }
18:
19: public DummyCondition(String name, String depends) {
20: super (name);
21: this .depends = depends;
22: }
23:
24: protected boolean wasAlreadPerformed(Object object, String name)
25: throws ConditionEvaluationException {
26: try {
27: Subject subject = controller.getSubject(controller
28: .getLoader().idOf(object), LockMode.NONE);
29: System.out.println("subject.getLogs() = "
30: + subject.getLogs());
31: for (Iterator iterator = subject.getLogs().iterator(); iterator
32: .hasNext();) {
33: Log log = (Log) iterator.next();
34: if (log.isSuccess() && name.equals(log.getActivity()))
35: return true;
36: }
37: return false;
38: } catch (SubjectNotFoundException e) {
39: throw new ConditionEvaluationException(e);
40: } catch (LoaderException e) {
41: throw new ConditionEvaluationException(e);
42: } catch (UnknownSubjectException e) {
43: throw new ConditionEvaluationException(e);
44: } catch (HibernateException e) {
45: throw new ConditionEvaluationException(e);
46: }
47: }
48:
49: protected boolean wasAlreadPerformed(Object subject)
50: throws ConditionEvaluationException {
51: return wasAlreadPerformed(subject, getName());
52: }
53:
54: public boolean eval(Object subject)
55: throws ConditionEvaluationException {
56: if (wasAlreadPerformed(subject)) {
57: System.out.println(getName() + ":" + subject
58: + " already performed");
59: return false;
60: }
61: // after dependencies
62: StringTokenizer tokens = new StringTokenizer(depends, ",");
63: while (tokens.hasMoreTokens()) {
64: String dependency = tokens.nextToken();
65: if (!wasAlreadPerformed(subject, dependency)) {
66: System.out.println(getName() + ":" + subject
67: + " depends on " + dependency);
68: return false;
69: }
70: }
71: return true;
72: }
73:
74: Integer dummy;
75:
76: public void setDummy(Integer dummy) {
77: this .dummy = dummy;
78: }
79:
80: public Integer getDummy() {
81: return dummy;
82: }
83: }
|