Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

XMLCOM.cpp

Go to the documentation of this file.
00001 //
00002 // XMLCOM.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza 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 Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "XMLCOM.h"
00025 #include "XML.h"
00026 
00027 #ifdef _DEBUG
00028 #undef THIS_FILE
00029 static char THIS_FILE[]=__FILE__;
00030 #define new DEBUG_NEW
00031 #endif
00032 
00033 BEGIN_INTERFACE_MAP(CXMLCOM, CComObject)
00034         INTERFACE_PART(CXMLCOM, IID_ISXMLNode, XMLNode)
00035         INTERFACE_PART(CXMLCOM, IID_ISXMLElement, XMLElement)
00036         INTERFACE_PART(CXMLCOM, IID_ISXMLAttribute, XMLAttribute)
00037 END_INTERFACE_MAP()
00038 
00039 BEGIN_INTERFACE_MAP(CXMLCOMCol, CComObject)
00040         INTERFACE_PART(CXMLCOMCol, IID_ISXMLElements, XMLElements)
00041         INTERFACE_PART(CXMLCOMCol, IID_ISXMLAttributes, XMLAttributes)
00042         INTERFACE_PART(CXMLCOMCol, IID_IEnumVARIANT, EnumVARIANT)
00043 END_INTERFACE_MAP()
00044 
00045 
00047 // CXMLCOM construction
00048 
00049 CXMLCOM::CXMLCOM(CXMLNode* pNode)
00050 {
00051         m_pNode = pNode ? pNode : new CXMLElement();
00052 
00053         EnableDispatch( IID_ISXMLNode );
00054         EnableDispatch( IID_ISXMLElement );
00055         EnableDispatch( IID_ISXMLAttribute );
00056 }
00057 
00058 CXMLCOM::~CXMLCOM()
00059 {
00060 }
00061 
00063 // CXMLCOM wrapper
00064 
00065 IUnknown* CXMLCOM::Wrap(CXMLNode* pNode, REFIID pIID)
00066 {
00067         if ( pNode == NULL ) return NULL;
00068 
00069         if ( pIID == IID_ISXMLElement )
00070         {
00071                 if ( pNode->m_nNode != CXMLNode::xmlElement ) return NULL;
00072         }
00073         else if ( pIID == IID_ISXMLAttribute )
00074         {
00075                 if ( pNode->m_nNode != CXMLNode::xmlAttribute ) return NULL;
00076         }
00077 
00078         CXMLCOM* pWrap = new CXMLCOM( pNode );
00079 
00080         IUnknown* pCom = pWrap->GetInterface( pIID, FALSE );
00081         if ( pCom == NULL ) delete pWrap;
00082 
00083         return pCom;
00084 }
00085 
00087 // CXMLCOM unwrapper
00088 
00089 CXMLElement* CXMLCOM::Unwrap(ISXMLElement* pInterface)
00090 {
00091         if ( pInterface == NULL ) return NULL;
00092         INTERFACE_TO_CLASS(CXMLCOM, XMLElement, pInterface, pWrapper)
00093         return (CXMLElement*)pWrapper->m_pNode;
00094 }
00095 
00097 // CXMLCOM ISXMLNode
00098 
00099 IMPLEMENT_DISPATCH( CXMLCOM, XMLNode )
00100 
00101 STDMETHODIMP CXMLCOM::XXMLNode::get_Parent(ISXMLElement FAR* FAR* ppParent)
00102 {
00103         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00104         if ( ppParent == NULL ) return E_INVALIDARG;
00105         CXMLElement* pParent = pThis->m_pNode->GetParent();
00106         if ( pParent )
00107                 *ppParent = (ISXMLElement*)Wrap( pParent, IID_ISXMLElement );
00108         else
00109                 *ppParent = NULL;
00110         return S_OK;
00111 }
00112 
00113 STDMETHODIMP CXMLCOM::XXMLNode::get_Type(SXMLNodeType FAR* pnType)
00114 {
00115         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00116         if ( pnType == NULL ) return E_INVALIDARG;
00117         *pnType = (SXMLNodeType)pThis->m_pNode->GetType();
00118         return S_OK;
00119 }
00120 
00121 STDMETHODIMP CXMLCOM::XXMLNode::get_AsNode(ISXMLNode FAR* FAR* ppNode)
00122 {
00123         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00124         if ( ppNode == NULL ) return E_INVALIDARG;
00125         *ppNode = (ISXMLNode*)Wrap( pThis->m_pNode, IID_ISXMLNode );
00126         return S_OK;
00127 }
00128 
00129 STDMETHODIMP CXMLCOM::XXMLNode::get_AsElement(ISXMLNode FAR* FAR* ppElement)
00130 {
00131         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00132         if ( ppElement == NULL ) return E_INVALIDARG;
00133         *ppElement = (ISXMLElement*)Wrap( pThis->m_pNode, IID_ISXMLElement );
00134         return S_OK;
00135 }
00136 
00137 STDMETHODIMP CXMLCOM::XXMLNode::get_AsAttribute(ISXMLNode FAR* FAR* ppAttribute)
00138 {
00139         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00140         if ( ppAttribute == NULL ) return E_INVALIDARG;
00141         *ppAttribute = (ISXMLAttribute*)Wrap( pThis->m_pNode, IID_ISXMLAttribute );
00142         return S_OK;
00143 }
00144 
00145 STDMETHODIMP CXMLCOM::XXMLNode::get_Name(BSTR FAR* psName)
00146 {
00147         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00148         if ( psName == NULL ) return E_INVALIDARG;
00149         pThis->m_pNode->GetName().SetSysString( psName );
00150         return S_OK;
00151 }
00152 
00153 STDMETHODIMP CXMLCOM::XXMLNode::put_Name(BSTR sName)
00154 {
00155         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00156         if ( sName == NULL ) return E_INVALIDARG;
00157         pThis->m_pNode->SetName( CString( sName ) );
00158         return S_OK;
00159 }
00160 
00161 STDMETHODIMP CXMLCOM::XXMLNode::get_Value(BSTR FAR* psValue)
00162 {
00163         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00164         if ( psValue == NULL ) return E_INVALIDARG;
00165         pThis->m_pNode->GetValue().SetSysString( psValue );
00166         return S_OK;
00167 }
00168 
00169 STDMETHODIMP CXMLCOM::XXMLNode::put_Value(BSTR sValue)
00170 {
00171         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00172         if ( sValue == NULL ) return E_INVALIDARG;
00173         pThis->m_pNode->SetValue( CString( sValue ) );
00174         return S_OK;
00175 }
00176 
00177 STDMETHODIMP CXMLCOM::XXMLNode::Delete()
00178 {
00179         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00180         pThis->m_pNode->Delete();
00181         pThis->m_pNode = NULL;
00182         return S_OK;
00183 }
00184 
00185 STDMETHODIMP CXMLCOM::XXMLNode::IsNamed(BSTR sName, VARIANT_BOOL FAR* pbResult)
00186 {
00187         METHOD_PROLOGUE( CXMLCOM, XMLNode )
00188         if ( sName == NULL || pbResult == NULL ) return E_INVALIDARG;
00189         *pbResult = pThis->m_pNode->IsNamed( CString( sName ) ) ? VARIANT_TRUE : VARIANT_FALSE;
00190         return S_OK;
00191 }
00192 
00194 // CXMLCOM ISXMLElement
00195 
00196 IMPLEMENT_DISPATCH( CXMLCOM, XMLElement )
00197 
00198 STDMETHODIMP CXMLCOM::XXMLElement::get_Parent(ISXMLElement FAR* FAR* ppParent)
00199 {
00200         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00201         if ( ppParent == NULL ) return E_INVALIDARG;
00202         CXMLElement* pParent = pThis->m_pNode->GetParent();
00203         if ( pParent )
00204                 *ppParent = (ISXMLElement*)Wrap( pParent, IID_ISXMLElement );
00205         else
00206                 *ppParent = NULL;
00207         return S_OK;
00208 }
00209 
00210 STDMETHODIMP CXMLCOM::XXMLElement::get_Type(SXMLNodeType FAR* pnType)
00211 {
00212         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00213         if ( pnType == NULL ) return E_INVALIDARG;
00214         *pnType = (SXMLNodeType)pThis->m_pNode->GetType();
00215         return S_OK;
00216 }
00217 
00218 STDMETHODIMP CXMLCOM::XXMLElement::get_AsNode(ISXMLNode FAR* FAR* ppNode)
00219 {
00220         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00221         if ( ppNode == NULL ) return E_INVALIDARG;
00222         *ppNode = (ISXMLNode*)Wrap( pThis->m_pNode, IID_ISXMLNode );
00223         return S_OK;
00224 }
00225 
00226 STDMETHODIMP CXMLCOM::XXMLElement::get_AsElement(ISXMLNode FAR* FAR* ppElement)
00227 {
00228         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00229         if ( ppElement == NULL ) return E_INVALIDARG;
00230         *ppElement = (ISXMLElement*)Wrap( pThis->m_pNode, IID_ISXMLElement );
00231         return S_OK;
00232 }
00233 
00234 STDMETHODIMP CXMLCOM::XXMLElement::get_AsAttribute(ISXMLNode FAR* FAR* ppAttribute)
00235 {
00236         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00237         if ( ppAttribute == NULL ) return E_INVALIDARG;
00238         *ppAttribute = (ISXMLAttribute*)Wrap( pThis->m_pNode, IID_ISXMLAttribute );
00239         return S_OK;
00240 }
00241 
00242 STDMETHODIMP CXMLCOM::XXMLElement::get_Name(BSTR FAR* psName)
00243 {
00244         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00245         if ( psName == NULL ) return E_INVALIDARG;
00246         pThis->m_pNode->GetName().SetSysString( psName );
00247         return S_OK;
00248 }
00249 
00250 STDMETHODIMP CXMLCOM::XXMLElement::put_Name(BSTR sName)
00251 {
00252         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00253         if ( sName == NULL ) return E_INVALIDARG;
00254         pThis->m_pNode->SetName( CString( sName ) );
00255         return S_OK;
00256 }
00257 
00258 STDMETHODIMP CXMLCOM::XXMLElement::get_Value(BSTR FAR* psValue)
00259 {
00260         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00261         if ( psValue == NULL ) return E_INVALIDARG;
00262         pThis->m_pNode->GetValue().SetSysString( psValue );
00263         return S_OK;
00264 }
00265 
00266 STDMETHODIMP CXMLCOM::XXMLElement::put_Value(BSTR sValue)
00267 {
00268         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00269         if ( sValue == NULL ) return E_INVALIDARG;
00270         pThis->m_pNode->SetValue( CString( sValue ) );
00271         return S_OK;
00272 }
00273 
00274 STDMETHODIMP CXMLCOM::XXMLElement::Delete()
00275 {
00276         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00277         pThis->m_pNode->Delete();
00278         pThis->m_pNode = NULL;
00279         return S_OK;
00280 }
00281 
00282 STDMETHODIMP CXMLCOM::XXMLElement::IsNamed(BSTR sName, VARIANT_BOOL FAR* pbResult)
00283 {
00284         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00285         if ( sName == NULL || pbResult == NULL ) return E_INVALIDARG;
00286         *pbResult = pThis->m_pNode->IsNamed( CString( sName ) ) ? VARIANT_TRUE : VARIANT_FALSE;
00287         return S_OK;
00288 }
00289 
00290 STDMETHODIMP CXMLCOM::XXMLElement::get_Elements(ISXMLElements FAR* FAR* ppElements)
00291 {
00292         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00293         if ( ppElements == NULL ) return E_INVALIDARG;
00294         *ppElements = CXMLCOMCol::WrapElements( (CXMLElement*)pThis->m_pNode );
00295         return S_OK;
00296 }
00297 
00298 STDMETHODIMP CXMLCOM::XXMLElement::get_Attributes(ISXMLAttributes FAR* FAR* ppAttributes)
00299 {
00300         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00301         if ( ppAttributes == NULL ) return E_INVALIDARG;
00302         *ppAttributes = CXMLCOMCol::WrapAttributes( (CXMLElement*)pThis->m_pNode );
00303         return S_OK;
00304 }
00305 
00306 STDMETHODIMP CXMLCOM::XXMLElement::Detach()
00307 {
00308         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00309         ((CXMLElement*)pThis->m_pNode)->Detach();
00310         return S_OK;
00311 }
00312 
00313 STDMETHODIMP CXMLCOM::XXMLElement::Clone(ISXMLElement FAR* FAR* ppClone)
00314 {
00315         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00316         if ( ppClone == NULL ) return E_INVALIDARG;
00317         *ppClone = (ISXMLElement*)Wrap( ((CXMLElement*)pThis->m_pNode)->Clone(), IID_ISXMLElement );
00318         return S_OK;
00319 }
00320 
00321 STDMETHODIMP CXMLCOM::XXMLElement::ToString(BSTR FAR* psValue)
00322 {
00323         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00324         if ( psValue == NULL ) return E_INVALIDARG;
00325         ((CXMLElement*)pThis->m_pNode)->ToString().SetSysString( psValue );
00326         return S_OK;
00327 }
00328 
00329 STDMETHODIMP CXMLCOM::XXMLElement::ToStringEx(VARIANT_BOOL bHeader, VARIANT_BOOL bNewlines, BSTR FAR* psValue)
00330 {
00331         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00332         if ( psValue == NULL ) return E_INVALIDARG;
00333         ((CXMLElement*)pThis->m_pNode)->ToString( (BOOL)bHeader, (BOOL)bNewlines ).SetSysString( psValue );
00334         return S_OK;
00335 }
00336 
00337 STDMETHODIMP CXMLCOM::XXMLElement::FromString(BSTR sXML, ISXMLElement FAR* FAR* ppElement)
00338 {
00339         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00340         if ( sXML == NULL || ppElement == NULL ) return E_INVALIDARG;
00341         CXMLElement* pElement = CXMLElement::FromString( CString( sXML ) );
00342         if ( ! pElement ) return E_FAIL;
00343         *ppElement = (ISXMLElement*)Wrap( pElement, IID_ISXMLElement );
00344         return S_OK;
00345 }
00346 
00347 STDMETHODIMP CXMLCOM::XXMLElement::GetWords(BSTR FAR* psWords)
00348 {
00349         METHOD_PROLOGUE( CXMLCOM, XMLElement )
00350         if ( psWords == NULL ) return E_INVALIDARG;
00351         ((CXMLElement*)pThis->m_pNode)->GetRecursiveWords().SetSysString( psWords );
00352         return S_OK;
00353 }
00354 
00355 
00357 // CXMLCOM ISXMLAttribute
00358 
00359 IMPLEMENT_DISPATCH( CXMLCOM, XMLAttribute )
00360 
00361 STDMETHODIMP CXMLCOM::XXMLAttribute::get_Parent(ISXMLElement FAR* FAR* ppParent)
00362 {
00363         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00364         if ( ppParent == NULL ) return E_INVALIDARG;
00365         CXMLElement* pParent = pThis->m_pNode->GetParent();
00366         if ( pParent )
00367                 *ppParent = (ISXMLElement*)Wrap( pParent, IID_ISXMLElement );
00368         else
00369                 *ppParent = NULL;
00370         return S_OK;
00371 }
00372 
00373 STDMETHODIMP CXMLCOM::XXMLAttribute::get_Type(SXMLNodeType FAR* pnType)
00374 {
00375         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00376         if ( pnType == NULL ) return E_INVALIDARG;
00377         *pnType = (SXMLNodeType)pThis->m_pNode->GetType();
00378         return S_OK;
00379 }
00380 
00381 STDMETHODIMP CXMLCOM::XXMLAttribute::get_AsNode(ISXMLNode FAR* FAR* ppNode)
00382 {
00383         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00384         if ( ppNode == NULL ) return E_INVALIDARG;
00385         *ppNode = (ISXMLNode*)Wrap( pThis->m_pNode, IID_ISXMLNode );
00386         return S_OK;
00387 }
00388 
00389 STDMETHODIMP CXMLCOM::XXMLAttribute::get_AsElement(ISXMLNode FAR* FAR* ppElement)
00390 {
00391         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00392         if ( ppElement == NULL ) return E_INVALIDARG;
00393         *ppElement = (ISXMLElement*)Wrap( pThis->m_pNode, IID_ISXMLElement );
00394         return S_OK;
00395 }
00396 
00397 STDMETHODIMP CXMLCOM::XXMLAttribute::get_AsAttribute(ISXMLNode FAR* FAR* ppAttribute)
00398 {
00399         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00400         if ( ppAttribute == NULL ) return E_INVALIDARG;
00401         *ppAttribute = (ISXMLAttribute*)Wrap( pThis->m_pNode, IID_ISXMLAttribute );
00402         return S_OK;
00403 }
00404 
00405 STDMETHODIMP CXMLCOM::XXMLAttribute::get_Name(BSTR FAR* psName)
00406 {
00407         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00408         if ( psName == NULL ) return E_INVALIDARG;
00409         pThis->m_pNode->GetName().SetSysString( psName );
00410         return S_OK;
00411 }
00412 
00413 STDMETHODIMP CXMLCOM::XXMLAttribute::put_Name(BSTR sName)
00414 {
00415         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00416         if ( sName == NULL ) return E_INVALIDARG;
00417         pThis->m_pNode->SetName( CString( sName ) );
00418         return S_OK;
00419 }
00420 
00421 STDMETHODIMP CXMLCOM::XXMLAttribute::get_Value(BSTR FAR* psValue)
00422 {
00423         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00424         if ( psValue == NULL ) return E_INVALIDARG;
00425         pThis->m_pNode->GetValue().SetSysString( psValue );
00426         return S_OK;
00427 }
00428 
00429 STDMETHODIMP CXMLCOM::XXMLAttribute::put_Value(BSTR sValue)
00430 {
00431         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00432         if ( sValue == NULL ) return E_INVALIDARG;
00433         pThis->m_pNode->SetValue( CString( sValue ) );
00434         return S_OK;
00435 }
00436 
00437 STDMETHODIMP CXMLCOM::XXMLAttribute::Delete()
00438 {
00439         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00440         pThis->m_pNode->Delete();
00441         pThis->m_pNode = NULL;
00442         return S_OK;
00443 }
00444 
00445 STDMETHODIMP CXMLCOM::XXMLAttribute::IsNamed(BSTR sName, VARIANT_BOOL FAR* pbResult)
00446 {
00447         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00448         if ( sName == NULL || pbResult == NULL ) return E_INVALIDARG;
00449         *pbResult = pThis->m_pNode->IsNamed( CString( sName ) ) ? VARIANT_TRUE : VARIANT_FALSE;
00450         return S_OK;
00451 }
00452 
00453 STDMETHODIMP CXMLCOM::XXMLAttribute::Detach()
00454 {
00455         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00456         return E_NOTIMPL;
00457 }
00458 
00459 STDMETHODIMP CXMLCOM::XXMLAttribute::Clone(ISXMLAttribute FAR* FAR* ppClone)
00460 {
00461         METHOD_PROLOGUE( CXMLCOM, XMLAttribute )
00462         if ( ppClone == NULL ) return E_INVALIDARG;
00463         *ppClone = (ISXMLAttribute*)Wrap( ((CXMLAttribute*)pThis->m_pNode)->Clone(), IID_ISXMLAttribute );
00464         return S_OK;
00465 }
00466 
00468 // CXMLCOMCol construction
00469 
00470 CXMLCOMCol::CXMLCOMCol(CXMLElement* pElement)
00471 {
00472         m_pElement = pElement;
00473 
00474         EnableDispatch( IID_ISXMLElements );
00475         EnableDispatch( IID_ISXMLAttributes );
00476 }
00477 
00478 CXMLCOMCol::~CXMLCOMCol()
00479 {
00480 }
00481 
00483 // CXMLCOMCol wrapper
00484 
00485 ISXMLElements* CXMLCOMCol::WrapElements(CXMLElement* pElement)
00486 {
00487         CXMLCOMCol* pWrap = new CXMLCOMCol( pElement );
00488 
00489         ISXMLElements* pCom = (ISXMLElements*)pWrap->GetInterface( IID_ISXMLElements, FALSE );
00490         if ( pCom == NULL ) delete pWrap;
00491 
00492         return pCom;
00493 }
00494 
00495 ISXMLAttributes* CXMLCOMCol::WrapAttributes(CXMLElement* pElement)
00496 {
00497         CXMLCOMCol* pWrap = new CXMLCOMCol( pElement );
00498 
00499         ISXMLAttributes* pCom = (ISXMLAttributes*)pWrap->GetInterface( IID_ISXMLAttributes, FALSE );
00500         if ( pCom == NULL ) delete pWrap;
00501 
00502         return pCom;
00503 }
00504 
00506 // CXMLCOMCol ISXMLElements
00507 
00508 IMPLEMENT_DISPATCH( CXMLCOMCol, XMLElements )
00509 
00510 STDMETHODIMP CXMLCOMCol::XXMLElements::get__NewEnum(IUnknown FAR* FAR* ppEnum)
00511 {
00512         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00513         AddRef();
00514         *ppEnum = &pThis->m_xEnumVARIANT;
00515         pThis->m_xEnumVARIANT.m_posCurrent = pThis->m_pElement->GetElementIterator();
00516         pThis->m_xEnumVARIANT.m_bAttributes = FALSE;
00517         return S_OK;
00518 }
00519 
00520 STDMETHODIMP CXMLCOMCol::XXMLElements::get_Item(VARIANT vIndex, ISXMLElement FAR* FAR* ppElement)
00521 {
00522         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00523 
00524         CXMLElement* pElement = NULL;
00525 
00526         if ( vIndex.vt == VT_BSTR )
00527         {
00528                 pElement = pThis->m_pElement->GetElementByName( CString( vIndex.bstrVal ) );
00529         }
00530         else
00531         {
00532                 VARIANT va;
00533                 VariantInit( &va );
00534 
00535                 if ( SUCCEEDED( VariantChangeType( &va, (VARIANT FAR*)&vIndex, 0, VT_I4 ) ) )
00536                 {
00537                         for ( POSITION pos = pThis->m_pElement->GetElementIterator() ; pos ; vIndex.lVal-- )
00538                         {
00539                                 pElement = pThis->m_pElement->GetNextElement( pos );
00540                                 if ( vIndex.lVal == 0 ) break;
00541                                 pElement = NULL;
00542                         }
00543                 }
00544         }
00545 
00546         *ppElement = (ISXMLElement*)CXMLCOM::Wrap( pElement, IID_ISXMLElement );
00547 
00548         return S_OK;
00549 }
00550 
00551 STDMETHODIMP CXMLCOMCol::XXMLElements::get_Count(LONG FAR* pnCount)
00552 {
00553         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00554         *pnCount = (LONG)pThis->m_pElement->GetElementCount();
00555         return S_OK;
00556 }
00557 
00558 STDMETHODIMP CXMLCOMCol::XXMLElements::Create(BSTR strName, ISXMLElement FAR* FAR* ppElement)
00559 {
00560         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00561         *ppElement = (ISXMLElement*)CXMLCOM::Wrap( pThis->m_pElement->AddElement( CString( strName ) ), IID_ISXMLElement );
00562         return S_OK;
00563 }
00564 
00565 STDMETHODIMP CXMLCOMCol::XXMLElements::Attach(ISXMLElement FAR* pElement)
00566 {
00567         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00568         INTERFACE_TO_CLASS( CXMLCOM, XMLElement, pElement, prWrap )
00569         pThis->m_pElement->AddElement( (CXMLElement*)prWrap->m_pNode );
00570         return S_OK;
00571 }
00572 
00573 STDMETHODIMP CXMLCOMCol::XXMLElements::RemoveAll()
00574 {
00575         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00576         pThis->m_pElement->DeleteAllElements();
00577         return S_OK;
00578 }
00579 
00580 STDMETHODIMP CXMLCOMCol::XXMLElements::get_First(ISXMLElement FAR* FAR* ppElement)
00581 {
00582         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00583         *ppElement = (ISXMLElement*)CXMLCOM::Wrap( pThis->m_pElement->GetFirstElement(), IID_ISXMLElement );
00584         return S_OK;
00585 }
00586 
00587 STDMETHODIMP CXMLCOMCol::XXMLElements::get_ByName(BSTR sName, ISXMLElement FAR* FAR* ppElement)
00588 {
00589         METHOD_PROLOGUE( CXMLCOMCol, XMLElements )
00590         *ppElement = (ISXMLElement*)CXMLCOM::Wrap( pThis->m_pElement->GetElementByName( CString( sName ) ), IID_ISXMLElement );
00591         return S_OK;
00592 }
00593 
00595 // CXMLCOMCol ISXMLAttributes
00596 
00597 IMPLEMENT_DISPATCH( CXMLCOMCol, XMLAttributes )
00598 
00599 STDMETHODIMP CXMLCOMCol::XXMLAttributes::get__NewEnum(IUnknown FAR* FAR* ppEnum)
00600 {
00601         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00602         AddRef();
00603         *ppEnum = &pThis->m_xEnumVARIANT;
00604         pThis->m_xEnumVARIANT.m_posCurrent = pThis->m_pElement->GetAttributeIterator();
00605         pThis->m_xEnumVARIANT.m_bAttributes = TRUE;
00606         return S_OK;
00607 }
00608 
00609 STDMETHODIMP CXMLCOMCol::XXMLAttributes::get_Item(VARIANT vIndex, ISXMLAttribute FAR* FAR* ppAttribute)
00610 {
00611         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00612 
00613         CXMLAttribute* pAttribute = NULL;
00614 
00615         if ( vIndex.vt == VT_BSTR )
00616         {
00617                 pAttribute = pThis->m_pElement->GetAttribute( CString( vIndex.bstrVal ) );
00618         }
00619         else
00620         {
00621                 VARIANT va;
00622                 VariantInit( &va );
00623 
00624                 if ( SUCCEEDED( VariantChangeType( &va, (VARIANT FAR*)&vIndex, 0, VT_I4 ) ) )
00625                 {
00626                         for ( POSITION pos = pThis->m_pElement->GetAttributeIterator() ; pos ; vIndex.lVal-- )
00627                         {
00628                                 pAttribute = pThis->m_pElement->GetNextAttribute( pos );
00629                                 if ( vIndex.lVal == 0 ) break;
00630                                 pAttribute = NULL;
00631                         }
00632                 }
00633         }
00634 
00635         *ppAttribute = (ISXMLAttribute*)CXMLCOM::Wrap( pAttribute, IID_ISXMLAttribute );
00636 
00637         return S_OK;
00638 }
00639 
00640 STDMETHODIMP CXMLCOMCol::XXMLAttributes::get_Count(LONG FAR* pnCount)
00641 {
00642         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00643         *pnCount = (LONG)pThis->m_pElement->GetAttributeCount();
00644         return S_OK;
00645 }
00646 
00647 STDMETHODIMP CXMLCOMCol::XXMLAttributes::Add(BSTR strName, BSTR strValue)
00648 {
00649         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00650         pThis->m_pElement->AddAttribute( CString( strName ), CString( strValue ) );
00651         return S_OK;
00652 }
00653 
00654 STDMETHODIMP CXMLCOMCol::XXMLAttributes::Create(BSTR strName, ISXMLAttribute FAR* FAR* ppAttribute)
00655 {
00656         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00657         *ppAttribute = (ISXMLAttribute*)CXMLCOM::Wrap( pThis->m_pElement->AddAttribute( CString( strName ) ), IID_ISXMLElement );
00658         return S_OK;
00659 }
00660 
00661 STDMETHODIMP CXMLCOMCol::XXMLAttributes::Attach(ISXMLAttribute FAR* pAttribute)
00662 {
00663         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00664         INTERFACE_TO_CLASS( CXMLCOM, XMLAttribute, pAttribute, prWrap )
00665         pThis->m_pElement->AddAttribute( (CXMLAttribute*)prWrap->m_pNode );
00666         return S_OK;
00667 }
00668 
00669 STDMETHODIMP CXMLCOMCol::XXMLAttributes::RemoveAll()
00670 {
00671         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00672         pThis->m_pElement->DeleteAllAttributes();
00673         return S_OK;
00674 }
00675 
00676 STDMETHODIMP CXMLCOMCol::XXMLAttributes::get_ByName(BSTR sName, ISXMLAttribute FAR* FAR* ppAttribute)
00677 {
00678         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00679         *ppAttribute = (ISXMLAttribute*)CXMLCOM::Wrap( pThis->m_pElement->GetAttribute( CString( sName ) ), IID_ISXMLAttribute );
00680         return S_OK;
00681 }
00682 
00683 STDMETHODIMP CXMLCOMCol::XXMLAttributes::get_Get(BSTR sName, BSTR FAR* psValue)
00684 {
00685         METHOD_PROLOGUE( CXMLCOMCol, XMLAttributes )
00686         pThis->m_pElement->GetAttributeValue( CString( sName ) ).SetSysString( psValue );
00687         return S_OK;
00688 }
00689 
00691 // CXMLCOMCol::XEnumVARIANT enumerator
00692 
00693 IMPLEMENT_UNKNOWN( CXMLCOMCol, EnumVARIANT )
00694 
00695 STDMETHODIMP CXMLCOMCol::XEnumVARIANT::Next(ULONG celt, VARIANT FAR* rgvar, ULONG FAR* pceltFetched)
00696 {
00697         METHOD_PROLOGUE( CXMLCOMCol, EnumVARIANT )
00698 
00699         ULONG i;
00700 
00701         if ( pceltFetched ) *pceltFetched = 0;
00702         else if ( celt > 1 ) return E_INVALIDARG;
00703 
00704         for ( i = 0 ; i < celt ; i++ ) VariantInit( &rgvar[i] );
00705 
00706         for ( i = 0 ; i < celt ; i++ )
00707         {
00708                 if ( m_bAttributes )
00709                 {
00710                         CXMLAttribute* pAttribute = pThis->m_pElement->GetNextAttribute( m_posCurrent );
00711                         if ( ! pAttribute ) break;
00712 
00713                         rgvar[i].vt                     = VT_DISPATCH;
00714                         rgvar[i].pdispVal       = (IDispatch*)CXMLCOM::Wrap( pAttribute, IID_ISXMLAttribute );
00715                 }
00716                 else
00717                 {
00718                         CXMLElement* pElement = pThis->m_pElement->GetNextElement( m_posCurrent );
00719                         if ( ! pElement ) break;
00720 
00721                         rgvar[i].vt                     = VT_DISPATCH;
00722                         rgvar[i].pdispVal       = (IDispatch*)CXMLCOM::Wrap( pElement, IID_ISXMLElement );
00723                 }
00724 
00725                 if ( pceltFetched ) (*pceltFetched)++;
00726         }
00727 
00728         if ( i < celt ) return ResultFromScode( S_FALSE );
00729 
00730         return S_OK;
00731 }
00732 
00733 STDMETHODIMP CXMLCOMCol::XEnumVARIANT::Skip(ULONG celt)
00734 {
00735     METHOD_PROLOGUE( CXMLCOMCol, EnumVARIANT )
00736 
00737         if ( m_bAttributes )
00738         {
00739                 while ( celt > 0 && pThis->m_pElement->GetNextAttribute( m_posCurrent ) ) celt--;
00740         }
00741         else
00742         {
00743                 while ( celt > 0 && pThis->m_pElement->GetNextElement( m_posCurrent ) ) celt--;
00744         }
00745 
00746     return ( celt == 0 ? S_OK : ResultFromScode( S_FALSE ) );
00747 }
00748 
00749 STDMETHODIMP CXMLCOMCol::XEnumVARIANT::Reset()
00750 {
00751     METHOD_PROLOGUE( CXMLCOMCol, EnumVARIANT )
00752         m_posCurrent = m_bAttributes ? pThis->m_pElement->GetAttributeIterator() : pThis->m_pElement->GetElementIterator();
00753     return S_OK;
00754 }
00755 
00756 STDMETHODIMP CXMLCOMCol::XEnumVARIANT::Clone(IEnumVARIANT FAR* FAR* ppenum)
00757 {
00758     METHOD_PROLOGUE( CXMLCOMCol, EnumVARIANT )
00759     return E_NOTIMPL;
00760 }

Generated on Thu Dec 15 10:39:54 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2