Esempio n. 1
0
 public static Namespace GetNamespace(this SoalType type, Namespace currentNamespace)
 {
     if (type is PrimitiveType)
     {
         return(SoalGenerator.XsdNamespace);
     }
     if (type is NullableType)
     {
         return(GetNamespace(((NullableType)type).InnerType, currentNamespace));
     }
     if (type is ArrayType)
     {
         if (((ArrayType)type).InnerType.MId == SoalInstance.Byte.MId)
         {
             return(SoalGenerator.XsdNamespace);
         }
         else
         {
             return(currentNamespace);
         }
     }
     if (type is Enum)
     {
         Enum etype = (Enum)type;
         return(etype.Namespace);
     }
     if (type is Struct)
     {
         Struct stype = (Struct)type;
         return(stype.Namespace);
     }
     return(null);
 }
Esempio n. 2
0
 private void CheckXsdNamespace(SoalType type, ISymbol symbol)
 {
     if (!type.HasXsdNamespace())
     {
         this.AddDiagnostic(symbol, SoalGeneratorErrorCode.TypeHasNoXsdNamespace);
     }
 }
Esempio n. 3
0
 public static bool IsNullable(this SoalType type)
 {
     if (type is NonNullableType)
     {
         return(false);
     }
     if (type is NullableType)
     {
         return(true);
     }
     if (type is PrimitiveType)
     {
         return(((PrimitiveType)type).Nullable);
     }
     if (type is ArrayType)
     {
         return(true);
     }
     if (type is Enum)
     {
         return(false);
     }
     if (type is Struct)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        public static string GetEntityMappingString(this Struct me, SoalType field)
        {
            Struct property = field as Struct;
            if (property != null && property.IsEntity())
            {
                // field typed entity is conatied in me
                string mapping = "@OneToOne";

                foreach (Property prop in property.Properties)
                {
                    SoalType type = prop.Type;
                    if (type.Equals(me))
                    {
                        return mapping;
                    }

                    ArrayType foraignArray = type as ArrayType;
                    if (foraignArray != null)
                    {
                        if (foraignArray.InnerType.Equals(me))
                        {
                            return "@ManyToOne";
                        }
                    }
                }
                return mapping;
            }

            ArrayType array = field as ArrayType;
            if (array != null)
            {
                Struct innerProperty = array.InnerType as Struct;
                if (innerProperty != null && innerProperty.IsEntity())
                {
                    // I have a list of an entity
                    string mapping = "@OneToMany";

                    foreach (Property prop in innerProperty.Properties)
                    {
                        SoalType type = prop.Type;
                        if (type.Equals(me))
                        {
                            return mapping + "(mappedBy=\"" + prop.Name.ToCamelCase() + "\")";
                        }

                        ArrayType foraignArray = type as ArrayType;
                        if (foraignArray != null)
                        {
                            if (foraignArray.InnerType.Equals(me))
                            {
                                return "@ManyToMany // TODO add @JoinTable";
                            }
                        }
                    }

                    return mapping + " // TODO add @JoinColumn";
                }
            }
            return "";
        }
Esempio n. 5
0
 public static bool HasXsdNamespace(this SoalType type)
 {
     if (type is PrimitiveType)
     {
         return(true);
     }
     if (type is NullableType)
     {
         return(HasXsdNamespace(((NullableType)type).InnerType));
     }
     if (type is NonNullableType)
     {
         return(HasXsdNamespace(((NonNullableType)type).InnerType));
     }
     if (type is ArrayType)
     {
         return(HasXsdNamespace(((ArrayType)type).InnerType));
     }
     if (type is Enum)
     {
         Enum etype = (Enum)type;
         return(etype.Namespace != null && etype.Namespace.Uri != null);
     }
     if (type is Struct)
     {
         Struct stype = (Struct)type;
         return(stype.Namespace != null && stype.Namespace.Uri != null);
     }
     return(false);
 }
Esempio n. 6
0
 private static void CheckArrayType(SoalType type, IList <Annotation> annotations, HashSet <string> arrayNames, List <ArrayType> arrayTypes)
 {
     if (annotations.Any(a => a.Name == SoalAnnotations.Element && !(bool)a.GetPropertyValue(SoalAnnotationProperties.Wrapped)))
     {
         return;
     }
     if (type is ArrayType)
     {
         ArrayType atype = (ArrayType)type;
         string    aname = atype.GetXsdName();
         if (atype.InnerType != SoalInstance.Byte && !arrayNames.Contains(aname))
         {
             arrayNames.Add(aname);
             arrayTypes.Add(atype);
         }
     }
     else if (type is NonNullableType)
     {
         ArrayType atype = ((NonNullableType)type).InnerType as ArrayType;
         if (atype != null)
         {
             string aname = atype.GetXsdName();
             if (atype.InnerType != SoalInstance.Byte && !arrayNames.Contains(aname))
             {
                 arrayNames.Add(aname);
                 arrayTypes.Add(atype);
             }
         }
     }
 }
Esempio n. 7
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);
                }
            }
        }
Esempio n. 8
0
 bool isFileGenerationNeeded(Component project, SoalType type)
 {
     foreach (var dec in project.Namespace.Declarations)
     {
         Struct obj = dec as Struct;
         if (obj != null)
         {
             if (obj.Name.Equals(type.MName))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 9
0
 public static SoalType GetCoreType(this SoalType type)
 {
     if (type == null)
     {
         return(null);
     }
     if (type is NullableType)
     {
         return(((NullableType)type).InnerType.GetCoreType());
     }
     if (type is ArrayType)
     {
         return(((ArrayType)type).InnerType.GetCoreType());
     }
     return(type);
 }
Esempio n. 10
0
 public static bool IsArrayType(this SoalType type)
 {
     if (type == null)
     {
         return(false);
     }
     if (type is NullableType)
     {
         return(((NullableType)type).InnerType.IsArrayType());
     }
     if (type is ArrayType)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 11
0
        public static string classNameConvention(SoalType c)
        {
            ArrayType at = c as ArrayType;

            if (c.MName != null)
            {
                return(JavaTypeConfigHandler.SwitchTypeName(c.MName));
            }
            else if (at.InnerType != null)
            {
                return(JavaTypeConfigHandler.SwitchTypeName(at.MMetaClass.Name) + "<" + JavaTypeConfigHandler.SwitchTypeName(at.InnerType.MName) + ">");
            }
            else
            {
                return("UNKNOWN_TYPE");
            }
        }
Esempio n. 12
0
 private void CheckXsdNamespace(SoalType type, ModelObject symbol)
 {
     if (!type.HasXsdNamespace())
     {
         this.Diagnostics.AddError("The type of this element has no XSD namespace.", this.FileName, symbol);
     }
 }
Esempio n. 13
0
 private SoalType ImportPhase2SimpleType(SoalType type, XElement elem)
 {
     XAttribute nameAttr = elem.Attribute("name");
     XAttribute typeAttr = elem.Attribute("type");
     XElement restriction = elem.Element(xsd + "restriction");
     if (restriction != null)
     {
         XAttribute baseAttr = restriction.Attribute("base");
         if (baseAttr != null)
         {
             XName baseRef = this.GetXName(restriction, baseAttr.Value);
             if (baseRef == null)
             {
                 return null;
             }
             SoalType baseType = this.Importer.ResolveXsdType(baseRef);
             if (baseType == null)
             {
                 this.Importer.Diagnostics.AddError("Could not resolve type '" + baseAttr.Value + "'.", this.Uri, this.GetTextSpan(baseAttr));
                 return null;
             }
             Enum enm = type as Enum;
             if (enm != null)
             {
                 string name = enm.Name;
                 if (baseType is Enum)
                 {
                     enm.BaseType = (Enum)baseType;
                 }
                 IEnumerable<XElement> enums = restriction.Elements(xsd + "enumeration");
                 foreach (var enumValue in enums)
                 {
                     XAttribute valueAttr = enumValue.Attribute("value");
                     if (valueAttr != null)
                     {
                         string value = valueAttr.Value;
                         EnumLiteral enmLit = SoalFactory.Instance.CreateEnumLiteral();
                         string newValue = this.GetNewEnumLiteralName(enm, value);
                         enmLit.Name = newValue;
                         enm.EnumLiterals.Add(enmLit);
                         if (value != newValue)
                         {
                             enmLit.SetAnnotationPropertyValue(SoalAnnotations.Enum, SoalAnnotationProperties.Name, value);
                         }
                     }
                     else
                     {
                         this.Importer.Diagnostics.AddError("The enumeration has no 'value' attribute.", this.Uri, this.GetTextSpan(restriction));
                         return null;
                     }
                 }
                 return enm;
             }
             else
             {
                 SoalImporter.CopyAnnotations(baseType as AnnotatedElement, type as AnnotatedElement);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.Pattern);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.Length);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.MinLength);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.MaxLength);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.MinInclusive);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.MinExclusive);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.MaxInclusive);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.MaxExclusive);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.TotalDigits);
                 this.ProcessXsdRestriction(type, restriction, SoalAnnotationProperties.FractionDigits);
                 this.Importer.RegisterReplacementType(type, baseType);
                 return type;
             }
         }
         else
         {
             return null;
         }
     }
     else
     {
         return null;
     }
 }
Esempio n. 14
0
 private void ProcessXsdRestriction(SoalType type, XElement elem, string restrictionName)
 {
     XElement restrElem = elem.Element(xsd + restrictionName);
     if (restrElem != null)
     {
         XAttribute valueAttr = restrElem.Attribute("value");
         if (valueAttr != null)
         {
             AnnotatedElement ae = type as AnnotatedElement;
             if (ae != null)
             {
                 long longValue = 0;
                 if (restrictionName == SoalAnnotationProperties.Pattern)
                 {
                     ae.SetAnnotationPropertyValue(SoalAnnotations.Restriction, restrictionName, valueAttr.Value);
                 }
                 else if (long.TryParse(valueAttr.Value, out longValue))
                 {
                     ae.SetAnnotationPropertyValue(SoalAnnotations.Restriction, restrictionName, longValue);
                 }
                 else
                 {
                     ae.SetAnnotationPropertyValue(SoalAnnotations.Restriction, restrictionName, valueAttr.Value);
                 }
             }
         }
     }
 }
Esempio n. 15
0
        private static List<SoalType> HandleArrayType(SoalType type)
        {
            List<SoalType> result = new List<SoalType>();
            ArrayType array = type as ArrayType;
            if (array != null)
            {
                if (array.InnerType != SoalInstance.Byte)
                {
                    result.Add(array);
                    result.Add(array.InnerType);
                }
            }
            else
            {
                result.Add(type);
            }

            return result;
        }
Esempio n. 16
0
 private static string SubPackage(SoalType type)
 {
     if (type is Interface)
     {
         Interface iface = type as Interface;
         if (iface.Name.Contains("Repository"))
         {
             return ".repository";
         }
         else
         {
             return ".interfaces";
         }
     }
     if (type is Enum)
         return ".enums";
     Struct str = type as Struct;
     if (str != null)
     {
         if (str.IsException())
             return ".exception";
         if (str.IsEntity())
             return ".entity";
     }
     return null;
 }
Esempio n. 17
0
 private static void CheckArrayType(SoalType type, IList<Annotation> annotations, HashSet<string> arrayNames, List<ArrayType> arrayTypes)
 {
     if (annotations.Any(a => a.Name == SoalAnnotations.Element && !(bool)a.GetPropertyValue(SoalAnnotationProperties.Wrapped))) return;
     if (type is ArrayType)
     {
         ArrayType atype = (ArrayType)type;
         string aname = atype.GetXsdName();
         if (atype.InnerType != SoalInstance.Byte && !arrayNames.Contains(aname))
         {
             arrayNames.Add(aname);
             arrayTypes.Add(atype);
         }
     }
     else if (type is NonNullableType)
     {
         ArrayType atype = ((NonNullableType)type).InnerType as ArrayType;
         if (atype != null)
         {
             string aname = atype.GetXsdName();
             if (atype.InnerType != SoalInstance.Byte && !arrayNames.Contains(aname))
             {
                 arrayNames.Add(aname);
                 arrayTypes.Add(atype);
             }
         }
     }
 }
Esempio n. 18
0
        internal SoalTypeBuilder ResolveXsdPrimitiveType(XName name)
        {
            if (name.NamespaceName == XsdReader.XsdNamespace)
            {
                SoalType        result          = null;
                SoalTypeBuilder resultAsBuilder = null;
                switch (name.LocalName)
                {
                case "any": result = SoalInstance.Object; break;

                case "anySimpleType": result = SoalInstance.Object; break;

                case "string": result = SoalInstance.String; break;

                case "anyURI": result = SoalInstance.String; break;

                case "QName": result = SoalInstance.String; break;

                case "NOTATION": result = SoalInstance.String; break;

                case "normalizedString": result = SoalInstance.String; break;

                case "token": result = SoalInstance.String; break;

                case "language": result = SoalInstance.String; break;

                case "Name": result = SoalInstance.String; break;

                case "NCName": result = SoalInstance.String; break;

                case "NMTOKEN": result = SoalInstance.String; break;

                case "NMTOKENS": result = SoalInstance.String; break;

                case "ID": result = SoalInstance.String; break;

                case "IDREF": result = SoalInstance.String; break;

                case "IDREFS": result = SoalInstance.String; break;

                case "ENTITY": result = SoalInstance.String; break;

                case "ENTITIES": result = SoalInstance.String; break;

                case "integer": result = SoalInstance.Int; break;

                case "nonPositiveInteger": result = SoalInstance.Int; break;

                case "negativeInteger": result = SoalInstance.Int; break;

                case "int": result = SoalInstance.Int; break;

                case "short": result = SoalInstance.Int; break;

                case "nonNegativeInteger": result = SoalInstance.Int; break;

                case "positiveInteger": result = SoalInstance.Int; break;

                case "unsignedInt": result = SoalInstance.Int; break;

                case "unsignedShort": result = SoalInstance.Int; break;

                case "long": result = SoalInstance.Long; break;

                case "unsignedLong": result = SoalInstance.Int; break;

                case "float": result = SoalInstance.Float; break;

                case "double": result = SoalInstance.Double; break;

                case "decimal": result = SoalInstance.Double; break;

                case "byte": result = SoalInstance.Byte; break;

                case "unsignedByte": result = SoalInstance.Byte; break;

                case "base64Binary": resultAsBuilder = this.byteArray; break;

                case "hexBinary": resultAsBuilder = this.byteArray; break;

                case "bool": result = SoalInstance.Bool; break;

                case "boolean": result = SoalInstance.Bool; break;

                case "time": result = SoalInstance.Time; break;

                case "date": result = SoalInstance.Date; break;

                case "dateTime": result = SoalInstance.DateTime; break;

                case "duration": result = SoalInstance.TimeSpan; break;

                case "gDay": result = SoalInstance.Date; break;

                case "gMonth": result = SoalInstance.Date; break;

                case "gMonthDay": result = SoalInstance.Date; break;

                case "gYear": result = SoalInstance.Date; break;

                case "gYearMonth": result = SoalInstance.Date; break;

                default:
                    break;
                }
                if (resultAsBuilder == null && result != null)
                {
                    resultAsBuilder = result.ToMutable();
                }
                return(resultAsBuilder);
            }
            return(null);
        }
Esempio n. 19
0
 public static string IsNullableXsd(this SoalType type)
 {
     return(type.IsNullable().ToString().ToLower());
 }
Esempio n. 20
0
 /// <summary>
 /// Implements the constructor: SoalType()
 /// </summary>
 public virtual void SoalType(SoalType @this)
 {
 }
Esempio n. 21
0
 public static bool IsNullable(this SoalType type)
 {
     return(type is NullableType);
 }
Esempio n. 22
0
        public static string GetXsdName(this SoalType type)
        {
            if (type is PrimitiveType)
            {
                string name = ((PrimitiveType)type).Name;
                switch (name)
                {
                case "int":
                case "long":
                case "float":
                case "double":
                case "string":
                case "byte":
                    return(name);

                case "object":
                    return("anyType");

                case "bool":
                    return("boolean");

                case "Date":
                    return("date");

                case "Time":
                    return("time");

                case "DateTime":
                    return("dateTime");

                case "TimeSpan":
                    return("duration");

                default:
                    break;
                }
            }
            if (type is NullableType)
            {
                return(GetXsdName(((NullableType)type).InnerType));
            }
            if (type is NonNullableType)
            {
                return(GetXsdName(((NonNullableType)type).InnerType));
            }
            if (type is ArrayType)
            {
                if (((ArrayType)type).InnerType == SoalInstance.Byte)
                {
                    return("base64Binary");
                }
                else
                {
                    return((GetXsdName(((ArrayType)type).InnerType) + "List").ToPascalCase());
                }
            }
            if (type is Enum)
            {
                Enum   etype   = (Enum)type;
                string newName = etype.GetAnnotationPropertyValue(SoalAnnotations.Type, SoalAnnotationProperties.Name) as string;
                return(newName ?? etype.Name);
            }
            if (type is Struct)
            {
                Struct stype   = (Struct)type;
                string newName = stype.GetAnnotationPropertyValue(SoalAnnotations.Type, SoalAnnotationProperties.Name) as string;
                return(newName ?? stype.Name);
            }
            return(null);
        }
Esempio n. 23
0
 private Property ImportPhase4ElementProperty(Struct st, SoalType rt, XElement elem, bool attribute)
 {
     XAttribute refAttr = elem.Attribute("ref");
     XAttribute nameAttr = elem.Attribute("name");
     XAttribute typeAttr = elem.Attribute("type");
     bool required = false;
     XAttribute useAttr = elem.Attribute("use");
     if (useAttr != null && useAttr.Value == "required")
     {
         required = true;
     }
     bool sap = false;
     ArrayType sapArray = null;
     string sapName = null;
     string name = null;
     SoalType type = null;
     if (refAttr != null)
     {
         XName refName = this.GetXName(elem, refAttr.Value);
         XElement originalElem = null;
         if (refName != null)
         {
             if (attribute)
             {
                 originalElem = this.Importer.XsdAttributes.GetX(refName);
             }
             else
             {
                 originalElem = this.Importer.XsdElements.GetX(refName);
             }
         }
         if (originalElem != null)
         {
             name = refName.LocalName;
             if (attribute)
             {
                 type = this.Importer.XsdAttributes.Get(refName);
                 useAttr = originalElem.Attribute("use");
                 if (useAttr != null && useAttr.Value == "required")
                 {
                     required = true;
                 }
             }
             else
             {
                 type = this.Importer.XsdElements.Get(refName);
             }
             if (type == null)
             {
                 this.Importer.Diagnostics.AddError("Could not resolve type '" + refAttr.Value + "'.", this.Uri, this.GetTextSpan(refAttr));
                 return null;
             }
         }
         else
         {
             this.Importer.Diagnostics.AddError("Could not resolve the reference.", this.Uri, this.GetTextSpan(refAttr));
             return null;
         }
     }
     else
     {
         if (nameAttr != null)
         {
             name = nameAttr.Value;
         }
         if (name == null)
         {
             this.Importer.Diagnostics.AddError("The element has no name.", this.Uri, this.GetTextSpan(elem));
             return null;
         }
         if (typeAttr == null)
         {
             XElement simpleType = elem.Element(xsd + "simpleType");
             XElement complexType = elem.Element(xsd + "complexType");
             string typeName = this.GetUniqueName(name, true);
             if (simpleType != null)
             {
                 type = this.ImportPhase1SimpleType(simpleType, typeName, attribute ? XsdTypeKind.Attribute : XsdTypeKind.Element, elem, false);
                 type = this.ImportPhase2SimpleType(type, simpleType);
             }
             else if (complexType != null)
             {
                 type = this.ImportPhase1ComplexType(complexType, typeName, attribute ? XsdTypeKind.Attribute : XsdTypeKind.Element, elem, false);
                 Struct childSt = type as Struct;
                 if (childSt != null)
                 {
                     type = this.ImportPhase2ComplexType(childSt, complexType);
                     childSt = type as Struct;
                     if (childSt != null)
                     {
                         type = this.ImportPhase4ComplexType(childSt, complexType);
                         childSt = type as Struct;
                         if (name == "item" && childSt != null && childSt.HasAnnotation(SoalAnnotations.All) && childSt.Properties.Count == 1)
                         {
                             SoalType innerType = childSt.Properties[0].Type;
                             if (innerType.IsArrayType())
                             {
                             }
                             else
                             {
                                 sap = true;
                                 sapName = childSt.Properties[0].Name;
                                 sapArray = SoalFactory.Instance.CreateArrayType();
                                 sapArray.InnerType = innerType;
                                 //this.Importer.RegisterReplacementType(type, sapArray);
                                 this.Importer.RemoveType(type);
                             }
                         }
                     }
                 }
             }
             else
             {
                 this.Importer.Diagnostics.AddError("The element has no type.", this.Uri, this.GetTextSpan(elem));
                 return null;
             }
         }
         else
         {
             XName typeRef = this.GetXName(elem, typeAttr.Value);
             if (typeRef == null)
             {
                 this.Importer.Diagnostics.AddError("Invalid type reference: '" + typeAttr.Value + "'", this.Uri, this.GetTextSpan(typeAttr));
                 return null;
             }
             type = this.Importer.XsdTypes.Get(typeRef) as SoalType;
             if (type == null)
             {
                 type = this.Importer.ResolveXsdPrimitiveType(typeRef) as SoalType;
             }
             if (type == null)
             {
                 this.Importer.Diagnostics.AddError("Could not resolve type '" + typeAttr.Value + "'.", this.Uri, this.GetTextSpan(typeAttr));
                 return null;
             }
         }
     }
     SoalType originalType = type;
     type = this.Importer.ResolveXsdReplacementType(type);
     XAttribute nillableAttr = elem.Attribute("nillable");
     XAttribute minOccursAttr = elem.Attribute("minOccurs");
     XAttribute maxOccursAttr = elem.Attribute("maxOccurs");
     bool nillable = false;
     int minOccurs = 1;
     int maxOccurs = 1;
     if (nillableAttr != null)
     {
         nillable = nillableAttr.Value == "1" || nillableAttr.Value.ToLower() == "true";
     }
     if (minOccursAttr != null)
     {
         if (!int.TryParse(minOccursAttr.Value, out minOccurs))
         {
             minOccurs = 1;
         }
     }
     if (maxOccursAttr != null)
     {
         if (maxOccursAttr.Value.ToLower() == "unbounded")
         {
             maxOccurs = -1;
         }
         else if (!int.TryParse(maxOccursAttr.Value, out maxOccurs))
         {
             maxOccurs = 1;
         }
     }
     if (type is PrimitiveType)
     {
         if (nillable && type != SoalInstance.Object && type != SoalInstance.String)
         {
             NullableType nullable = SoalFactory.Instance.CreateNullableType();
             nullable.InnerType = type;
             type = nullable;
         }
         else if (!nillable && (type == SoalInstance.Object || type == SoalInstance.String))
         {
             NonNullableType nonNull = SoalFactory.Instance.CreateNonNullableType();
             nonNull.InnerType = type;
             type = nonNull;
         }
     }
     else
     {
         if (!nillable)
         {
             NonNullableType nonNull = SoalFactory.Instance.CreateNonNullableType();
             nonNull.InnerType = type;
             type = nonNull;
         }
     }
     Property prop = SoalFactory.Instance.CreateProperty();
     string newName = this.GetNewPropertyName(st, name);
     prop.Name = newName;
     if (attribute)
     {
         prop.Type = type;
         Annotation attrAnnot = prop.AddAnnotation(SoalAnnotations.Attribute);
         if (required)
         {
             attrAnnot.SetPropertyValue(SoalAnnotationProperties.Required, true);
         }
         if (newName != name)
         {
             attrAnnot.SetPropertyValue(SoalAnnotationProperties.Name, name);
         }
     }
     else
     {
         if (newName != name)
         {
             Annotation elemAnnot = prop.AddAnnotation(SoalAnnotations.Element);
             elemAnnot.SetPropertyValue(SoalAnnotationProperties.Name, name);
         }
         if (rt != null && rt is ArrayType)
         {
             if (sap)
             {
                 ((ArrayType)rt).InnerType = sapArray.InnerType;
                 this.Importer.RegisterReplacementType(type, rt);
                 Annotation arrayAnnot = st.AddAnnotation(SoalAnnotations.Type);
                 arrayAnnot.SetPropertyValue(SoalAnnotationProperties.Wrapped, true);
                 arrayAnnot.SetPropertyValue(SoalAnnotationProperties.Items, sapName);
                 arrayAnnot.SetPropertyValue(SoalAnnotationProperties.Sap, true);
             }
             else
             {
                 if (type.IsArrayType())
                 {
                     type = originalType;
                     this.Importer.Reference(type);
                 }
                 ((ArrayType)rt).InnerType = type;
                 SoalType coreType = type.GetCoreType();
                 Annotation arrayAnnot = st.AddAnnotation(SoalAnnotations.Type);
                 arrayAnnot.SetPropertyValue(SoalAnnotationProperties.Wrapped, true);
                 if (coreType is NamedElement && ((NamedElement)coreType).Name != prop.Name)
                 {
                     arrayAnnot.SetPropertyValue(SoalAnnotationProperties.Items, prop.Name);
                 }
             }
             prop.Type = rt;
         }
         else
         {
             if (maxOccurs < 0 || maxOccurs > 1)
             {
                 ArrayType array = SoalFactory.Instance.CreateArrayType();
                 array.InnerType = type;
                 type = array;
             }
             prop.Type = type;
         }
         if (minOccurs == 0 && maxOccurs == 1)
         {
             prop.SetAnnotationPropertyValue(SoalAnnotations.Element, SoalAnnotationProperties.Optional, true);
         }
     }
     this.Importer.RegisterOriginalType((ModelObject)prop, originalType);
     st.Properties.Add(prop);
     return prop;
 }