示例#1
0
        public static CppType FromParticle(ProxyWriter pw, MSXML2.ISchemaParticle p)
        {
            MSXML2.ISchemaElement e     = p as MSXML2.ISchemaElement;
            wsdlParser.qname      ptype = new wsdlParser.qnameClass();
            ptype.localname  = e.type.name;
            ptype.@namespace = e.type.namespaceURI;
            CppType itemType  = pw.mapType(ptype);
            int     minOccurs = int.Parse(p.minOccurs.ToString());
            int     maxOccurs = int.Parse(p.maxOccurs.ToString());

            if ((maxOccurs == 1) && (minOccurs == 0))
            {
                itemType.Optional = true;
            }
            else if ((maxOccurs != 1) || (minOccurs != 1))
            {
                itemType.Array = ArrayType.Literal;
            }
            else if (e != null && e.isNillable)
            {
                itemType.Optional = true;
            }

            return(itemType);
        }
示例#2
0
        public void AddElement(string propertyName, CppType propType, MSXML2.ISchemaElement elem)
        {
            // serialization
            getValItf();
            if (propType.Array == CppType.ArrayType.Literal)
            {
            }
            else
            {
                m_impl.WriteLine("\t{0} {1};", propType.LocalStorageName, propertyName);
                m_impl.WriteLine("\t_HR(obj->get_{0}(&{0}));", propertyName);
                m_impl.WriteLine("\t_HR(dest->SerializeValue(&CComVariant({0}), CComBSTR(OLESTR(\"{1}\")), CComBSTR(OLESTR(\"{2}\"))));", propertyName, elem.name, elem.namespaceURI);
            }

            // de-serialization
            m_deserE.Add(string.Format("\tif (wcscmp(name, L\"{0}\") == 0 && wcscmp(namespaceURI, L\"{1}\") == 0)", elem.name, elem.namespaceURI));
            m_deserE.Add("\t{");
            m_deserE.Add(string.Format("\t\treturn m_obj->put_{0}(v.{1});", propertyName, propType.VariantFieldName));
            m_deserE.Add("\t}");

            if (propType.Array == CppType.ArrayType.Literal)
            {
            }
            else
            {
            }
        }
示例#3
0
 public Parameter(CppType cppType, string cppName, wsdlParser.qname xmlName, bool isHeader, IdlDirection dir)
 {
     populateWords();
     this.cppType      = cppType;
     this.cppName      = safeCppName(cppName);
     this.xmlName      = xmlName;
     this.isHeader     = isHeader;
     this.idlDirection = dir;
 }
示例#4
0
 public void AddPropertyField(string propertyName, CppType propertyType)
 {
     m_vars.Add(string.Format("{0} {1}{2};", propertyType.LocalStorageName, PROP_PREFIX, propertyName));
     GeneratePropertyAccessor(propertyName, PROP_PREFIX + propertyName, OPT_PREFIX + propertyName, propertyType);
     if (propertyType.Optional)
     {
         m_vars.Add(string.Format("VARIANT_BOOL {0}{1};", OPT_PREFIX, propertyName));
         m_finalconstruct.Add(string.Format("{0}{1} = VARIANT_FALSE;", OPT_PREFIX, propertyName));
         GenerateOptionalAccessor(propertyName);
     }
 }
示例#5
0
        internal CppType mapType(wsdlParser.qname type)
        {
            if (m_sf.IsAnyType(type.localname, type.@namespace))
            {
                return(CppType.Create((int)VarEnum.VT_VARIANT, "VARIANT", CppType.ArrayType.NotArray, CppType.TypeStyle.Primative, false, type));
            }
            CppType t = null;

            try
            {
                Object ct = m_sf.FindComType(type.localname, type.@namespace);
                if (ct is int)
                {
                    return(CppType.TypeFromVariantType((int)ct, type));
                }
                return(CppType.Create((int)VarEnum.VT_VARIANT, "VARIANT", type));
            }
            catch (Exception ex)
            {
                // todo, catch specific exception
                // todo, handle complex types.
                // Console.WriteLine(type.ExpandedName + " : " + ex.Message);
            }
            // handle non-primitive types

            // first off, check the cache
            t = (CppType)m_typesCache[type.ExpandedName];
            if (t != null)
            {
                return(t);
            }

            // look for a schema definition
            MSXML2.ISchema     schema = SchemaForType(type);
            MSXML2.ISchemaType oType  = (MSXML2.ISchemaType)schema.types.itemByQName(type.localname, type.@namespace);
            if (oType is MSXML2.ISchemaComplexType)
            {
                t = CreateComplexType(type, (MSXML2.ISchemaComplexType)oType);
            }
            else if (oType.enumeration.length > 0)
            {
                t = CreateEnumType(type, oType);
            }
            else if ((oType.itemType == MSXML2.SOMITEMTYPE.SOMITEM_SIMPLETYPE) && (oType.derivedBy == MSXML2.SCHEMADERIVATIONMETHOD.SCHEMADERIVATIONMETHOD_RESTRICTION))
            {
                t = CreateRestrictedSimpleType(type, oType);
            }
            else
            {
                throw new ApplicationException("Sorry, this type " + type.ExpandedName + " is not yet supported");
            }
            return(t);
        }
示例#6
0
        CppType HandleArrayType(wsdlParser.qname typeName, MSXML2.ISchemaComplexType typeDesc)
        {
            MSXML2.ISchemaComplexType ct           = typeDesc;
            MSXML2.ISchemaItem        encArrayType = ct.attributes.itemByQName("arrayType", Consts.SOAP_11_ENCODING);
            string wsdlArrayType = null;

            for (int idx = 0; idx < encArrayType.unhandledAttributes.length; idx++)
            {
                if ((encArrayType.unhandledAttributes.getLocalName(idx) == "arrayType") &&
                    (encArrayType.unhandledAttributes.getURI(idx) == Consts.WSDL_URL))
                {
                    wsdlArrayType = encArrayType.unhandledAttributes.getValue(idx);
                    break;
                }
            }
            if (wsdlArrayType == null)
            {
                throw new ApplicationException("SOAP-ENC:Array derivation must include a wsdl:arrayType attribute");
            }

            wsdlParser.qname qn = new wsdlParser.qnameClass();
            int lastColon       = wsdlArrayType.LastIndexOf(":");

            qn.@namespace = wsdlArrayType.Substring(0, lastColon);
            int rank = wsdlArrayType.IndexOf("[", lastColon);

            qn.localname = wsdlArrayType.Substring(lastColon + 1, rank - lastColon - 1);
            CppType itemType = mapType(qn);

            CppType t = CppType.CreateArray(itemType, CppType.ArrayType.Encoded, false, qn);

            m_typesCache.Add(typeName.ExpandedName, t);

            if (t.Style == CppType.TypeStyle.Object)
            {
                string qnln = m_factory.IdForString(qn.localname, IdType.Localname);
                string qnns = m_factory.IdForString(qn.@namespace, IdType.Namespace);
                string psad = m_factory.IdForString("PocketSOAP.ArrayDeserializer.1", IdType.ProgId);
                string psas = m_factory.IdForString("PocketSOAP.ArraySerializer.1", IdType.ProgId);
                m_factory.Add(string.Format("m_sf->Deserializer({0}, {1}, VARIANT_TRUE, VT_UNKNOWN, {2});", qnln, qnns, psad));
                m_factory.Add(string.Format("m_sf->Serializer(VT_UNKNOWN | VT_ARRAY, {0}, {1}, {2});", qnln, qnns, psas));
            }
            return(t);
        }
示例#7
0
        void AddElementsToContainer(wsdlParser.qname xmlName, MSXML2.ISchemaModelGroup smg, ComplexTypeWriter ctw, SerializerWriter sw)
        {
            foreach (MSXML2.ISchemaParticle particle in smg.particles)
            {
                if ((particle.itemType == MSXML2.SOMITEMTYPE.SOMITEM_ALL) || (particle.itemType == MSXML2.SOMITEMTYPE.SOMITEM_SEQUENCE))
                {
                    AddElementsToContainer(xmlName, particle as MSXML2.ISchemaModelGroup, ctw, sw);
                }
                else if (particle.itemType == MSXML2.SOMITEMTYPE.SOMITEM_ELEMENT)
                {
                    MSXML2.ISchemaElement e = (MSXML2.ISchemaElement)particle;
                    CppType itemType        = CppType.FromParticle(this, particle);
                    string  itemName        = vcProject.safeClassName(particle.name);

                    ctw.AddPropertyField(itemName, itemType);
                    sw.AddElement(itemName, itemType, e);
                }
            }
        }
示例#8
0
        public static CppType TypeFromVariantType(int vt, wsdlParser.qname xmlType)
        {
            CppType t = null;
            Mapping m = (Mapping)mappings[(VarEnum)vt];

            if (m != null)
            {
                t = Create((int)m.vt, m.name, xmlType, m.style);
            }
            else
            {
                t = Create(vt, "VARIANT", xmlType, TypeStyle.Primative);
            }

            if ((vt & (int)VarEnum.VT_ARRAY) > 0)
            {
                return(Factory(t, ArrayType.Encoded, TypeStyle.Primative, false, xmlType));
            }
            return(t);
        }
示例#9
0
        public void AddAttribute(string propertyName, CppType propType, MSXML2.ISchemaAttribute attr, wsdlParser.qname xmlType)
        {
            getValItf();
            if (m_firstAttr)
            {
                m_firstAttr = false;
                m_impl.WriteLine("\tCComQIPtr<ISerializerOutput2> dest2(dest);");
                m_deserA.Add("\tCComQIPtr<ISoapDeSerializerAttributes2> a(Attributes);");
                m_deserA.Add("\tCComVariant av;");
            }
            // serializer
            m_impl.WriteLine("\t{0} {1};", propType.CppName, propertyName);
            m_impl.WriteLine("\t_HR(obj->get_{0}(&{1}));", propertyName, propertyName);
            m_impl.WriteLine("\t_HR(dest2->SerializeAttribute(CComVariant({0}), CComBSTR(OLESTR(\"{1}\")), CComBSTR(OLESTR(\"{2}\"))));", propertyName, attr.name, attr.namespaceURI);

            // de-serializer
            m_deserA.Add(string.Format("\t_HR(a->get_AsValue(CComBSTR(OLESTR(\"{0}\")), CComBSTR(OLESTR(\"{1}\")), CComBSTR(OLESTR(\"{2}\")), CComBSTR(OLESTR(\"{3}\")), &av);", attr.name, attr.namespaceURI, xmlType.localname, xmlType.@namespace));
            m_deserA.Add(string.Format("\t_HR(m_obj->put_{1}(av);"));
            m_deserA.Add("\tav.Clear();");
        }
示例#10
0
 public CppTypeArray(int vt, CppType arrayItem, ArrayType array, TypeStyle style, bool optional, wsdlParser.qname xmlType) : base(vt, "SAFEARRAY *", array, style, optional, xmlType)
 {
     this.arrayItemType = arrayItem;
 }
示例#11
0
 public static CppType CreateArray(CppType arrayItem, ArrayType array, bool optional, wsdlParser.qname xmlType)
 {
     return(Factory(arrayItem, array, TypeStyle.Primative, optional, xmlType));
 }
示例#12
0
        void GenerateOptionalAccessor(string propertyName)
        {
            CppType variant_bool = CppType.Create("VARIANT_BOOL");

            GeneratePropertyAccessor(propertyName + Consts.OPTIONAL_PROPERTY_SUFFIX, OPT_PREFIX + propertyName, "", variant_bool);
        }
示例#13
0
        void GeneratePropertyAccessor(string propertyName, string memberName, string optionalMemberName, CppType propType)
        {
            m_hdr.WriteLine("\tSTDMETHOD(get_{0})({1} *val);", propertyName, propType.CppName);
            m_impl.WriteLine("STDMETHODIMP {0}::get_{1}({2} *val)", m_cppName, propertyName, propType.CppName);
            m_impl.WriteLine("{");
            m_impl.WriteLine("\tif(!val) return E_POINTER;");
            m_impl.WriteLine("\t{0}", propType.AssignCopy(memberName, "val"));
            m_impl.WriteLine("\treturn S_OK;");
            m_impl.WriteLine("}\n");
            m_hdr.WriteLine("\tSTDMETHOD(put_{0})({1} val);", propertyName, propType.CppName);
            m_impl.WriteLine("STDMETHODIMP {0}::put_{1}({2} val)", m_cppName, propertyName, propType.CppName);
            m_impl.WriteLine("{");
            m_impl.WriteLine("\t{0} = val;", memberName);
            if (propType.Optional)
            {
                m_impl.WriteLine("\t{0} = VARIANT_TRUE;", optionalMemberName);
            }
            m_impl.WriteLine("\treturn S_OK;");
            m_impl.WriteLine("}\n");

            ArrayList props = new ArrayList();

            props.Add(new Parameter(propType, propertyName, null, false, IdlDirection.In));
            m_itf.AddMethod("[propput] HRESULT " + propertyName, props);
            props = new ArrayList();
            props.Add(new Parameter(propType, propertyName, null, false, IdlDirection.Retval | IdlDirection.Out));
            m_itf.AddMethod("[propget] HRESULT " + propertyName, props);
        }
示例#14
0
 private CppType genDocLiteralType(wsdlParser.qname elementName)
 {
     // todo
     return(CppType.Create("VARIANT"));
 }
示例#15
0
        private void GenerateRpcEncOperation(string opName, wsdlParser.portTypeOperation pto, wsdlParser.operation bo)
        {
            wsdlParser.message msgIn, msgOut = null;
            msgIn = m_wsdl.findMessage(pto.inputMessage.msg.localname, pto.inputMessage.msg.@namespace);
            if (pto.outputMessage.Name.Length > 0)
            {
                msgOut = m_wsdl.findMessage(pto.outputMessage.msg.localname, pto.outputMessage.msg.@namespace);
            }

            // serializerFactory setup goo
            string ln = string.Format("// type mappings for operation {0}", opName);

            m_factory.Add("");
            m_factory.Add(ln);

            string opIn    = m_factory.IdForString(opName, IdType.Localname);
            string opOut   = m_factory.IdForString(opName + "Response", IdType.Localname);
            string opInNS  = m_factory.IdForString(bo.inputBody.@namespace, IdType.Namespace);
            string opOutNS = m_factory.IdForString(bo.outputBody.@namespace, IdType.Namespace);

            ln = string.Format("m_sf->ElementMapping({0}, {1}, {0}, {1});", opIn, opInNS);
            m_factory.Add(ln);
            ln = string.Format("m_sf->ElementMapping({0}, {1}, {0}, {1});", opOut, opOutNS);
            m_factory.Add(ln);

            // work out all the parameters
            ArrayList parameters = new ArrayList();

            // first the body parameters
            foreach (wsdlParser.part p in msgIn.parts)
            {
                CppType type = mapType(p.XmlType);
                // add type mappings
                string pn    = m_factory.IdForString(p.Name, IdType.Localname);
                string nons  = m_factory.IdForString("", IdType.Namespace);
                string xmlln = m_factory.IdForString(type.XmlType.localname, IdType.Type);
                string xmlns = m_factory.IdForString(type.XmlType.@namespace, IdType.Namespace);
                ln = string.Format("m_sf->LocalTypeMapping({0}, {1}, {2}, {3}, {4}, {5});", opIn, opInNS, pn, nons, xmlln, xmlns);
                m_factory.Add(ln);
                parameters.Add(new Parameter(type, p.Name, p.XmlType, false, IdlDirection.In));
            }
            // now the headers
            foreach (wsdlParser.soapHeader header in bo.inputHeaders)
            {
                wsdlParser.message hdrMsg = m_wsdl.findMessage(header.message.localname, header.message.@namespace);
                foreach (wsdlParser.part hdrPart in hdrMsg.parts)
                {
                    if (hdrPart.Name == header.part)
                    {
                        CppType type = mapPart(hdrPart);
                        parameters.Add(new Parameter(type, hdrPart.Name, hdrPart.XmlType, true, IdlDirection.In));
                    }
                }
            }
            // finally, any return parameter ?
            Parameter retParam = null;

            if (msgOut != null)
            {
                if (msgOut.parts.Count() > 0)
                {
                    object          idxOne = 1;
                    wsdlParser.part p      = (wsdlParser.part)msgOut.parts.Item(ref idxOne);
                    CppType         type   = mapType(p.XmlType);

                    // add type mappings
                    string pn    = m_factory.IdForString(p.Name, IdType.Localname);
                    string nons  = m_factory.IdForString("", IdType.Namespace);
                    string xmlln = m_factory.IdForString(type.XmlType.localname, IdType.Type);
                    string xmlns = m_factory.IdForString(type.XmlType.@namespace, IdType.Namespace);
                    ln = string.Format("m_sf->LocalTypeMapping({0}, {1}, {2}, {3}, {4}, {5});", opOut, opOutNS, pn, nons, xmlln, xmlns);
                    m_factory.Add(ln);
                    retParam = new Parameter(type, p.Name, p.XmlType, false, IdlDirection.Out | IdlDirection.Retval);
                    parameters.Add(retParam);
                }
            }

            // now generate the stub
            m_proxyFileHeader.Write("\tSTDMETHOD({0})(", opName);
            m_proxyFileCpp.Write("STDMETHODIMP {0}::{1}(", m_className, opName);
            bool first = true;

            foreach (Parameter p in parameters)
            {
                string prm = string.Format("{0}{1} {2} {3}", first ? "" : ", ", p.cppType.CPPParameterName, p.IsOutParam ? "*" : "", p.cppName);
                m_proxyFileHeader.Write(prm);
                m_proxyFileCpp.Write(prm);
                first = false;
            }
            m_proxyFileHeader.WriteLine(");");
            m_proxyFileCpp.WriteLine(")\n{");
            // update the interface
            m_interface.AddMethod("HRESULT " + opName, parameters);
            // generate the stub body
            m_proxyFileCpp.WriteLine("\tHRESULT hr;");
            m_proxyFileCpp.WriteLine("\tCComPtr<ISOAPEnvelope> env = newEnvelope(CComBSTR(OLESTR(\"{0}\")), CComBSTR(OLESTR(\"{1}\")), hr);", opName, bo.inputBody.@namespace);
            m_proxyFileCpp.WriteLine("\tif (FAILED(hr)) return hr;");
            bool gotParams = false, gotHeader = false;

            foreach (Parameter p in parameters)
            {
                if (p.IsOutParam)
                {
                    continue;
                }
                if (p.isHeader)
                {
                    if (!gotHeader)
                    {
                        m_proxyFileCpp.WriteLine("\tCComPtr<ISOAPNodes> headers;");
                        m_proxyFileCpp.WriteLine("\tenv->get_Headers(&headers);");
                        gotHeader = true;
                    }
                    m_proxyFileCpp.WriteLine("\tif({0} != null)");
                    m_proxyFileCpp.WriteLine(p.cppType.ConstructVariant(1, "v" + p.cppName, p.cppName));
                    m_proxyFileCpp.WriteLine("\t\theaders->Create(CComBSTR(OLESTR(\"{0}\")), v{1}, NULL, NULL, NULL, NULL);", p.xmlName.localname, p.cppName);
                }
                else
                {
                    if (!gotParams)
                    {
                        m_proxyFileCpp.WriteLine("\tCComPtr<ISOAPNodes> params;");
                        m_proxyFileCpp.WriteLine("\tenv->get_Parameters(&params);");
                        gotParams = true;
                    }
                    m_proxyFileCpp.WriteLine(p.cppType.ConstructVariant(1, "v" + p.cppName, p.cppName));
                    m_proxyFileCpp.WriteLine("\tparams->Create(CComBSTR(OLESTR(\"{0}\")), v{1}, NULL, NULL, NULL, NULL);", p.cppName, p.cppName);
                }
            }
            m_proxyFileCpp.WriteLine("\thr = SendRecv( env, CComBSTR(OLESTR(\"{0}\")));", bo.inputBody.encodingStyle);
            m_proxyFileCpp.WriteLine("\tif (FAILED(hr)) return hr;");
            // decode the return parameter
            if (retParam != null)
            {
                m_proxyFileCpp.WriteLine("\thr = extractRetVal{3}(env, CComBSTR(\"{0}\"), CComBSTR(\"{1}\"), {2});", retParam.xmlName.localname, retParam.xmlName.@namespace, retParam.cppName, retParam.cppType.ExtracRetValSuffix);
            }
            m_proxyFileCpp.WriteLine("\treturn hr;");
            m_proxyFileCpp.WriteLine("}\n");
        }
示例#16
0
 // todo: fix all the VarEnum/int casting nonsense
 private static CppType Factory(CppType arrayItem, ArrayType array, TypeStyle style, bool optional, wsdlParser.qname xmlType)
 {
     return(new CppTypeArray((int)VarEnum.VT_ARRAY, arrayItem, array, style, optional, xmlType));
 }
示例#17
0
        CppType CreateComplexType(wsdlParser.qname typeName, MSXML2.ISchemaComplexType typeDesc)
        {
            // look to see if its a section 5 encoded array first
            foreach (MSXML2.ISchemaType bt in typeDesc.baseTypes)
            {
                if ((bt.name == "Array") && (bt.namespaceURI == Consts.SOAP_11_ENCODING))
                {
                    return(HandleArrayType(typeName, typeDesc));
                }
            }

            CppType t = CppType.Create((int)VarEnum.VT_UNKNOWN, NameBuilder(typeName), CppType.ArrayType.NotArray, CppType.TypeStyle.Object, false, typeName);

            // a qname for the serializer class
            wsdlParser.qname tSerQName = new wsdlParser.qnameClass();
            tSerQName.localname  = "s" + typeName.localname;
            tSerQName.@namespace = "http://serializers.schemas.pocketsoap.com/";

            // register the type mapping now, incase there is some recursive nonsense going on
            m_typesCache[typeName.ExpandedName] = t;

            // a complexTypeWriter
            ComplexTypeWriter ctw = new ComplexTypeWriter(m_project, typeName.ExpandedName, t.CppName);

            // a SerializerWriter
            SerializerWriter sw = new SerializerWriter(m_project, tSerQName, NameBuilder(tSerQName), t.CppName);

            MSXML2.ISchemaComplexType complexType = typeDesc;
            MSXML2.ISchemaModelGroup  smg         = complexType.contentModel;

            // walk through each contained particle

            // attributes
            foreach (MSXML2.ISchemaAttribute attr in complexType.attributes)
            {
                wsdlParser.qname ptype = new wsdlParser.qnameClass();
                ptype.@namespace = attr.type.namespaceURI;
                ptype.localname  = attr.type.name;
                CppType itemType = mapType(ptype);
                string  itemName = vcProject.safeClassName(attr.name);
                ctw.AddPropertyField(itemName, itemType);
                sw.AddAttribute(itemName, itemType, attr, ptype);
            }

            AddElementsToContainer(typeName, smg, ctw, sw);

            ctw.Complete();
            sw.Complete();

            // add type registrations
            string serProgId = m_project.ProjectName + "." + sw.SerializerName;
            string clsProgId = m_project.ProjectName + "." + ctw.ComplexTypeName;
            string clsItfIID = string.Format("CComVariant(OLESTR(\"{{{0}}}\"))", ctw.InterfaceIID);

            m_factory.Add(string.Format("m_sf->Serializer({0}, CComBSTR(OLESTR(\"{1}\")), CComBSTR(OLESTR(\"{2}\")), CComBSTR(OLESTR(\"{3}\")));", clsItfIID, typeDesc.name, typeDesc.namespaceURI, serProgId));

            string typeLN = string.Format("CComBSTR(OLESTR(\"{0}\"))", typeName.localname);
            string typeNS = string.Format("CComBSTR(OLESTR(\"{0}\"))", typeName.@namespace);

            m_factory.Add(string.Format("m_sf->Deserializer({0}, {1}, VARIANT_FALSE, CComVariant(OLESTR(\"{2}\")), {3});", typeLN, typeNS, clsProgId, makeBstr(serProgId)));
            return(t);
        }