CMS 3D CMS Logo

DDLSAX2FileHandler Class Reference

DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file. More...

#include <DetectorDescription/Parser/interface/DDLSAX2FileHandler.h>

Inheritance diagram for DDLSAX2FileHandler:

DDLSAX2Handler DDLSAX2ExpressionHandler

List of all members.

Public Member Functions

void characters (const XMLCh *const chars, const unsigned int length)
void comment (const XMLCh *const chars, const unsigned int length)
 DDLSAX2FileHandler ()
void dumpElementTypeCounter ()
 This dumps some statistics on elements encountered in the file.
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
virtual std::string extractFileName (std::string fullname)
virtual std::string & parent ()
virtual std::string & self ()
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
 ~DDLSAX2FileHandler ()

Protected Member Functions

void createDDConstants () const
 creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the documents

Protected Attributes

std::map< std::string, intelementTypeCounter_
std::vector< std::string * > names_
std::map< std::string,
std::string * > 
namesMap_


Detailed Description

DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file.

Author:
Michael Case
DDLSAX2FileHandler.h - description ------------------- begin: Tue Oct 23 2001 email: case@ucdhep.ucdavis.edu

DDLSAX2FileHandler has the same structure as the DDLSAX2ConfigHandler as they both inherit from DDLSAX2Handler which inherits from Xerces C++ DefaultHandler. SAX2 is event driven. So, when the start of an element is encountered in the XML, then a call is made to the handler's startElement. The same for endElement.

The design of DDXMLElement allows for processing whichever type of Element the XML Parser encounters.

Definition at line 38 of file DDLSAX2FileHandler.h.


Constructor & Destructor Documentation

DDLSAX2FileHandler::DDLSAX2FileHandler (  ) 

Definition at line 41 of file DDLSAX2FileHandler.cc.

References createDDConstants(), names_, and namesMap_.

00042 {
00043   createDDConstants();
00044   std::string* sp = new std::string("*** root ***");
00045   namesMap_[*sp] = sp;
00046   names_.push_back(sp);
00047   
00048 }

DDLSAX2FileHandler::~DDLSAX2FileHandler (  ) 

Definition at line 50 of file DDLSAX2FileHandler.cc.

00051 { }


Member Function Documentation

void DDLSAX2FileHandler::characters ( const XMLCh *const   chars,
const unsigned int  length 
) [virtual]

Reimplemented from DDLSAX2Handler.

Definition at line 117 of file DDLSAX2FileHandler.cc.

References DDXMLElement::appendText(), DCOUT_V, DDLElementRegistry::getElement(), DDXMLElement::gotText(), i, DDXMLElement::loadText(), names_, NULL, and s.

00119 {
00120   DCOUT_V('P', "DDLSAX2FileHandler::characters started");
00121 
00122   DDXMLElement* myElement = NULL;
00123   myElement = DDLElementRegistry::getElement(*(names_.back()));
00124 
00125   std::string inString = "";
00126   for (unsigned int i = 0; i < length; ++i)
00127     {
00128       char s = chars[i];
00129       inString = inString + s;
00130     }
00131   if (myElement->gotText())
00132     myElement->appendText(inString);
00133   else
00134     myElement->loadText(inString);
00135 
00136   DCOUT_V('P', "DDLSAX2FileHandler::characters completed"); 
00137 }

void DDLSAX2FileHandler::comment ( const XMLCh *const   chars,
const unsigned int  length 
) [virtual]

Reimplemented from DDLSAX2Handler.

Definition at line 139 of file DDLSAX2FileHandler.cc.

00141 {
00142   // ignore, discard, overkill since base class also has this...
00143 }

void DDLSAX2FileHandler::createDDConstants (  )  const [protected]

creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the documents

Definition at line 162 of file DDLSAX2FileHandler.cc.

References DDConstant::createConstantsFromEvaluator().

Referenced by DDLSAX2FileHandler().

void DDLSAX2FileHandler::dumpElementTypeCounter (  ) 

This dumps some statistics on elements encountered in the file.

Definition at line 155 of file DDLSAX2FileHandler.cc.

Referenced by DDLParser::parse().

00156 {
00157     //for (std::map<std::string, int>::const_iterator it = elementTypeCounter_.begin();
00158     //   it != elementTypeCounter_.end(); ++it)
00159     // There used to be cout printout here. No longer.
00160 }

void DDLSAX2FileHandler::endElement ( const XMLCh *const   uri,
const XMLCh *const   localname,
const XMLCh *const   qname 
) [virtual]

Reimplemented from DDLSAX2Handler.

Reimplemented in DDLSAX2ExpressionHandler.

Definition at line 99 of file DDLSAX2FileHandler.cc.

References DCOUT_V, extractFileName(), DDLParser::getCurrFileName(), DDLElementRegistry::getElement(), DDLSAX2Handler::getnmspace(), DDLParser::instance(), names_, DDCurrentNamespace::ns(), and DDXMLElement::processElement().

00102 {
00103   std::string myElementName = *(names_.back());
00104 
00105   DCOUT_V('P', "DDLSAX2FileHandler::endElement started");
00106   DCOUT_V('P', "    " + myElementName);
00107 
00108   DDXMLElement* myElement = DDLElementRegistry::getElement(myElementName);
00109   DDLParser* beingParsed = DDLParser::instance();
00110   std::string nmspace = getnmspace(extractFileName( beingParsed->getCurrFileName()));
00111   DDCurrentNamespace::ns() = nmspace;
00112   myElement->processElement(myElementName, nmspace);
00113   DCOUT_V('P', "DDLSAX2FileHandler::endElement completed");
00114   names_.pop_back();
00115 }

std::string DDLSAX2FileHandler::extractFileName ( std::string  fullname  )  [virtual]

Definition at line 145 of file DDLSAX2FileHandler.cc.

Referenced by endElement(), DDLParser::parse(), DDLParser::parseOneFile(), DDLSAX2ExpressionHandler::startElement(), and startElement().

00146 {
00147   std::string ret = "";
00148   size_t bit = fullname.rfind('/');
00149   if ( bit < fullname.size() - 2 ) {
00150     ret=fullname.substr(bit+1);
00151   }
00152   return ret;
00153 }

std::string & DDLSAX2FileHandler::parent (  )  [virtual]

Definition at line 167 of file DDLSAX2FileHandler.cc.

References names_.

Referenced by DDXMLElement::parent().

00168 {
00169   if (names_.size() > 1)
00170     {
00171       return *(names_[names_.size() - 2]);
00172     }
00173   return *(names_[0]);
00174 }

std::string & DDLSAX2FileHandler::self (  )  [virtual]

Definition at line 176 of file DDLSAX2FileHandler.cc.

References names_.

Referenced by DDXMLElement::throwError().

00177 {
00178   if (names_.size() > 2)
00179     return *(names_[names_.size() - 1]);
00180   return *(names_[0]);
00181 }

void DDLSAX2FileHandler::startElement ( const XMLCh *const   uri,
const XMLCh *const   localname,
const XMLCh *const   qname,
const Attributes attrs 
)

Reimplemented in DDLSAX2ExpressionHandler.

Definition at line 56 of file DDLSAX2FileHandler.cc.

References DCOUT_V, elementTypeCounter_, extractFileName(), DDLParser::getCurrFileName(), DDLElementRegistry::getElement(), DDLSAX2Handler::getnmspace(), i, DDLParser::instance(), DDXMLElement::loadAttributes(), DDXMLElement::loadText(), names_, and namesMap_.

00060 {
00061 
00062   DCOUT_V('P', "DDLSAX2FileHandler::startElement started");
00063   
00064   std::map<std::string, std::string*>::const_iterator namePtr = namesMap_.find(std::string(StrX(qname).localForm()));
00065   std::string* nameInt;
00066   if (namePtr != namesMap_.end())
00067     {
00068       nameInt = namePtr->second;
00069     }
00070   else
00071     {
00072       std::string * sp = new std::string(StrX(qname).localForm());
00073       nameInt = sp;
00074       namesMap_[*sp] = nameInt;
00075     }
00076   names_.push_back(nameInt);
00077   std::string myElementName(StrX(qname).localForm());
00078 
00079   ++elementTypeCounter_[myElementName];
00080   DDXMLElement* myElement = DDLElementRegistry::getElement(myElementName);
00081 
00082   unsigned int numAtts = attrs.getLength();
00083   std::vector<std::string> attrNames, attrValues;
00084 
00085   for (unsigned int i = 0; i < numAtts; ++i)
00086     {
00087       attrNames.push_back(std::string(StrX(attrs.getLocalName(i)).localForm()));
00088       attrValues.push_back(std::string(StrX(attrs.getValue(i)).localForm()));
00089     }
00090 
00091   DDLParser* beingParsed = DDLParser::instance();
00092   std::string nmspace = getnmspace(extractFileName( beingParsed->getCurrFileName()));
00093   myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace);
00094   //  initialize text
00095   myElement->loadText(std::string()); 
00096   DCOUT_V('P', "DDLSAX2FileHandler::startElement completed");
00097 }


Member Data Documentation

std::map< std::string, int> DDLSAX2FileHandler::elementTypeCounter_ [protected]

Definition at line 76 of file DDLSAX2FileHandler.h.

Referenced by DDLSAX2ExpressionHandler::startElement(), and startElement().

std::vector< std::string* > DDLSAX2FileHandler::names_ [protected]

Definition at line 79 of file DDLSAX2FileHandler.h.

Referenced by characters(), DDLSAX2FileHandler(), endElement(), parent(), self(), and startElement().

std::map< std::string, std::string* > DDLSAX2FileHandler::namesMap_ [protected]

Definition at line 78 of file DDLSAX2FileHandler.h.

Referenced by DDLSAX2FileHandler(), and startElement().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:18:05 2009 for CMSSW by  doxygen 1.5.4