CMS 3D CMS Logo

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