Esempio n. 1
0
        private void CreateComplexClass(SoapClasses complexClass)
        {
            if (complexClasses.Contains(complexClass.Name))
            {
                return;
            }

            if (complexClass.IsEnum)
            {
                CreateEnum(complexClass);
                return;
            }
            else if (complexClass.IsArray)
            {
                CreateArrayClass(complexClass);
                return;
            }

            StringBuilder propText   = new StringBuilder();
            StringBuilder propinfstr = new StringBuilder();
            StringBuilder setpropstr = new StringBuilder();
            StringBuilder getpropstr = new StringBuilder();
            string        complexstr = FileHelper.GetManifestResourceStream("SoapComplexTypeClassTemplate");

            complexstr = complexstr.Replace("%%DATE%%", DateTime.Now.ToString()).Replace("%%PACKAGENAME%%", WebService.PackageName);
            complexstr = complexstr.Replace("%%CLASSNAME%%", complexClass.Name).Replace("%%PROPCOUNT%%", complexClass.Properties.Count.ToString());

            for (int i = 0; i < complexClass.Properties.Count; i++)
            {
                SoapClassProperties property = complexClass.Properties[i];

                propinfstr.AppendFormat("           case {0}:", i).AppendLine();
                propinfstr.AppendFormat("                info.name = \"{0}\";", property.Name).AppendLine();
                propinfstr.AppendFormat("                info.type = {0};", JavaTypeConverter.ClassTypeRetrievalString(property)).AppendLine();
                propinfstr.AppendLine("                break;");

                getpropstr.AppendFormat("           case {0}:", i).AppendLine();
                getpropstr.AppendFormat("                return {0};", property.Name).AppendLine();

                setpropstr.AppendFormat("           case {0}:", i).AppendLine();
                setpropstr.AppendLine("                if (value.toString().equalsIgnoreCase(\"anyType{}\")) {");
                setpropstr.AppendFormat("                    {0} = {1};", property.Name, JavaTypeConverter.InitialToJavaType(property)).AppendLine("                }");
                setpropstr.AppendLine("                else {");

                if (property.IsEnum)
                {
                    propText.AppendFormat("     public String {0} = {1}; //Enum {2}", property.Name, JavaTypeConverter.InitialToJavaType(property), property.PropertyClassType);
                    setpropstr.AppendFormat("                    {0} = value.toString();", property.Name).AppendLine();
                }
                else if (property.IsArray)
                {
                    propText.AppendFormat("     public {0} {1} = {2}; //array\n", property.PropertyClassType, property.Name, JavaTypeConverter.InitialToJavaType(property));
                    setpropstr.AppendFormat("                  {0} = {1};", property.Name, JavaTypeConverter.InitialToJavaType(property)).AppendLine();
                    setpropstr.AppendFormat("                  SoapObject prp = (SoapObject)value; ").AppendLine();
                    setpropstr.AppendFormat("                  {0}.loadSoapObject(prp); ", property.Name).AppendLine();
                }
                else
                {
                    propText.AppendFormat("     public {0} {1} = {2};\n", property.PropertyClassType, property.Name, JavaTypeConverter.InitialToJavaType(property));
                    if (property.IsComplexType)
                    {
                        setpropstr.AppendFormat("	                {0} = new {1}(); ", property.Name, property.PropertyClassType).AppendLine();
                        setpropstr.AppendFormat("                    {0}.loadSoapObject((SoapObject) value);", property.Name).AppendLine();
                    }
                    else
                    {
                        setpropstr.AppendFormat("	                {0} = {1}; ", property.Name, JavaTypeConverter.ConvertorForJavaType(property)).AppendLine();
                    }
                }

                setpropstr.AppendLine("                }").AppendLine("                break;");

                if (property.IsComplexType)
                {
                    SoapClasses _complexClass = WebService.SoapClasses.Where(x => x.Name == property.PropertyClassType).FirstOrDefault();
                    if (_complexClass != null)
                    {
                        CreateComplexClass(_complexClass);
                    }
                }
            }

            complexstr = complexstr.Replace("%%PROPERTIES%%", propText.ToString()).Replace("%%GETPROPERTY%%", getpropstr.ToString());
            complexstr = complexstr.Replace("%%SETPROP%%", setpropstr.ToString()).Replace("%%GETPROPINFO%%", propinfstr.ToString());


            using (FileHelper file = new FileHelper(string.Concat(ProjectFolder, complexClass.Name, ".java")))
            {
                file.WriteLine(complexstr.ToString());
                file.Close();
            }
            Utility.WriteTrace(string.Format("{0}.java Oluşturuldu", complexClass.Name));
            complexClasses.Add(complexClass.Name);

            complexClass.Output = true;
            complexClass.Save();
        }
Esempio n. 2
0
        public string Create(SoapClasses soapClass, WebServices webService)
        {
            StringBuilder strgetter = new StringBuilder();
            StringBuilder str       = new StringBuilder();

            str.AppendFormat("package {0};", webService.PackageName).AppendLine().AppendLine();
            str.AppendLine("import java.util.Date;").AppendLine("import java.math.BigDecimal;").AppendLine();
            str.AppendLine(string.Concat("public class ", soapClass.Name, " {")).AppendLine();

            str.AppendFormat("    public {0}(){1}", soapClass.Name, "{}").AppendLine();

            for (int i = 0; i < soapClass.Properties.Count; i++)
            {
                SoapClassProperties property = soapClass.Properties[i];
                if (property.IsEnum)
                {
                    str.AppendFormat("    private String _{0} = {1}; //Enum {2}", property.Name, JavaTypeConverter.InitialToJavaType(property), property.PropertyClassType).AppendLine();

                    strgetter.AppendFormat("     public String get{0}() {1}", property.Name, "{").AppendLine();
                    strgetter.AppendFormat("        return _{0};", property.Name).AppendLine();
                    strgetter.AppendLine("    }").AppendLine();

                    strgetter.AppendFormat("    public void set{0}(String improvable) {1}", property.Name, "{").AppendLine();
                    strgetter.AppendFormat("        this._{0} = improvable;", property.Name).AppendLine();
                    strgetter.AppendLine("    }").AppendLine();
                }
                else if (property.IsArray)
                {
                    str.AppendFormat("    private {0} _{1} = {2}; //array\n", property.PropertyClassType, property.Name, JavaTypeConverter.InitialToJavaType(property)).AppendLine();

                    strgetter.AppendFormat("     public String get{0}() {1}", property.Name, "{").AppendLine();
                    strgetter.AppendFormat("        return _{0};", property.Name).AppendLine();
                    strgetter.AppendLine("    }").AppendLine();

                    strgetter.AppendFormat("    public void set{0}({1} improvable) {2}", property.Name, property.PropertyClassType, "{").AppendLine();
                    strgetter.AppendFormat("        this._{0} = improvable;", property.Name).AppendLine();
                    strgetter.AppendLine("    }").AppendLine();
                }
                else
                {
                    str.AppendFormat("    private {0} _{1} = {2};\n", property.PropertyClassType, property.Name, JavaTypeConverter.InitialToJavaType(property)).AppendLine();

                    strgetter.AppendFormat("     public {0} get{1}() {2}", property.PropertyClassType, property.Name, "{").AppendLine();
                    strgetter.AppendFormat("        return _{0};", property.Name).AppendLine();
                    strgetter.AppendLine("    }").AppendLine();

                    strgetter.AppendFormat("    public void set{0}({1} improvable) {2}", property.Name, property.PropertyClassType, "{").AppendLine();
                    strgetter.AppendFormat("        this._{0} = improvable;", property.Name).AppendLine();
                    strgetter.AppendLine("    }").AppendLine();
                }
            }

            str.Append(strgetter.ToString());


            str.AppendLine("}");
            return(str.ToString());
        }
Esempio n. 3
0
        private string CreateMethods()
        {
            string        methodstrorj = FileHelper.GetManifestResourceStream("MethodTemplate");
            StringBuilder strmethods   = new StringBuilder();
            var           functions    = WebService.Functions.Where(x => x.Output == true).ToList();

            for (int loop = 0; loop < functions.Count; loop++)
            {
                keysRegister    = new List <string>();
                registerStrings = new StringBuilder();

                var    webfunc   = functions[loop];
                string methodstr = methodstrorj.Replace("%%METHODNAME%%", webfunc.Name).Replace("%%OUTPUT%%", webfunc.OutputType).Replace("%%INPUT%%", webfunc.InputType);

                SoapClasses paramClass = WebService.SoapClasses.Where(x => x.Name == webfunc.InputType).FirstOrDefault();

                #region InputClass
                if (paramClass != null)
                {
                    StringBuilder propText    = new StringBuilder();
                    StringBuilder propinfstr  = new StringBuilder();
                    StringBuilder setpropstr  = new StringBuilder();
                    StringBuilder getpropstr  = new StringBuilder();
                    StringBuilder soappropstr = new StringBuilder();
                    string        paramstr    = FileHelper.GetManifestResourceStream("ParameterClassTemplate");
                    paramstr = paramstr.Replace("%%DATE%%", DateTime.Now.ToString()).Replace("%%PACKAGENAME%%", WebService.PackageName);
                    paramstr = paramstr.Replace("%%CLASSNAME%%", paramClass.Name).Replace("%%SOAPMETHODNAME%%", webfunc.Name);
                    paramstr = paramstr.Replace("%%NAMESPACE%%", WebService.NameSpace).Replace("%%SOAPMETHODNAME%%", webfunc.Name);
                    paramstr = paramstr.Replace("%%PROPCOUNT%%", paramClass.Properties.Count.ToString());

                    webfunc.RegisterClasses = paramClass.Name;
                    keysRegister.Add(paramClass.Name);
                    registerStrings.AppendLine(paramClass.RegisterText);
                    GetRegisterClasses(paramClass, webfunc);
                    CreateComplexClass(paramClass);

                    for (int i = 0; i < paramClass.Properties.Count; i++)
                    {
                        SoapClassProperties property = paramClass.Properties[i];

                        soappropstr.AppendFormat("\t\tPropertyInfo p{0} = new PropertyInfo();", i).AppendLine();
                        soappropstr.AppendFormat("\t\tp{1}.setName(\"{0}\");", property.Name, i).AppendLine();
                        soappropstr.AppendFormat("\t\tp{1}.setValue({0});", property.Name, i).AppendLine();
                        soappropstr.AppendFormat("\t\tp{1}.setType({0}.class);", property.PropertyClassType, i);
                        soappropstr.AppendFormat("\t\tp{0}.setNamespace(NAMESPACE);", i).AppendLine();
                        soappropstr.AppendFormat("\t\trequest.addProperty(p{0});", i).AppendLine().AppendLine();

                        propinfstr.AppendFormat("           case {0}:", i).AppendLine();
                        propinfstr.AppendFormat("                info.name = \"{0}\";", property.Name).AppendLine();
                        propinfstr.AppendFormat("                info.type = {0};", JavaTypeConverter.ClassTypeRetrievalString(property)).AppendLine();
                        propinfstr.AppendLine("                break;");

                        getpropstr.AppendFormat("           case {0}:", i).AppendLine();
                        getpropstr.AppendFormat("                return {0};", property.Name).AppendLine();

                        setpropstr.AppendFormat("           case {0}:", i).AppendLine();
                        setpropstr.AppendLine("                if (value.toString().equalsIgnoreCase(\"anyType{}\")) {");
                        setpropstr.AppendFormat("                    {0} = {1};", property.Name, JavaTypeConverter.InitialToJavaType(property)).AppendLine("                }");
                        setpropstr.AppendLine("                else {");

                        if (property.IsEnum)
                        {
                            propText.AppendFormat("     public String {0} = {1}; //Enum {2}", property.Name, JavaTypeConverter.InitialToJavaType(property), property.PropertyClassType);
                            setpropstr.AppendFormat("                    {0} = value.toString();", property.Name).AppendLine();
                        }
                        else if (property.IsArray)
                        {
                            setpropstr.AppendFormat("                  {0} = {1};", property.Name, JavaTypeConverter.InitialToJavaType(property)).AppendLine();
                            setpropstr.AppendFormat("                  SoapObject prp = (SoapObject)value; ").AppendLine();
                            setpropstr.AppendFormat("                  {0}.loadSoapObject(prp); ", property.Name).AppendLine();
                        }
                        else
                        {
                            propText.AppendFormat("     public {0} {1} = {2};\n", property.PropertyClassType, property.Name, JavaTypeConverter.InitialToJavaType(property));
                            setpropstr.AppendFormat("	                {0} = {1}; ", property.Name, JavaTypeConverter.ConvertorForJavaType(property)).AppendLine();
                        }

                        if (property.IsComplexType)
                        {
                            SoapClasses complexClass = WebService.SoapClasses.Where(x => x.Name == property.PropertyClassType).FirstOrDefault();
                            if (complexClass != null)
                            {
                                if (complexClass != null && !complexClass.IsEnum && !keysRegister.Contains(complexClass.Name))
                                {
                                    complexClass.Output = true;
                                    complexClass.Save();
                                    webfunc.RegisterClasses = string.Format("{0};{1}", webfunc.RegisterClasses, complexClass.Name);
                                    webfunc.Save();
                                    keysRegister.Add(complexClass.Name);
                                    registerStrings.AppendLine(complexClass.RegisterText);
                                    GetRegisterClasses(complexClass, webfunc);
                                }

                                CreateComplexClass(complexClass);
                            }
                        }

                        setpropstr.AppendLine("                }").AppendLine("                break;");
                    }

                    paramstr = paramstr.Replace("%%PROPERTIES%%", propText.ToString()).Replace("%%GETPROPERTY%%", getpropstr.ToString());
                    paramstr = paramstr.Replace("%%SETPROP%%", setpropstr.ToString()).Replace("%%GETPROPINFO%%", propinfstr.ToString());
                    paramstr = paramstr.Replace("%%SOAPPROPERTIES%%", soappropstr.ToString());


                    using (FileHelper file = new FileHelper(string.Concat(ProjectFolder, paramClass.Name, ".java")))
                    {
                        file.Write(paramstr);
                        file.Close();
                    }

                    Utility.WriteTrace(string.Format("{0}.java Oluşturuldu", paramClass.Name));
                    complexClasses.Add(paramClass.Name);

                    paramClass.Output = true;
                    paramClass.Save();
                }
                #endregion

                #region ReturnClass
                SoapClasses returnClass = WebService.SoapClasses.Where(x => x.Name == webfunc.OutputType).FirstOrDefault();

                if (returnClass != null)
                {
                    StringBuilder propinfstr = new StringBuilder();
                    StringBuilder setpropstr = new StringBuilder();
                    StringBuilder getpropstr = new StringBuilder();
                    StringBuilder propText   = new StringBuilder();
                    string        returnstr  = FileHelper.GetManifestResourceStream("ResponseTemplate");
                    returnstr = returnstr.Replace("%%DATE%%", DateTime.Now.ToString()).Replace("%%PACKAGENAME%%", WebService.PackageName);
                    returnstr = returnstr.Replace("%%CLASSNAME%%", returnClass.Name);
                    returnstr = returnstr.Replace("%%PROPCOUNT%%", returnClass.Properties.Count.ToString());


                    if (returnClass.Properties.Count > 0)
                    {
                        SoapClassProperties property = returnClass.Properties[0];


                        returnstr = returnstr.Replace("%%RESULTPROPNAME%%", property.Name);
                        returnstr = returnstr.Replace("%%RESULTPROPTYPE%%", property.PropertyClassType);
                        returnstr = returnstr.Replace("%%GETPROPINFO%%", JavaTypeConverter.ClassTypeRetrievalString(property));
                        returnstr = returnstr.Replace("%%RESULTPROPTYPE%%", property.PropertyClassType);
                        returnstr = returnstr.Replace("%%SETPROP%%", JavaTypeConverter.ConvertorForJavaType(property));

                        if (property.IsComplexType)
                        {
                            SoapClasses complexClass = WebService.SoapClasses.Where(x => x.Name == property.PropertyClassType).FirstOrDefault();
                            if (complexClass != null)
                            {
                                CreateComplexClass(complexClass);
                            }

                            StringBuilder loadobjstr = new StringBuilder();
                            loadobjstr.AppendFormat("		{0} = new {1}();", property.Name, property.PropertyClassType).AppendLine();
                            loadobjstr.AppendFormat("		{0}.loadSoapObject(property);", property.Name).AppendLine();
                            returnstr = returnstr.Replace("%%LOADSOAPOBJECT%%", loadobjstr.ToString());
                        }
                        else
                        {
                            returnstr = returnstr.Replace("%%LOADSOAPOBJECT%%", "");
                        }
                    }
                    else
                    {
                        returnstr = returnstr.Replace("%%RESULTPROPNAME%%", "");
                        returnstr = returnstr.Replace("%%RESULTPROPTYPE%%", "");
                        returnstr = returnstr.Replace("%%GETPROPINFO%%", "");
                        returnstr = returnstr.Replace("%%RESULTPROPNAME%%", "").Replace("%%GETPROPINFO%%", "");
                        returnstr = returnstr.Replace("%%RESULTPROPTYPE%%", "");
                    }

                    methodstr = methodstr.Replace("%%REGISTERCLASS%%", registerStrings.ToString());
                    strmethods.Append(methodstr);

                    using (FileHelper file = new FileHelper(string.Concat(ProjectFolder, returnClass.Name, ".java")))
                    {
                        file.Write(returnstr);
                        file.Close();
                    }
                    Utility.WriteTrace(string.Format("{0}.java Oluşturuldu", returnClass.Name));
                    complexClasses.Add(returnClass.Name);

                    returnClass.Output = true;
                    returnClass.Save();
                }
                #endregion
            }

            return(strmethods.ToString());
        }