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.internal.conversion.ConversionException;
25 import org.peaseplate.locator.TemplateLocator;
26
27 public abstract class AbstractBooleanCommand extends AbstractDoubleParameterCommand {
28
29 public AbstractBooleanCommand(TemplateLocator locator, int line, int column, ICommand leftCommand, ICommand rightCommand) {
30 super(locator, line, column, leftCommand, rightCommand);
31 }
32
33 protected boolean callBooleanLeftCommand(BuildContext context) throws TemplateRuntimeException {
34 Object result = super.callLeftCommand(context);
35
36 try {
37 return context.getEngine().getConversionService().convey(result, Boolean.class).booleanValue();
38 }
39 catch (ConversionException e) {
40 throw new TemplateRuntimeException(
41 getLeftCommand().getLocator(), getLeftCommand().getLine(), getLeftCommand().getColumn(),
42 "Cannot convert " + result.getClass() + " to boolean"
43 );
44 }
45 }
46
47 protected boolean callBooleanRightCommand(BuildContext context) throws TemplateRuntimeException {
48 Object result = super.callRightCommand(context);
49
50 try {
51 return context.getEngine().getConversionService().convey(result, Boolean.class).booleanValue();
52 }
53 catch (ConversionException e) {
54 throw new TemplateRuntimeException(
55 getRightCommand().getLocator(), getRightCommand().getLine(), getRightCommand().getColumn(),
56 "Cannot convert " + result.getClass() + " to boolean"
57 );
58 }
59 }
60
61 public abstract String getSign();
62
63
64
65
66 @Override
67 public String toString() {
68 return "(" + getLeftCommand() + " " + getSign() + " " + getRightCommand() + ")";
69 }
70
71 }