GME  13
MgaParser.h
Go to the documentation of this file.
00001 
00002 #ifndef MGA_MGAPARSER_H_
00003 #define MGA_MGAPARSER_H_
00004 
00005 #ifndef MGA_GENPARSER_H
00006 #include "GenParser.h"
00007 #endif
00008 
00009 #include "resource.h"
00010 #include "CommonVersionInfo.h"
00011 #include <hash_map>
00012 #include <list>
00013 #include <vector>
00014 #include <map>
00015 #include <exception>
00016 #include "MgaUtil.h"
00017 #include "Gme.h"
00018 
00019 class CompareCComObj
00020 {
00021  public:
00022          bool operator()( const CComObjPtr<IMgaFCO>& p1, const CComObjPtr<IMgaFCO>& p2) const
00023          {
00024                  // FIXME: comparing IMgaFCO* is not defined
00025                  return p1.p < p2.p;
00026          }
00027 };
00028 
00029 // --------------------------- CMgaParser
00030 
00031 class ATL_NO_VTABLE CMgaParser : 
00032         public CComObjectRootEx<CComSingleThreadModel>,
00033         public CComCoClass<CMgaParser, &__uuidof(MgaParser)>,
00034         public ISupportErrorInfoImpl3<&__uuidof(IMgaParser), &__uuidof(IMgaParser2), &__uuidof(IMgaParser3)>,
00035         public IDispatchImpl<IMgaParser3, &__uuidof(IMgaParser3), &__uuidof(__MGAParserLib), 1, 1>,
00036         public IGMEVersionInfoImpl,
00037         public CGenParser
00038 {
00039 public:
00040         CMgaParser()
00041                 : m_maintainGuids( false)
00042         { 
00043                 m_resolveDerFuncPtr = &CMgaParser::ResolveDerivation;
00044         }
00045 
00046 DECLARE_REGISTRY_RESOURCEID(IDR_MGAPARSER)
00047 DECLARE_PROTECT_FINAL_CONSTRUCT()
00048 
00049 BEGIN_COM_MAP(CMgaParser)
00050         COM_INTERFACE_ENTRY2(IMgaParser, IMgaParser3)
00051         COM_INTERFACE_ENTRY2(IDispatch, IMgaParser3)
00052         COM_INTERFACE_ENTRY(IMgaParser2)
00053         COM_INTERFACE_ENTRY2(IMgaParser3, IMgaParser3)
00054         COM_INTERFACE_ENTRY(ISupportErrorInfo)
00055         COM_INTERFACE_ENTRY_IID(__uuidof(IGMEVersionInfo), IGMEVersionInfoImpl)
00056 END_COM_MAP()
00057 
00058 // ------- Methods
00059 
00060 public:
00061         STDMETHOD(GetXMLInfo)(BSTR filename, BSTR *paradigm, BSTR* parversion, VARIANT *parguid, BSTR* basename, BSTR* version);
00062         STDMETHOD(GetXMLParadigm)(BSTR filename, BSTR *paradigm);
00063         STDMETHOD(GetClipXMLInfo)(BSTR filename, IMgaObject *target, VARIANT_BOOL *isacceptable, BSTR* p_acckind, BSTR* p_version);
00064         STDMETHOD(ParseFCOs)(IMgaObject *p, BSTR filename);
00065         STDMETHOD(ParseFCOs2)(IMgaObject *p, BSTR filename, ULONGLONG hwndParent);
00066         STDMETHOD(ParseClos1)(IMgaObject *p, BSTR filename); // basic
00067         STDMETHOD(ParseClos4)(IMgaObject *p, BSTR filename, int options); // smart
00068         STDMETHOD(ParseProject)(IMgaProject *p, BSTR filename);
00069         STDMETHOD(ParseProject2)(IMgaProject *p, BSTR filename, ULONGLONG hwndParent);
00070 
00071         std::tstring GetClipXMLInfo2();
00072 
00073         void CloseAll();
00074 
00075 // ------- Passes
00076 
00077 public:
00078         virtual void startElement(const XMLCh* const name, AttributeList& attributes);
00079     virtual void endElement(const XMLCh* const name);
00080         void fireStartFunction(const std::tstring& name, const attributes_type& attributes);
00081         void fireEndFunction(const std::tstring& name);
00082 
00083         struct range_type
00084         {
00085                 counter_type begin;
00086                 counter_type end;
00087 
00088                 element_type previous;
00089         };
00090 
00091         std::list<range_type> ranges;
00092 
00093         int skip_element_level;
00094         class pass_exception : public std::exception
00095         {
00096                 std::wstring w;
00097         public:
00098                 pass_exception() { }
00099                 pass_exception(std::wstring what) : w(what) { }
00100                 virtual const char *what() const {
00101                         return static_cast<const char*>(_bstr_t(w.c_str()));
00102                 }
00103                 virtual const wchar_t *wwhat() const {
00104                         return w.c_str();
00105                 }
00106         };
00107 
00108         typedef struct librecord {
00109                 std::tstring libname;
00110                 CComPtr<IMgaFolder> f;
00111         } librecord;
00112 
00113         typedef std::vector<librecord> librecords;
00114         librecords libstodo;
00115         CComVariant projectguid;
00116         _bstr_t projectversion;
00117 
00118 // ------- Logging
00119 
00120 public:
00121 
00122 // ------- Attributes
00123 
00124 public:
00125         typedef CGenParserFunc<CMgaParser> elementfunc;
00126 
00127         enum FUNC_TABLE_STATE{MGA,MGA_INFO,BC_MGA,SC_MGA, CLIP_MGA_INFO};
00128         FUNC_TABLE_STATE funcTableState;
00129 
00130         static elementfunc elementfuncs_mga[];
00131         static elementfunc elementfuncs_mgainfo[];
00132         static elementfunc elementfuncs_bcmga[];
00133         static elementfunc elementfuncs_scmga[];
00134         static elementfunc elementfuncs_clipmgainfo[];
00135 
00136         CComObjPtr<IMgaProject> project;
00137         CComObjPtr<IMgaTerritory> territory;
00138         CComObjPtr<IMgaResolver> resolver;
00139         CComObjPtr<IMgaProgressDlg> progress;
00140 
00141         CComObjPtr<IMgaObject> m_target;
00142 
00143         BSTR *closversion;
00144         BSTR *closacckind;
00145         BSTR *infoparname;
00146         BSTR *infoparversion;
00147         VARIANT *infoparguid;
00148         BSTR *infoprojname;
00149         BSTR *infoversion;
00150 
00151         long project_prefs, project_prefs_orig;
00152 
00153         std::tstring constraint_name;
00154         std::tstring constraint_value;
00155 
00156         counter_type max_counter;
00157         int pass_count;
00158 
00159 // ------- Lookup
00160 
00161 public:
00162         void LookupByID(const std::tstring &id, CComObjPtr<IMgaObject> &object);
00163         void LookupByID(const std::tstring &id, CComObjPtr<IMgaFCO> &fco);
00164         // return true if successful
00165         bool RegisterLookup(const std::tstring &id, IMgaObject *object);
00166         void RegisterLookup(const attributes_type &attributes, IMgaObject *object);
00167 
00168         //void RegisterReadOnlyStatus( const attributes_type &attributes);
00169         bool GetIntendedReadOnlyFlag( bool *p_isReadOnly);
00170 
00171         typedef stdext::hash_map<std::tstring, CComBstrObj> id_lookup_type;
00172         typedef id_lookup_type::iterator id_lookup_iterator;
00173 
00174         id_lookup_type id_lookup;
00175 
00176         typedef std::list< bool > readonly_stack_type;
00177         readonly_stack_type readonly_stack;
00178 
00179 // ------- Derivation
00180 
00181 public:
00182         struct deriv_type
00183         {
00184                 CComObjPtr<IMgaFCO> from;
00185                 VARIANT_BOOL isinstance;
00186                 bool isprimary;
00187         };
00188 
00189         typedef void (CMgaParser::*ResolverFuncType) (const attributes_type &, deriv_type &);
00190         ResolverFuncType m_resolveDerFuncPtr;
00191 
00192         void ResolveDerivation(const attributes_type &attributes, deriv_type &deriv);
00193         void ResolveClosure1Derivation(const attributes_type &attributes, deriv_type &deriv);
00194         void ResolveClosure4Derivation(const attributes_type &attributes, deriv_type &deriv);
00195 
00196         bool findPlaceForElem( const attributes_type &attributes, deriv_type& deriv, CComObjPtr<IMgaObject>& place);
00197         bool findPlaceForElem( const attributes_type &attributes, deriv_type& deriv, CComObjPtr<IMgaFolder>& place_fld, CComObjPtr<IMgaModel>& place_mdl);
00198 
00199         bool parseConnection( CComObjPtr<IMgaObject> prev, const attributes_type &attributes, CComObjPtr<IMgaFCO>& pFoundSrcObj, CComObjPtr<IMgaFCO>& pFoundDstObj, CComObjPtr<IMgaFCOs>& pFoundSrcRefChain, CComObjPtr<IMgaFCOs>& pFoundDstRefChain);
00200         bool findConnectionEnd( CComObjPtr<IMgaObject> prev, const std::tstring& isbound, const std::tstring& role, const std::tstring& targetGUID, const std::tstring& target, const std::tstring& refchainGUID, const std::tstring& refchain, CComObjPtr<IMgaFCO>& pFoundObj, CComObjPtr<IMgaFCOs>& pFoundRefChain);
00201         bool findObject( const CComObjPtr<IMgaModel>& prev, const attributes_type& attributes, CComObjPtr<IMgaFCO>& obj, const char type);
00202         bool findObject( const CComObjPtr<IMgaFolder>& prev, const attributes_type& attributes, CComObjPtr<IMgaFCO>& obj, const char type);
00203         bool findObjectIn( const CComObjPtr<IMgaObject>& parent, const CComObjPtrVector<IMgaFCO>& vec, const attributes_type& attributes, CComObjPtr<IMgaFCO>& obj, const char type);
00204         bool findFolderIn( const CComObjPtr<IMgaFolder>& prev, const attributes_type& attributes, CComObjPtr<IMgaFolder>& fol);
00205         void findObjOnRelPath( CComObjPtr<IMgaObject> obj_rel_to, const std::tstring& relpath , CComObjPtr<IMgaObject>& obj, const std::tstring& text);
00206         void findObjOnAbsPath( CComObjPtr<IMgaProject> project, const std::tstring& abspath , CComObjPtr<IMgaObject>& obj, const std::tstring& text);
00207         void findFCOWithRelPathAndGUID( CComObjPtr<IMgaObject> obj_rel_to, const std::tstring& relpath, const std::tstring& guid, CComObjPtr<IMgaFCO>& pFoundFco);
00208         void findFCOWithGUIDInTree( CComObjPtr<IMgaObject> pParent, const std::tstring& guid, CComObjPtr<IMgaFCO>& pFoundFCO);
00209         void findFCOWithGUID( CComObjPtr<IMgaObject> prev, const std::tstring& guid, CComObjPtr<IMgaFCO>& pFoundFCO);
00210         void stepUpInHierarchy( CComObjPtr<IMgaObject>& pCurrentObj, const std::tstring& originalPath, CComObjPtr<IMgaObject>& pNewParent, std::tstring& remainingPath);
00211 
00212         static bool isNullRef( CComObjPtr<IMgaFCO>& ref);
00213         static bool isEmptySet( CComObjPtr<IMgaFCO>& set);
00214         bool isNeedFor2ndStep();
00215         void tryToFindMissedReferreds();
00216         void tryToFindMissedSetMembers();
00217         std::map< CComObjPtr<IMgaFCO>, std::tstring, CompareCComObj > m_notFoundReferredObject;
00218         std::map< CComObjPtr<IMgaFCO>, std::vector< std::tstring >, CompareCComObj > m_notFoundSetMembers;
00219         std::tstring m_clVerStr;
00220 
00221         bool manual_relid_mode;
00222         long relid;
00223 
00224         void preparerelid(const attributes_type &attributes);
00225         void assignrelid(IMgaObject *obj);      
00226 
00227         bool m_maintainGuids; // if parser should parse and set (into MGA layer) the found guids
00228 // ------- Element Handlers
00229         
00230         public:
00231         void StartProject(const attributes_type &attributes);
00232         void EndName();
00233         void EndComment();
00234         void EndAuthor();
00235         void EndValue();
00236         void StartFolder(const attributes_type &attributes);
00237         void StartModel(const attributes_type &attributes);
00238         void StartAtom(const attributes_type &attributes);
00239         void StartRegNode(const attributes_type &attributes);
00240         void StartAttribute(const attributes_type &attributes);
00241         void StartConnection(const attributes_type &attributes);
00242         void StartConnPoint(const attributes_type &attributes);
00243         void EndConstraint();
00244         void StartReference(const attributes_type &attributes);
00245         void StartSet(const attributes_type &attributes);
00246         void StartClipboard(const attributes_type &attributes);
00247         void EndObject();
00248 
00249         void StartProjectInfo(const attributes_type &attributes);
00250         void EndNameInfo();
00251 
00252         void StartBCConnPoint(const attributes_type &attributes);
00253         void StartBCReference(const attributes_type &attributes);
00254         void StartBCSet(const attributes_type &attributes);
00255         void StartBCClipboard(const attributes_type &attributes);
00256 
00257         void StartSCFolder(const attributes_type &attributes);
00258         void StartSCConnection(const attributes_type &attributes);
00259         void StartSCConnPoint(const attributes_type &attributes);
00260         void StartSCReference(const attributes_type &attributes);
00261         void StartSCSet(const attributes_type &attributes);
00262         void StartSCAtom(const attributes_type &attributes);
00263         void StartSCModel(const attributes_type &attributes);
00264         void msgSC( CComBSTR& msg, msgtype_enum type);
00265 
00266         void EndSCConnection();
00267         void EndSCName();
00268         void EndSCValue();
00269         void EndSCConstraint();
00270         void StartSCRegNode(const attributes_type &attributes);
00271         void StartSCAttribute(const attributes_type &attributes);
00272         void EndSCRegNode();
00273         bool m_mergeAllowed;
00274 
00275 
00276         void StartClipboardInfo(const attributes_type &attributes);
00277 
00278         STDMETHOD(get_Resolver)(IMgaResolver **MgaResolver) {
00279                 if (this->resolver)
00280                 {
00281                         resolver->AddRef();
00282                 }
00283                 *MgaResolver = this->resolver;
00284                 return S_OK;
00285         }
00286     STDMETHOD(put_Resolver)(IMgaResolver *MgaResolver)
00287         {
00288                 if (this->resolver)
00289                 {
00290                         this->resolver.Release();
00291                 }
00292                 this->resolver = MgaResolver;
00293                 return S_OK;
00294         }
00295 
00296         protected:
00297                 static CComPtr<IGMEOLEApp>      get_GME(CComObjPtr<IMgaProject> project);
00298                 static void                                     clear_GME( CComPtr<IGMEOLEApp>& p_GME);
00299                 CComPtr<IGMEOLEApp> m_GME;
00300 
00301 };
00302 
00303 #endif //__MGAPARSER_H_