KickJava   Java API By Example, From Geeks To Geeks.

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


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.ETCLEvaluator;
25 import org.jacorb.notification.filter.EvaluationContext;
26 import org.jacorb.notification.filter.EvaluationException;
27 import org.jacorb.notification.filter.EvaluationResult;
28 import org.omg.CORBA.Any JavaDoc;
29
30 import antlr.Token;
31
32 /**
33  * @author Alphonse Bendt
34  * @version $Id: ImplicitOperatorNode.java,v 1.4 2005/02/14 00:07:08 alphonse.bendt Exp $
35  */

36
37 public class ImplicitOperatorNode extends AbstractTCLNode {
38
39     static final String JavaDoc DISCRIM = "_d";
40
41     static final String JavaDoc LENGTH = "_length";
42
43     static final String JavaDoc REPO_ID = "_repos_id";
44
45     static final String JavaDoc TYPE_ID = "_type_id";
46
47     public final static ImplicitOperator OPERATOR_DISCRIM =
48         new DiscrimOperator();
49
50     public final static ImplicitOperator OPERATOR_LENGTH =
51         new LengthOperator();
52
53     public final static ImplicitOperator OPERATOR_REPO_ID =
54         new RepoOperator();
55
56     public final static ImplicitOperator OPERATOR_TYPE_ID =
57         new TypeOperator();
58
59     static final EvaluationException EVALUATION_EXCEPTION =
60         new EvaluationException();
61
62     ImplicitOperator operator_;
63
64
65     public ImplicitOperatorNode(Token token) {
66         super(token);
67         String JavaDoc _tokenText = token.getText();
68
69         if (DISCRIM.equals(_tokenText)) {
70             operator_ = OPERATOR_DISCRIM;
71             //operatorName_ = DISCRIM;
72
setName("ImplicitOperator - _d");
73         } else if (LENGTH.equals(_tokenText)) {
74             operator_ = OPERATOR_LENGTH;
75             // operatorName_ = LENGTH;
76
setName("ImplicitOperator - _length");
77         } else if (REPO_ID.equals(_tokenText)) {
78             operator_ = OPERATOR_REPO_ID;
79             //operatorName_ = REPO_ID;
80
setName("Implicit - _repos_id");
81         } else if (TYPE_ID.equals(_tokenText)) {
82             operator_ = OPERATOR_TYPE_ID;
83             // operatorName_ = TYPE_ID;
84
setName("Implicit - _type_id");
85         } else {
86             throw new RuntimeException JavaDoc();
87         }
88     }
89
90     public ImplicitOperator getOperator() {
91         return operator_;
92     }
93
94     public EvaluationResult evaluate(EvaluationContext context)
95         throws EvaluationException {
96
97         return null;
98     }
99
100     public void acceptInOrder(AbstractTCLVisitor visitor) throws VisitorException {
101         visitor.visitImplicit(this);
102     }
103     public void acceptPreOrder(AbstractTCLVisitor visitor) throws VisitorException {
104         visitor.visitImplicit(this);
105     }
106     public void acceptPostOrder(AbstractTCLVisitor visitor) throws VisitorException {
107         visitor.visitImplicit(this);
108     }
109
110     public String JavaDoc toString() {
111         return operator_.toString();
112     }
113
114 }
115
116 class RepoOperator implements ImplicitOperator {
117
118     public String JavaDoc toString() {
119         return "_repos_id";
120     }
121
122     public Any JavaDoc evaluateImplicit(ETCLEvaluator evaluator,
123                                 Any JavaDoc value) throws EvaluationException {
124
125         return evaluator.evaluateRepositoryId(value);
126
127     }
128 }
129
130
131 class TypeOperator implements ImplicitOperator {
132
133     public String JavaDoc toString() {
134         return "_type_id";
135     }
136
137     public Any JavaDoc evaluateImplicit(ETCLEvaluator evaluator,
138                                 Any JavaDoc value) throws EvaluationException {
139
140         return evaluator.evaluateTypeName(value);
141     }
142 }
143
144
145 class DiscrimOperator implements ImplicitOperator {
146
147     public String JavaDoc toString() {
148         return "_d";
149     }
150
151     public Any JavaDoc evaluateImplicit(ETCLEvaluator evaluator,
152                                 Any JavaDoc value) throws EvaluationException {
153
154         return evaluator.evaluateDiscriminator(value);
155
156     }
157
158 }
159
160
161 class LengthOperator implements ImplicitOperator {
162
163     public String JavaDoc toString() {
164         return "_length";
165     }
166
167     public Any JavaDoc evaluateImplicit(ETCLEvaluator evaluator,
168                                 Any JavaDoc value) throws EvaluationException {
169
170         return evaluator.evaluateListLength(value);
171
172     }
173 }
174
Popular Tags