KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > expression > NegationParser


1 package org.jicengine.expression;
2
3 import org.jicengine.operation.*;
4
5 /**
6  * <p> </p>
7  *
8  * <p> </p>
9  *
10  * <p> </p>
11  *
12  * <p> </p>
13  *
14  * @author timo laitinen
15  */

16 public class NegationParser implements Parser {
17     private Parser parser;
18     public NegationParser(Parser subParser)
19     {
20         this.parser = subParser;
21     }
22
23     /**
24      * @return Parsers may return null in order to signal 'abort' i.e.
25      *
26      * @return Parsers may return null in order to signal 'abort' i.e. if the
27      * syntax of the expression is not understood by the parser
28      * implementation. i.e. NumberParser returns null if the expression is a
29      * string-expression..
30      * @throws SyntaxException
31      * @param expression String
32      */

33     public Operation parse(String JavaDoc expression) throws SyntaxException
34     {
35         if( expression.startsWith("!") ){
36             // looks promising..
37
Operation operation = this.parser.parse(expression.substring(1));
38             if( operation != null ){
39                 // looks still ok.
40
return new NegationOperation(operation);
41             }
42             else {
43                 return null;
44             }
45         }
46         else {
47             return null;
48         }
49     }
50 }
51
Popular Tags