summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Locator_XMLHandler.cpp
blob: ee133fb6a7d7dd5eee34dee6aec3617c5ac1edc7 (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
// $Id$

#include "Locator_XMLHandler.h"
#include "ace/OS_NS_strings.h"

ACE_RCSID (ImplRepo_Service,Locator_XMLHandler,"$Id$")

  const ACE_TCHAR* Locator_XMLHandler::ROOT_TAG = ACE_TEXT("ImplementationRepository");
const ACE_TCHAR* Locator_XMLHandler::SERVER_INFO_TAG = ACE_TEXT("Servers");
const ACE_TCHAR* Locator_XMLHandler::ACTIVATOR_INFO_TAG = ACE_TEXT("Activators");
const ACE_TCHAR* Locator_XMLHandler::ENVIRONMENT_TAG = ACE_TEXT("EnvironmentVariables");

Locator_XMLHandler::Locator_XMLHandler (Callback& cb)
  : callback_ (cb)
{
}

void
Locator_XMLHandler::startElement (const ACEXML_Char*,
                                  const ACEXML_Char*,
                                  const ACEXML_Char* qName,
                                  ACEXML_Attributes* attrs ACEXML_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACE_ASSERT (qName != 0);
  if (ACE_OS::strcasecmp (qName, SERVER_INFO_TAG) == 0)
    {
      // We'll use this as a key to determine if we've got a valid record
      this->server_name_ = "";
      this->env_vars_.clear();

      if (attrs != 0 && attrs->getLength () == 8)
        {
          this->server_name_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)0)));
          this->activator_name_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)1)));
          this->command_line_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)2)));
          this->working_dir_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)3)));
          this->activation_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)4)));

          this->env_vars_.clear();

          int limit = ACE_OS::atoi (attrs->getValue((size_t)5));
          this->start_limit_ = limit;
          this->partial_ior_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)6)));
          this->server_object_ior_.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)7)));
        }
    }
  else if (ACE_OS::strcasecmp (qName, ACTIVATOR_INFO_TAG) == 0)
    {
      if (attrs != 0 && attrs->getLength () == 3)
        {
          ACE_CString aname (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)0)));
          ACE_CString token_str (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)1)));
          long token = ACE_OS::atoi (token_str.c_str());
          ACE_CString ior (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)2)));
          this->callback_.next_activator(aname, token, ior);
        }
    }
  else if (ACE_OS::strcasecmp (qName, ENVIRONMENT_TAG) == 0)
    {
      if (attrs != 0 && attrs->getLength() == 2)
        {
          EnvVar ev;
          ev.name.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)0)));
          ev.value.set (ACE_TEXT_TO_CHAR_IN (attrs->getValue((size_t)1)));
          this->env_vars_.push_back(ev);
        }
    }
}

void
Locator_XMLHandler::endElement (const ACEXML_Char*,
                                const ACEXML_Char*,
                                const ACEXML_Char* qName ACEXML_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACE_ASSERT(qName != 0);
  if (ACE_OS::strcasecmp (qName, SERVER_INFO_TAG) == 0
      && this->server_name_.length () > 0)
    {
      this->callback_.next_server (this->server_name_,
                                   this->activator_name_, this->command_line_,
                                   this->env_vars_, this->working_dir_, this->activation_,
                                   this->start_limit_, this->partial_ior_, this->server_object_ior_);
    }
  // activator info is handled in the startElement
}

bool
Locator_XMLHandler::EnvVar::operator== (const EnvVar& rhs) const
{
  return name == rhs.name && value == rhs.value;
}
bool
Locator_XMLHandler::EnvVar::operator!= (const EnvVar& rhs) const
{
  return ! (rhs == *this);
}