1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.peaseplate.internal.lang.command;
21
22 import org.peaseplate.TemplateRuntimeException;
23 import org.peaseplate.internal.BuildContext;
24 import org.peaseplate.locator.TemplateLocator;
25
26 public class PopCommand extends AbstractSingleParameterCommand {
27
28 public PopCommand(TemplateLocator locator, int line, int column, ICommand command) {
29 super(locator, line, column, command);
30 }
31
32
33
34
35 public Object call(BuildContext context) throws TemplateRuntimeException {
36 Object result = null;
37 Object stackedObject = context.popWorkingObject();
38
39 try {
40 if (getCommand() != null)
41 result = callCommand(context);
42 else
43 result = context.getWorkingObject();
44 }
45 finally {
46 context.pushWorkingObject(stackedObject);
47 }
48
49 return result;
50 }
51
52
53
54
55 @Override
56 public String toString() {
57 StringBuilder builder = new StringBuilder("$pop");
58
59 if (getCommand() != null)
60 builder.append(".").append(getCommand());
61
62 return builder.toString();
63 }
64
65 }