Beispiel #1
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());
        }
Beispiel #2
0
 private void listView1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listView1.SelectedIndices.Count > 0)
     {
         SoapClasses soapClass = listView1.Items[listView1.SelectedIndices[0]].Tag as SoapClasses;
         if (soapClass != null)
         {
             propertyGrid1.SelectedObject = soapClass;
             Utility.WriteTrace(string.Format("Seçilen Class: {0}, Property:{1}", soapClass.Name, soapClass.Properties.Count));
         }
     }
 }
Beispiel #3
0
 private void btnclass_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedIndices.Count > 0)
     {
         SoapClasses soapClass = listView1.Items[listView1.SelectedIndices[0]].Tag as SoapClasses;
         if (soapClass != null && webserv != null)
         {
             JavaClassCreator jvcreator = new JavaClassCreator();
             JavaClassForm    frm       = new JavaClassForm(jvcreator.Create(soapClass, webserv));
             frm.Show();
         }
     }
 }
Beispiel #4
0
        private SoapClasses GetClass(string name)
        {
            SoapClasses newClass = this.ComplexTypes.Where(x => x.Name == name).FirstOrDefault <SoapClasses>();

            if (newClass == null)
            {
                newClass         = new SoapClasses(XpoDefault.Session);
                newClass.Name    = name;
                newClass.Service = webserv;
                newClass.Output  = false;
                this.ComplexTypes.Add(newClass);
            }
            return(newClass);
        }
Beispiel #5
0
        private void CreateEnum(SoapClasses enumClass)
        {
            try
            {
                using (FileHelper file = new FileHelper(string.Concat(ProjectFolder, Utility.ClearString(enumClass.Name), ".java")))
                {
                    file.WriteLine(FileHelper.COMPANY_DESC);
                    file.WriteLine("");
                    file.WriteLine(string.Concat("package ", WebService.PackageName, ";\n"));

                    StringBuilder enumstring = new StringBuilder();
                    enumstring.Append(string.Concat("public enum ", Utility.ClearString(enumClass.Name), " {")).AppendLine();
                    for (int k = 0; k < enumClass.Properties.Count; k++)
                    {
                        if (k > 0)
                        {
                            enumstring.Append(",");
                        }
                        enumstring.AppendFormat("{0}(\"{1}\",{2})", Utility.ClearString(enumClass.Properties[k].Name), enumClass.Properties[k].Name, k);
                        if (k == enumClass.Properties.Count - 1 || k > 100)
                        {
                            enumstring.AppendLine(";");
                            break;
                        }
                    }

                    enumstring.AppendLine();
                    enumstring.AppendLine("    private String stringValue;").AppendLine("    private int intValue;").AppendLine();

                    enumstring.Append(string.Concat("    private ", Utility.ClearString(enumClass.Name), "(String strvalue, int value) {\n"));
                    enumstring.AppendLine("        stringValue = strvalue;").AppendLine("        intValue = value;").AppendLine("    }");
                    enumstring.AppendLine("    public int getNumericType() {\n        return intValue;\n                        }\n");
                    enumstring.AppendLine("    public String getStringType() {\n        return stringValue;\n                        \n}");
                    enumstring.AppendLine("    @Override");
                    enumstring.AppendLine("    public String toString() {\n        return stringValue;\n                        \n}");
                    enumstring.AppendLine("    public final boolean equals(int other) {\n        return this.intValue == other;\n                        }\n");
                    enumstring.AppendLine("    public final boolean equals(String other) {\n        return this.stringValue == other;\n                        }\n");
                    enumstring.AppendLine().Append("    }").AppendLine();
                    file.WriteLine(enumstring.ToString());
                    file.Close();
                }
                Utility.WriteTrace(string.Format("{0}.java Oluşturuldu", Utility.ClearString(enumClass.Name)));
                complexClasses.Add(enumClass.Name);
            }
            catch (Exception exc)
            {
                Utility.Hata(exc);
            }
        }
Beispiel #6
0
        private void GetProperties(XmlSchema xmlSchema, string elementname)
        {
            foreach (object xItem in xmlSchema.SchemaTypes.Values)
            {
                XmlSchemaComplexType item = xItem as XmlSchemaComplexType;
                #region item
                if (item != null)
                {
                    if (item.Name.Equals(elementname))
                    {
                        XmlSchemaContentModel   model    = item.ContentModel;
                        XmlSchemaComplexContent complex  = model as XmlSchemaComplexContent;
                        SoapClasses             newClass = this.GetClass(elementname);

                        if (complex != null && newClass != null)
                        {
                            XmlSchemaComplexContentExtension extension = complex.Content as XmlSchemaComplexContentExtension;
                            XmlSchemaParticle particle = extension.Particle;
                            XmlSchemaSequence sequence = particle as XmlSchemaSequence;

                            if (extension != null)
                            {
                                newClass.SuperClassType = extension.BaseTypeName.Name;
                            }

                            if (sequence != null)
                            {
                                foreach (XmlSchemaElement childElement in sequence.Items)
                                {
                                    if (newClass != null)
                                    {
                                        SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session);
                                        newProp.Name = childElement.Name;

                                        newProp.PropertyClassType = childElement.SchemaTypeName.Name;
                                        newProp.IsArray           = childElement.SchemaTypeName.Name.StartsWith("ArrayOf");//.Equals("unbounded"));
                                        newClass.Properties.Add(newProp);
                                    }
                                }
                            }

                            newClass.Save();
                        }
                        return;
                    }
                }
                #endregion
            }
        }
Beispiel #7
0
        private void GetEnum(XmlSchema xmlSchema, string enumName)
        {
            var simpleTypes = xmlSchema.SchemaTypes.Values.OfType <XmlSchemaSimpleType>()
                              .Where(t => t.Content is XmlSchemaSimpleTypeRestriction && t.Name == enumName);
            SoapClasses newClass = this.GetClass(enumName);

            if (newClass != null)
            {
                newClass.Service        = webserv;
                newClass.IsArray        = false;
                newClass.IsEnum         = true;
                newClass.Output         = false;
                newClass.SuperClassType = string.Empty;
                foreach (var simpleType in simpleTypes)
                {
                    var restriction = (XmlSchemaSimpleTypeRestriction)simpleType.Content;
                    var enumFacets  = restriction.Facets.OfType <XmlSchemaEnumerationFacet>();

                    if (enumFacets.Any())
                    {
                        foreach (var facet in enumFacets)
                        {
                            SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session);
                            newProp.Name = facet.Value;
                            newProp.PropertyClassType = "String";
                            newProp.IsArray           = false;
                            newClass.Properties.Add(newProp);
                        }

                        foreach (SoapClasses cls in this.ComplexTypes)
                        {
                            foreach (SoapClassProperties prp in cls.Properties)
                            {
                                if (prp.PropertyClassType == simpleType.Name)
                                {
                                    prp.IsEnum = true;
                                    prp.Save();
                                }
                            }
                        }
                    }
                }
                newClass.Save();
            }
        }
Beispiel #8
0
 private void CreateClasses()
 {
     for (int loop = 0; loop < WebService.SoapClasses.Count; loop++)
     {
         SoapClasses soapClass = WebService.SoapClasses[loop];
         if (soapClass.IsEnum)
         {
             CreateEnum(soapClass);
         }
         else if (soapClass.IsArray)
         {
             CreateArrayClass(soapClass);
         }
         else
         {
             CreateComplexClass(soapClass);
         }
     }
 }
Beispiel #9
0
 private void GetRegisterClasses(SoapClasses soapClass, WebFunctions webfunc)
 {
     for (int loop = 0; loop < soapClass.Properties.Count; loop++)
     {
         SoapClassProperties property = soapClass.Properties[loop];
         if (property.IsComplexType && !keysRegister.Contains(property.Name))
         {
             var complexClass = WebService.SoapClasses.Where(x => x.Name == property.PropertyClassType).FirstOrDefault();
             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);
             }
         }
     }
 }
Beispiel #10
0
        public static string InitialToJavaType(SoapClassProperties prop)
        {
            if (prop.IsEnum)
            {
                SoapClasses cls = (from q in new XPQuery <SoapClasses>(XpoDefault.Session)
                                   where q.Name == prop.PropertyClassType
                                   select q).FirstOrDefault();
                if (cls != null)
                {
                    if (cls.Properties != null && cls.Properties.Count > 0)
                    {
                        return(string.Format("\"{0}\"", cls.Properties[0].Name));
                    }
                    else
                    {
                        return("");
                    }
                }
            }

            //check for string
            if (prop.PropertyClassType == "String")
            {
                return("\"\"");
            }
            if (prop.PropertyClassType == "string")
            {
                return("\"\"");
            }
            if (prop.PropertyClassType == "char")
            {
                return("' '");
            }

            if (prop.PropertyClassType == "dateTime")
            {
                return("new Date(1900, 1, 1)");
            }
            if (prop.PropertyClassType == "Date")
            {
                return("new Date(1900, 1, 1)");
            }

            if (prop.PropertyClassType == "boolean")
            {
                return("false");
            }
            if (prop.PropertyClassType == "Boolean")
            {
                return("false");
            }

            if (prop.PropertyClassType == "double")
            {
                return("new Double(0)");                                   //Double
            }
            if (prop.PropertyClassType == "Double")
            {
                return("new Double(0)");
            }

            if (prop.PropertyClassType == "float")
            {
                return("new Float(0)");
            }
            if (prop.PropertyClassType == "Float")
            {
                return("new Float(0)");
            }

            if (prop.PropertyClassType == "int")
            {
                return("0");
            }
            if (prop.PropertyClassType == "Integer")
            {
                return("0");
            }

            if (prop.PropertyClassType == "byte[]")
            {
                return("null");
            }

            //check for decimal and convert to float
            //if (prop.getPropertyClassType().Equals("decimal")) return "new Float(0)";//BigDecimal, new BigDecimal(0)
            if (prop.PropertyClassType == "BigDecimal")
            {
                return("new BigDecimal(0)");                                       //BigDecimal, new BigDecimal(0)
            }
            if (prop.IsComplexType && prop.IsEnum == false)
            {
                return(string.Format("new {0}()", prop.PropertyClassType));
            }

            if (prop.PropertyClassType == "Object")
            {
                return("null");
            }

            return("\"\"");
        }
Beispiel #11
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();
        }
Beispiel #12
0
        private void CreateArrayClass(SoapClasses arrClass)
        {
            try
            {
                string arraystr = FileHelper.GetManifestResourceStream("ArrayObjectTemplate");
                arraystr = arraystr.Replace("%%DATE%%", DateTime.Now.ToString()).Replace("%%PACKAGENAME%%", WebService.PackageName);
                arraystr = arraystr.Replace("%%NAMESPACE%%", WebService.NameSpace).Replace("%%CLASSNAME%%", arrClass.Name);
                arraystr = arraystr.Replace("%%ELEMENTTYPE%%", JavaTypeConverter.ToElementJavaType(arrClass.ElementType)).Replace("%%ELEMENTTYPEDESC%%", JavaTypeConverter.ArrayElementTypeDesc(arrClass.ElementType));

                StringBuilder loadstr = new StringBuilder();
                if (arrClass.ElementType == "char")
                {
                    loadstr.AppendLine("                if (property.getProperty(loop) instanceof SoapPrimitive) {");
                    loadstr.AppendLine("                    SoapPrimitive pi = (SoapPrimitive) property.getProperty(loop);");
                    loadstr.AppendLine("                    int intchar = Integer.valueOf(pi.toString());");
                    loadstr.AppendLine("                    this.add((char) intchar);");
                    loadstr.AppendLine("                }");
                }
                else if (arrClass.ElementType == "Integer")
                {
                    loadstr.AppendLine("                if (property.getProperty(loop) instanceof SoapPrimitive) {");
                    loadstr.AppendLine("                    SoapPrimitive pi = (SoapPrimitive) property.getProperty(loop);");
                    loadstr.AppendLine("                    Integer item = Integer.valueOf(pi.toString());");
                    loadstr.AppendLine("                    this.add(item);");
                    loadstr.AppendLine("                }");
                }
                else if (arrClass.ElementType == "String")
                {
                    loadstr.AppendLine("                if (property.getProperty(loop) instanceof SoapPrimitive) {");
                    loadstr.AppendLine("                    SoapPrimitive pi = (SoapPrimitive) property.getProperty(loop);");
                    loadstr.AppendLine("                    String item = pi.toString();");
                    loadstr.AppendLine("                    this.add(item);");
                    loadstr.AppendLine("                }");
                }
                else if (arrClass.ElementType == "BigDecimal")
                {
                    loadstr.AppendLine("                if (property.getProperty(loop) instanceof SoapPrimitive) {");
                    loadstr.AppendLine("                    SoapPrimitive pi = (SoapPrimitive) property.getProperty(loop);");
                    loadstr.AppendLine("                    BigDecimal item = BigDecimal.valueOf(Double.parseDouble(pi.toString()));");
                    loadstr.AppendLine("                    this.add(item);");
                    loadstr.AppendLine("                }");
                }
                else if (arrClass.ElementType == "Object")
                {
                    loadstr.AppendLine("                if (property.getProperty(loop) != null) {");
                    loadstr.AppendLine("                    this.add((Object) property.getProperty(loop));");
                    loadstr.AppendLine("                }");
                }
                else
                {
                    loadstr.AppendLine("                if (property.getProperty(loop) instanceof SoapObject) {");
                    loadstr.AppendLine("                    SoapObject so = (SoapObject) property.getProperty(loop);");
                    loadstr.AppendFormat("                  {0} item = new {0}(); \n", arrClass.ElementType);
                    loadstr.AppendLine("                    item.loadSoapObject(so);");
                    loadstr.AppendLine("                    this.add(item);");
                    loadstr.AppendLine("                }");

                    SoapClasses elementClass = WebService.SoapClasses.Where(x => x.Name == arrClass.ElementType).FirstOrDefault();
                    if (elementClass != null)
                    {
                        CreateComplexClass(elementClass);
                    }
                }

                arraystr = arraystr.Replace("%%LOADSOAPOBJECTS%%", loadstr.ToString());

                using (FileHelper file = new FileHelper(string.Concat(ProjectFolder, arrClass.Name, ".java")))
                {
                    file.Write(arraystr);
                }
                Utility.WriteTrace(string.Format("{0}.java Oluşturuldu", arrClass.Name));
                complexClasses.Add(arrClass.Name);
            }
            catch (Exception exc)
            {
                Utility.Hata(exc);
            }
        }
Beispiel #13
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());
        }
Beispiel #14
0
        public void Parse()
        {
            UriBuilder uriBuilder = new UriBuilder(webserv.Url);

            uriBuilder.Query = "WSDL";
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Method      = "GET";
            webRequest.Accept      = "text/xml";

            ServiceDescription serviceDescription;

            using (WebResponse response = webRequest.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    serviceDescription = ServiceDescription.Read(stream);
                }
            }

            var oldfuncs = (from q in new XPQuery <WebFunctions>(XpoDefault.Session)
                            where q.Service.Oid == webserv.Oid
                            select q).ToList();



            if (serviceDescription != null && serviceDescription.Services.Count > 0)
            {
                ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
                importer.ProtocolName = "Soap11";
                importer.AddServiceDescription(serviceDescription, null, null);
                importer.Style = ServiceDescriptionImportStyle.Client;
                importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;

                Service service = serviceDescription.Services[0];

                this.Namespace   = serviceDescription.TargetNamespace;
                this.ServiceName = service.Name;

                webserv.ServiceName = service.Name;
                webserv.NameSpace   = serviceDescription.TargetNamespace;
                webserv.UpdateDate  = DateTime.Now;

                for (int i = webserv.SoapClasses.Count - 1; i >= 0; i--)
                {
                    webserv.SoapClasses[i].Delete();
                }

                #region Operation
                List <string> operationNames = new List <string>();
                //Loop through the port types in the service description and list all of the
                //web service's operations and each operations input/output

                PortType portType = serviceDescription.PortTypes[0];
                //foreach (PortType portType in serviceDescription.PortTypes)
                {
                    int FunctionIndex = 0;
                    this.Functions = new List <WebFunctions>();
                    foreach (Operation operation in portType.Operations)
                    {
                        WebFunctions newFunc = new WebFunctions();
                        newFunc.Service = webserv;
                        var oldfunc = oldfuncs.Where(x => x.Name == operation.Name).FirstOrDefault();
                        if (oldfunc != null)
                        {
                            newFunc.Output = oldfunc.Output;
                        }
                        newFunc.Name       = operation.Name;
                        newFunc.SoapAction = this.Namespace + operation.Name;
                        operationNames.Add(operation.Name);

                        foreach (var message in operation.Messages)
                        {
                            if (message is OperationInput)
                            {
                                foreach (Message messagePart in serviceDescription.Messages)
                                {
                                    if (messagePart.Name != ((OperationMessage)message).Message.Name)
                                    {
                                        continue;
                                    }

                                    foreach (MessagePart part in messagePart.Parts)
                                    {
                                        newFunc.InputType = part.Element.Name;
                                    }
                                }
                            }
                            if (message is OperationOutput)
                            {
                                foreach (Message messagePart in serviceDescription.Messages)
                                {
                                    if (messagePart.Name != ((OperationMessage)message).Message.Name)
                                    {
                                        continue;
                                    }

                                    foreach (MessagePart part in messagePart.Parts)
                                    {
                                        newFunc.OutputType = part.Element.Name;
                                    }
                                }
                            }
                        }
                        newFunc.Save();
                        this.Functions.Add(newFunc);
                        FunctionIndex++;
                    }
                } //End listing of types

                for (int i = oldfuncs.Count - 1; i >= 0; i--)
                {
                    oldfuncs[i].Delete();
                }

                #endregion

                #region Types

                Types     types     = serviceDescription.Types;
                XmlSchema xmlSchema = types.Schemas[0];

                foreach (object item in xmlSchema.Items)
                {
                    XmlSchemaComplexType _complexType  = item as System.Xml.Schema.XmlSchemaComplexType;
                    XmlSchemaElement     schemaElement = item as XmlSchemaElement;
                    XmlSchemaComplexType complexType   = item as XmlSchemaComplexType;

                    if (schemaElement != null && JavaTypeConverter.IsComplexType(schemaElement.Name))
                    {
                        SoapClasses newClass = this.GetClass(schemaElement.Name);
                        newClass.Name           = schemaElement.Name;
                        newClass.Service        = webserv;
                        newClass.Type           = ClassType.Unknown;
                        newClass.SuperClassType = string.Empty;
                        newClass.Output         = false;

                        if (_complexType != null)
                        {
                            XmlSchemaContentModel   model   = _complexType.ContentModel;
                            XmlSchemaComplexContent complex = model as XmlSchemaComplexContent;
                            if (complex != null)
                            {
                                XmlSchemaComplexContentExtension extension = complex.Content as XmlSchemaComplexContentExtension;
                                if (extension != null)
                                {
                                    newClass.SuperClassType = extension.BaseTypeName.Name;
                                }
                            }
                        }

                        XmlSchemaType        schemaType        = schemaElement.SchemaType;
                        XmlSchemaComplexType schemaComplexType = schemaType as XmlSchemaComplexType;


                        if (schemaComplexType != null)
                        {
                            XmlSchemaParticle particle = schemaComplexType.Particle;
                            XmlSchemaSequence sequence = particle as XmlSchemaSequence;
                            if (sequence != null)
                            {
                                foreach (XmlSchemaElement childElement in sequence.Items)
                                {
                                    SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session);
                                    newProp.Name = childElement.Name;

                                    newProp.PropertyClassType = childElement.SchemaTypeName.Name;
                                    newProp.IsArray           = childElement.SchemaTypeName.Name.StartsWith("ArrayOf");
                                    newClass.Properties.Add(newProp);
                                }
                            }
                        }

                        newClass.Save();
                        //this.ComplexTypes.Add(newClass);
                    }
                    else if (complexType != null)
                    {
                        OutputElements(complexType.Particle, complexType.Name);

                        if (complexType.Particle == null)
                        {
                            GetProperties(xmlSchema, complexType.Name);
                        }
                    }
                }

                #region enums
                foreach (object xItem in xmlSchema.SchemaTypes.Values)
                {
                    XmlSchemaSimpleType item2 = xItem as XmlSchemaSimpleType;
                    if (item2 != null)
                    {
                        GetEnum(xmlSchema, item2.Name);
                    }
                }
                #endregion

                #endregion
            }

            webserv.Save();
        }
Beispiel #15
0
        private void OutputElements(XmlSchemaParticle particle, string name)
        {
            SoapClasses newClass = this.GetClass(name);

            newClass.Name    = name;
            newClass.Type    = ClassType.Unknown;
            newClass.IsArray = name.StartsWith("ArrayOf");
            newClass.Output  = false;

            XmlSchemaSequence sequence = particle as XmlSchemaSequence;
            XmlSchemaChoice   choice   = particle as XmlSchemaChoice;
            XmlSchemaAll      all      = particle as XmlSchemaAll;

            if (sequence != null)
            {
                for (int i = 0; i < sequence.Items.Count; i++)
                {
                    XmlSchemaElement  childElement  = sequence.Items[i] as XmlSchemaElement;
                    XmlSchemaSequence innerSequence = sequence.Items[i] as XmlSchemaSequence;
                    XmlSchemaChoice   innerChoice   = sequence.Items[i] as XmlSchemaChoice;
                    XmlSchemaAll      innerAll      = sequence.Items[i] as XmlSchemaAll;

                    if (childElement != null)
                    {
                        SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session);
                        newProp.Name = childElement.Name;

                        newProp.PropertyClassType = childElement.SchemaTypeName.Name;
                        newProp.IsArray           = childElement.SchemaTypeName.Name.StartsWith("ArrayOf");
                        newClass.Properties.Add(newProp);
                        newClass.ElementType = JavaTypeConverter.ToElementJavaType(childElement.SchemaTypeName.Name);
                    }
                    else
                    {
                        OutputElements(sequence.Items[i] as XmlSchemaParticle, name);
                    }
                }
            }
            else if (choice != null)
            {
                for (int i = 0; i < choice.Items.Count; i++)
                {
                    XmlSchemaElement  childElement  = choice.Items[i] as XmlSchemaElement;
                    XmlSchemaSequence innerSequence = choice.Items[i] as XmlSchemaSequence;
                    XmlSchemaChoice   innerChoice   = choice.Items[i] as XmlSchemaChoice;
                    XmlSchemaAll      innerAll      = choice.Items[i] as XmlSchemaAll;

                    if (childElement != null)
                    {
                        SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session);
                        newProp.Name = childElement.Name;
                        newProp.PropertyClassType = childElement.SchemaTypeName.Name;
                        newProp.IsArray           = childElement.SchemaTypeName.Name.StartsWith("ArrayOf");
                        newClass.Properties.Add(newProp);
                    }
                    else
                    {
                        OutputElements(choice.Items[i] as XmlSchemaParticle, name);
                    }
                }
            }
            else if (all != null)
            {
                for (int i = 0; i < all.Items.Count; i++)
                {
                    XmlSchemaElement  childElement  = all.Items[i] as XmlSchemaElement;
                    XmlSchemaSequence innerSequence = all.Items[i] as XmlSchemaSequence;
                    XmlSchemaChoice   innerChoice   = all.Items[i] as XmlSchemaChoice;
                    XmlSchemaAll      innerAll      = all.Items[i] as XmlSchemaAll;

                    if (childElement != null)
                    {
                        SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session);
                        newProp.Name = childElement.Name;

                        newProp.PropertyClassType = childElement.SchemaTypeName.Name;
                        newProp.IsArray           = childElement.SchemaTypeName.Name.StartsWith("ArrayOf");
                        newClass.Properties.Add(newProp);
                    }
                    else
                    {
                        OutputElements(all.Items[i] as XmlSchemaParticle, name);
                    }
                }
            }
            newClass.Save();
            //this.ComplexTypes.Add(newClass);
        }