KickJava   Java API By Example, From Geeks To Geeks.

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


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.FilterConstraint;
28 import org.jacorb.notification.filter.ParseException;
29 import org.jacorb.notification.interfaces.Message;
30 import org.omg.CosNotifyFilter.ConstraintExp;
31 import org.omg.CosNotifyFilter.InvalidConstraint;
32
33 /**
34  * Representation of a Constraint.
35  * A {@link org.jacorb.notification.FilterImpl FilterImpl} encapsulates
36  * several Constraints. Each Constraint is represented by an instance
37  * of this Class.
38  *
39  * @author Alphonse Bendt
40  * @version $Id: ETCLFilterConstraint.java,v 1.3 2005/02/14 00:07:08 alphonse.bendt Exp $
41  */

42
43 public class ETCLFilterConstraint implements FilterConstraint
44 {
45     /**
46      * AST for the Constraint
47      */

48     private AbstractTCLNode rootNode_;
49
50     ////////////////////////////////////////
51

52     public ETCLFilterConstraint( AbstractTCLNode root )
53     {
54         rootNode_ = root;
55     }
56
57
58     public ETCLFilterConstraint( ConstraintExp constraintExp )
59         throws InvalidConstraint
60     {
61         try
62         {
63             rootNode_ = TCLParser.parse( constraintExp.constraint_expr );
64
65             if (rootNode_ != null) {
66                 TCLCleanUp _cleanUp = new TCLCleanUp();
67                 _cleanUp.fix( rootNode_ );
68
69                 StaticTypeChecker _checker = new StaticTypeChecker();
70                 _checker.check( rootNode_ );
71             }
72             return;
73         }
74         catch ( StaticTypeException e )
75         {
76             throw new InvalidConstraint( e.getMessage(), constraintExp );
77         }
78         catch ( ParseException e )
79         {
80             throw new InvalidConstraint( e.getMessage(), constraintExp );
81         }
82     }
83
84     ////////////////////////////////////////
85

86     public EvaluationResult evaluate( EvaluationContext evaluationContext,
87                                       Message event )
88         throws EvaluationException
89     {
90         if (rootNode_ == null) {
91             return EvaluationResult.BOOL_TRUE;
92         }
93
94         evaluationContext.setCurrentMessage( event );
95
96         EvaluationResult _res = rootNode_.evaluate( evaluationContext );
97
98         return _res;
99     }
100
101
102     public String JavaDoc toString()
103     {
104         StringBuffer JavaDoc _buffer = new StringBuffer JavaDoc("<FilterConstraint: ");
105
106         rootNode_.printToStringBuffer(_buffer);
107         _buffer.append(" >");
108
109         return _buffer.toString();
110     }
111 }
112
Popular Tags