/*
  * Get package name from namespace uri, splitted at : / and . characters, in reverse order
 */
 public static string GetPackage(Namespace ns)
 {
     return ns.FullName;
     //string[] withoutprefix = GetUriWithSlash(ns).Split(new char[] { ':', '/', '.' });
     //string retVal = "";
     //for (int i = withoutprefix.Length - 2; ; i--)
     //{
     //    if (withoutprefix[i] == "")
     //    {
     //        break;
     //    }
     //    retVal += withoutprefix[i] + ".";
     //}
     //return retVal.Remove(retVal.Length - 1);
 }
Exemple #2
0
        public static void CreateOperationInputOutputTypes(Namespace ns)
        {
            foreach (Interface intf in ns.Declarations.OfType<Interface>())
            {
                foreach(Operation operation in intf.Operations)
                {
                    StructType inputType =
                        new StructType()
                        {
                            Name = operation.Name,
                            Namespace = intf.Namespace
                        };
                    foreach (OperationParameter param in operation.Parameters)
                    {
                        inputType.Fields.Add(
                            new StructField()
                            {
                                Name = param.Name,
                                Type = param.Type
                            });
                    }
                    StructType outputType =
                        new StructType()
                        {
                            Name = operation.Name + "Response",
                            Namespace = intf.Namespace
                        };
                    outputType.Fields.Add(
                        new StructField()
                        {
                            Name = operation.Name + "Result",
                            Type = operation.ReturnType
                        });

                    operation.InputType = inputType;
                    operation.OutputType = outputType;
                }
            }
        }
 public List<string> Generated_GenerateExpressionHelper(Namespace ns)
 {
     List<string> __result = new List<string>();
         using(TemplatePrinter __printer = new TemplatePrinter(__result))
         {
             __printer.WriteTemplateOutput("^");
             __printer.WriteLine();
             __printer.WriteTemplateOutput("package ");
             __printer.Write(Generated_GetPackage(ns).ToLower());
             __printer.WriteTemplateOutput(";");
             __printer.WriteLine();
             __printer.WriteTemplateOutput("^");
             __printer.WriteLine();
             __printer.WriteTemplateOutput("public interface ExpressionHelper<T> {");
             __printer.WriteLine();
             __printer.WriteTemplateOutput("^");
             __printer.WriteLine();
             __printer.WriteTemplateOutput("    T doWork();");
             __printer.WriteLine();
             __printer.WriteTemplateOutput("}");
             __printer.WriteLine();
         }
         return __result;
 }
 protected void Error_NamespaceUri(ISourceLocation site, Namespace @namespace)
 {
     errorReporter.Error(site, "URI for namespace \"{0}\" is redefined.", @namespace.FullName);
 }
 protected void Error_NamespaceImport(ISourceLocation site, Namespace @namespace)
 {
     errorReporter.Error(site, "Using namespace \"{0}\" is redundant.", @namespace.FullName);
 }
 /*
  * Returns the not null Uri with slash at end
  */
 public static string GetUriWithSlash(Namespace ns)
 {
     return GetUri(ns).EndsWith("/") ? GetUri(ns) : GetUri(ns) + "/";
 }
 /*
  * Returns Uri, if null returns http://default
 */
 public static string GetUri(Namespace ns)
 {
     if (ns.Uri == null)
         return "http://default";
     else
         return ns.Uri;
 }
        /// <summary>
        /// Processes one identifier of a dotted namespace name.
        /// </summary>
        /// <remarks>
        /// The method is called recursively until only the last identifier remains.
        /// </remarks>
        /// <param name="identifiers">The list of identifiers.</param>
        /// <param name="scope">The parent namespace to search next identifier in.</param>
        /// <returns>The namespace that the list identifies.</returns>
        private Namespace Process_NamespaceReference(List<string> identifiers, SoaObject scope)
        {
            Namespace @namespace = null;
            try
            {
                // Try to find the namespace identified by the first of the remaining name parts
                @namespace = (Namespace)NameContext.ResolveName(scope, identifiers[0], typeof(Namespace));
            }
            catch (NameNotFoundException)
            {
                // If not found, create
                @namespace = new Namespace();
                @namespace.Name = identifiers[0];
                @namespace.Namespace = (Namespace)scope;
            }

            if (identifiers.Count == 1)
            {
                // If this is the last part, simply return it
                return @namespace;
            }
            else
            {
                // Otherwise continue searching/creating with the next part of the name
                identifiers.RemoveAt(0);
                return this.Process_NamespaceReference(identifiers, @namespace);
            }
        }
 public string Generated_GetUriWithSlash(Namespace ns)
 {
     return GeneratorLibExtensions.GetUriWithSlash(ns);
 }
 public string Generated_GetPackage(Namespace ns)
 {
     return GeneratorLibExtensions.GetPackage(ns);
 }
Exemple #11
0
        private void Read()
        {
            try
            {

                // Beolvasandó dokumentumok listája
                LinkedList<XDocument> documentList = new LinkedList<XDocument>();

                // Imprortálások bekérése
                XDocument doc = XDocument.Load(System.IO.Path.Combine(this.Path, this.FileName));

                // Rekurzív függvény az importálások kifejtésére
                CheckImports(documentList, doc, Path);

                //--------------------------------------------------------------------

                // Az összes fájl feldolgozása
                foreach (XDocument xd in documentList)
                {
                    XNamespace targetNS = "";
                    XNamespace defNS = "";
                    try
                    {
                        targetNS = (string)xd.Element("definitions").Attribute("targetNamespace");
                        defNS = "";
                    }
                    catch { }
                    try
                    {
                        targetNS = (string)xd.Element("schema").Attribute("targetNamespace");
                        defNS = "";
                    }
                    catch { }
                    try
                    {
                        targetNS = (string)xd.Element(xsdNS + "schema").Attribute("targetNamespace");
                        defNS = xsdNS;
                    }
                    catch { }
                    try
                    {
                        targetNS = (string)xd.Element(wsdlNS + "definitions").Attribute("targetNamespace");
                        defNS = wsdlNS;
                    }
                    catch { }

                    if (!nsDictionary.ContainsKey(targetNS))
                    {
                        Namespace myNs = new Namespace()
                        {
                            Name = "namespace" + fileCount.ToString(),
                            Uri = targetNS.NamespaceName
                        };

                        nsDictionary.Add(targetNS, myNs);
                        fileCount++;
                    }

                    // services
                    var services = from c in xd.Descendants(wsdlNS + "service")
                                   select c;

                    foreach (XElement xe in services)
                    {
                        StoreItem coll = new StoreItem()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = StoreItemType.service,
                            ownNS = targetNS
                        };

                        store.Add(coll);
                    }

                    // binding
                    var bindings = from c in xd.Descendants(wsdlNS + "binding")
                                   select c;

                    foreach (XElement xe in bindings)
                    {
                        StoreItem coll = new StoreItem()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = StoreItemType.binding,
                            ownNS = targetNS
                        };

                        store.Add(coll);
                    }

                    // porttype
                    var portTypes = from c in xd.Descendants(wsdlNS + "portType")
                                    select c;

                    foreach (XElement xe in portTypes)
                    {
                        StoreItem coll = new StoreItem()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = StoreItemType.portType,
                            ownNS = targetNS
                        };

                        store.Add(coll);
                    }

                    // message
                    var messages = from c in xd.Descendants(wsdlNS + "message")
                                   select c;

                    foreach (XElement xe in messages)
                    {
                        StoreItem coll = new StoreItem()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = StoreItemType.message,
                            ownNS = targetNS
                        };

                        store.Add(coll);
                    }

                    //TODO: <type> és <schema> ellenőrzése a targetNamespace miatt!!!
                    var schemas = from c in xd.Descendants(xsdNS + "schema")
                                  select c;

                    foreach (XElement schema in schemas)
                    {
                        targetNS = (string)schema.Attribute("targetNamespace");

                        if (!nsDictionary.ContainsKey(targetNS))
                        {
                            Namespace myxsdNs = new Namespace()
                            {
                                Name = "namespace" + fileCount.ToString(),
                                Uri = targetNS.NamespaceName
                            };

                            nsDictionary.Add(targetNS, myxsdNs);
                            fileCount++;
                        }

                        // simpleTypes
                        var simpleTypes = from c in schema.Elements(xsdNS + "simpleType")
                                          select c;
                        //var simpleTypes = from c in xd.Descendants(xsdNS + "simpleType")
                        //                  select c;

                        foreach (XElement xe in simpleTypes)
                        {
                            StoreItem coll = new StoreItem()
                            {
                                name = (string)xe.Attribute("name"),
                                definition = xe,
                                objectType = StoreItemType.enumType,
                                ownNS = targetNS
                            };

                            store.Add(coll);
                        }

                        // complexTypes
                        //var complexTypes = from c in xd.Descendants(xsdNS + "complexType")
                        //                   select c;
                        var complexTypes = from c in schema.Elements(xsdNS + "complexType")
                                           select c;

                        foreach (XElement xe in complexTypes)
                        {

                            StoreItem coll = new StoreItem()
                            {
                                name = (string)xe.Attribute("name"),
                                definition = xe,
                                objectType = StoreItemType.complexType,
                                ownNS = targetNS

                            };

                            store.Add(coll);
                        }

                        var elements = from c in schema.Elements(xsdNS + "element")
                                       select c;

                        foreach (XElement xe in elements)
                        {
                            if (xe.Attribute("type") != null)
                            {
                                StoreItem coll = new StoreItem()
                                {
                                    name = (string)xe.Attribute("name"),
                                    definition = xe,
                                    objectType = StoreItemType.unNamedElementType,
                                    ownNS = targetNS
                                };
                                //Wr(coll.name);
                                store.Add(coll);
                            }
                            else
                            {
                                XAttribute nameAttribute = xe.Attribute("name");
                                XElement cType = xe.Element(xsdNS + "complexType");
                                XElement modifiendXe = cType;
                                modifiendXe.Add(nameAttribute);
                                StoreItem coll = new StoreItem()
                                {
                                    name = (string)modifiendXe.Attribute("name"),
                                    definition = modifiendXe,
                                    objectType = StoreItemType.complexType,
                                    ownNS = targetNS
                                };
                                //Wr(coll.name);
                                store.Add(coll);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }