summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.cpp
blob: 5d1d6638916d3b4ba44a3b3cc9186654d2e03591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// $Id$

#include "Property_Filter.h"

TAO_Property_Filter::
TAO_Property_Filter (const SPECIFIED_PROPS& desired_props,
		     CORBA::Environment& _env)
  TAO_THROW_SPEC ((CosTrading::IllegalPropertyName,
		   CosTrading::DuplicatePropertyName))
  : policy_  (desired_props._d ())
{
  if (this->policy_ == CosTrading::Lookup::some)
    {
    const CosTrading::PropertyNameSeq& prop_seq = desired_props.prop_names ();
      int length = prop_seq.length ();

      for (int i = 0; i < length; i++)
	{
	  const char* pname = prop_seq[i];

	  // Check for errors or duplicates
	  if (! TAO_Trader_Base::is_valid_identifier_name (pname))
	    TAO_THROW_SPEC (CosTrading::IllegalPropertyName (pname));
	  else
	    {
	      // Insert returns a pair whose second element is a flag
	      // indicating whether a collision occured.
	      TAO_String_Hash_Key prop_name (pname);
	      if (this->props_.insert (prop_name) == 1)
		TAO_THROW_SPEC (CosTrading::DuplicatePropertyName (pname));
	    }	    
	}
    }
}

TAO_Property_Filter::
TAO_Property_Filter (const TAO_Property_Filter& prop_filter)
  : props_ (prop_filter.props_),
    policy_ (prop_filter.policy_)
{  
}

void
TAO_Property_Filter::filter_offer (CosTrading::Offer& source,
				   CosTrading::Offer& destination)
{
  Prop_Queue prop_queue;
  CosTrading::PropertySeq& s_props = source.properties;
  CosTrading::PropertySeq& d_props = destination.properties;
  int length = s_props.length (), elem = 0;

  destination.reference = source.reference->_duplicate (source.reference);
  if (this->policy_ != CosTrading::Lookup::none)
    {
      for (int i = 0; i < length; i++)
	{
	  if (this->policy_ == CosTrading::Lookup::all)
	    prop_queue.enqueue_tail (&s_props[i]);
	  else
	    {
	      TAO_String_Hash_Key prop_name ((const char*) s_props[i].name);

	      // Save those property that match.
	      if (this->props_.find (prop_name) == 0)
		prop_queue.enqueue_tail (&s_props[i]);
	    }
	}

      // Shove the matched properties into the destination property
      // sequence. 
      length = prop_queue.size ();
      d_props.length (prop_queue.size ());
      for (Prop_Queue::ITERATOR prop_iter (prop_queue);
	   ! prop_iter.done ();
	   prop_iter.advance (), elem++)
	{
	  CosTrading::Property** prop_ptr = 0;
	  
	  prop_iter.next (prop_ptr);
	  d_props[elem] = **prop_ptr;
	}
    }
}

int
TAO_Property_Filter::verify_property_name (const char* name)
{
  int return_value = -1,
    length = ACE_OS::strlen (name);

  if (length >= 1 && isalpha (name[0]))
      {
	for (int i = 0; i < length; i++)
	  {
	    if (! (isalnum (name[i]) || name[i] == '_'))
	      break;
	  }

	return_value = 0;
      }

  return return_value;
}