📄 soapmapr.cpp
字号:
// function:HRESULT CSoapMapper::get_encoding(BSTR *pbstrEncoding)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::get_encoding(BSTR *pbstrEncoding)
{
ASSERT(m_pOwner!=0);
if (m_pOwner==0)
{
return(E_FAIL);
}
return _WSDLUtilReturnAutomationBSTR(pbstrEncoding, m_pOwner->getEncoding(m_enInput!=smOutput));
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CSoapMapper::Init(IXMLDOMNode *pPartNode, ISoapTypeMapperFactory *ptypeFactory, bool fInput,
// BSTR bstrSchemaNS, CWSDLOperation *pParent)
//
// parameters:
//
// description:
// takes the pointer to the message part, sucks info out of it and
// finds corresponding schema info
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::Init(IXMLDOMNode *pPartNode, ISoapTypeMapperFactory *ptypeFactory, bool fInput, BSTR bstrSchemaNS, CWSDLOperation *pParent)
{
HRESULT hr = E_FAIL;
CAutoBSTR bstrTemp;
TCHAR achPrefix[_MAX_ATTRIBUTE_LEN+1];
CAutoBSTR bstrURI;
ASSERT(pPartNode!=0);
ASSERT(pParent!=0);
ASSERT(ptypeFactory!=0);
assign(&m_pOwner,pParent);
assign(&m_ptypeFactory, ptypeFactory);
m_enInput = fInput ? smInput : smOutput;
if (!bstrSchemaNS)
{
hr = _WSDLUtilFindAttribute(pPartNode, _T("name"), &m_bstrPartName);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_MAPPERNONAME, WSDL_IDS_MAPPER, hr);
goto Cleanup;
}
// check for uniqueness of partname
hr = pParent->verifyPartName(m_enInput, m_bstrPartName);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_MAPPERDUPLICATENAME, WSDL_IDS_MAPPER, hr, m_bstrPartName);
goto Cleanup;
}
hr = _WSDLUtilFindAttribute(pPartNode, _T("element"), &bstrTemp);
if (FAILED(hr))
{
bstrTemp.Clear();
// if there is NO element declaration, there must be type declaration
hr = _WSDLUtilFindAttribute(pPartNode, _T("type"), &bstrTemp);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_MAPPERNOELEMENTORTYPE, WSDL_IDS_MAPPER, hr, m_bstrPartName);
goto Cleanup;
}
m_basedOnType = true;
}
CHK(_WSDLUtilSplitQName(bstrTemp, achPrefix, &m_bstrSchemaElement));
hr = _XSDFindURIForPrefix(pPartNode, achPrefix, &bstrURI);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_URIFORQNAMENF, WSDL_IDS_MAPPER, hr, achPrefix, bstrTemp);
goto Cleanup;
}
}
else
{
// so this is PID case
// we might need to do an additonal lookup if there is no NAME, because then it might be a REF situaion
// as a REF points to another ELEMENT of the same NAME we can just stick the REF value into our NAME
// property and let the typefactory worry about finding the type
if (FAILED(_WSDLUtilFindAttribute(pPartNode, _T("name"), &bstrTemp)))
{
CHK(_WSDLUtilFindAttribute(pPartNode, _T("ref"), &bstrTemp));
}
CHK(_WSDLUtilSplitQName(bstrTemp, achPrefix, &m_bstrSchemaElement));
// remember this guy for later use
m_pSchemaNode = pPartNode;
m_pSchemaNode->AddRef();
}
CHK(setSchemaURI(bstrSchemaNS ? bstrSchemaNS : bstrURI));
CHK(setVarName(m_basedOnType ? m_bstrPartName : m_bstrSchemaElement));
CHK(createTypeMapper());
TRACEL((3, "Mapper %S created\n",getVarName()));
Cleanup:
ASSERT(hr==S_OK);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CSoapMapper::AddWSMLMetaInfo(IUnknown *pExecuteNode,CWSDLService *pService,
// IXMLDOMDocument *pWSDLDom, IXMLDOMDocument *pWSMLDom,
// bool bLoadOnServer)
//
// parameters:
//
// description:
// the method is called during initialisation to give a mapper a chance
// to read the information he stored in the WSML file
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::AddWSMLMetaInfo(IXMLDOMNode *pExecuteNode,
CWSDLService *pService,
IXMLDOMDocument *pWSDLDom,
IXMLDOMDocument *pWSMLDom,
bool bLoadOnServer)
{
HRESULT hr = E_FAIL;
CAutoRefc<IXMLDOMNode> pExecute=0;
CAutoRefc<IXMLDOMNode> pPara=0;
CAutoRefc<IXMLDOMNode> pType=0;
CAutoFormat autoFormat;
#ifndef UNDER_CE
CDispatchHolder *pDispatchHolder;
#endif
if (bLoadOnServer)
{
hr = pExecuteNode->QueryInterface(IID_IXMLDOMNode, (void **)&pExecute);
if (FAILED(hr))
{
goto Cleanup;
}
CHK(autoFormat.sprintf(_T("./parameter[@elementName=\"%s\"]"), getVarName()));
hr = pExecute->selectSingleNode(&autoFormat, &pPara);
if (hr != S_OK)
{
globalAddError(WSML_IDS_MAPPERNOELEMENTNAME, WSDL_IDS_MAPPER, hr, getVarName());
hr = E_FAIL;
goto Cleanup;
}
if (pPara)
{
CAutoBSTR bstrTemp;
hr = _WSDLUtilFindAttribute(pPara, _T("callIndex"), &bstrTemp);
if (FAILED(hr))
{
globalAddError(WSML_IDS_MAPPERNOCALLINDEX, WSDL_IDS_MAPPER, hr, getVarName());
goto Cleanup;
}
m_lCallIndex = _wtoi(bstrTemp);
}
}
else
{
hr = pWSMLDom->QueryInterface(IID_IXMLDOMNode, (void **)&pExecute);
if (FAILED(hr))
{
goto Cleanup;
}
}
if (pService->doCustomMappersExist())
{
// at least one, recreated the mappers
// they were all registered during WSDLService::AddWSMLMetaInfo, just call create
CHK(createTypeMapper());
}
else
{
// we don't have to have a custom mapper, so ignore
hr = S_OK;
}
Cleanup:
ASSERT(hr==S_OK);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CSoapMapper::createTypeMapper()
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::createTypeMapper()
{
HRESULT hr;
m_pTypeMapper.Clear();
if (m_pSchemaNode)
{
// in this case we have a node inside a complex definition
hr = m_ptypeFactory->getElementMapper(m_pSchemaNode, &m_pTypeMapper);
}
else
{
if (m_basedOnType)
{
// can only happen from our code above
hr = m_ptypeFactory->getTypeMapperbyName(m_bstrSchemaElement, getSchemaURI(), &m_pTypeMapper);
}
else
{
hr = m_ptypeFactory->getElementMapperbyName(m_bstrSchemaElement, getSchemaURI(), &m_pTypeMapper);
}
}
if (FAILED(hr))
{
globalAddError(WSDL_IDS_MAPPERNOTCREATED, WSDL_IDS_MAPPER, hr, m_bstrSchemaElement);
goto Cleanup;
}
CHK(m_pTypeMapper->varType(&m_vtType));
Cleanup:
ASSERT(SUCCEEDED(hr));
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CSoapMapper::get_xmlNameSpace(BSTR *pbstrxmlNameSpace)
//
// parameters:
//
// description:
// returns the targetnamespace of the schema
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::get_xmlNameSpace(BSTR *pbstrxmlNameSpace)
{
if (!pbstrxmlNameSpace)
return(E_INVALIDARG);
*pbstrxmlNameSpace=0;
if (m_bstrSchemaURI.Len()>0)
{
*pbstrxmlNameSpace = ::SysAllocString(m_bstrSchemaURI);
if (!(*pbstrxmlNameSpace))
return(E_OUTOFMEMORY);
}
return(S_OK);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CSoapMapper::get_comValue(VARIANT *pVarOut)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::get_comValue(VARIANT *pVarOut)
{
HRESULT hr;
VARIANT *pVar;
pVar = m_variantList.Lookup(GetCurrentThreadId());
if (pVar)
{
CHK (VariantCopy(pVarOut, pVar));
}
else
{
CHK(PrepareVarOut(pVarOut));
}
Cleanup:
ASSERT(hr==S_OK);
if (FAILED(hr))
{
globalAddError(WSML_IDS_TYPEMAPPERPUTVALUE, WSDL_IDS_MAPPER, hr, m_bstrSchemaElement);
}
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CSoapMapper::put_comValue(VARIANT varIn)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::put_comValue(VARIANT varIn)
{
HRESULT hr = E_INVALIDARG;
if (V_VT(&varIn)==VT_RECORD)
{
globalAddError(WSDL_IDS_VTRECORDNOTSUPPORTED, WSDL_IDS_MAPPER, hr, m_bstrSchemaElement);
goto Cleanup;
}
CHK( m_variantList.Replace(&varIn, GetCurrentThreadId()));
Cleanup:
ASSERT(hr==S_OK);
if (FAILED(hr))
{
globalAddError(WSML_IDS_TYPEMAPPERPUTVALUE, WSDL_IDS_MAPPER, hr, m_bstrSchemaElement);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -