⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typefact.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    HRESULT hr = E_INVALIDARG;
    CAutoBSTR   bstrTypeNameSpace;
    CAutoBSTR   bstrNodeName;
    CAutoBSTR   bstrTypeName;
    CAutoBSTR   bstrTemp;
    CAutoBSTR   bstrURI;
    CAutoBSTR   bstrBuffer;
    TCHAR       achPrefix[_MAX_ATTRIBUTE_LEN];
#ifndef UNDER_CE
    TCHAR       achName[_MAX_ATTRIBUTE_LEN];
    TCHAR       achURI[_MAX_ATTRIBUTE_LEN];
#endif 

    XPathState xp;
    
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        CHK_BOOL(m_pSchemaDocument, E_FAIL);

        CHK(xp.init(m_pSchemaDocument));

        CHK(_XSDSetupDefaultXPath(m_pSchemaDocument, m_enRevision));        
        if (!pSchemaNode)
        {
            goto Cleanup;
        }

        // get the 3 things we need: simple/complextype, namespace and name
        CHK(pSchemaNode->get_nodeName(&bstrNodeName));
        CHK(_XSDFindTargetNameSpace(pSchemaNode, &bstrTypeNameSpace));
        CHK(_WSDLUtilFindAttribute(pSchemaNode, _T("name"), &bstrTypeName));

        // first verify if there is a buildin/custom one for this
        hr = findRegisteredTypeMapper(bstrTypeName, bstrTypeNameSpace, true, pSchemaNode, pptypeMapper);
        if (hr == S_FALSE)
        {
            // none found
            if (_tcscmp(bstrNodeName, _T("simpleType"))==0)
            {
                // we can deal with simple types just fine, look up the reference for this guy
                // to do this, we just call getmapperbyname

                // look up the type and get the new typename, and namespace
                hr = _WSDLUtilFindAttribute(pSchemaNode, _T("type"), &bstrTemp);
                if (FAILED(hr))
                {
                    // a simple type with no type attribute, may mean subclassing
                    // this either succeeds: and we have one
                    // or it fails: and then all is lost anyway
                    //  so goto cleanup
                    hr = checkForXSDSubclassing(pptypeMapper, pSchemaNode);
                    goto Cleanup;
                }
            
                CHK(_WSDLUtilSplitQName(bstrTemp, achPrefix,&bstrBuffer));            
                hr = _XSDFindURIForPrefix(pSchemaNode, achPrefix, &bstrURI);
                if (FAILED(hr))
                {
                    globalAddError(WSDL_IDS_URIFORQNAMENF, WSDL_IDS_MAPPER, hr, achPrefix, bstrTemp);                
                    goto Cleanup;
                }
                hr = getTypeMapperbyName(bstrBuffer, bstrURI, pptypeMapper);            
            }
            else
            {
                hr = E_FAIL;
                // create a dom mapper for everything that is not simple
                // BUT : first check for array possibility:
                if (IsArrayDefinition(pSchemaNode))
                {
                    // let's assume we have found an array for now
                    hr = createBuildInMapper(pptypeMapper, pSchemaNode, enXSDarray);                        
                }
                
                if (FAILED(hr))
                {
                    // NO Array, so let's fall back to DOM mapper
                    hr = createBuildInMapper(pptypeMapper, pSchemaNode, enXSDDOM);                                                                        
                }
            }
        }
#ifndef CE_NO_EXCEPTIONS
    }
    catch(...)
    {
        hr = E_UNEXPECTED;
    }
#endif 
  
Cleanup:    
    return hr;    
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////






/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT  CTypeMapperFactory::getTypeMapperbyName( BSTR bstrTypeName, BSTR bstrTypeNamespace,
//														ISoapTypeMapper **ppSoapTypeMapper)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::getTypeMapperbyName(
					BSTR bstrTypeName,
					BSTR bstrTypeNamespace,
					ISoapTypeMapper **ppSoapTypeMapper)
{
    HRESULT                      hr=S_FALSE;
	CAutoRefc<IXMLDOMNode>		 pTargetNode=0;
	CAutoRefc<IXMLDOMNode>		 pTargetSchema=0;
	CAutoFormat                  autoFormat;
    CAutoBSTR                    bstrTemp;
    CAutoBSTR                    bstrURI;
    XPathState  xp;
    
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        CHK_BOOL(m_pSchemaDocument, E_FAIL);

        CHK(xp.init(m_pSchemaDocument));

        CHK(_XSDSetupDefaultXPath(m_pSchemaDocument, m_enRevision));        

        hr = S_FALSE;
        
        if (_XSDIsPublicSchema(bstrTypeNamespace))
        {
            hr = findRegisteredTypeMapper(bstrTypeName, bstrTypeNamespace, true, m_pSchemaDocument, ppSoapTypeMapper);
        }    

      	if (hr==S_FALSE)
        {
            // user schema, look for the node
            hr = _XSDLFindTargetSchema(bstrTypeNamespace,m_pSchemaDocument, &pTargetSchema);
            if (FAILED(hr)) 
            {
                globalAddError(WSDL_IDS_MAPPERNOSCHEMA, WSDL_IDS_MAPPER, hr, bstrTypeNamespace, bstrTypeName);    
                goto Cleanup;
            }
            // now search for the subnode:
            CHK(autoFormat.sprintf(_T(".//schema:simpleType[@name=\"%s\"]"), bstrTypeName));
            pTargetSchema->selectSingleNode(&autoFormat, &pTargetNode);
            if (!pTargetNode)
            {
                CHK(autoFormat.sprintf(_T(".//schema:complexType[@name=\"%s\"]"), bstrTypeName));
                pTargetSchema->selectSingleNode(&autoFormat, &pTargetNode);
            }
            if (!pTargetNode)
            {
                hr = E_FAIL;                            
                globalAddError(WSDL_IDS_MAPPERNODEFINITION, WSDL_IDS_MAPPER, hr, bstrTypeName);                  
                goto Cleanup;
                
            }
            hr = getTypeMapper(pTargetNode, ppSoapTypeMapper);
        }
#ifndef CE_NO_EXCEPTIONS
    }
    catch(...)
    {
        hr = E_UNEXPECTED;
    }
#endif 

Cleanup:
	ASSERT(hr==S_OK);
	return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT  CTypeMapperFactory::addSchema( IXMLDOMNode *pSchema )
//
//  parameters:
//
//  description:
//      registeres a new schema document for lookup
//
//  returns: 
//      S_OK if everything is fine
//      S_FALSE if this resulted in a REPLACE
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::addSchema(
                IXMLDOMNode *pSchema
                )
{
    HRESULT hr = E_INVALIDARG; 

#ifndef CE_NO_EXCEPTIONS
    try
#else
    __try
#endif     
    {
        if (!pSchema)
            goto Cleanup;

        
        hr = m_pSchemaDocument ? S_FALSE : S_OK;
        assign(&m_pSchemaDocument, pSchema);
        _XSDFindRevision(pSchema, &m_enRevision);
    }
#ifndef CE_NO_EXCEPTIONS    
    catch(...)
#else
    __except(1)
#endif     
    {
        hr = E_UNEXPECTED;
    }


Cleanup:
    return hr;    
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT  CTypeMapperFactory::addType( BSTR bstrTypeName, BSTR bstrTypeNameSpace, BSTR bstrProgID)
//
//  parameters:
//
//  description:
//      registeres a new type for the typefactory
//
//  returns: 
//      S_OK if everything is fine
//      E_OUTOFMEMORY
//      S_FALSE if this resulted in a REPLACE
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::addType(
				BSTR bstrTypeName, 
				BSTR bstrTypeNameSpace, 
				BSTR bstrProgID
				)
{
    return addTypeObjectMapper(bstrTypeName, bstrTypeNameSpace, bstrProgID, 0);     
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CTypeMapperFactory::addElement( BSTR bstrTypeName,  BSTR bstrTypeNameSpace,  BSTR bstrProgID)
//
//  parameters:
//
//  description:
//      registeres a new element for the typefactory
//
//  returns: 
//      S_OK if everything is fine
//      E_OUTOFMEMORY
//      S_FALSE if this resulted in a REPLACE
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::addElement(
				BSTR bstrTypeName, 
				BSTR bstrTypeNameSpace, 
				BSTR bstrProgID
				)
{
    return addElementObjectMapper(bstrTypeName, bstrTypeNameSpace, bstrProgID, 0); 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CTypeMapperFactory::addElementObjectMapper( BSTR bstrTypeName,  BSTR bstrTypeNameSpace,  BSTR bstrProgID)
//
//  parameters:
//
//  description:
//      registeres a new element for the typefactory
//
//  returns: 
//      S_OK if everything is fine
//      E_OUTOFMEMORY
//      S_FALSE if this resulted in a REPLACE
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::addElementObjectMapper(
				BSTR bstrTypeName, 
				BSTR bstrTypeNameSpace, 
				BSTR bstrProgID,
				BSTR bstrIID
				)
{
    HRESULT hr = S_OK;
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        hr =_addCustomMapper(bstrTypeName, bstrTypeNameSpace, bstrProgID, bstrIID, false); 
#ifndef CE_NO_EXCEPTIONS
    }
    catch(...)
    {
        hr = E_UNEXPECTED;
    }
#endif 
    return hr;
  
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CTypeMapperFactory::addTypeObjectMapper( BSTR bstrTypeName,  BSTR bstrTypeNameSpace,  BSTR bstrProgID)
//
//  parameters:
//
//  description:
//      registeres a new element for the typefactory
//
//  returns: 
//      S_OK if everything is fine
//      E_OUTOFMEMORY
//      S_FALSE if this resulted in a REPLACE
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::addTypeObjectMapper(
				BSTR bstrTypeName, 
				BSTR bstrTypeNameSpace, 
				BSTR bstrProgID,
				BSTR bstrIID
				)
{
    HRESULT hr = S_OK;
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        hr =_addCustomMapper(bstrTypeName, bstrTypeNameSpace, bstrProgID, bstrIID, true); 
#ifndef CE_NO_EXCEPTIONS
    }
    catch(...)
    {
        hr = E_UNEXPECTED;
    }
#endif 
    return hr;
  
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT  CTypeMapperFactory::_addCustomMapper( BSTR bstrTypeName,  BSTR bstrTypeNameSpace, BSTR bstrProgID, 
//												bool bIsType)
//
//  parameters:
//
//  description:
//      registeres a new element or type for the typefactory
//
//  returns: 
//      S_OK if everything is fine
//      E_OUTOFMEMORY
//      E_INVALIDARG it the mapper is already registered
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTypeMapperFactory::_addCustomMapper(
				BSTR bstrTypeName, 
				BSTR bstrTypeNameSpace, 
				BSTR bstrProgID, 
				BSTR bstrIID, 
				bool bIsType
				)
{
    // first do a lookup by typename/namespace to see if this guy is already there
    HRESULT          hr = S_OK;
    long              lMapperIndex;

    lMapperIndex= _findCustomMapper(bstrTypeName, bstrTypeNameSpace, bIsType);

    if (lMapperIndex== (long) enXSDUndefined)
    {
        // need a new one
       lMapperIndex= m_lNextMapperID;        
        if (!m_ppCustomMapperInfo)
        {
            m_lCacheSize = c_growSize;
            m_ppCustomMapperInfo= new CCustomMapperInfo*[m_lCacheSize];
            CHK_BOOL(m_ppCustomMapperInfo, E_OUTOFMEMORY);        
            ZeroMemory(m_ppCustomMapperInfo, sizeof(CCustomMapperInfo*)*m_lCacheSize);
        }
        if (m_lNextMapperID >= m_lCacheSize)
        {
            m_lCacheSize += c_growSize; 
            // need to grow the array
#ifndef UNDER_CE
            m_ppCustomMapperInfo = (CCustomMapperInfo**)realloc(m_ppCustomMapperInfo, m_lCacheSize * sizeof(CCustomMapperInfo*));
            CHK_BOOL(m_ppCustomMapperInfo!=0, E_OUTOFMEMORY);        
#else
            CCustomMapperInfo** pTempCustomMapper = (CCustomMapperInfo**)realloc(m_ppCustomMapperInfo, m_lCacheSize * sizeof(CCustomMapperInfo*));
            if(NULL == pTempCustomMapper)
            {
                delete [] m_ppCustomMapperInfo;
                m_ppCustomMapperInfo = NULL;
                hr = E_OUTOFMEMORY;
                goto Cleanup;
            }            
            m_ppCustomMapperInfo = pTempCustomMapper;
#endif 
            
            // now we need to walk over that memory and 0 it out 
            for (long l=m_lNextMapperID; l<m_lCacheSize; l++)
            {
                m_ppCustomMapperInfo[l] = 0; 
            }
        }

        m_ppCustomMapperInfo[m_lNextMapperID] = new CCustomMapperInfo();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -