TAO_Notify::XML_Loader Class Reference

Load Notification Service Topology from an XML file. More...

#include <XML_Loader.h>

Inheritance diagram for TAO_Notify::XML_Loader:

Inheritance graph
[legend]
Collaboration diagram for TAO_Notify::XML_Loader:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 XML_Loader ()
 The constructor.
virtual ~XML_Loader ()
bool open (const ACE_CString &file_name)
virtual void load (Topology_Object *root)
 Begin the restore process.
virtual void startElement (const ACEXML_Char *namespaceURI, const ACEXML_Char *localName, const ACEXML_Char *qName, ACEXML_Attributes *atts ACEXML_ENV_ARG_DECL)
virtual void endElement (const ACEXML_Char *, const ACEXML_Char *, const ACEXML_Char *name ACEXML_ENV_ARG_DECL_NOT_USED)

Private Types

typedef ACE_Unbounded_Stack<
Topology_Object * > 
TopoStack

Private Attributes

ACE_CString file_name_
 The name of the file from which data is read.
FILE * input_
 A stream representing our current output.
TopoStack object_stack_
bool live_
 if false, then we're just checking syntax of topology file.

Detailed Description

Load Notification Service Topology from an XML file.

Definition at line 37 of file XML_Loader.h.


Member Typedef Documentation

typedef ACE_Unbounded_Stack<Topology_Object*> TAO_Notify::XML_Loader::TopoStack [private]

Definition at line 73 of file XML_Loader.h.


Constructor & Destructor Documentation

TAO_Notify::XML_Loader::XML_Loader (  ) 

The constructor.

Definition at line 52 of file XML_Loader.cpp.

00053     : input_ (0)
00054     , live_ (false)
00055   {
00056   }

TAO_Notify::XML_Loader::~XML_Loader (  )  [virtual]

Definition at line 58 of file XML_Loader.cpp.

00059   {
00060   }


Member Function Documentation

virtual void TAO_Notify::XML_Loader::endElement ( const ACEXML_Char *  ,
const ACEXML_Char *  ,
const ACEXML_Char *name  ACEXML_ENV_ARG_DECL_NOT_USED 
) [virtual]

void TAO_Notify::XML_Loader::load ( Topology_Object root  )  [virtual]

Begin the restore process.

Call this function to start the reload of data from a persistent store. When the Topology_Loader detects a child object, it should call the load_child method of the object passed in, then do the same loading process on the returned object.

Implements TAO_Notify::Topology_Loader.

Definition at line 126 of file XML_Loader.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_ERROR, ACE_TEXT(), ACE_String_Base< CHAR >::c_str(), file_name_, ACE_Auto_Basic_Ptr< X >::get(), live_, LM_DEBUG, LM_ERROR, object_stack_, ACE_Unbounded_Stack< T >::pop(), ACE_Unbounded_Stack< T >::push(), ACE_Auto_Basic_Ptr< X >::release(), and ACE_Unbounded_Stack< T >::size().

00127   {
00128     ACE_ASSERT (root != 0);
00129     this->live_ = true;
00130 
00131     auto_ptr<ACEXML_FileCharStream> fstm (new ACEXML_FileCharStream);
00132     // xml input source will take ownership
00133 
00134     if (fstm->open (this->file_name_.c_str ()) == 0)
00135     {
00136       // InputSource takes ownership
00137       ACEXML_InputSource input (fstm.get ());
00138       (void) fstm.release ();
00139 
00140       ACEXML_Parser parser;
00141       parser.setContentHandler (this);
00142       parser.setDTDHandler (this);
00143       parser.setErrorHandler (this);
00144       parser.setEntityResolver (this);
00145 
00146       try
00147       {
00148         object_stack_.push (root);
00149         parser.parse (&input ACEXML_ENV_ARG_PARAMETER);
00150         ACEXML_TRY_CHECK;
00151         ACE_ASSERT (object_stack_.size () == 1);
00152         Topology_Object* cur;
00153         object_stack_.pop (cur);
00154       }
00155       catch (const ACEXML_Exception& ex)
00156       {
00157         // The only way to find out what it is, it to let it print itself, so...
00158         ACE_ERROR ((LM_ERROR, "Unable to load \"%s\".\n", this->file_name_.c_str ()));
00159         ex.print ();
00160         throw CORBA::INTERNAL();
00161       }
00162     }
00163     else
00164     {
00165       ACE_DEBUG((LM_DEBUG, ACE_TEXT("Unable to open the XML input file: %s.\n"), file_name_.c_str()));
00166       throw CORBA::INTERNAL();
00167     }
00168   }

bool TAO_Notify::XML_Loader::open ( const ACE_CString file_name  ) 

Open a file and perform preliminary validation to determine whether the file is complete and valid.

Definition at line 63 of file XML_Loader.cpp.

References ACE_OS::access(), ACE_DEBUG, ACE_ERROR, ACE_TEXT(), ACE_String_Base< CHAR >::c_str(), file_name_, ACE_Auto_Basic_Ptr< X >::get(), live_, LM_DEBUG, LM_ERROR, and ACE_Auto_Basic_Ptr< X >::release().

Referenced by TAO_Notify::XML_Topology_Factory::create_loader().

00064   {
00065     bool result = false;
00066 
00067     // if *.xml exists, use it
00068     // if it does not exist then
00069     // use the previous one was renamed to *.000
00070     // If neither *.xml nor *.000 exist then something
00071     // "impossible" happened (or its a new system with no saved state).
00072 
00073     this->file_name_ = base_name;
00074     this->file_name_ += ".xml";
00075 
00076     // 4 is "read permission"
00077     result =  (0 == ACE_OS::access (this->file_name_.c_str (), 4));
00078     if (result)
00079     {
00080       this->live_ = false;
00081       auto_ptr<ACEXML_FileCharStream> fstm (new ACEXML_FileCharStream);
00082       // xml input source will take ownership
00083 
00084       if (fstm->open (this->file_name_.c_str ()) == 0)
00085       {
00086         // InputSource takes ownership
00087         ACEXML_InputSource input (fstm.get ());
00088         (void) fstm.release ();
00089 
00090         ACEXML_Parser parser;
00091         parser.setContentHandler (this);
00092         parser.setDTDHandler (this);
00093         parser.setErrorHandler (this);
00094         parser.setEntityResolver (this);
00095 
00096         try
00097         {
00098           parser.parse (&input);
00099         }
00100         catch (const ACEXML_Exception& ex)
00101         {
00102           // The only way to find out what it is, it to let it print itself, so...
00103           ACE_ERROR ((LM_ERROR, "Unable to load \"%s\".\n Will try backup file.\n", this->file_name_.c_str ()));
00104           ex.print ();
00105           result = false;
00106         }
00107       }
00108       else
00109       {
00110         ACE_DEBUG((LM_DEBUG, ACE_TEXT("Unable to open the XML input file: %s.\n Will try backup file.\n"), file_name_.c_str()));
00111         result = false;
00112       }
00113     }
00114 
00115     if (! result)
00116     {
00117       this->file_name_ = base_name;
00118       this->file_name_ += ".000";
00119       result = (0 == ACE_OS::access (this->file_name_.c_str (), 4));
00120     }
00121     return result;
00122   }

virtual void TAO_Notify::XML_Loader::startElement ( const ACEXML_Char *  namespaceURI,
const ACEXML_Char *  localName,
const ACEXML_Char *  qName,
ACEXML_Attributes *atts  ACEXML_ENV_ARG_DECL 
) [virtual]


Member Data Documentation

ACE_CString TAO_Notify::XML_Loader::file_name_ [private]

The name of the file from which data is read.

Definition at line 69 of file XML_Loader.h.

Referenced by load(), and open().

FILE* TAO_Notify::XML_Loader::input_ [private]

A stream representing our current output.

Definition at line 71 of file XML_Loader.h.

bool TAO_Notify::XML_Loader::live_ [private]

if false, then we're just checking syntax of topology file.

Definition at line 76 of file XML_Loader.h.

Referenced by load(), and open().

TopoStack TAO_Notify::XML_Loader::object_stack_ [private]

Definition at line 74 of file XML_Loader.h.

Referenced by load().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:46:46 2010 for TAO_CosNotification by  doxygen 1.4.7