CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DetectorDescription/Parser/src/DDLSAX2ConfigHandler.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLSAX2ConfigHandler.cc  -  description
00003                              -------------------
00004     begin                : Mon Oct 22 2001
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "DetectorDescription/Parser/interface/DDLParser.h"
00015 #include "DetectorDescription/Parser/src/StrX.h"
00016 #include "DetectorDescription/Parser/interface/DDLSAX2ConfigHandler.h"
00017 
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019 #include "DetectorDescription/Core/interface/DDRoot.h"
00020 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00021 
00022 #include <iostream>
00023 
00024 DDLSAX2ConfigHandler::DDLSAX2ConfigHandler( DDCompactView& cpv)
00025   : doValidation_(false),
00026     files_(),
00027     urls_(),
00028     schemaLocation_(),
00029     cpv_(cpv)
00030 {}
00031 
00032 DDLSAX2ConfigHandler::~DDLSAX2ConfigHandler( void )
00033 {}
00034 
00035 // ---------------------------------------------------------------------------
00036 //  DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
00037 //  
00038 //  This is kind-of sneaky-cheating.  Basically it ignores all elements except 
00039 //  File elements, and displays attributes up to the name attribute because that
00040 //  is the only one it cares about at this time.  Later we would need a mechanism
00041 //  to exclude and include sections based on the configuration if we proceed with
00042 //  that level of selectivity.
00043 //
00044 //  The file name is passed back to DDLParser via SetDDLFileName in order to 
00045 //  process this list of files later.
00046 // ---------------------------------------------------------------------------
00047 void
00048 DDLSAX2ConfigHandler::startElement( const XMLCh* const uri,
00049                                     const XMLCh* const localname,
00050                                     const XMLCh* const qname,
00051                                     const Attributes& attrs )
00052 {
00053 
00054   ++elementCount_;
00055   attrCount_ += attrs.getLength();
00056 
00057   std::string myelemname(StrX(qname).localForm());
00058   DCOUT_V('P', "DetectorDescription/Parser/interface/DDLSAX2ConfigHandler::startElement" << myelemname << " started...");
00059 
00060   unsigned int numAtts = attrs.getLength();
00061   unsigned int i = 0;
00062   if (myelemname == "File")
00063   {
00064     std::string name="", url="";
00065     while ( i < numAtts )
00066     {
00067       std::string myattname(StrX(attrs.getLocalName(i)).localForm());
00068       std::string myvalue(StrX(attrs.getValue(i)).localForm());
00069 
00070       if (myattname == "name")
00071         name=myvalue;
00072       if (myattname == "url")
00073         url=myvalue;
00074       ++i;
00075     }
00076     DCOUT('P', "file name = " << name << " and url = " << url);
00077     files_.push_back(name);
00078     urls_.push_back(url);
00079   }
00080   else if (myelemname == "Root")
00081   {
00082     std::string fileName="", logicalPartName="";
00083     while ( i < numAtts )
00084     {
00085       std::string myattname(StrX(attrs.getLocalName(i)).localForm());
00086       std::string myvalue(StrX(attrs.getValue(i)).localForm());
00087 
00088       if (myattname == "fileName")
00089         fileName = myvalue;
00090       if (myattname == "logicalPartName")
00091         logicalPartName = myvalue;
00092       ++i;
00093     }
00094 
00095     fileName = fileName.substr(0, fileName.find("."));
00096     //      std::cout << fileName << ":" << logicalPartName << " is the ROOT" << std::endl;
00097     DDLogicalPart root(DDName(logicalPartName,fileName));
00098     DDRootDef::instance().set(root);//DDName(logicalPartName, fileName));
00100     //      DDCompactView cpv;
00101     //DDName rt(DDName(logicalPartName, fileName));
00102     cpv_.setRoot(root);
00103     DCOUT_V('P', std::string("DetectorDescription/Parser/interface/DDLSAX2ConfigHandler::startElement.  Setting DDRoot LogicalPart=") + logicalPartName + std::string(" in ") + fileName);  
00104 
00105   }
00106   else if (myelemname == "Schema")
00107   {
00108     while ( i < numAtts )
00109     {
00110       std::string myattname(StrX(attrs.getLocalName(i)).localForm());
00111       std::string myvalue(StrX(attrs.getValue(i)).localForm());
00112       if (myattname == "schemaLocation")
00113         schemaLocation_ = myvalue;
00114       else if (myattname == "validation")
00115         doValidation_ = (myvalue == "true" ? true : false);
00116       ++i;
00117     }
00118   }
00119   //  std::cout <<  "DetectorDescription/Parser/interface/DDLSAX2ConfigHandler::startElement " << myelemname << " completed..." << std::endl;
00120 }
00121 
00122 const std::vector<std::string>&
00123 DDLSAX2ConfigHandler::getFileNames( void ) const
00124 {
00125   return files_;
00126 }
00127 
00128 const std::vector<std::string>&
00129 DDLSAX2ConfigHandler::getURLs( void ) const
00130 {
00131   return urls_;
00132 }
00133 
00134 const std::string
00135 DDLSAX2ConfigHandler::getSchemaLocation( void ) const
00136 {
00137   return schemaLocation_;
00138 }
00139 
00140 const bool
00141 DDLSAX2ConfigHandler::doValidation( void ) const
00142 {
00143   return doValidation_;
00144 }