summaryrefslogtreecommitdiff
path: root/modules/CIAO/tools/Config_Handlers/XML_File_Intf.cpp
blob: eed90d47245cee65bc568f0048b15b2fac12ab57 (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 "XML_File_Intf.h"
#include "XML_Typedefs.h"
#include "Deployment.hpp"
#include "DP_Handler.h"
#include "Common.h"

#include "DAnCE/Deployment/Deployment_DataC.h"
#include "ciao/CIAO_common.h"

namespace CIAO
{
  namespace Config_Handlers
  {
    XML_File_Intf::XML_File_Intf (const ACE_TCHAR *file)
      : file_ (file),
        idl_dp_ (0)
    {
    }

    bool
    XML_File_Intf::read_process_file (const ACE_TCHAR *file)
    {
      CIAO_TRACE("XML_File_Intf::read_process_file");

      try
        {
          if (!XML_Helper::XML_HELPER.is_initialized ())
            return false;

          CIAO_DEBUG ((LM_TRACE, CLINFO "XML_File_Intf::read_process_file - "
                       "Constructing DOM\n"));
          XERCES_CPP_NAMESPACE::DOMDocument *dom =
            XML_Helper::XML_HELPER.create_dom ((file));

          if (dom == 0)
            {
              CIAO_DEBUG ((LM_TRACE, CLINFO "XML_File_Intf::read_process_file - "
                           "Failed to open file %s\n", file));
              return false;
            }

          XERCES_CPP_NAMESPACE::DOMElement *foo = dom->getDocumentElement ();
          CIAO_DEBUG ((LM_TRACE, CLINFO "XML_File_Intf::read_process_file - "
                       "DOMElement pointer: %u\n", foo));

          CIAO_DEBUG ((LM_TRACE, CLINFO "XML_File_Intf::read_process_file - "
                       "Parsing XML file with XSC\n"));
          deploymentPlan dp =
            CIAO::Config_Handlers::reader::DeploymentPlan (dom);

          CIAO_DEBUG ((LM_TRACE, CLINFO "XML_File_Intf::read_process_file - "
                       "Processing using config handlers\n"));
          DP_Handler dp_handler (dp);

          this->idl_dp_.reset (dp_handler.plan ());

          if (this->idl_dp_.get ())
            return true;
        }
      catch (const Config_Error &ex)
        {
          CIAO_ERROR ((LM_ERROR, CLINFO "XML_File_Intf::error at %C: %C\n",
                      ex.name_.c_str (), ex.error_.c_str ()));
        }
      catch (...)
        {
          CIAO_ERROR ((LM_ERROR, CLINFO "XML_File_Intf::caught - "
                                        "Unexpected exception whilst parsing XML into IDL.\n"));
        }

      return false;
    }

    ::Deployment::DeploymentPlan const *
    XML_File_Intf::get_plan (void)
    {
      CIAO_TRACE("get_plan");
      if (this->idl_dp_.get () == 0 && !this->read_process_file (this->file_.c_str ()))
        return 0;

      return this->idl_dp_.get ();
    }

    ::Deployment::DeploymentPlan *
    XML_File_Intf::release_plan (void)
    {
      CIAO_TRACE("XML_File_Intf::get_plan");
      if (this->idl_dp_.get () == 0 && !this->read_process_file (this->file_.c_str ()))
        return 0;
      return this->idl_dp_.release ();
    }

    void
    XML_File_Intf::add_search_path (const ACE_TCHAR *environment,
                                    const ACE_TCHAR *relpath)
    {
      XML_Helper::_path_resolver.add_path (environment, relpath);
    }

  }
}