00001 /*******************************************************************\ 00002 00003 SESAME project software license 00004 00005 Copyright (C) 2002 University of Amsterdam 00006 00007 This program is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License 00009 as published by the Free Software Foundation; either version 2 00010 of the License, or (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. 00021 00022 For information regarding the SESAME software project see 00023 http://sesamesim.sourceforge.net or email 00024 jcofflan@users.sourceforge.net 00025 00026 \*******************************************************************/ 00036 #ifndef MAPPINGSAXHANDLER_H 00037 #define MAPPINGSAXHANDLER_H 00038 00039 #include <BasicUtils/BasicException.h> 00040 #include <BasicUtils/BasicSmartPointer.h> 00041 00042 #include <xercesc/sax2/DefaultHandler.hpp> 00043 00044 #include <stack> 00045 #include <list> 00046 00047 class MappingFactory; 00048 class MappingObj; 00049 class MappingContainer; 00050 class InstructionContext; 00051 class ChannelMapping; 00052 00053 typedef enum {SOURCE_SIDE, DEST_SIDE} side_t; 00054 typedef std::list<ChannelMapping *> channelList_t; 00055 00056 class MappingSAXHandler : public XERCES_CPP_NAMESPACE::DefaultHandler { 00057 // Attributes 00058 public: 00060 MappingFactory *factory; 00062 side_t side; 00063 00065 int nextChannelId; 00066 00068 MappingContainer *root; 00069 00071 channelList_t channelList; 00072 00074 int depth; 00075 00077 BasicSmartPointer<InstructionContext> instrContext; 00078 00080 std::stack<MappingObj *> context; 00081 00082 bool commChannelMap; 00083 00084 // Operations 00085 public: 00086 // Constructor 00087 MappingSAXHandler(MappingFactory *factory, side_t side); 00088 virtual ~MappingSAXHandler(); 00089 00090 MappingContainer *getRoot() {return root;} 00091 channelList_t getChannelList() {return channelList;} 00092 00093 // Begin Mapping SAX interface 00094 void startMappingElement(const XERCES_CPP_NAMESPACE::Attributes &attributes); 00095 void startInstructionElement(const XERCES_CPP_NAMESPACE::Attributes &); 00096 void startMapElement(const XERCES_CPP_NAMESPACE::Attributes &attributes); 00097 void startPortElement(const XERCES_CPP_NAMESPACE::Attributes &attributes); 00098 void endMappingElement(); 00099 void endInstructionElement(); 00100 void endMapElement(); 00101 void endPortElement(); 00102 00103 // Begin SAX2 interface 00104 void startDocument(); 00105 void endDocument(); 00106 void startElement(const XMLCh *const uri, const XMLCh *const localname, 00107 const XMLCh *const qname, 00108 const XERCES_CPP_NAMESPACE::Attributes &attributes); 00109 void endElement(const XMLCh *const uri, const XMLCh *const localname, 00110 const XMLCh *const qname); 00111 void characters(const XMLCh *const chars, const unsigned int length); 00112 00113 private: 00114 int getNextChannelId() {++nextChannelId; return (nextChannelId - 1);} 00115 void upInstrContext(); 00116 void downInstrContext(); 00117 }; 00118 00119 #endif