00001 // $Id: Notify_Constraint_Interpreter.cpp 85534 2009-06-05 21:02:41Z dai_y $ 00002 00003 #include "orbsvcs/Notify/Notify_Constraint_Interpreter.h" 00004 #include "orbsvcs/Notify/Notify_Constraint_Visitors.h" 00005 #include "orbsvcs/Notify/EventType.h" 00006 #include "tao/debug.h" 00007 00008 ACE_RCSID (Notify, 00009 NS_Constraint_Interpreter, 00010 "$Id: Notify_Constraint_Interpreter.cpp 85534 2009-06-05 21:02:41Z dai_y $") 00011 00012 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00013 00014 TAO_Notify_Constraint_Interpreter::TAO_Notify_Constraint_Interpreter (void) 00015 { 00016 } 00017 00018 TAO_Notify_Constraint_Interpreter::~TAO_Notify_Constraint_Interpreter (void) 00019 { 00020 } 00021 00022 void 00023 TAO_Notify_Constraint_Interpreter::build_tree ( 00024 const char *constraints) 00025 { 00026 if (ETCL_Interpreter::is_empty_string (constraints)) 00027 { 00028 // Root is deleted in the TAO_Interpreter's destructor. 00029 ACE_NEW_THROW_EX (this->root_, 00030 ETCL_Literal_Constraint (true), 00031 CORBA::NO_MEMORY ()); 00032 } 00033 else 00034 { 00035 // root_ is set in this base class call. 00036 if (ETCL_Interpreter::build_tree (constraints) != 0) 00037 { 00038 throw CosNotifyFilter::InvalidConstraint (); 00039 } 00040 } 00041 } 00042 00043 void 00044 TAO_Notify_Constraint_Interpreter::build_tree ( 00045 const CosNotifyFilter::ConstraintExp& exp) 00046 { 00047 ACE_CString exp_str; 00048 ACE_CString et_exp; 00049 00050 CORBA::ULong const len = exp.event_types.length (); 00051 00052 bool has_et_exp = false; 00053 00054 for (CORBA::ULong ii = 0; ii < len; ++ii) 00055 { 00056 TAO_Notify_EventType et; 00057 bool const d = et.domain_is_wildcard (exp.event_types [ii].domain_name.in ()); 00058 bool const t = et.type_is_wildcard (exp.event_types [ii].type_name.in ()); 00059 00060 if (d && t) 00061 { 00062 exp_str = ""; 00063 break; 00064 } 00065 00066 if (has_et_exp) 00067 et_exp += " or "; 00068 et_exp += "("; 00069 00070 has_et_exp = has_et_exp || 1; 00071 00072 if (! d) 00073 { 00074 et_exp += "$domain_name=='"; 00075 et_exp += exp.event_types [ii].domain_name.in (); 00076 et_exp += "'"; 00077 } 00078 00079 if (! t) 00080 { 00081 if (!d) 00082 et_exp += " and "; 00083 00084 et_exp += "$type_name=='"; 00085 et_exp += exp.event_types [ii].type_name.in (); 00086 et_exp += "'"; 00087 } 00088 00089 et_exp += ")"; 00090 } 00091 00092 bool const valid_constraint = !ETCL_Interpreter::is_empty_string (exp.constraint_expr.in ()); 00093 00094 if (has_et_exp && valid_constraint) 00095 { 00096 exp_str = "(("; 00097 exp_str += et_exp; 00098 exp_str += ") and ("; 00099 exp_str += exp.constraint_expr.in (); 00100 exp_str += "))"; 00101 } 00102 else if (has_et_exp) 00103 exp_str = et_exp; 00104 else if (valid_constraint) 00105 exp_str = exp.constraint_expr.in (); 00106 00107 if (TAO_debug_level > 0) 00108 { 00109 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Constraint: %C\n"), 00110 exp_str.c_str ())); 00111 } 00112 this->build_tree (exp_str.c_str ()); 00113 } 00114 00115 CORBA::Boolean 00116 TAO_Notify_Constraint_Interpreter::evaluate (TAO_Notify_Constraint_Visitor &evaluator) 00117 { 00118 return evaluator.evaluate_constraint (this->root_); 00119 } 00120 00121 TAO_END_VERSIONED_NAMESPACE_DECL