KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > filter > etcl > SubstrOperator


1 package org.jacorb.notification.filter.etcl;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import org.jacorb.notification.filter.EvaluationContext;
25 import org.jacorb.notification.filter.EvaluationException;
26 import org.jacorb.notification.filter.EvaluationResult;
27
28 import antlr.Token;
29
30 public class SubstrOperator extends BinaryOperator {
31
32     static final String JavaDoc NAME = "SubstrOperator";
33
34     public SubstrOperator(Token tok) {
35         super(tok);
36         setName(NAME);
37     }
38
39
40     public String JavaDoc toString() {
41         return " ~";
42     }
43
44     public EvaluationResult evaluate(EvaluationContext context,
45             EvaluationResult left, EvaluationResult right)
46         throws EvaluationException {
47
48         EvaluationResult _res;
49
50         String JavaDoc _l, _r;
51
52         _l = left.getString();
53         _r = right.getString();
54
55         int _idx = _r.indexOf(_l);
56
57         if (_idx == -1) {
58             _res = EvaluationResult.BOOL_FALSE;
59         } else {
60             _res = EvaluationResult.BOOL_TRUE;
61         }
62
63         return _res;
64     }
65
66     public boolean isStatic() {
67         return (left().isStatic() && right().isStatic());
68     }
69
70     public void acceptInOrder(AbstractTCLVisitor visitor)
71         throws VisitorException {
72
73         left().acceptInOrder(visitor);
74         visitor.visitSubstr(this);
75         right().acceptInOrder(visitor);
76     }
77
78     public void acceptPostOrder(AbstractTCLVisitor visitor)
79         throws VisitorException {
80
81         left().acceptPostOrder(visitor);
82         right().acceptPostOrder(visitor);
83         visitor.visitSubstr(this);
84     }
85
86     public void acceptPreOrder(AbstractTCLVisitor visitor)
87         throws VisitorException {
88
89         visitor.visitSubstr(this);
90         left().acceptPreOrder(visitor);
91         right().acceptPreOrder(visitor);
92     }
93 }
94
Popular Tags