KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.jacorb.notification.filter.ParseException;
28 import org.jacorb.notification.filter.PropertyDoesNotExistException;
29 import org.jacorb.notification.interfaces.Message;
30
31 /**
32  * @author Alphonse Bendt
33  * @version $Id: PropertyShorthandNode.java,v 1.7 2005/02/14 00:07:08 alphonse.bendt Exp $
34  */

35
36 public class PropertyShorthandNode extends AbstractTCLNode
37 {
38     private final String JavaDoc value_;
39
40     private final ETCLComponentName shorthandVariableHeader_;
41
42     private final ETCLComponentName shorthandFilterableData_;
43
44     private final ETCLComponentName shorthandDefault_;
45
46     private final ETCLComponentName shorthandDefaultAny_;
47
48     ////////////////////////////////////////
49

50     public PropertyShorthandNode(String JavaDoc value)
51     {
52         try
53         {
54             value_ = value;
55
56             shorthandVariableHeader_ = (ETCLComponentName) TCLParser
57                     .parse("$.header.variable_header(" + value + ")");
58
59             shorthandVariableHeader_.acceptInOrder(new TCLCleanUp());
60
61             shorthandFilterableData_ = (ETCLComponentName) TCLParser.parse("$.filterable_data("
62                     + value + ")");
63
64             shorthandFilterableData_.acceptInOrder(new TCLCleanUp());
65
66             shorthandDefault_ = (ETCLComponentName) TCLParser.parse("$." + value);
67             shorthandDefault_.acceptInOrder(new TCLCleanUp());
68
69             shorthandDefaultAny_ = (ETCLComponentName) TCLParser.parse("$(" + value + ")");
70             shorthandDefaultAny_.acceptInOrder(new TCLCleanUp());
71
72         } catch (ParseException e)
73         {
74             throw new RuntimeException JavaDoc();
75         } catch (VisitorException e)
76         {
77             throw new RuntimeException JavaDoc();
78         }
79     }
80
81     public EvaluationResult evaluate(EvaluationContext context)
82             throws PropertyDoesNotExistException
83     {
84         Message _event = context.getCurrentMessage();
85         EvaluationResult _res = null;
86
87         try
88         {
89             _res = _event.extractVariableHeader(context, shorthandVariableHeader_, value_);
90
91         } catch (EvaluationException e)
92         {
93             // can be safely ignored
94
// three more methods will be tried ...
95
}
96
97         if (_res == null)
98         {
99             try
100             {
101                 _res = _event.extractFilterableData(context, shorthandFilterableData_, value_);
102             } catch (EvaluationException e)
103             {
104                 // can be safely ignored
105
// two more methods will be tried ...
106
}
107
108             if (_res == null)
109             {
110                 _res = extractDefaultValue(context);
111             }
112
113             if (_res == null)
114             {
115                 _res = extractDefaultAnyValue(context);
116             }
117
118             if (_res == null)
119             {
120                 throw new PropertyDoesNotExistException(value_);
121             }
122         }
123
124         return _res;
125     }
126
127     public EvaluationResult extractDefaultValue(EvaluationContext context)
128     {
129         try
130         {
131             return context.getCurrentMessage().extractValue(context, shorthandDefault_);
132         } catch (Exception JavaDoc e)
133         {
134             return null;
135         }
136     }
137
138     public EvaluationResult extractDefaultAnyValue(EvaluationContext context)
139     {
140         try
141         {
142             return context.getCurrentMessage().extractValue(context, shorthandDefaultAny_);
143         } catch (Exception JavaDoc e)
144         {
145             return null;
146         }
147     }
148
149     public String JavaDoc toString()
150     {
151         return "PropertyShorthandNode: " + value_;
152     }
153
154     public void acceptPostOrder(AbstractTCLVisitor visitor) throws VisitorException
155     {
156         if (getFirstChild() != null)
157         {
158             ((AbstractTCLNode) getFirstChild()).acceptPostOrder(visitor);
159         }
160     }
161
162     public void acceptPreOrder(AbstractTCLVisitor visitor) throws VisitorException
163     {
164         ((AbstractTCLNode) getFirstChild()).acceptPreOrder(visitor);
165     }
166
167     public void acceptInOrder(AbstractTCLVisitor visitor) throws VisitorException
168     {
169         ((AbstractTCLNode) getFirstChild()).acceptInOrder(visitor);
170     }
171 }
Popular Tags