summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.cpp
blob: 1692b46a1449713a82946cd20da0b352fc14197c (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
// $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 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.
	      string prop_name (pname);
	      if (this->props_.insert (prop_name).second == 0)
		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;
  
  if (this->policy_ != CosTrading::Lookup::none)
    {
      for (int i = 0; i < length; i++)
	{
	  if (this->policy_ == CosTrading::Lookup::all)
	    prop_queue.push_back (&s_props[i]);
	  else
	    {
	      string prop_name (s_props[i].name);

	      // Save those property that match.
	      if (this->props_.find (prop_name) != this->props_.end ())
		prop_queue.push_back (&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.begin ();
	   prop_iter != prop_queue.end ();
	   prop_iter++)      
	d_props[elem++] = *(*prop_iter);
    }
}

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;
}