private String definition;
private String whereClause;
private String orderByClause;
- private int nrEntitiesToSkip;
- private int nrEntitiesPerBatch;
- private int minNrEntitiesInFirstBatch;
+ private String nrEntitiesToSkipExpression;
+ private String nrEntitiesPerBatchExpression;
+ private String minNrEntitiesInFirstBatchExpression;
+ private String defaultNrBatchesToProcessExpression;
private ProducerNode batchSubNode;
private ProducerNode batchListSubNode;
String aDefinition,
String aWhereClause,
String anOrderByClause,
- int aNrEntitiesPerBatch,
- int aMinNrEntitiesInFirstBatch,
- int aNrEntitiesToSkip,
+ int anrEntitiesPerBatchExpression,
+ int aminNrEntitiesInFirstBatchExpression,
+ int anrEntitiesToSkipExpression,
ProducerNode aBatchSubNode) {
this(aBatchDataKey, aBatchInfoKey, aModel, aDefinition, aWhereClause,
- anOrderByClause, aNrEntitiesPerBatch, aMinNrEntitiesInFirstBatch, aNrEntitiesToSkip,
+ anOrderByClause, anrEntitiesPerBatchExpression, aminNrEntitiesInFirstBatchExpression, anrEntitiesToSkipExpression,
aBatchSubNode, null);
}
-
public EntityBatchingProducerNode(
String aBatchDataKey,
String aBatchInfoKey,
ProducerNode aBatchSubNode,
ProducerNode aBatchListSubNode) {
+ this(aBatchDataKey, aBatchInfoKey, aModel, aDefinition,
+ aWhereClause, anOrderByClause,
+ Integer.toString(aNrEntitiesPerBatch),
+ Integer.toString(aMinNrEntitiesInFirstBatch),
+ Integer.toString(aNrEntitiesToSkip),
+ "1",
+ aBatchSubNode, aBatchListSubNode);
+
+ }
+
+ public EntityBatchingProducerNode(
+ String aBatchDataKey,
+ String aBatchInfoKey,
+ EntityAdapterModel aModel,
+ String aDefinition,
+ String aWhereClause,
+ String anOrderByClause,
+ String anrEntitiesPerBatchExpression,
+ String aminNrEntitiesInFirstBatchExpression,
+ String anrEntitiesToSkipExpression,
+ String aDefaultNrBatchesToProcessExpression,
+ ProducerNode aBatchSubNode,
+ ProducerNode aBatchListSubNode) {
+
batchSubNode = aBatchSubNode;
batchListSubNode = aBatchListSubNode;
definition = aDefinition;
whereClause = aWhereClause;
orderByClause = anOrderByClause;
- nrEntitiesToSkip = aNrEntitiesToSkip;
- nrEntitiesPerBatch = aNrEntitiesPerBatch;
- minNrEntitiesInFirstBatch = aMinNrEntitiesInFirstBatch;
+ nrEntitiesToSkipExpression = anrEntitiesToSkipExpression;
+ nrEntitiesPerBatchExpression = anrEntitiesPerBatchExpression;
+ minNrEntitiesInFirstBatchExpression = aminNrEntitiesInFirstBatchExpression;
+ defaultNrBatchesToProcessExpression = aDefaultNrBatchesToProcessExpression;
}
public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
List batchLocations;
BatchLocation location;
+ int nrEntitiesToSkip;
+ int nrEntitiesPerBatch;
+ int minNrEntitiesInFirstBatch;
+
// ML: The order by clause should lead to a result set in _reverse order_: the first row will be
// the last entity presented on the last page
- if (verb==null)
- throw new ProducerFailure("EntityBatchingProducerNode: unknown verb '"+aVerb+"'", null);
-
try {
+ if (verb==null) {
+ nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault( aValueMap, defaultNrBatchesToProcessExpression, -1 );
+ }
+ else {
+ nrBatchesToProcess=verb.nrBatchesToProcess;
+ }
+
expandedWhereClause = ParameterExpander.expandExpression( aValueMap, whereClause );
expandedOrderByClause = ParameterExpander.expandExpression( aValueMap, orderByClause );
+ nrEntitiesToSkip = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesToSkipExpression);
+ nrEntitiesPerBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesPerBatchExpression);
+ minNrEntitiesInFirstBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, minNrEntitiesInFirstBatchExpression);
+
batchesData = new Vector();
batchLocations = new Vector();
batchLocations.add(new BatchLocation(nrBatchesAfterFirst*nrEntitiesPerBatch, nrEntitiesInFirstBatch));
batchData = new HashMap();
batchData.put("identifier", "");
- batchData.put("index", Integer.toString(nrBatchesAfterFirst+1));
- batchData.put("size", Integer.toString(nrEntitiesInFirstBatch));
+ batchData.put("index", new Integer(nrBatchesAfterFirst+1));
+ batchData.put("size", new Integer(nrEntitiesInFirstBatch));
batchesData.add(batchData);
for (i=0; i<nrBatchesAfterFirst; i++) {
batchLocations.add(1, new BatchLocation(i*nrEntitiesPerBatch, nrEntitiesPerBatch));
batchData = new HashMap();
- batchData.put("identifier", Integer.toString(i));
- batchData.put("index", Integer.toString(i+1));
- batchData.put("size", Integer.toString(nrEntitiesPerBatch));
+ batchData.put("identifier", new Integer(i));
+ batchData.put("index", new Integer(i+1));
+ batchData.put("size", new Integer(nrEntitiesPerBatch));
batchesData.add(1, batchData);
}
batchData.put("all", batchesData);
batchData.put("first", batchesData.get(0));
batchData.put("last", batchesData.get(batchesData.size()-1));
- batchData.put("count", Integer.toString(batchesData.size()));
+ batchData.put("count", new Integer(batchesData.size()));
if (batchListSubNode!=null) {
batchListSubNode.produce(aValueMap, aVerb, aLogger);
}
- nrBatchesToProcess = nrBatchesAfterFirst+1;
- if (verb.nrBatchesToProcess>-1 && verb.nrBatchesToProcess<nrBatchesToProcess) {
- nrBatchesToProcess=verb.nrBatchesToProcess;
+ if (nrBatchesToProcess<0 || nrBatchesToProcess>nrBatchesAfterFirst+1) {
+ nrBatchesToProcess = nrBatchesAfterFirst+1;
}
if (batchSubNode!=null) {
}
endTime = System.currentTimeMillis();
- aLogger.println(" Time: " + (endTime-startTime) + " ms<br>");
+ aLogger.println(" Time: " + (endTime-startTime) + " ms");
aLogger.flush();
}
public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
Object messages;
+
try {
if (languageIdentifier!=null) {
messages =
new ResourceBundleGeneratorFunction(
- new Locale(ParameterExpander.expandExpression( aValueMap, languageIdentifier ), null ),
- MessageResources.getMessageResources(ParameterExpander.expandExpression( aValueMap, bundleIdentifier ))
+ new Locale(ParameterExpander.expandExpression( aValueMap, languageIdentifier ), "" ),
+ MessageResources.getMessageResources( ParameterExpander.expandExpression( aValueMap, bundleIdentifier ))
);
}
else {
key = (String) anAttributes.get(ENUMERATION_KEY_ATTRIBUTE);
definition = (String) anAttributes.get(ENUMERATION_DEFINITION_ATTRIBUTE);
- selection = (String) anAttributes.get(ENUMERATION_SELECTION_ATTRIBUTE);
- order = (String) anAttributes.get(ENUMERATION_ORDER_ATTRIBUTE);
+ selection = (String) ReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_SELECTION_ATTRIBUTE, "");
+ order = (String) ReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_ORDER_ATTRIBUTE, "");
limit = (String) anAttributes.get(ENUMERATION_LIMIT_ATTRIBUTE);
skip = (String) anAttributes.get(ENUMERATION_SKIP_ATTRIBUTE);
};
private final static String LIST_SKIP_ATTRIBUTE = SKIP_ATTRIBUTE;
private final static String[] LIST_REQUIRED_ATTRIBUTES = { LIST_KEY_ATTRIBUTE, LIST_DEFINITION_ATTRIBUTE };
private final static String[] LIST_OPTIONAL_ATTRIBUTES = { LIST_SELECTION_ATTRIBUTE, LIST_ORDER_ATTRIBUTE, LIST_SKIP_ATTRIBUTE, LIST_LIMIT_ATTRIBUTE};
- private final static String[] LIST_SUBNODES = {LIST_DEFAULT_SUBNODE};
+ private final static String[] LIST_SUBNODES = {};
private String key;
private String definition;
key = (String) anAttributes.get(LIST_KEY_ATTRIBUTE);
definition = (String) anAttributes.get(LIST_DEFINITION_ATTRIBUTE);
- selection = (String) anAttributes.get(LIST_SELECTION_ATTRIBUTE);
- order = (String) anAttributes.get(LIST_ORDER_ATTRIBUTE);
+ selection = (String) ReaderTool.getStringAttributeWithDefault(anAttributes, LIST_SELECTION_ATTRIBUTE, "");
+ order = (String) ReaderTool.getStringAttributeWithDefault(anAttributes, LIST_ORDER_ATTRIBUTE, "");
limit = (String) anAttributes.get(LIST_LIMIT_ATTRIBUTE);
skip = (String) anAttributes.get(LIST_SKIP_ATTRIBUTE);
};
public ProducerNode constructNode() {
- return new EntityListProducerNode(key, model, definition, selection, order, limit, skip, getSubNode(LIST_DEFAULT_SUBNODE ));
+ return new EntityListProducerNode(key, model, definition, selection, order, limit, skip, null );
};
public static class factory implements ProducerNodeBuilderFactory {
private final static String RESOURCEBUNDLE_DEFAULT_SUBNODE = "default";
private final static String[] RESOURCEBUNDLE_REQUIRED_ATTRIBUTES = { RESOURCEBUNDLE_KEY_ATTRIBUTE, RESOURCEBUNDLE_BUNDLE_ATTRIBUTE };
private final static String[] RESOURCEBUNDLE_OPTIONAL_ATTRIBUTES = { RESOURCEBUNDLE_LANGUAGE_ATTRIBUTE};
- private final static String[] RESOURCEBUNDLE_SUBNODES = {RESOURCEBUNDLE_DEFAULT_SUBNODE};
+ private final static String[] RESOURCEBUNDLE_SUBNODES = {};
private String key;
private String bundle;
};
public ProducerNode constructNode() {
- return new ResourceBundleProducerNode(key, bundle, language, getSubNode(RESOURCEBUNDLE_DEFAULT_SUBNODE ));
+ return new ResourceBundleProducerNode(key, bundle, language, null );
};
}
private final static String BATCHER_MINBATCHSIZE_ATTRIBUTE = "minbatchsize";
private final static String BATCHER_SKIP_ATTRIBUTE = SKIP_ATTRIBUTE;
+ private final static String BATCHER_PROCESS_ATTRIBUTE = "process";
+
private final static String BATCHER_BATCH_SUBNODE = "batches";
private final static String BATCHER_BATCHLIST_SUBNODE = "batchlist";
private final static String[] BATCHER_REQUIRED_ATTRIBUTES = { BATCHER_DATAKEY_ATTRIBUTE, BATCHER_INFOKEY_ATTRIBUTE, BATCHER_DEFINITION_ATTRIBUTE, BATCHER_BATCHSIZE_ATTRIBUTE };
- private final static String[] BATCHER_OPTIONAL_ATTRIBUTES = { BATCHER_SELECTION_ATTRIBUTE, BATCHER_ORDER_ATTRIBUTE, BATCHER_MINBATCHSIZE_ATTRIBUTE, BATCHER_SKIP_ATTRIBUTE };
+ private final static String[] BATCHER_OPTIONAL_ATTRIBUTES = { BATCHER_SELECTION_ATTRIBUTE, BATCHER_ORDER_ATTRIBUTE, BATCHER_MINBATCHSIZE_ATTRIBUTE, BATCHER_SKIP_ATTRIBUTE, BATCHER_PROCESS_ATTRIBUTE };
private final static String[] BATCHER_SUBNODES = { BATCHER_BATCH_SUBNODE, BATCHER_BATCHLIST_SUBNODE };
// ML: batchSize, minBatchSize, skip should be expressions!
private String definition;
private String selection;
private String order;
- private int batchSize;
- private int minBatchSize;
- private int skip;
-
+ private String batchSize;
+ private String minBatchSize;
+ private String skip;
+ private String process;
public BatchingProducerNodeBuilder(EntityAdapterModel aModel) {
super(BATCHER_SUBNODES);
selection = ReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SELECTION_ATTRIBUTE, "" );
order = ReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_ORDER_ATTRIBUTE, "" );
- batchSize = ReaderTool.getIntegerAttributeWithDefault(anAttributes, BATCHER_BATCHSIZE_ATTRIBUTE, 20 );
- minBatchSize = ReaderTool.getIntegerAttributeWithDefault(anAttributes, BATCHER_MINBATCHSIZE_ATTRIBUTE, 0 );
- skip = ReaderTool.getIntegerAttributeWithDefault(anAttributes, BATCHER_SKIP_ATTRIBUTE, 0 );
+ batchSize = ReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_BATCHSIZE_ATTRIBUTE, "20" );
+ minBatchSize = ReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_MINBATCHSIZE_ATTRIBUTE, "0" );
+ skip = ReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SKIP_ATTRIBUTE, "0" );
+ process = ReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_PROCESS_ATTRIBUTE, "-1" );
};
public ProducerNode constructNode() {
batchSize,
minBatchSize,
skip,
+ process,
getSubNode( BATCHER_BATCH_SUBNODE ),
getSubNode( BATCHER_BATCHLIST_SUBNODE )
);
////////////////////////////////////////////////////////////////////////////////
+ public static class ScriptedProducerParameterNodeBuilder implements ProducerNodeBuilder {
+ private String parameterName;
+ private String scriptedNodeName;
+
+ public ScriptedProducerParameterNodeBuilder(String aScriptedNodeName, String aParameterName) {
+ parameterName = aParameterName;
+ scriptedNodeName = aScriptedNodeName;
+ }
+
+ public void setSubNode(String aName, ProducerNode aNode) {
+ };
+
+ public Set getAvailableSubNodes() {
+ return new HashSet();
+ };
+
+ public void setAttributes(Map anAttributes) throws ProducerConfigExc {
+ if (!anAttributes.isEmpty())
+ throw new ProducerConfigExc("No parameters allowed here");
+ };
+
+ public ProducerNode constructNode() {
+ return new ScriptedProducerNodeDefinition.NodeParameterProducerNode(scriptedNodeName, parameterName);
+ };
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+
public static class ScriptedProducerNodeBuilder implements ProducerNodeBuilder {
private ScriptedProducerNodeDefinition definition;
private Map nodeParameterValues;
name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
ReaderTool.checkValidIdentifier( name );
- if (producers.containsKey(name))
- throw new ProducerConfigExc("Duplicate producer name: '" + name + "'");
+// if (producers.containsKey(name))
+// throw new ProducerConfigExc("Duplicate producer name: '" + name + "'");
name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
producers.put(name, ((ProducerSectionHandler) aHandler).getProducerFactory());
}
else if (aHandler instanceof NodeDefinitionSectionHandler) {
-
scriptedNodeBuilderLibrary.registerFactory(name,
new DefaultProducerNodeBuilders.ScriptedProducerNodeBuilder.factory(
((NodeDefinitionSectionHandler) aHandler).getDefinition()));
if (!anAttributes.isEmpty()) {
throw new ProducerConfigExc( "No attributes allowed" );
}
- producerNode.addSubNode(new ScriptedProducerNodeDefinition.NodeParameterProducerNode(scriptedNodeName, aTag));
+ currentBuilder = new DefaultProducerNodeBuilders.ScriptedProducerParameterNodeBuilder(scriptedNodeName, aTag);
+// producerNode.addSubNode(
+// new ScriptedProducerNodeDefinition.NodeParameterProducerNode(scriptedNodeName, aTag));
return new EmptySectionHandler();
}
else if (scriptedNodeBuilderLibrary.hasBuilderForName(aTag) || builderLibrary.hasBuilderForName((aTag))) {
public class NodeDefinitionSectionHandler extends SectionHandler {
private ScriptedProducerNodeDefinition nodeDefinition;
- private ProducerNode definition;
+ private ProducerNode body;
private Map stringParameters;
private Map nodeParameters;
private String name;
public NodeDefinitionSectionHandler(String aName) {
- definition = null;
+ body = null;
nodeParameters = null;
stringParameters = null;
name = aName;
if (nodeParameters!=null) {
throw new ProducerConfigExc( "Parameters have already been declared" );
}
- if (definition!=null) {
+ if (body!=null) {
throw new ProducerConfigExc( "Parameters should come before definition" );
}
else if (aTag.equals("definition")) {
return new ProducerNodeSectionHandler(name, nodeParameters.keySet());
}
- else throw new ProducerConfigExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
+ else throw new ProducerConfigExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered.");
}
public void endElement(SectionHandler aHandler) {
nodeParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getNodeParameters();
}
else if (aHandler instanceof ProducerNodeSectionHandler) {
- definition = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
+ body = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
}
}
public void finishSection() throws ProducerConfigExc {
Iterator i;
- if (definition == null)
+ if (body == null)
throw new ProducerConfigExc( "Definition missing" );
nodeDefinition = new ScriptedProducerNodeDefinition(name);
+ nodeDefinition.setBody(body);
+
i = nodeParameters.keySet().iterator();
while (i.hasNext()) {
nodeDefinition.addNodeParameter((String) i.next());
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
- if (entry.getValue() == null && aRequired ) {
+ if ((entry.getValue() == null) == aRequired ) {
result.add(entry.getKey());
}
}
}
if (endOfExpressionPosition<anExpression.length()) {
result.append(evaluateStringExpression(aMap, anExpression.substring(position+2, endOfExpressionPosition)));
-// findStringForKey(aMap, anExpression.substring(position+2, endOfExpressionPosition))
-// );
previousPosition=endOfExpressionPosition+1;
}
else {
return result;
}
- public int getPosition() {
- return position;
+ public String getPositionString() {
+ return data.substring(0, position) + "<__>" + data.substring(position) ;
}
}
public static abstract class PunctuationToken extends Token { public PunctuationToken() { }; }
private static class LeftSquareBraceToken extends PunctuationToken {};
private static class RightSquareBraceToken extends PunctuationToken {};
- private static class ANDToken extends PunctuationToken {};
- private static class ORToken extends PunctuationToken {};
private static class EqualsToken extends PunctuationToken {};
private static class EqualsNotToken extends PunctuationToken {};
private static class NOTToken extends PunctuationToken {};
private static class Scanner {
private Reader reader;
private Token nextToken;
+ private String positionString;
public Scanner(Reader aReader) {
reader = aReader;
+ skipWhitespace();
+ positionString = reader.getPositionString();
}
public Token scanStringLiteral() {
return new LiteralToken(result.toString());
}
- public int getPosition() {
- return reader.getPosition();
+ public String getPositionString() {
+ return positionString;
}
private Token scanNumber() {
switch(c.charValue()) {
case '[': return new LeftSquareBraceToken();
case ']': return new RightSquareBraceToken();
- case '&':
- if (reader.hasNext() && reader.peek().charValue() == '&') {
- reader.getNext();
- return new ANDToken();
- }
- else {
- return new ConcatenateToken();
- }
- case '|':
- if (reader.hasNext() && reader.peek().charValue() == '|') {
- reader.getNext();
- return new ORToken();
- }
- else {
- throw new RuntimeException("Unknown character: '|'");
- }
-
case '=':
if (reader.hasNext() && reader.peek().charValue() == '=') {
reader.getNext();
case ')': return new RightParenthesisToken ();
case ',': return new CommaToken ();
case '.': return new PeriodToken ();
- case '+': return new PlusToken ();
+ case '+':
+ if (reader.hasNext() && reader.peek().charValue() == '+') {
+ reader.getNext();
+ return new ConcatenateToken();
+ }
+ else {
+ return new PlusToken ();
+ }
case '*': return new TimesToken ();
case '/': return new DivideToken ();
case '-': return new MinusToken ();
}
public Token scanNext() {
- skipWhitespace();
+ Token result = null;
- if (!reader.hasNext())
- return null;
+ skipWhitespace();
- Character c = reader.peek();
+ if (reader.hasNext()) {
+ Character c = reader.peek();
- switch(c.charValue()) {
- case '\'':
- case '"': return scanStringLiteral();
+ switch(c.charValue()) {
+ case '\'':
+ case '"':
+ result = scanStringLiteral();
+ break;
- default: {
- if (isIdentifierStart(c.charValue())) {
- return scanIdentifierKeyword();
- }
- else if (isNumberStart(c.charValue())) {
- return scanNumber();
+ default: {
+ if (isIdentifierStart(c.charValue())) {
+ result = scanIdentifierKeyword();
+ }
+ else if (isNumberStart(c.charValue())) {
+ result = scanNumber();
+ }
+ else
+ result = scanPunctuation();
}
- else
- return scanPunctuation();
}
}
- }
- public Token scan() {
- Token result = null;
+ skipWhitespace();
- if (nextToken!=null) {
- result = nextToken;
- }
- else {
- result = scanNext();
- }
+ return result;
+ }
- nextToken=null;
+ public Token scan() {
+ Token result = peek();
+ nextToken = null;
+ positionString = reader.getPositionString();
return result;
}
public Token peek() {
- nextToken = scan();
+ if (nextToken==null) {
+ nextToken = scanNext();
+ }
return nextToken;
}
return interpretAsBoolean(parseWhole());
}
catch (Throwable t) {
- t.printStackTrace(System.out);
- throw new RuntimeException("Parser error at position "+getLocation()+":"+t.getMessage());
+ throw new RuntimeException("Parser error at '" + getLocation()+ "': "+t.getMessage());
}
}
return interpretAsInteger(parseWhole());
}
catch (Throwable t) {
- t.printStackTrace(System.out);
- throw new RuntimeException("Parser error at position "+getLocation()+":"+t.getMessage());
+ throw new RuntimeException("Parser error at '" + getLocation()+ "': "+t.getMessage());
}
}
return interpretAsString(parseWhole());
}
catch (Throwable t) {
- throw new RuntimeException("Parser error at position "+getLocation()+":"+t.getMessage());
+ throw new RuntimeException("Parser error at '" + getLocation()+ "': "+t.getMessage());
}
}
private String getLocation() {
- int position = scanner.getPosition();
-
- return Integer.toString(position);
+ return scanner.getPositionString();
}
private Object parseWhole() {
result.add(expression);
token = scanner.scan();
- } while (token instanceof CommaToken);
+ }
+ while (token instanceof CommaToken);
if (!(token instanceof RightParenthesisToken)) {
throw new RuntimeException(") or , expected");
}
private int binaryOperatorLevel(Token aToken) {
- if ((aToken instanceof ANDToken) ||
- (aToken instanceof ORToken))
+ if (isANDOperator(aToken) ||
+ isOROperator(aToken))
return LOGICAL_OPERATOR_LEVEL;
if ((aToken instanceof EqualsToken) ||
return (aToken instanceof IdentifierToken && ((IdentifierToken) aToken).getName().equals("in"));
}
+ private boolean isANDOperator(Token aToken) {
+ return (aToken instanceof IdentifierToken && ((IdentifierToken) aToken).getName().equals("and"));
+ }
+
+ private boolean isOROperator(Token aToken) {
+ return (aToken instanceof IdentifierToken && ((IdentifierToken) aToken).getName().equals("or"));
+ }
+
private boolean isBinaryOperator(Token aToken) {
return
- (aToken instanceof ANDToken) ||
- (aToken instanceof ORToken) ||
(aToken instanceof EqualsToken) ||
(aToken instanceof EqualsNotToken) ||
(aToken instanceof PlusToken) ||
(aToken instanceof LessThanToken) ||
(aToken instanceof GreaterThanOrEqualsToken) ||
(aToken instanceof GreaterThanToken) ||
- isINOperator(aToken);
+ isINOperator(aToken) ||
+ isOROperator(aToken) ||
+ isANDOperator(aToken);
}
private boolean interpretAsBoolean(Object aValue) {
}
private int interpretAsInteger(Object aValue) {
- System.out.println(" interpret: " + aValue );
-
if (aValue instanceof Integer)
return ((Integer) aValue).intValue();
return Boolean.FALSE;
}
- if (aToken instanceof ANDToken)
+ if (isANDOperator(aToken))
return new Boolean(interpretAsBoolean(aValue1) && interpretAsBoolean(aValue2));
- if (aToken instanceof ORToken)
+ if (isOROperator(aToken))
return new Boolean(interpretAsBoolean(aValue1) || interpretAsBoolean(aValue2));
if (aToken instanceof EqualsToken) {
return new Boolean(areEqual(aValue1, aValue2));
return new Integer(interpretAsInteger(aValue1) - interpretAsInteger(aValue2));
if (aToken instanceof ConcatenateToken)
- return interpretAsString(aValue1) + interpretAsString(aValue1);
+ return interpretAsString(aValue1) + interpretAsString(aValue2);
if (aToken instanceof LessThanOrEqualsToken)
return new Boolean(interpretAsInteger(aValue1) <= interpretAsInteger(aValue2));