Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

SemanticValidator.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Andreas Bertsch $
00032 // $Authors: Marc Sturm, Andreas Bertsch $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_FORMAT_VALIDATORS_SEMANTICVALIDATOR_H
00036 #define OPENMS_FORMAT_VALIDATORS_SEMANTICVALIDATOR_H
00037 
00038 #include <OpenMS/FORMAT/XMLFile.h>
00039 #include <OpenMS/FORMAT/HANDLERS/XMLHandler.h>
00040 #include <OpenMS/DATASTRUCTURES/Map.h>
00041 #include <OpenMS/DATASTRUCTURES/CVMappings.h>
00042 
00043 
00044 namespace OpenMS
00045 {
00046   class ControlledVocabulary;
00047   namespace Internal
00048   {
00049 
00056     class OPENMS_DLLAPI SemanticValidator :
00057       protected Internal::XMLHandler,
00058       public Internal::XMLFile
00059     {
00060 public:
00067       SemanticValidator(const CVMappings & mapping, const ControlledVocabulary & cv);
00068 
00070       virtual ~SemanticValidator();
00071 
00073       struct CVTerm
00074       {
00075         String accession;
00076         String name;
00077         String value;
00078         bool has_value;
00079         String unit_accession;
00080         bool has_unit_accession;
00081         String unit_name;
00082         bool has_unit_name;
00083       };
00084 
00096       bool validate(const String & filename, StringList & errors, StringList & warnings);
00097 
00099       bool locateTerm(const String & path, const CVTerm & parsed_term) const;
00100 
00102       void setTag(const String & tag);
00103 
00105       void setAccessionAttribute(const String & accession);
00106 
00108       void setNameAttribute(const String & name);
00109 
00111       void setValueAttribute(const String & value);
00112 
00121       void setCheckTermValueTypes(bool check);
00122 
00130       void setCheckUnits(bool check);
00131 
00133       void setUnitAccessionAttribute(const String & accession);
00134 
00136       void setUnitNameAttribute(const String & name);
00137 
00138 protected:
00139 
00140       // Docu in base class
00141       void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes);
00142 
00143       // Docu in base class
00144       void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname);
00145 
00146       // Docu in base class
00147       void characters(const XMLCh * const chars, const XMLSize_t /*length*/);
00148 
00150       virtual String getPath_(UInt remove_from_end = 0) const;
00151 
00153       virtual void getCVTerm_(const xercesc::Attributes & attributes, CVTerm & parsed_term);
00154 
00155       //~ forward dekl. of a inner struct/class not possible in C++ - or our Library is overtemplated
00156       //~ /// make a SemanticValidator::CVTerm from a ControlledVocabulary::CVTerm (without any value or unit), needed for writing only cvs at the right places in the xml (i.e. with cvmapping)
00157       //~ virtual void makeCVTerm_(const ControlledVocabulary::CVTerm & lc, CVTerm & parsed_term);
00158 
00160       virtual void handleTerm_(const String & path, const CVTerm & parsed_term);
00161 
00163       const CVMappings & mapping_;
00164 
00166       const ControlledVocabulary & cv_;
00167 
00169       StringList errors_;
00170 
00172       StringList warnings_;
00173 
00175       StringList open_tags_;
00176 
00178       Map<String, std::vector<CVMappingRule> > rules_;
00179 
00183       Map<String, Map<String, Map<String, UInt> > > fulfilled_;
00184 
00185 
00187 
00188       String cv_tag_;
00189       String accession_att_;
00190       String name_att_;
00191       String value_att_;
00192       String unit_accession_att_;
00193       String unit_name_att_;
00194       bool check_term_value_types_;
00195       bool check_units_;
00197 
00198 private:
00199 
00201       SemanticValidator();
00202 
00204       SemanticValidator(const SemanticValidator & rhs);
00205 
00207       SemanticValidator & operator=(const SemanticValidator & rhs);
00208 
00209     };
00210 
00211   }   // namespace Internal
00212 
00213 } // namespace OpenMS
00214 
00215 #endif // OPENMS_FORMAT_VSLIDATORS_SEMANTICVALIDATOR_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:44 using doxygen 1.7.1