1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.jsieve.exception.SieveException;
24 import org.apache.jsieve.mail.MailAdapter;
25
26
27
28
29
30
31
32
33 public class Command implements Executable {
34
35
36 private String fieldName;
37
38
39 private Arguments fieldArguments;
40
41
42 private Block fieldBlock;
43
44
45
46
47
48
49 private ScriptCoordinate coordinate;
50
51
52
53
54 private Command() {
55 super();
56 }
57
58
59
60
61
62
63
64
65 public Command(String name, Arguments arguments, Block block,
66 ScriptCoordinate coordinate) {
67 this();
68 this.coordinate = coordinate;
69 setName(name);
70 setArguments(arguments);
71 setBlock(block);
72 }
73
74
75
76
77
78
79 public String getName() {
80 return fieldName;
81 }
82
83
84
85
86
87
88
89 protected void setName(String name) {
90 fieldName = name;
91 }
92
93
94
95
96 public String toString() {
97 return "Command name: "
98 + getName()
99 + " "
100 + ((getArguments() == null) ? "null" : getArguments()
101 .toString()) + " Block: "
102 + ((getBlock() == null) ? "null" : getBlock().toString());
103 }
104
105
106
107
108
109
110 public Arguments getArguments() {
111 return fieldArguments;
112 }
113
114
115
116
117
118
119 public Block getBlock() {
120 return fieldBlock;
121 }
122
123
124
125
126
127
128
129 protected void setArguments(Arguments arguments) {
130 fieldArguments = arguments;
131 }
132
133
134
135
136
137
138
139 protected void setBlock(Block block) {
140 fieldBlock = block;
141 }
142
143
144
145
146 public Object execute(MailAdapter mail, SieveContext context)
147 throws SieveException {
148 Log log = context.getLog();
149 if (log.isDebugEnabled()) {
150 log.debug(toString());
151 coordinate.debugDiagnostics(log);
152 }
153
154
155
156 context.setCoordinate(coordinate);
157 final ExecutableCommand executable = context.getCommandManager().getCommand(getName());
158 final Object result = executable.execute(mail, getArguments(),
159 getBlock(), context);
160 return result;
161 }
162 }