00001
00002
00003 #include "orbsvcs/Notify/Notify_Constraint_Visitors.h"
00004 #include "orbsvcs/ETCL/ETCL_Constraint.h"
00005 #include "orbsvcs/ETCL/ETCL_y.h"
00006
00007 #include "tao/DynamicAny/DynArray_i.h"
00008 #include "tao/DynamicAny/DynSequence_i.h"
00009 #include "tao/DynamicAny/DynStruct_i.h"
00010 #include "tao/DynamicAny/DynUnion_i.h"
00011 #include "tao/DynamicAny/DynEnum_i.h"
00012 #include "tao/DynamicAny/DynAnyFactory.h"
00013 #include "tao/DynamicAny/DynAnyUtils_T.h"
00014
00015 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
00016 #include "tao/CDR.h"
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 TAO_Notify_Constraint_Visitor::TAO_Notify_Constraint_Visitor (void)
00021 : implicit_id_ (TAO_Notify_Constraint_Visitor::EMPTY),
00022 implicit_ids_(implicit_ids_size_),
00023 filterable_data_(filterable_data_size_),
00024 variable_header_(variable_header_size_)
00025 {
00026 (void) this->implicit_ids_.bind (ACE_CString ("filterable_data",
00027 0,
00028 false),
00029 FILTERABLE_DATA);
00030 (void) this->implicit_ids_.bind (ACE_CString ("header",
00031 0,
00032 false),
00033 HEADER);
00034 (void) this->implicit_ids_.bind (ACE_CString ("remainder_of_body",
00035 0,
00036 false),
00037 REMAINDER_OF_BODY);
00038 (void) this->implicit_ids_.bind (ACE_CString ("fixed_header",
00039 0,
00040 false),
00041 FIXED_HEADER);
00042 (void) this->implicit_ids_.bind (ACE_CString ("variable_header",
00043 0,
00044 false),
00045 VARIABLE_HEADER);
00046 (void) this->implicit_ids_.bind (ACE_CString ("event_name",
00047 0,
00048 false),
00049 EVENT_NAME);
00050 (void) this->implicit_ids_.bind (ACE_CString ("event_type",
00051 0,
00052 false),
00053 EVENT_TYPE);
00054 (void) this->implicit_ids_.bind (ACE_CString ("domain_name",
00055 0,
00056 false),
00057 DOMAIN_NAME);
00058 (void) this->implicit_ids_.bind (ACE_CString ("type_name",
00059 0,
00060 false),
00061 TYPE_NAME);
00062 }
00063
00064 int
00065 TAO_Notify_Constraint_Visitor::bind_structured_event (const CosNotification::StructuredEvent &s_event)
00066 {
00067
00068
00069
00070 CORBA::ULong length = s_event.filterable_data.length ();
00071 CORBA::ULong index = 0;
00072
00073 for (index = 0; index < length; ++index)
00074 {
00075 ACE_CString name_str (s_event.filterable_data[index].name, 0, false);
00076
00077 int status =
00078 this->filterable_data_.bind (
00079 name_str,
00080 s_event.filterable_data[index].value
00081 );
00082
00083 if (status != 0)
00084 return -1;
00085 }
00086
00087 length = s_event.header.variable_header.length ();
00088
00089 for (index = 0; index < length; ++index)
00090 {
00091 ACE_CString name_str (s_event.header.variable_header[index].name, 0, false);
00092
00093 int status =
00094 this->variable_header_.bind (
00095 name_str,
00096 s_event.header.variable_header[index].value
00097 );
00098
00099 if (status != 0)
00100 return -1;
00101 }
00102
00103 this->domain_name_ =
00104 CORBA::string_dup (s_event.header.fixed_header.event_type.domain_name);
00105
00106 this->type_name_ =
00107 CORBA::string_dup (s_event.header.fixed_header.event_type.type_name);
00108
00109 this->event_name_ =
00110 CORBA::string_dup (s_event.header.fixed_header.event_name);
00111
00112 this->remainder_of_body_ = s_event.remainder_of_body;
00113
00114 return 0;
00115 }
00116
00117 CORBA::Boolean
00118 TAO_Notify_Constraint_Visitor::evaluate_constraint (
00119 TAO_ETCL_Constraint* root
00120 )
00121 {
00122 CORBA::Boolean result = 0;
00123 this->queue_.reset ();
00124
00125
00126 if (root != 0)
00127 {
00128 if ((root->accept (this) == 0) &&
00129 (! this->queue_.is_empty ()))
00130 {
00131 TAO_ETCL_Literal_Constraint top;
00132 this->queue_.dequeue_head (top);
00133 result = (CORBA::Boolean) top;
00134 }
00135 }
00136
00137
00138 return result;
00139 }
00140
00141 int
00142 TAO_Notify_Constraint_Visitor::visit_literal (
00143 TAO_ETCL_Literal_Constraint *literal
00144 )
00145 {
00146 this->queue_.enqueue_head (*literal);
00147 return 0;
00148 }
00149
00150 int
00151 TAO_Notify_Constraint_Visitor::visit_identifier (TAO_ETCL_Identifier *ident)
00152 {
00153 int return_value = -1;
00154 const char *name = ident->value ();
00155 ACE_CString key (name, 0, false);
00156
00157 CORBA::Any any;
00158
00159 if (this->filterable_data_.find (key, any) == 0)
00160 {
00161 if (any.impl() != 0)
00162 {
00163 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (&any));
00164 return_value = 0;
00165 }
00166 }
00167
00168 return return_value;
00169 }
00170
00171 int
00172 TAO_Notify_Constraint_Visitor::visit_union_value (
00173 TAO_ETCL_Union_Value *union_value
00174 )
00175 {
00176 switch (union_value->sign ())
00177 {
00178 case 0:
00179 this->queue_.enqueue_head (*union_value->string ());
00180 break;
00181 case -1:
00182 this->queue_.enqueue_head (-(*union_value->integer ()));
00183 break;
00184 case 1:
00185 this->queue_.enqueue_head (*union_value->integer ());
00186 break;
00187 default:
00188 return -1;
00189 }
00190
00191 return 0;
00192 }
00193
00194 int
00195 TAO_Notify_Constraint_Visitor::visit_union_pos (
00196 TAO_ETCL_Union_Pos *union_pos
00197 )
00198 {
00199 try
00200 {
00201 if (union_pos->union_value ()->accept (this) == 0)
00202 {
00203 TAO_ETCL_Literal_Constraint disc_val;
00204 this->queue_.dequeue_head (disc_val);
00205
00206 TAO_DynUnion_i dyn_union;
00207 dyn_union.init (this->current_value_.in ());
00208
00209 CORBA::TypeCode_var tc = this->current_value_->type ();
00210
00211 switch (disc_val.expr_type ())
00212 {
00213 case TAO_ETCL_INTEGER:
00214 case TAO_ETCL_SIGNED:
00215 case TAO_ETCL_UNSIGNED:
00216 {
00217 CORBA::Any disc_any;
00218 CORBA::TypeCode_var disc_tc =
00219 tc->discriminator_type ();
00220 CORBA::TCKind disc_kind =
00221 TAO_DynAnyFactory::unalias (disc_tc.in ());
00222
00223 switch (disc_kind)
00224 {
00225 case CORBA::tk_boolean:
00226 disc_any <<= CORBA::Any::from_boolean ((CORBA::Boolean) disc_val);
00227 break;
00228 case CORBA::tk_short:
00229 disc_any <<= (CORBA::Short) ((CORBA::Long) disc_val);
00230 break;
00231 case CORBA::tk_ushort:
00232 disc_any <<= (CORBA::UShort) ((CORBA::ULong) disc_val);
00233 break;
00234 case CORBA::tk_long:
00235 disc_any <<= (CORBA::Long) disc_val;
00236 break;
00237 case CORBA::tk_ulong:
00238 disc_any <<= (CORBA::ULong) disc_val;
00239 break;
00240 case CORBA::tk_enum:
00241 {
00242 TAO_OutputCDR cdr;
00243 cdr.write_ulong ((CORBA::ULong) disc_val);
00244 TAO_InputCDR in_cdr (cdr);
00245 TAO::Unknown_IDL_Type *unk = 0;
00246 ACE_NEW_RETURN (unk,
00247 TAO::Unknown_IDL_Type (disc_tc.in (),
00248 in_cdr),
00249 -1);
00250
00251 disc_any.replace (unk);
00252 break;
00253 }
00254
00255
00256
00257
00258 case CORBA::tk_longlong:
00259 case CORBA::tk_ulonglong:
00260 case CORBA::tk_char:
00261 case CORBA::tk_wchar:
00262 default:
00263 return -1;
00264 }
00265
00266 DynamicAny::DynAny_var dyn_any =
00267 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any &> (
00268 disc_tc.in (),
00269 disc_any);
00270 dyn_union.set_discriminator (dyn_any.in ());
00271 DynamicAny::DynAny_var u_member =
00272 dyn_union.member ();
00273 this->current_value_ =
00274 u_member->to_any ();
00275
00276 break;
00277 }
00278 case TAO_ETCL_STRING:
00279 {
00280 const char *name = (const char *) disc_val;
00281 CORBA::ULong count =
00282 tc->member_count ();
00283
00284 const char *member_name = 0;
00285 CORBA::ULong i = 0;
00286
00287 for (i = 0; i < count; ++i)
00288 {
00289 member_name = tc->member_name (i);
00290
00291 if (ACE_OS::strcmp (name, member_name) == 0)
00292 break;
00293 }
00294
00295
00296
00297
00298 this->current_value_ = tc->member_label (i);
00299
00300 break;
00301 }
00302
00303
00304 default:
00305 return -1;
00306 }
00307
00308 TAO_ETCL_Constraint *nested = union_pos->component ();
00309
00310
00311
00312
00313
00314 if (nested == 0)
00315 {
00316 TAO_ETCL_Literal_Constraint lit (this->current_value_.ptr ());
00317 this->queue_.enqueue_head (lit);
00318 return 0;
00319 }
00320 else
00321 return nested->accept (this);
00322 }
00323 else
00324 return -1;
00325 }
00326 catch (const CORBA::Exception&)
00327 {
00328 return -1;
00329 }
00330 }
00331
00332 int
00333 TAO_Notify_Constraint_Visitor::visit_component_pos (
00334 TAO_ETCL_Component_Pos *pos
00335 )
00336 {
00337 try
00338 {
00339
00340
00341 CORBA::TypeCode_var tc = this->current_value_->type ();
00342 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());
00343
00344 DynamicAny::DynAny_var member;
00345 CORBA::Boolean success = 0;
00346 CORBA::ULong slot = (CORBA::ULong) *pos->integer ();
00347
00348 switch (kind)
00349 {
00350 case CORBA::tk_enum:
00351 {
00352 TAO_DynEnum_i dyn_enum;
00353 dyn_enum.init (this->current_value_.in ());
00354
00355 success = dyn_enum.seek (slot);
00356
00357 if (success == 0)
00358 return -1;
00359
00360 member =
00361 dyn_enum.current_component ();
00362
00363 break;
00364 }
00365 case CORBA::tk_struct:
00366 {
00367 TAO_DynStruct_i dyn_struct;
00368 dyn_struct.init (this->current_value_.in ());
00369
00370 success = dyn_struct.seek (slot);
00371
00372 if (success == 0)
00373 return -1;
00374
00375 member = dyn_struct.current_component ();
00376
00377 break;
00378 }
00379
00380
00381
00382
00383 default:
00384 return -1;
00385 }
00386
00387 CORBA::Any_var value = member->to_any ();
00388
00389 TAO_ETCL_Constraint *comp = pos->component ();
00390
00391 if (comp == 0)
00392 {
00393 TAO_ETCL_Literal_Constraint result (value.ptr ());
00394 this->queue_.enqueue_head (result);
00395 return 0;
00396 }
00397 else
00398 {
00399 this->current_value_ = value._retn ();
00400 return comp->accept (this);
00401 }
00402 }
00403 catch (const CORBA::Exception&)
00404 {
00405 return -1;
00406 }
00407 }
00408
00409 int
00410 TAO_Notify_Constraint_Visitor::visit_component_assoc (
00411 TAO_ETCL_Component_Assoc *assoc
00412 )
00413 {
00414 CORBA::Any any;
00415 ACE_CString name (assoc->identifier ()->value (),
00416 0,
00417 false);
00418
00419 switch (this->implicit_id_)
00420 {
00421 case FILTERABLE_DATA:
00422 if (this->filterable_data_.find (name, any) != 0
00423 || any.impl() == 0)
00424 return -1;
00425 break;
00426 case VARIABLE_HEADER:
00427 if (this->variable_header_.find (name, any) != 0
00428 || any.impl() == 0)
00429 return -1;
00430 break;
00431
00432
00433 default:
00434 return -1;
00435 }
00436
00437 TAO_ETCL_Constraint *comp = assoc->component ();
00438 CORBA::Any *any_ptr = 0;
00439
00440 if (comp == 0)
00441 {
00442 TAO_ETCL_Literal_Constraint result (&any);
00443 this->queue_.enqueue_head (result);
00444
00445
00446
00447 ACE_NEW_RETURN (any_ptr,
00448 CORBA::Any,
00449 -1);
00450 (*any_ptr) <<= name.c_str ();
00451 this->current_value_ = any_ptr;
00452
00453 return 0;
00454 }
00455 else
00456 {
00457 ACE_NEW_RETURN (any_ptr,
00458 CORBA::Any (any),
00459 -1);
00460 this->current_value_ = any_ptr;
00461 return comp->accept (this);
00462 }
00463 }
00464
00465 int
00466 TAO_Notify_Constraint_Visitor::visit_component_array (TAO_ETCL_Component_Array *array)
00467 {
00468 try
00469 {
00470
00471
00472
00473 CORBA::TypeCode_var tc = this->current_value_->type ();
00474 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());
00475
00476 DynamicAny::DynAny_var member;
00477 CORBA::Boolean success = 0;
00478 CORBA::ULong slot = (CORBA::ULong) *array->integer ();
00479
00480 switch (kind)
00481 {
00482 case CORBA::tk_array:
00483 {
00484 TAO_DynEnum_i dyn_array;
00485 dyn_array.init (this->current_value_.in ());
00486
00487 success = dyn_array.seek (slot);
00488
00489 if (success == 0)
00490 return -1;
00491
00492 member = dyn_array.current_component ();
00493
00494 break;
00495 }
00496 case CORBA::tk_sequence:
00497 {
00498 TAO_DynStruct_i dyn_sequence;
00499 dyn_sequence.init (this->current_value_.in ());
00500
00501 success = dyn_sequence.seek (slot);
00502
00503 if (success == 0)
00504 return -1;
00505
00506 member =
00507 dyn_sequence.current_component ();
00508
00509 break;
00510 }
00511
00512
00513 default:
00514 return -1;
00515 }
00516
00517 CORBA::Any_var value = member->to_any ();
00518
00519 TAO_ETCL_Constraint *comp = array->component ();
00520
00521 if (comp == 0)
00522 {
00523 TAO_ETCL_Literal_Constraint result (value.ptr ());
00524 this->queue_.enqueue_head (result);
00525 return 0;
00526 }
00527 else
00528 {
00529 this->current_value_ = value._retn ();
00530 return comp->accept (this);
00531 }
00532 }
00533 catch (const CORBA::Exception&)
00534 {
00535 return -1;
00536 }
00537 }
00538
00539 int
00540 TAO_Notify_Constraint_Visitor::visit_special (TAO_ETCL_Special *special)
00541 {
00542 try
00543 {
00544 CORBA::TypeCode_var tc = this->current_value_->type ();
00545 tc = TAO_DynAnyFactory::strip_alias (tc.in ());
00546
00547 CORBA::TCKind kind = tc->kind ();
00548
00549 switch (special->type ())
00550 {
00551 case TAO_ETCL_LENGTH:
00552 {
00553 CORBA::ULong length;
00554
00555 switch (kind)
00556 {
00557 case CORBA::tk_sequence:
00558 {
00559 TAO_DynSequence_i dyn_seq;
00560 dyn_seq.init (current_value_.in());
00561
00562 DynamicAny::AnySeq_var any_seq =
00563 dyn_seq.get_elements ();
00564
00565 length = any_seq->length ();
00566 }
00567 break;
00568 case CORBA::tk_array:
00569 {
00570 length = tc->length ();
00571 }
00572 break;
00573 default:
00574 return -1;
00575 }
00576
00577 TAO_ETCL_Literal_Constraint lit (length);
00578 this->queue_.enqueue_head (lit);
00579 return 0;
00580 }
00581 case TAO_ETCL_DISCRIMINANT:
00582 {
00583
00584
00585 TAO_DynUnion_i dyn_union;
00586 dyn_union.init (this->current_value_.in ());
00587
00588 DynamicAny::DynAny_var disc =
00589 dyn_union.get_discriminator ();
00590
00591 CORBA::Any_var disc_any = disc->to_any ();
00592
00593 TAO_ETCL_Literal_Constraint lit (disc_any.ptr ());
00594 this->queue_.enqueue_head (lit);
00595 return 0;
00596 }
00597 case TAO_ETCL_TYPE_ID:
00598 {
00599 const char *name = tc->name ();
00600
00601 TAO_ETCL_Literal_Constraint lit (name);
00602 this->queue_.enqueue_head (lit);
00603 return 0;
00604 }
00605 case TAO_ETCL_REPOS_ID:
00606 {
00607 const char *id = tc->id ();
00608
00609 TAO_ETCL_Literal_Constraint lit (id);
00610 this->queue_.enqueue_head (lit);
00611 return 0;
00612 }
00613 default:
00614 return -1;
00615 }
00616 }
00617 catch (const CORBA::Exception&)
00618 {
00619 return -1;
00620 }
00621 }
00622
00623 int
00624 TAO_Notify_Constraint_Visitor::visit_component (
00625 TAO_ETCL_Component *component
00626 )
00627 {
00628 TAO_ETCL_Constraint *nested = component->component ();
00629 TAO_ETCL_Identifier *identifier = component->identifier ();
00630 ACE_CString component_name (identifier->value (),
00631 0,
00632 false);
00633 CORBA::Any *any_ptr = 0;
00634
00635 if (this->implicit_ids_.find (component_name, this->implicit_id_) != 0)
00636 this->implicit_id_ = TAO_Notify_Constraint_Visitor::EMPTY;
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646 if (this->implicit_id_ == TAO_Notify_Constraint_Visitor::EMPTY)
00647 {
00648 if (nested == 0)
00649 {
00650
00651
00652 ACE_NEW_RETURN (any_ptr,
00653 CORBA::Any,
00654 -1);
00655 (*any_ptr) <<= component_name.c_str ();
00656 this->current_value_ = any_ptr;
00657 return identifier->accept (this);
00658 }
00659 else
00660 {
00661 int result = identifier->accept (this);
00662
00663 if (result != 0)
00664 return result;
00665
00666 TAO_ETCL_Literal_Constraint id;
00667 this->queue_.dequeue_head (id);
00668 ACE_NEW_RETURN (any_ptr,
00669 CORBA::Any (),
00670 -1);
00671 any_ptr->replace (id);
00672 any_ptr->impl ()->_add_ref ();
00673 this->current_value_ = any_ptr;
00674 }
00675 }
00676
00677 if (nested != 0)
00678 return nested->accept (this);
00679 else
00680 {
00681 switch (this->implicit_id_)
00682 {
00683 case TYPE_NAME:
00684 {
00685 TAO_ETCL_Literal_Constraint tn (this->type_name_.in ());
00686 this->queue_.enqueue_head (tn);
00687 return 0;
00688 }
00689 case EVENT_NAME:
00690 {
00691 TAO_ETCL_Literal_Constraint en (this->event_name_.in ());
00692 this->queue_.enqueue_head (en);
00693 return 0;
00694 }
00695 case DOMAIN_NAME:
00696 {
00697 TAO_ETCL_Literal_Constraint dn (this->domain_name_.in ());
00698 this->queue_.enqueue_head (dn);
00699 return 0;
00700 }
00701 case REMAINDER_OF_BODY:
00702 {
00703 TAO_ETCL_Literal_Constraint rob (&this->remainder_of_body_);
00704 this->queue_.enqueue_head (rob);
00705 return 0;
00706 }
00707
00708
00709
00710 default:
00711 return -1;
00712 }
00713 }
00714 }
00715
00716 int
00717 TAO_Notify_Constraint_Visitor::visit_dot (TAO_ETCL_Dot *dot)
00718 {
00719
00720
00721
00722 return dot->component ()->accept (this);
00723 }
00724
00725 int
00726 TAO_Notify_Constraint_Visitor::visit_eval (TAO_ETCL_Eval *eval)
00727 {
00728
00729 return eval->component ()->accept (this);
00730 }
00731
00732 int
00733 TAO_Notify_Constraint_Visitor::visit_default (TAO_ETCL_Default *def)
00734 {
00735 TAO_ETCL_Constraint *comp = def->component ();
00736
00737 if (comp == 0)
00738 return -1;
00739
00740 if (comp->accept (this) != 0)
00741 return -1;
00742
00743 try
00744 {
00745 CORBA::TypeCode_var tc = this->current_value_->type ();
00746
00747
00748
00749 CORBA::Long default_index = tc->default_index ();
00750
00751
00752 if (default_index == -1)
00753 {
00754 TAO_ETCL_Literal_Constraint result ((CORBA::Boolean) 0);
00755 this->queue_.enqueue_head (result);
00756 return 0;
00757 }
00758
00759
00760
00761 TAO_ETCL_Literal_Constraint disc;
00762 this->queue_.dequeue_head (disc);
00763 TAO_ETCL_Literal_Constraint default_index_value (default_index);
00764 return (disc == default_index_value);
00765 }
00766 catch (const CORBA::Exception&)
00767 {
00768 return -1;
00769 }
00770 }
00771
00772 int
00773 TAO_Notify_Constraint_Visitor::visit_exist (TAO_ETCL_Exist *exist)
00774 {
00775 TAO_ETCL_Constraint *component = exist->component ();
00776
00777 if (component->accept (this) == 0)
00778 {
00779 const char *value = 0;
00780 CORBA::Boolean result = 0;
00781
00782
00783
00784
00785
00786 if (this->implicit_id_ == FILTERABLE_DATA
00787 || this->implicit_id_ == VARIABLE_HEADER)
00788 {
00789 this->current_value_ >>= value;
00790 }
00791
00792
00793 else if (this->implicit_id_ == EMPTY)
00794 {
00795 TAO_ETCL_Identifier* ident =
00796 dynamic_cast<TAO_ETCL_Identifier*> (component);
00797 if (ident != 0)
00798 {
00799 this->implicit_id_ = FILTERABLE_DATA;
00800 value = ident->value ();
00801 }
00802 }
00803
00804
00805 switch (this->implicit_id_)
00806 {
00807 case FILTERABLE_DATA:
00808 result =
00809 (this->filterable_data_.find (ACE_CString (value, 0, false)) == 0);
00810 break;
00811 case VARIABLE_HEADER:
00812 result =
00813 (this->variable_header_.find (ACE_CString (value, 0, false)) == 0);
00814 break;
00815 case TYPE_NAME:
00816 result = (this->type_name_.in () != 0);
00817 break;
00818 case EVENT_NAME:
00819 result = (this->event_name_.in () != 0);
00820 break;
00821 case DOMAIN_NAME:
00822 result = (this->domain_name_.in () != 0);
00823 break;
00824
00825 default:
00826 return -1;
00827 }
00828
00829 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
00830
00831 return 0;
00832 }
00833
00834 return -1;
00835 }
00836
00837 int
00838 TAO_Notify_Constraint_Visitor::visit_unary_expr (
00839 TAO_ETCL_Unary_Expr *unary_expr
00840 )
00841 {
00842 TAO_ETCL_Constraint *subexpr = unary_expr->subexpr ();
00843
00844 if (subexpr->accept (this) == 0)
00845 {
00846 TAO_ETCL_Literal_Constraint subexpr_result;
00847 CORBA::Boolean result = 0;
00848 int op_type = unary_expr->type ();
00849
00850 switch (op_type)
00851 {
00852 case TAO_ETCL_NOT:
00853 this->queue_.dequeue_head (subexpr_result);
00854 result = ! (CORBA::Boolean) subexpr_result;
00855 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
00856 return 0;
00857 case TAO_ETCL_MINUS:
00858
00859
00860
00861 this->queue_.dequeue_head (subexpr_result);
00862 this->queue_.enqueue_head (-subexpr_result);
00863 return 0;
00864 case TAO_ETCL_PLUS:
00865
00866
00867 return 0;
00868 default:
00869
00870
00871 return -1;
00872 }
00873 }
00874
00875 return -1;
00876 }
00877
00878 int
00879 TAO_Notify_Constraint_Visitor::visit_binary_expr (
00880 TAO_ETCL_Binary_Expr *binary_expr
00881 )
00882 {
00883 int bin_op_type = binary_expr->type ();
00884
00885 switch (bin_op_type)
00886 {
00887 case TAO_ETCL_OR:
00888 return this->visit_or (binary_expr);
00889 case TAO_ETCL_AND:
00890 return this->visit_and (binary_expr);
00891 case TAO_ETCL_LT:
00892 case TAO_ETCL_LE:
00893 case TAO_ETCL_GT:
00894 case TAO_ETCL_GE:
00895 case TAO_ETCL_EQ:
00896 case TAO_ETCL_NE:
00897 case TAO_ETCL_PLUS:
00898 case TAO_ETCL_MINUS:
00899 case TAO_ETCL_MULT:
00900 case TAO_ETCL_DIV:
00901 return this->visit_binary_op (binary_expr,
00902 bin_op_type);
00903 case TAO_ETCL_TWIDDLE:
00904 return this->visit_twiddle (binary_expr);
00905 case TAO_ETCL_IN:
00906 return this->visit_in (binary_expr);
00907 default:
00908 return -1;
00909 }
00910 }
00911
00912 int
00913 TAO_Notify_Constraint_Visitor::visit_or (
00914 TAO_ETCL_Binary_Expr *binary
00915 )
00916 {
00917 int return_value = -1;
00918 CORBA::Boolean result = 0;
00919 TAO_ETCL_Constraint *lhs = binary->lhs ();
00920
00921 if (lhs->accept (this) == 0)
00922 {
00923 TAO_ETCL_Literal_Constraint lhs_result;
00924 this->queue_.dequeue_head (lhs_result);
00925 result = (CORBA::Boolean) lhs_result;
00926
00927
00928 if (result == 0)
00929 {
00930 TAO_ETCL_Constraint *rhs = binary->rhs ();
00931
00932 if (rhs->accept (this) == 0)
00933 {
00934 TAO_ETCL_Literal_Constraint rhs_result;
00935 this->queue_.dequeue_head (rhs_result);
00936 result = (CORBA::Boolean) rhs_result;
00937 return_value = 0;
00938 }
00939 }
00940 else
00941 return_value = 0;
00942 }
00943
00944 if (return_value == 0)
00945 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
00946
00947 return return_value;
00948 }
00949
00950 int
00951 TAO_Notify_Constraint_Visitor::visit_and (TAO_ETCL_Binary_Expr *binary)
00952 {
00953 int return_value = -1;
00954 CORBA::Boolean result = 0;
00955 TAO_ETCL_Constraint *lhs = binary->lhs ();
00956
00957 if (lhs->accept (this) == 0)
00958 {
00959 TAO_ETCL_Literal_Constraint lhs_result;
00960 this->queue_.dequeue_head (lhs_result);
00961 result = (CORBA::Boolean) lhs_result;
00962
00963
00964 if (result == 1)
00965 {
00966 TAO_ETCL_Constraint *rhs = binary->rhs ();
00967
00968 if (rhs->accept (this) == 0)
00969 {
00970 TAO_ETCL_Literal_Constraint rhs_result;
00971 this->queue_.dequeue_head (rhs_result);
00972 result = (CORBA::Boolean) rhs_result;
00973 return_value = 0;
00974 }
00975 }
00976 else
00977 return_value = 0;
00978 }
00979
00980 if (return_value == 0)
00981 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
00982
00983 return return_value;
00984 }
00985
00986 int
00987 TAO_Notify_Constraint_Visitor::visit_binary_op (TAO_ETCL_Binary_Expr *binary,
00988 int op_type)
00989 {
00990 int return_value = -1;
00991 TAO_ETCL_Constraint *lhs = binary->lhs ();
00992 CORBA::Boolean result = 0;
00993
00994
00995
00996 if (lhs->accept (this) == 0)
00997 {
00998 TAO_ETCL_Literal_Constraint left_operand;
00999 this->queue_.dequeue_head (left_operand);
01000 TAO_ETCL_Constraint *rhs = binary->rhs ();
01001
01002 if (rhs->accept (this) == 0)
01003 {
01004 TAO_ETCL_Literal_Constraint right_operand;
01005 this->queue_.dequeue_head (right_operand);
01006 return_value = 0;
01007
01008 switch (op_type)
01009 {
01010 case TAO_ETCL_LT:
01011 result = left_operand < right_operand;
01012 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01013 break;
01014 case TAO_ETCL_LE:
01015 result = left_operand <= right_operand;
01016 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01017 break;
01018 case TAO_ETCL_GT:
01019 result = left_operand > right_operand;
01020 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01021 break;
01022 case TAO_ETCL_GE:
01023 result = left_operand >= right_operand;
01024 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01025 break;
01026 case TAO_ETCL_EQ:
01027 result = left_operand == right_operand;
01028 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01029 break;
01030 case TAO_ETCL_NE:
01031 result = left_operand != right_operand;
01032 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01033 break;
01034 case TAO_ETCL_PLUS:
01035 this->queue_.enqueue_head (left_operand + right_operand);
01036 break;
01037 case TAO_ETCL_MINUS:
01038 this->queue_.enqueue_head (left_operand - right_operand);
01039 break;
01040 case TAO_ETCL_MULT:
01041 this->queue_.enqueue_head (left_operand * right_operand);
01042 break;
01043 case TAO_ETCL_DIV:
01044 this->queue_.enqueue_head (left_operand / right_operand);
01045 break;
01046 default:
01047 return_value = -1;
01048 }
01049 }
01050 }
01051
01052 return return_value;
01053 }
01054
01055 int
01056 TAO_Notify_Constraint_Visitor::visit_twiddle (TAO_ETCL_Binary_Expr *binary)
01057 {
01058 int return_value = -1;
01059 TAO_ETCL_Constraint *lhs = binary->lhs ();
01060
01061
01062 if (lhs->accept (this) == 0)
01063 {
01064 TAO_ETCL_Literal_Constraint left;
01065 this->queue_.dequeue_head (left);
01066 TAO_ETCL_Constraint *rhs = binary->rhs ();
01067
01068 if (rhs->accept (this) == 0)
01069 {
01070 TAO_ETCL_Literal_Constraint right;
01071 this->queue_.dequeue_head (right);
01072 CORBA::Boolean result =
01073 (ACE_OS::strstr ((const char *) right,
01074 (const char *) left) != 0);
01075 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01076 return_value = 0;
01077 }
01078 }
01079
01080 return return_value;
01081 }
01082
01083 int
01084 TAO_Notify_Constraint_Visitor::visit_in (TAO_ETCL_Binary_Expr *binary)
01085 {
01086 int return_value = -1;
01087 TAO_ETCL_Constraint *lhs = binary->lhs ();
01088
01089
01090 if (lhs->accept (this) == 0)
01091 {
01092 TAO_ETCL_Literal_Constraint left;
01093 this->queue_.dequeue_head (left);
01094
01095 TAO_ETCL_Constraint *rhs = binary->rhs ();
01096
01097 if (rhs->accept (this) == 0)
01098 {
01099 TAO_ETCL_Literal_Constraint bag;
01100 this->queue_.dequeue_head (bag);
01101
01102 if (bag.expr_type () == TAO_ETCL_COMPONENT)
01103 {
01104 CORBA::Any_var component = new CORBA::Any ();
01105 component->replace (bag);
01106 component->impl ()->_add_ref ();
01107 CORBA::TCKind kind = CORBA::tk_null;
01108
01109 try
01110 {
01111 CORBA::TypeCode_var tc = component->type ();
01112 kind = TAO_DynAnyFactory::unalias (tc.in ());
01113 }
01114 catch (const CORBA::Exception&)
01115 {
01116 return return_value;
01117 }
01118
01119 CORBA::Boolean result = 0;
01120
01121 switch (kind)
01122 {
01123 case CORBA::tk_sequence:
01124 result = this->sequence_does_contain (&component.in (),
01125 left);
01126 break;
01127 case CORBA::tk_array:
01128 result = this->array_does_contain (&component.in (),
01129 left);
01130 break;
01131 case CORBA::tk_struct:
01132 result = this->struct_does_contain (&component.in (),
01133 left);
01134 break;
01135 case CORBA::tk_union:
01136 result = this->union_does_contain (&component.in (),
01137 left);
01138 break;
01139 case CORBA::tk_any:
01140 result = this->any_does_contain (&component.in (),
01141 left);
01142 break;
01143 default:
01144 return return_value;
01145 }
01146
01147 this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
01148 return_value = 0;
01149 }
01150 }
01151 }
01152
01153 return return_value;
01154 }
01155
01156 int
01157 TAO_Notify_Constraint_Visitor::visit_preference (TAO_ETCL_Preference *)
01158 {
01159
01160
01161
01162
01163 return -1;
01164 }
01165
01166 CORBA::Boolean
01167 TAO_Notify_Constraint_Visitor::sequence_does_contain (const CORBA::Any *any,
01168 TAO_ETCL_Literal_Constraint &item)
01169 {
01170 try
01171 {
01172 CORBA::TypeCode_var type = any->type ();
01173 CORBA::TypeCode_var base_type =
01174 TAO_DynAnyFactory::strip_alias (type.in ());
01175 CORBA::TypeCode_var content_type =
01176 base_type->content_type ();
01177 CORBA::TCKind kind =
01178 TAO_DynAnyFactory::unalias (content_type.in());
01179
01180
01181
01182 CORBA::Boolean match = this->simple_type_match (item.expr_type (),
01183 kind);
01184
01185 if (match == 0)
01186 return 0;
01187
01188 TAO_DynSequence_i dyn_seq;
01189 dyn_seq.init (*any);
01190
01191 DynamicAny::AnySeq_var any_seq =
01192 dyn_seq.get_elements ();
01193
01194 CORBA::ULong length = any_seq->length ();
01195
01196 for (CORBA::ULong i = 0; i < length; ++i)
01197 {
01198 TAO_ETCL_Literal_Constraint element (&any_seq[i]);
01199
01200 if (item == element)
01201 return 1;
01202 }
01203 }
01204 catch (const CORBA::Exception&)
01205 {
01206 return 0;
01207 }
01208
01209 return 0;
01210 }
01211
01212 CORBA::Boolean
01213 TAO_Notify_Constraint_Visitor::array_does_contain (const CORBA::Any *any,
01214 TAO_ETCL_Literal_Constraint &item)
01215 {
01216 try
01217 {
01218 CORBA::TypeCode_var type = any->type ();
01219 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (type.in ());
01220
01221
01222
01223 CORBA::Boolean match = this->simple_type_match (item.expr_type (),
01224 kind);
01225
01226 if (match == 0)
01227 return 0;
01228
01229 TAO_DynArray_i dyn_array;
01230 dyn_array.init (*any);
01231
01232 DynamicAny::AnySeq_var any_seq =
01233 dyn_array.get_elements ();
01234
01235 CORBA::ULong length = any_seq->length ();
01236
01237 for (CORBA::ULong i = 0; i < length; ++i)
01238 {
01239 TAO_ETCL_Literal_Constraint element (&any_seq[i]);
01240
01241 if (item == element)
01242 return 1;
01243 }
01244 }
01245 catch (const CORBA::Exception&)
01246 {
01247 return 0;
01248 }
01249
01250 return 0;
01251 }
01252
01253 CORBA::Boolean
01254 TAO_Notify_Constraint_Visitor::struct_does_contain (const CORBA::Any *any,
01255 TAO_ETCL_Literal_Constraint &item)
01256 {
01257 try
01258 {
01259 TAO_DynStruct_i dyn_struct;
01260 dyn_struct.init (*any);
01261
01262 DynamicAny::NameValuePairSeq_var members =
01263 dyn_struct.get_members ();
01264
01265 CORBA::ULong length = members->length ();
01266 CORBA::TypeCode_var tc;
01267 CORBA::TCKind kind;
01268
01269 for (CORBA::ULong i = 0; i < length; ++i)
01270 {
01271 tc = members[i].value.type ();
01272 kind = TAO_DynAnyFactory::unalias (tc.in ());
01273
01274
01275
01276 CORBA::Boolean match = this->simple_type_match (item.expr_type (),
01277 kind);
01278
01279 if (match == 0)
01280 continue;
01281
01282 TAO_ETCL_Literal_Constraint element (&members[i].value);
01283
01284 if (item == element)
01285 return 1;
01286 }
01287 }
01288 catch (const CORBA::Exception&)
01289 {
01290 return 0;
01291 }
01292
01293 return 0;
01294 }
01295
01296 CORBA::Boolean
01297 TAO_Notify_Constraint_Visitor::union_does_contain (const CORBA::Any *any,
01298 TAO_ETCL_Literal_Constraint &item)
01299 {
01300 try
01301 {
01302 TAO_DynUnion_i dyn_union;
01303 dyn_union.init (*any);
01304
01305 DynamicAny::DynAny_var cc =
01306 dyn_union.current_component ();
01307
01308 CORBA::Any_var member = cc->to_any ();
01309
01310 CORBA::TypeCode_var tc = member->type ();
01311 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());
01312
01313
01314
01315 CORBA::Boolean match = this->simple_type_match (item.expr_type (),
01316 kind);
01317
01318 if (match == 0)
01319 return 0;
01320
01321 TAO_ETCL_Literal_Constraint element (&member.inout ());
01322
01323 return (item == element);
01324 }
01325 catch (const CORBA::Exception&)
01326 {
01327 return 0;
01328 }
01329 }
01330
01331 CORBA::Boolean
01332 TAO_Notify_Constraint_Visitor::any_does_contain (
01333 const CORBA::Any *any,
01334 TAO_ETCL_Literal_Constraint &item
01335 )
01336 {
01337 const CORBA::Any *result = 0;
01338
01339 *any >>= result;
01340
01341 TAO_ETCL_Literal_Constraint element (const_cast<CORBA::Any *>(result));
01342 return item == element;
01343 }
01344
01345 CORBA::Boolean
01346 TAO_Notify_Constraint_Visitor::simple_type_match (int expr_type,
01347 CORBA::TCKind tc_kind)
01348 {
01349 switch (expr_type)
01350 {
01351 case TAO_ETCL_STRING:
01352 if (tc_kind != CORBA::tk_string)
01353 return 0;
01354 break;
01355 case TAO_ETCL_DOUBLE:
01356 if (tc_kind != CORBA::tk_double
01357 && tc_kind != CORBA::tk_float)
01358 return 0;
01359 break;
01360 case TAO_ETCL_INTEGER:
01361 case TAO_ETCL_SIGNED:
01362 if (tc_kind != CORBA::tk_short
01363 && tc_kind != CORBA::tk_long
01364 && tc_kind != CORBA::tk_longlong)
01365 return 0;
01366 break;
01367 case TAO_ETCL_UNSIGNED:
01368 if (tc_kind != CORBA::tk_ushort
01369 && tc_kind != CORBA::tk_ulong
01370 && tc_kind != CORBA::tk_ulonglong)
01371 return 0;
01372 break;
01373 case TAO_ETCL_BOOLEAN:
01374 if (tc_kind != CORBA::tk_boolean)
01375 return 0;
01376 break;
01377 default:
01378 return 0;
01379 }
01380 return 1;
01381 }
01382
01383 const size_t TAO_Notify_Constraint_Visitor::implicit_ids_size_ = 27;
01384 const size_t TAO_Notify_Constraint_Visitor::filterable_data_size_ = 31;
01385 const size_t TAO_Notify_Constraint_Visitor::variable_header_size_ = 31;
01386
01387 TAO_END_VERSIONED_NAMESPACE_DECL