xml4com.cpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:12k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: xml4com.cpp,v $
  58.  * Revision 1.6  2001/05/11 13:25:08  tng
  59.  * Copyright update.
  60.  *
  61.  * Revision 1.5  2001/01/19 15:18:39  tng
  62.  * COM Updates by Curt Arnold: changed 1.3 to 1.4, updated the GUID's so
  63.  * both can coexist and fixed a new minor bugs.  Most of the changes involved
  64.  * error reporting, now a DOM defined error will return an HRESULT of
  65.  * 0x80040600 + code and will set an error description to the error name.
  66.  *
  67.  * Revision 1.4  2000/06/19 20:05:59  rahulj
  68.  * Changes for increased conformance and stability. Submitted by
  69.  * Curt.Arnold@hyprotech.com. Verified by Joe Polastre.
  70.  *
  71.  * Revision 1.3  2000/06/03 00:29:04  andyh
  72.  * COM Wrapper changes from Curt Arnold
  73.  *
  74.  * Revision 1.2  2000/03/30 02:00:12  abagchi
  75.  * Initial checkin of working code with Copyright Notice
  76.  *
  77.  */
  78. // xml4com.cpp : Implementation of DLL Exports.
  79. // Note: Proxy/Stub Information
  80. //      To merge the proxy/stub code into the object DLL, add the file
  81. //      dlldatax.c to the project.  Make sure precompiled headers
  82. //      are turned off for this file, and add _MERGE_PROXYSTUB to the
  83. //      defines for the project.
  84. //
  85. //      If you are not running WinNT4.0 or Win95 with DCOM, then you
  86. //      need to remove the following define from dlldatax.c
  87. //      #define _WIN32_WINNT 0x0400
  88. //
  89. //      Further, if you are running MIDL without /Oicf switch, you also
  90. //      need to remove the following define from dlldatax.c.
  91. //      #define USE_STUBLESS_PROXY
  92. //
  93. //      Modify the custom build rule for xml4com.idl by adding the following
  94. //      files to the Outputs.
  95. //          xml4com_p.c
  96. //          dlldata.c
  97. //      To build a separate proxy/stub DLL,
  98. //      run nmake -f xml4comps.mk in the project directory.
  99. #include "stdafx.h"
  100. #include "resource.h"
  101. #include <initguid.h>
  102. #include <util/PlatformUtils.hpp>
  103. #include "xml4com.h"
  104. #include <dom/DOM_DOMException.hpp>
  105. //
  106. //
  107. //    These were extracted from an identifier definition file
  108. //       generated by compiling MSXML.IDL using the MIDL compiler
  109. //        (and removing CLSID_DOMDocument, CLSID_XMLHttpRequest, et al)
  110. //
  111. const IID LIBID_MSXML = {0xd63e0ce2,0xa0a2,0x11d0,{0x9c,0x02,0x00,0xc0,0x4f,0xc9,0x9c,0x8e}};
  112. const IID IID_IXMLDOMImplementation = {0x2933BF8F,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  113. const IID IID_IXMLDOMNode = {0x2933BF80,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  114. const IID IID_IXMLDOMDocumentFragment = {0x3efaa413,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  115. const IID IID_IXMLDOMDocument = {0x2933BF81,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  116. const IID IID_IXMLDOMNodeList = {0x2933BF82,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  117. const IID IID_IXMLDOMNamedNodeMap = {0x2933BF83,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  118. const IID IID_IXMLDOMCharacterData = {0x2933BF84,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  119. const IID IID_IXMLDOMAttribute = {0x2933BF85,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  120. const IID IID_IXMLDOMElement = {0x2933BF86,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  121. const IID IID_IXMLDOMText = {0x2933BF87,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  122. const IID IID_IXMLDOMComment = {0x2933BF88,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  123. const IID IID_IXMLDOMProcessingInstruction = {0x2933BF89,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  124. const IID IID_IXMLDOMCDATASection = {0x2933BF8A,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  125. const IID IID_IXMLDOMDocumentType = {0x2933BF8B,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  126. const IID IID_IXMLDOMNotation = {0x2933BF8C,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  127. const IID IID_IXMLDOMEntity = {0x2933BF8D,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  128. const IID IID_IXMLDOMEntityReference = {0x2933BF8E,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  129. const IID IID_IXMLDOMParseError = {0x3efaa426,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  130. const IID IID_IXTLRuntime = {0x3efaa425,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  131. const IID DIID_XMLDOMDocumentEvents = {0x3efaa427,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  132. const IID IID_IXMLHttpRequest = {0xED8C108D,0x4349,0x11D2,{0x91,0xA4,0x00,0xC0,0x4F,0x79,0x69,0xE8}};
  133. const IID IID_IXMLDSOControl = {0x310afa62,0x0575,0x11d2,{0x9c,0xa9,0x00,0x60,0xb0,0xec,0x3d,0x39}};
  134. const IID IID_IXMLElementCollection = {0x65725580,0x9B5D,0x11d0,{0x9B,0xFE,0x00,0xC0,0x4F,0xC9,0x9C,0x8E}};
  135. const IID IID_IXMLDocument = {0xF52E2B61,0x18A1,0x11d1,{0xB1,0x05,0x00,0x80,0x5F,0x49,0x91,0x6B}};
  136. const IID IID_IXMLDocument2 = {0x2B8DE2FE,0x8D2D,0x11d1,{0xB2,0xFC,0x00,0xC0,0x4F,0xD9,0x15,0xA9}};
  137. const IID IID_IXMLElement = {0x3F7F31AC,0xE15F,0x11d0,{0x9C,0x25,0x00,0xC0,0x4F,0xC9,0x9C,0x8E}};
  138. const IID IID_IXMLElement2 = {0x2B8DE2FF,0x8D2D,0x11d1,{0xB2,0xFC,0x00,0xC0,0x4F,0xD9,0x15,0xA9}};
  139. const IID IID_IXMLAttribute = {0xD4D4A0FC,0x3B73,0x11d1,{0xB2,0xB4,0x00,0xC0,0x4F,0xB9,0x25,0x96}};
  140. const IID IID_IXMLError = {0x948C5AD3,0xC58D,0x11d0,{0x9C,0x0B,0x00,0xC0,0x4F,0xC9,0x9C,0x8E}};
  141. //
  142. //   This file is generated from the type library compilation
  143. //       of xml4com.idl
  144. //
  145. #include "xml4com_i.c"
  146. #include "XMLDOMDocument.h"
  147. #include "XMLHTTPRequest.h"
  148. #ifdef _MERGE_PROXYSTUB
  149. extern "C" HINSTANCE hProxyDll;
  150. #endif
  151. CComModule _Module;
  152. BEGIN_OBJECT_MAP(ObjectMap)
  153. OBJECT_ENTRY(CLSID_DOMDocument, CXMLDOMDocument)
  154. OBJECT_ENTRY(CLSID_XMLHTTPRequest, CXMLHttpRequest)
  155. END_OBJECT_MAP()
  156. /////////////////////////////////////////////////////////////////////////////
  157. // DLL Entry Point
  158. extern "C"
  159. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  160. {
  161.     lpReserved;
  162. #ifdef _MERGE_PROXYSTUB
  163.     if (!PrxDllMain(hInstance, dwReason, lpReserved))
  164.         return FALSE;
  165. #endif
  166.     if (dwReason == DLL_PROCESS_ATTACH)
  167.     {
  168.         _Module.Init(ObjectMap, hInstance, &LIBID_Xerces);
  169.         DisableThreadLibraryCalls(hInstance);
  170. XMLPlatformUtils::Initialize();
  171.     }
  172.     else if (dwReason == DLL_PROCESS_DETACH)
  173.         _Module.Term();
  174.     return TRUE;    // ok
  175. }
  176. /////////////////////////////////////////////////////////////////////////////
  177. // Used to determine whether the DLL can be unloaded by OLE
  178. STDAPI DllCanUnloadNow(void)
  179. {
  180. #ifdef _MERGE_PROXYSTUB
  181.     if (PrxDllCanUnloadNow() != S_OK)
  182.         return S_FALSE;
  183. #endif
  184.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  185. }
  186. /////////////////////////////////////////////////////////////////////////////
  187. // Returns a class factory to create an object of the requested type
  188. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  189. {
  190. #ifdef _MERGE_PROXYSTUB
  191.     if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  192.         return S_OK;
  193. #endif
  194.     return _Module.GetClassObject(rclsid, riid, ppv);
  195. }
  196. /////////////////////////////////////////////////////////////////////////////
  197. // DllRegisterServer - Adds entries to the system registry
  198. STDAPI DllRegisterServer(void)
  199. {
  200. #ifdef _MERGE_PROXYSTUB
  201.     HRESULT hRes = PrxDllRegisterServer();
  202.     if (FAILED(hRes))
  203.         return hRes;
  204. #endif
  205.     // registers object, typelib and all interfaces in typelib
  206.     return _Module.RegisterServer(TRUE);
  207. }
  208. /////////////////////////////////////////////////////////////////////////////
  209. // DllUnregisterServer - Removes entries from the system registry
  210. STDAPI DllUnregisterServer(void)
  211. {
  212. #ifdef _MERGE_PROXYSTUB
  213.     PrxDllUnregisterServer();
  214. #endif
  215.     return _Module.UnregisterServer(TRUE);
  216. }
  217. static LPOLESTR Msgs[] =
  218. {
  219. OLESTR("UNDEFINED DOM ERROR"),
  220. OLESTR("INDEX_SIZE_ERR"),   // INDEX_SIZE_ERR =  1
  221. OLESTR("DOMSTRING_SIZE_ERR"),  // DOMSTRING_SIZE_ERR =  2
  222. OLESTR("HIERARCHY_REQUEST_ERR"),   // HIERARCHY_REQUEST_ERR =  3
  223. OLESTR("WRONG_DOCUMENT_ERR"),   // WRONG_DOCUMENT_ERR =  4
  224. OLESTR("INVALID_CHARACTER_ERR"),   // INVALID_CHARACTER_ERR =  5
  225. OLESTR("NO_DATA_ALLOWED_ERR"),   // NO_DATA_ALLOWED_ERR =  6
  226. OLESTR("NO_MODIFICATION_ALLOWED_ERR"),   // NO_MODIFICATION_ALLOWED_ERR =  7
  227. OLESTR("NOT_FOUND_ERR"),   // NOT_FOUND_ERR =  8
  228. OLESTR("NOT_SUPPORTED_ERR"),   // NOT_SUPPORTED_ERR =  9
  229. OLESTR("INUSE_ATTRIBUTE_ERR"),   // INUSE_ATTRIBUTE_ERR =  10
  230. OLESTR("INVALID_STATE_ERR"),   // INVALID_STATE_ERR =  11
  231. OLESTR("SYNTAX_ERR "),   //  SYNTAX_ERR  =  12
  232. OLESTR("INVALID_MODIFICATION_ERR"),   //  INVALID_MODIFICATION_ERR =  13
  233. OLESTR("NAMESPACE_ERR"),   //  NAMESPACE_ERR  =  14
  234. OLESTR("INVALID_ACCESS_ERR") // INVALID_ACCESS_ERR   = 15
  235. };
  236. //
  237. //
  238. //   makes an HRESULT with a code based on the DOM error code
  239. //
  240. HRESULT MakeHRESULT(DOM_DOMException& ex)
  241. {
  242. ICreateErrorInfo* pCErr = NULL;
  243. HRESULT sc = CreateErrorInfo(&pCErr);
  244. if(SUCCEEDED(sc)) {
  245. DOMString msg = ex.msg;
  246. if(msg == NULL)
  247. {
  248. if(ex.code >= DOM_DOMException::INDEX_SIZE_ERR &&
  249. ex.code <= DOM_DOMException::INVALID_ACCESS_ERR)
  250. {
  251. sc = pCErr->SetDescription(Msgs[ex.code]);
  252. }
  253. else
  254. {
  255. sc = pCErr->SetDescription(Msgs[0]);
  256. }
  257. }
  258. else
  259. {
  260. sc = pCErr->SetDescription((BSTR) ex.msg.rawBuffer());
  261. }
  262. IErrorInfo* pErr = NULL;
  263. sc = pCErr->QueryInterface(IID_IErrorInfo,(void**) &pErr);
  264. if(SUCCEEDED(sc))
  265. {
  266. sc = SetErrorInfo(0,pErr);
  267. pErr->Release();
  268. }
  269. pCErr->Release();
  270. }
  271. return 0x80040600 + ex.code;
  272. }