예제 #1
0
        private void AnalyseSoalType(Component project, string typeOwnerName, SoalType type)
        {
            Struct    entity = type as Struct;
            ArrayType list   = type as ArrayType;

            Symbols.Enum  enumtype = type as Symbols.Enum;
            PrimitiveType primitiv = type as PrimitiveType;

            if (list != null)
            {
                entity = list.InnerType as Struct;
                string importString = JavaImportConfigHandler.getValue(JavaTypeConfigHandler.SwitchTypeName(list.MMetaClass.Name));
                if (importString != null)
                {
                    string importPackage    = importString.Substring(0, importString.LastIndexOf("."));
                    string importObjectName = importString.Substring(importString.LastIndexOf(".") + 1);
                    AddImport(project.Name, project.Namespace.Name, typeOwnerName, importPackage, importObjectName, false);
                }
            }

            if (entity != null)
            {
                bool success = AddImport(project.Name, project.Namespace.Name, typeOwnerName,
                                         JavaConventionHelper.packageConvention(project.Namespace.Name) + ".entities", entity.Name, isFileGenerationNeeded(project, entity));
                if (success)
                {
                    foreach (var attr in entity.Properties)
                    {
                        SoalType     attrToType = attr.Type as SoalType;
                        Symbols.Enum attrToEnum = attr.Type as Symbols.Enum;

                        if (attrToEnum != null)
                        {
                            AddImport(project.Name, project.Namespace.Name, entity.Name,
                                      JavaConventionHelper.packageConvention(project.Namespace.Name) + ".enums", attrToEnum.Name, isFileGenerationNeeded(project, attrToEnum));
                        }
                        else if (attrToType != null)
                        {
                            AnalyseSoalType(project, entity.Name, attrToType);
                        }
                    }
                }
            }
            else if (primitiv != null)
            {
                string importString = JavaImportConfigHandler.getValue(JavaTypeConfigHandler.SwitchTypeName(primitiv.MName));
                if (importString != null)
                {
                    string importPackage    = importString.Substring(0, importString.LastIndexOf("."));
                    string importObjectName = importString.Substring(importString.LastIndexOf(".") + 1);
                    AddImport(project.Name, project.Namespace.Name, typeOwnerName, importPackage, importObjectName, false);
                }
            }
        }
예제 #2
0
        public static void PrintEnum(Symbols.Enum en, string root)
        {
            string packageDirectory = Path.Combine(root, JavaConventionHelper.packageConvention(en.Namespace.Name));
            string enumDirectory    = Path.Combine(packageDirectory, "enums");

            Directory.CreateDirectory(enumDirectory);
            using (StreamWriter writer = new StreamWriter(Path.Combine(enumDirectory, en.Name + ".java")))
            {
                EnumGenerator javaGen = new EnumGenerator();
                writer.WriteLine(javaGen.Generate(en));
            }
        }
예제 #3
0
        private void PrepareGeneration()
        {
            HashSet <string> prefixes = new HashSet <string>();

            prefixes.Add("xs");
            prefixes.Add("wsdl");
            prefixes.Add("soap");
            prefixes.Add("soap12");
            prefixes.Add("wsp");
            prefixes.Add("wsu");
            prefixes.Add("wsoma");
            prefixes.Add("wsam");
            prefixes.Add("wsaw");
            prefixes.Add("wsrmp");
            prefixes.Add("wsat");
            prefixes.Add("sp");
            prefixes.Add("wst");
            prefixes.Add("wsx");
            int prefixCounter     = 0;
            var namespaceBuilders = this.modelBuilder.Symbols.OfType <NamespaceBuilder>().ToList();

            foreach (var ns in namespaceBuilders)
            {
                if (ns.Uri != null)
                {
                    if (ns.Prefix == null || prefixes.Contains(ns.Prefix))
                    {
                        while (prefixes.Contains("ns" + prefixCounter))
                        {
                            ++prefixCounter;
                        }
                        ns.Prefix = "ns" + prefixCounter;
                    }
                }
            }
            this.Model = this.modelBuilder.ToImmutable();
            var namespaces = this.Model.Symbols.OfType <Namespace>().ToList();

            foreach (var ns in namespaces)
            {
                Dictionary <string, List <ISymbol> > typeNames = new Dictionary <string, List <ISymbol> >();
                if (ns.Uri != null)
                {
                    foreach (var decl in ns.Declarations)
                    {
                        Interface intf = decl as Interface;
                        if (intf != null && !intf.HasAnnotation(SoalAnnotations.NoWrap) && !intf.HasAnnotation(SoalAnnotations.Rpc))
                        {
                            foreach (var op in intf.Operations)
                            {
                                string         key     = op.Name;
                                List <ISymbol> symbols = null;
                                if (!typeNames.TryGetValue(key, out symbols))
                                {
                                    symbols = new List <ISymbol>();
                                    typeNames.Add(key, symbols);
                                }
                                symbols.Add((ISymbol)op);
                                key     = op.Name + "Response";
                                symbols = null;
                                if (!typeNames.TryGetValue(key, out symbols))
                                {
                                    symbols = new List <ISymbol>();
                                    typeNames.Add(key, symbols);
                                }
                                symbols.Add((ISymbol)op);
                            }
                        }
                        Struct stype = decl as Struct;
                        if (stype != null)
                        {
                            string         key     = stype.GetXsdName();
                            List <ISymbol> symbols = null;
                            if (!typeNames.TryGetValue(key, out symbols))
                            {
                                symbols = new List <ISymbol>();
                                typeNames.Add(key, symbols);
                            }
                            symbols.Add((ISymbol)stype);
                        }
                        Symbols.Enum etype = decl as Symbols.Enum;
                        if (etype != null)
                        {
                            string         key     = etype.GetXsdName();
                            List <ISymbol> symbols = null;
                            if (!typeNames.TryGetValue(key, out symbols))
                            {
                                symbols = new List <ISymbol>();
                                typeNames.Add(key, symbols);
                            }
                            symbols.Add((ISymbol)etype);
                        }
                    }
                    foreach (var key in typeNames.Keys)
                    {
                        List <ISymbol> symbols = typeNames[key];
                        if (symbols.Count > 1)
                        {
                            foreach (var symbol in symbols)
                            {
                                this.AddDiagnostic(symbol, SoalGeneratorErrorCode.XsdTypeDefinedMultipleTimes, key);
                            }
                        }
                    }
                }
            }
            foreach (var ns in namespaces)
            {
                if (ns.Uri != null)
                {
                    foreach (var decl in ns.Declarations)
                    {
                        Interface intf = decl as Interface;
                        if (intf != null)
                        {
                            foreach (var op in intf.Operations)
                            {
                                this.CheckXsdNamespace(op.Result.Type, (ISymbol)op);
                                foreach (var param in op.Parameters)
                                {
                                    this.CheckXsdNamespace(param.Type, (ISymbol)param);
                                }
                            }
                        }
                        Struct stype = decl as Struct;
                        if (stype != null)
                        {
                            foreach (var prop in stype.Properties)
                            {
                                this.CheckXsdNamespace(prop.Type, (ISymbol)prop);
                            }
                        }
                    }
                }
            }
        }