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 abstract class AbstractNativeCallCommand extends AbstractSingleParameterCommand {
27
28 private final ICommand[] parameterCommands;
29
30 public AbstractNativeCallCommand(TemplateLocator locator, int line, int column, ICommand command, ICommand... parameterCommands) {
31 super(locator, line, column, command);
32
33 this.parameterCommands = parameterCommands;
34 }
35
36 public ICommand[] getParameterCommands() {
37 return parameterCommands;
38 }
39
40 public boolean hasParameters() {
41 return (parameterCommands != null);
42 }
43
44 public int getNumberOfParameters() {
45 return (parameterCommands != null) ? parameterCommands.length : 0;
46 }
47
48
49
50
51 @Override
52 public Object callCommand(BuildContext context) throws TemplateRuntimeException {
53 if (getCommand() != null)
54 return super.callCommand(context);
55
56 return context.getWorkingObject();
57 }
58
59
60
61
62 @Override
63 public String toString() {
64 StringBuilder result = new StringBuilder();
65
66 if (parameterCommands != null) {
67 result.append("(");
68
69 for (int i=0; i<parameterCommands.length; i+=1) {
70 if (i>0)
71 result.append(", ");
72
73 result.append(parameterCommands[i]);
74 }
75
76 result.append(")");
77 }
78
79 return result.toString();
80 }
81
82 }