1
2
3
4
5
6
7 package org.asyrinx.joey.gen.model.command;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14 import org.asyrinx.brownie.core.log.DispatchLog;
15 import org.asyrinx.brownie.core.log.LogLevel;
16 import org.asyrinx.joey.gen.model.Element;
17 import org.asyrinx.joey.gen.model.ElementVisitor;
18
19 /***
20 * @author takeshi
21 */
22 public class Command implements ElementVisitor {
23
24 private boolean strict = true;
25
26 protected final List errors = new ArrayList();
27
28 protected final DispatchLog log = new DispatchLog(LogFactory.getLog(this.getClass()), "info");
29
30 /***
31 *
32 */
33 public Command() {
34 super();
35 }
36
37 protected String element2String(Element element, String msg) {
38 if (element != null)
39 msg += " @" + element.getFullName();
40 msg += " (by command '" + this.getClass().getName() + "')";
41 return msg;
42 }
43
44 protected void addError(String msg) {
45 addError(null, msg);
46 }
47
48 protected void addError(Element element, String msg) {
49 addError(element, msg, isStrict());
50 }
51
52 protected void addError(Element element, String msg, boolean exit) {
53 msg = element2String(element, msg);
54 if (exit)
55 throw new ValidationError(msg, element);
56 else
57 log.warn(msg);
58 }
59
60 protected void log(String msg) {
61 log(null, msg);
62 }
63
64 protected void log(Element element, String msg) {
65 msg = element2String(element, msg);
66 log.log(msg);
67 }
68
69 /***
70 * @return Returns the strict.
71 */
72 public boolean isStrict() {
73 return strict;
74 }
75
76 /***
77 * @param strict
78 * The strict to set.
79 */
80 public void setStrict(boolean strict) {
81 this.strict = strict;
82 }
83
84
85
86
87
88
89 public void execute(Element element) {
90 throw new UnsupportedOperationException("subclass must override");
91 }
92
93
94
95
96
97
98 public void visit(Element element) {
99 throw new UnsupportedOperationException();
100 }
101
102 }