Exemplo n.º 1
0
bool Wsdl::CreateArrayType( QObject      *pParent,
                            QString      &sTypeName, 
                            QString       sElementName,
                            QString       sElementType,
                            bool          bCustomType )
{
    QString sOrigTypeName( sTypeName );

    sTypeName = "ArrayOf" + sElementType;

    if ( m_typesCreated.contains( sTypeName ))
        return bCustomType;

    QDomElement oTypeNode = createElement( "xs:complexType" );
    QDomElement oSeqNode  = createElement( "xs:sequence"    );

    oTypeNode.setAttribute( "name", sTypeName );

    oTypeNode.appendChild( oSeqNode  );

    QDomElement oNode = createElement( "xs:element" );

    oNode.setAttribute( "name"     , sElementName );
    oNode.setAttribute( "type"     , ConvertTypeToXSD( sElementType, false ));

    oNode.setAttribute( "nillable" , true        );   //-=>TODO: This may need to be determined by sParamType
    oNode.setAttribute( "minOccurs", 0           );
    oNode.setAttribute( "maxOccurs", "unbounded" );

    oSeqNode.appendChild( oNode );

    QDomElement oElementNode = createElement( "xs:element" );

    oElementNode.setAttribute( "name"    , sTypeName );
    oElementNode.setAttribute( "nillable", "true" );
    oElementNode.setAttribute( "type"    , "tns:" + sTypeName );

    m_oTypes.appendChild( oTypeNode    );
    m_oTypes.appendChild( oElementNode );

    m_typesCreated.insert( sTypeName, true );

    return bCustomType;
}
Exemplo n.º 2
0
bool Xsd::RenderMapXSD( HTTPRequest   *pRequest, 
                        const QString &sClassName, 
                        bool           bCustomType )
{
    QString     sArrayName   = "MapOfString" + sClassName;
    QString     sMapItemName = pRequest->m_mapParams[ "name" ];
    QString     sType;

    if (sMapItemName.isEmpty())
        sMapItemName = sClassName;

    if (bCustomType)
        sType = "tns:" + sMapItemName;
    else
        sType = "xs:" + ConvertTypeToXSD( sMapItemName, false );

    QDomElement oRoot      = CreateSchemaRoot();

    // ------------------------------------------------------------------
    // Create xs:complexType structure
    // ------------------------------------------------------------------
    
    QDomElement oTypeNode = createElement( "xs:complexType" );
    QDomElement oSeqNode  = createElement( "xs:sequence"    );
    QDomElement oAnno     = createElement( "xs:annotation"  );
    QDomElement oAppInfo  = createElement( "xs:appinfo"     );

    QDomElement oNode = createElement( "IsDictionary" );
    oNode.setAttribute( "xmlns", "http://schemas.microsoft.com/2003/10/Serialization/" );
    oNode.appendChild( createTextNode( "true" ));

    oTypeNode.appendChild( oAnno    );
    oAnno    .appendChild( oAppInfo );
    oAppInfo .appendChild( oNode    );

    // -=>TODO: Add an xs:annotation node with class descriptions

    // ----------------------------------------------------------------------
    //  <xs:sequence>
    // ----------------------------------------------------------------------

    oTypeNode.setAttribute( "name", sArrayName );
    oTypeNode.appendChild( oSeqNode  );

    // ----------------------------------------------------------------------
    //    <xs:element minOccurs="0" maxOccurs="unbounded" name="KeyValueOfString<Type>">
    // ----------------------------------------------------------------------

    QDomElement oInnerNode = createElement( "xs:element" );

    oInnerNode.setAttribute( "name"      , sClassName  );
    oInnerNode.setAttribute( "maxOccurs" , "unbounded" );
    oInnerNode.setAttribute( "minOccurs" , "0"         );

    oSeqNode.appendChild( oInnerNode );

    // ----------------------------------------------------------------------
    //      <xs:complexType>
    // ----------------------------------------------------------------------
    oNode = createElement( "xs:complexType" );

    oInnerNode.appendChild( oNode );

    // ----------------------------------------------------------------------
    //        <xs:sequence>
    // ----------------------------------------------------------------------

    QDomElement oInnerSeq = createElement( "xs:sequence" );

    oNode.appendChild( oInnerSeq );

    // ----------------------------------------------------------------------
    //           <xs:element name="Key" nillable="true" type="xs:string" /> 
    // ----------------------------------------------------------------------

    oNode = createElement( "xs:element" );

    oNode.setAttribute( "type"      , "xs:string" );
    oNode.setAttribute( "nillable"  , "true" );
    oNode.setAttribute( "name"      , "Key" );

    oInnerSeq.appendChild( oNode  );

    // ----------------------------------------------------------------------
    //           <xs:element name="Value" nillable="true" type="<Type>"  /> 
    // ----------------------------------------------------------------------

    oNode = createElement( "xs:element" );

    oNode.setAttribute( "type"      , sType );
    oNode.setAttribute( "nillable"  , "true" );
    oNode.setAttribute( "name"      , "Value" );

    oInnerSeq.appendChild( oNode  );

    // ----------------------------------------------------------------------
    //<xs:element name="MapOfString<Type>" nillable="true" type="tns:MapOfString<Type>" /> 
    // ----------------------------------------------------------------------
    
    QDomElement oElementNode = createElement( "xs:element" );

    oElementNode.setAttribute( "type"    , "tns:" + sArrayName );
    oElementNode.setAttribute( "nillable", "true" );
    oElementNode.setAttribute( "name"    , sArrayName );

    // ----------------------------------------------------------------------
    // Build xml tree...
    // ----------------------------------------------------------------------

    appendChild( oRoot );

    if (bCustomType)
    {
        QDomElement oIncNode = createElement( "xs:include" );

        QString sBaseUri = "http://" + pRequest->m_mapHeaders[ "host" ] + pRequest->m_sResourceUrl + "?type=";

        oIncNode.setAttribute( "schemaLocation", sBaseUri + sClassName );

        oRoot.appendChild( oIncNode );
    }
    
    oRoot.appendChild( oTypeNode    );
    oRoot.appendChild( oElementNode );

    // ----------------------------------------------------------------------
    // Return xsd doc to caller
    // ----------------------------------------------------------------------

    QTextStream os( &(pRequest->m_response) );

    pRequest->m_eResponseType   = ResponseTypeXML;

    save( os, 0 );

    return true;

}
Exemplo n.º 3
0
bool Xsd::RenderArrayXSD( HTTPRequest   *pRequest, 
                          const QString &sClassName, 
                          bool           bCustomType )
{
    QString     sArrayName = "ArrayOf" + sClassName;
    QString     sType;

    if (bCustomType)
        sType = "tns:" + sClassName;
    else
        sType = "xs:" + ConvertTypeToXSD( sClassName, false );

    QDomElement oRoot      = CreateSchemaRoot();

    // ------------------------------------------------------------------
    // Create xs:complexType structure
    // ------------------------------------------------------------------
    
    QDomElement oTypeNode = createElement( "xs:complexType" );
    QDomElement oSeqNode  = createElement( "xs:sequence"    );

    // -=>TODO: Add an xs:annotation node with class descriptions

    oTypeNode.setAttribute( "name", sArrayName );
    oTypeNode.appendChild( oSeqNode  );

    QDomElement oNode = createElement( "xs:element" );

    oNode.setAttribute( "type"      , sType );
    oNode.setAttribute( "nillable"  , "true" );
    oNode.setAttribute( "name"      , sClassName );
    oNode.setAttribute( "maxOccurs" , "unbounded" );
    oNode.setAttribute( "minOccurs" , "0"         );

    oSeqNode.appendChild( oNode  );
    
    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------
    
    QDomElement oElementNode = createElement( "xs:element" );

    oElementNode.setAttribute( "type"    , "tns:" + sArrayName );
    oElementNode.setAttribute( "nillable", "true" );
    oElementNode.setAttribute( "name"    , sArrayName );

    // ----------------------------------------------------------------------
    // Build xml tree...
    // ----------------------------------------------------------------------

    appendChild( oRoot );

    if (bCustomType)
    {
        QDomElement oIncNode = createElement( "xs:include" );

        QString sBaseUri = "http://" + pRequest->m_mapHeaders[ "host" ] + 
                                       pRequest->m_sResourceUrl + "?type=";

        oIncNode.setAttribute( "schemaLocation", sBaseUri + sClassName );

        oRoot.appendChild( oIncNode );
    }
    
    oRoot.appendChild( oTypeNode    );
    oRoot.appendChild( oElementNode );

    // ----------------------------------------------------------------------
    // Return xsd doc to caller
    // ----------------------------------------------------------------------

    QTextStream os( &(pRequest->m_response) );

    pRequest->m_eResponseType   = ResponseTypeXML;

    save( os, 0 );

    return true;

}
Exemplo n.º 4
0
bool Xsd::RenderXSD( HTTPRequest *pRequest, QObject *pClass )
{
    const QMetaObject *pMetaObject = pClass->metaObject();

    QString     sClassName = ConvertTypeToXSD( pMetaObject->className(), true);
    QDomElement oRoot      = CreateSchemaRoot();

    QMap<QString, TypeInfo> typesToInclude;

    // ------------------------------------------------------------------
    // Create xs:complexType structure
    // ------------------------------------------------------------------
    
    QDomElement oTypeNode = createElement( "xs:complexType" );
    QDomElement oSeqNode  = createElement( "xs:sequence"    );

    oTypeNode.setAttribute( "name", sClassName );

    oTypeNode.appendChild( oSeqNode  );
    
    // -=>TODO: Add an xs:annotation node with class descriptions

    // ------------------------------------------------------------------
    // Add all properties for this type
    //
    //  <xs:element minOccurs="0" name="<propName>" type="<propType>"/>
    //    <xs:element minOccurs="0" name="<childName>" nillable="true" 
    //              type="tns:<ChildType>"/>
    // ------------------------------------------------------------------
    
    int nCount = pMetaObject->propertyCount();

    for (int nIdx=0; nIdx < nCount; ++nIdx ) 
    {
        QMetaProperty metaProperty = pMetaObject->property( nIdx );

        if (metaProperty.isDesignable( pClass ))
        {
            const char *pszPropName = metaProperty.name();
            QString     sPropName( pszPropName );

            if ( sPropName.compare( "objectName" ) == 0)
                continue;

            // ----------------------------------------------------------
            // Create xs:element for this property
            // ----------------------------------------------------------

            QDomElement oNode        = createElement( "xs:element" );
            QString     sType        = metaProperty.typeName();
            bool        bCustomType  = false;
            QString        sCustomAttr  = "type";
            QString     sContentName = QString();
            QString     sContentType = QString();

            // if this is a child object, sType will be QObject*
            // which we can't use, so we need to read the
            // properties value, and read it's metaObject data

            if (sType == "QObject*")
            {
                QVariant val = metaProperty.read( pClass );
                const QObject *pObject = val.value< QObject* >(); 

                sType = pObject->metaObject()->className();
                bCustomType = true;
            }
            else if ((sType == "QVariantList" ) || (sType == "QVariantMap"))
            {
                sContentType = ReadPropertyMetadata( pClass, 
                                                     sPropName, 
                                                     "type" );

                if (sContentType.at(0) == 'Q')
                    sContentType = sContentType.mid( 1 );

                sContentType.remove( "DTC::"    );
                sContentType.remove( QChar('*') );

                if (sType == "QVariantMap")
                {
                    sContentName = ReadPropertyMetadata( pClass, 
                                                         sPropName, 
                                                         "name" );

                    if (sContentName.isEmpty())
                        sContentName = sContentType;

                    sType = "MapOfString" + sContentName;
                }
                else
                    sType = "ArrayOf" + sContentType;

                bCustomType = true;

            }
            else if (sType == "QStringList") 
            { 
                sType = "ArrayOfString"; 
                bCustomType = true;
            }
            else if (metaProperty.isEnumType() || metaProperty.isFlagType() )
            {
                sCustomAttr = "enum";
                sType       = sClassName + "." + sType;
                bCustomType = true;
            }

            QString sNewPropName( metaProperty.name() );

            if (IsNillable( sType ))
                oNode.setAttribute( "nillable" , true );   

            if (bCustomType)
            {
                TypeInfo info = { sCustomAttr, sContentType };
                typesToInclude.insert( sType, info );
            }
    
            oNode.setAttribute( "type"     , (bCustomType ? "tns:" : "xs:") +
                                       ConvertTypeToXSD( sType, bCustomType ));

            oNode.setAttribute( "name"     , sNewPropName );
            oNode.setAttribute( "minOccurs", 0            );

            oSeqNode.appendChild( oNode );
        }
    }

    // ------------------------------------------------------------------
    // Create element for class
    //
    //       <xs:element name="<className>" nillable="true" type="tns:<className>"/>
    // ------------------------------------------------------------------

    QDomElement oElementNode = createElement( "xs:element" );

    oElementNode.setAttribute( "type"    , "tns:" + sClassName );
    oElementNode.setAttribute( "nillable", "true" );
    oElementNode.setAttribute( "name"    , sClassName );

    // ----------------------------------------------------------------------
    // Build xml tree...
    // ----------------------------------------------------------------------

    appendChild( oRoot );

    if (typesToInclude.count() > 0)
    {
        // ------------------------------------------------------------------
        // Create all needed includes
        //
        //    <xs:include schemaLocation="<path to dependant schema"/>
        // ------------------------------------------------------------------

        QString sBaseUri = "http://" + pRequest->m_mapHeaders[ "host" ] + 
                                       pRequest->m_sResourceUrl;

        QMap<QString, TypeInfo >::const_iterator it = typesToInclude.constBegin();
        while( it != typesToInclude.constEnd())
        {
            QDomElement oIncNode = createElement( "xs:include" );
            QString     sType    = it.key();

            sType.remove( "DTC::" );

            TypeInfo info = it.value();

            QString sValue = QString( "%1?%2=%3" ).arg( sBaseUri       )
                                                  .arg( info.sAttrName )
                                                  .arg( sType          );

            if (!info.sContentType.isEmpty())
                sValue += "&name=" + info.sContentType;

            oIncNode.setAttribute( "schemaLocation", sValue );

            oRoot.appendChild( oIncNode );
            ++it;
        }
    }

    oRoot.appendChild( oTypeNode    );
    oRoot.appendChild( oElementNode );

    // ----------------------------------------------------------------------
    // Return xsd doc to caller
    // ----------------------------------------------------------------------

    QTextStream os( &(pRequest->m_response) );

    pRequest->m_eResponseType   = ResponseTypeXML;

    save( os, 0 );

    return true;
}
Exemplo n.º 5
0
bool Wsdl::CreateType( QObject *pParent, QString &sTypeName )
{
    if ( m_typesCreated.contains( sTypeName ))
        return true;

//    sTypeName.remove( "DTC::" );
    sTypeName.remove( QChar('*') );

    int id = QMetaType::type( sTypeName.toUtf8() );

    switch( id )
    {
        case QMetaType::QStringList:
            return CreateArrayType( pParent, sTypeName, "Value",  "string", true );

        case QMetaType::QVariantMap:
            return CreateMapType( pParent, sTypeName, "Settings", "string", true );

        default:
            // for not, treat QFileInfo as a string.  Need to turn into MTOM later.
            if (id == QMetaType::type( "QFileInfo" ))
            {
                sTypeName = "QString";
                return false;
            }
            break;
    }

    if ((id == -1) || (id < QMetaType::User)) 
        return false;

    // ------------------------------------------------------------------
    // Need to create an instance of the class to access it's metadata.
    // ------------------------------------------------------------------

    QObject *pClass = (QObject *)QMetaType::construct( id );

    if (pClass != NULL)
    {
        const QMetaObject *pMetaObject = pClass->metaObject();

        // ------------------------------------------------------------------
        // Create xsd element structure
        // ------------------------------------------------------------------
    
        QDomElement oTypeNode = createElement( "xs:complexType" );
        QDomElement oSeqNode  = createElement( "xs:sequence"    );

        oTypeNode.setAttribute( "name", ConvertTypeToXSD( sTypeName, true));

//        oElementNode.appendChild( oTypeNode );
        oTypeNode   .appendChild( oSeqNode  );
    
        // ------------------------------------------------------------------
        // Add all properties for this type
        // ------------------------------------------------------------------
    
		int nCount = pMetaObject->propertyCount();

		for (int nIdx=0; nIdx < nCount; ++nIdx ) 
		{
			QMetaProperty metaProperty = pMetaObject->property( nIdx );

            if (metaProperty.isDesignable( pClass ))
            {
                const char *pszPropName = metaProperty.name();
                QString     sPropName( pszPropName );

                if ( sPropName.compare( "objectName" ) == 0)
                    continue;

                QDomElement oNode = createElement( "xs:element" );

                QString sType = metaProperty.typeName();

                // if this is a child object, sType will be QObject*
                // which we can't use, so we need to read the
                // properties value, and read it's metaObject data

                if (sType == "QObject*")
                {
                    QVariant val = metaProperty.read( pClass );
                    const QObject *pObject = val.value< QObject* >(); 

                    sType = pObject->metaObject()->className();

//                    sType.remove( "DTC::" );
                }

                oNode.setAttribute( "minOccurs", 0       );
                oNode.setAttribute( "name"     , metaProperty.name() );
                oNode.setAttribute( "nillable" , true    );   //-=>TODO: This may need to be determined by sParamType
    
                bool bCustomType = CreateType( pClass, sType );

                oNode.setAttribute( "type"     , ((bCustomType) ? "tns:" : "") + ConvertTypeToXSD( sType, bCustomType ));

                oSeqNode.appendChild( oNode );
            }
		}

        QDomElement oElementNode = createElement( "xs:element" );

        oElementNode.setAttribute( "name"    , ConvertTypeToXSD( sTypeName, true));
        oElementNode.setAttribute( "nillable", "true" );
        oElementNode.setAttribute( "type"    , "tns:" + ConvertTypeToXSD( sTypeName, true));

        m_oTypes.appendChild( oTypeNode    );
        m_oTypes.appendChild( oElementNode );

        QMetaType::destroy( id, pClass );
     }

    m_typesCreated.insert( sTypeName, true );

    return true;
}
Exemplo n.º 6
0
QDomElement Wsdl::CreateMethodType( MethodInfo   &oInfo,
                                    QString       sTypeName,
                                    bool          bReturnType /* = false */)
{
    QDomElement oElementNode = createElement( "xs:element" );

    oElementNode.setAttribute( "name", sTypeName );

    QDomElement oTypeNode = createElement( "xs:complexType" );
    QDomElement oSeqNode  = createElement( "xs:sequence"    );
    
    oElementNode.appendChild( oTypeNode );
    oTypeNode   .appendChild( oSeqNode  );

    // ------------------------------------------------------------------
    // Create message for parameters
    // ------------------------------------------------------------------

    if (bReturnType)
    {
        QDomElement oNode = createElement( "xs:element" );

        QString sType = oInfo.m_oMethod.typeName();

//        sType.remove( "DTC::" );
        sType.remove( QChar('*') );

        sTypeName.remove( "Response" );

        oNode.setAttribute( "minOccurs", 0       );
        oNode.setAttribute( "name"     , sTypeName + "Result" );
        oNode.setAttribute( "nillable" , true    );   //-=>TODO: This may need to be determined by sParamType

        bool bCustomType = CreateType( NULL, sType );

        oNode.setAttribute( "type"     , "tns:" + ConvertTypeToXSD( sType, bCustomType ));

        oSeqNode.appendChild( oNode );
    }
    else
    {
        QList<QByteArray> paramNames = oInfo.m_oMethod.parameterNames();
        QList<QByteArray> paramTypes = oInfo.m_oMethod.parameterTypes();

        for( int nIdx = 0; nIdx < paramNames.length(); nIdx++ )
        {
            QString sName      = paramNames[ nIdx ];
            QString sParamType = paramTypes[ nIdx ];

            QDomElement oNode = createElement( "xs:element" );

            oNode.setAttribute( "minOccurs", 0     );
            oNode.setAttribute( "name"     , sName );
            oNode.setAttribute( "nillable" , true  );   //-=>TODO: This may need to be determined by sParamType
            oNode.setAttribute( "type"     , ConvertTypeToXSD( sParamType ));

            oSeqNode.appendChild( oNode );
        }
    }

    return oElementNode;
}