コード例 #1
0
        internal override void CommandOperation()
        {
            oldType           = PSMAttribute.Type;
            PSMAttribute.Type = Type;

            oldAlias = PSMAttribute.Alias;
            if (Alias != null)
            {
                PSMAttribute.Alias = Alias;
            }

            oldLower = PSMAttribute.Lower;
            oldUpper = PSMAttribute.Upper;

            if (customMultiplicity)
            {
                PSMAttribute.Lower = Lower;
                PSMAttribute.Upper = Upper;
            }

            oldDefault           = PSMAttribute.Default;
            PSMAttribute.Default = Default;

            oldName           = PSMAttribute.Name;
            PSMAttribute.Name = Name;

            AssociatedElements.Add(PSMAttribute.Class);
        }
コード例 #2
0
        public void AddNewAttribute(string attributeName, DataType type, uint?lower, UnlimitedNatural?upper, string @default)
        {
            NewAttributeCommand c = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController);

            if (!String.IsNullOrEmpty(attributeName))
            {
                c.Name = attributeName;
            }
            else
            {
                c.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name);
            }
            c.Type = new ElementHolder <DataType> {
                Element = type
            };
            c.Lower   = lower;
            c.Upper   = upper;
            c.Default = @default;
            c.Owner   = Class;
            c.Execute();
        }
コード例 #3
0
        /// <summary>
        /// Writes type attribute
        /// </summary>
        /// <param name="property">property whose <see cref="Model.TypedElement.Type"/> attribute is being written</param>
        /// <param name="simpleTypeWriter">writer where simple type definition is written if the type was not
        /// yet used</param>
        /// <param name="useOccurs">if set to true, minOccurs and maxOccurs attributes are also written if
        /// <paramref name="property"/> multipicity is non-default</param>
        /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and
        /// use="optional" is written.</param>
        public void TypeAttribute(Property property, ref SimpleTypesWriter simpleTypeWriter, bool useOccurs, bool forceOptional)
        {
            DataType type = property.Type;

            if (type == null)
            {
                Writer.WriteAttributeString("type", "xs:string");
                Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property));
            }
            else
            {
                SimpleDataType simpleType = type as SimpleDataType;
                if (simpleType != null)
                {
                    if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation))
                    {
                        if (simpleType.Parent != null)
                        {
                            simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType);
                            Writer.WriteAttributeString("type", simpleType.Name);
                        }
                        else
                        {
                            Writer.WriteAttributeString("type", NamespacePrefix + ":" + simpleType.DefaultXSDImplementation);
                        }
                    }
                    else
                    {
                        if (type is SimpleDataType)
                        {
                            Writer.WriteAttributeString("type", NamespacePrefix + ":" + type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                        else
                        {
                            Writer.WriteAttributeString("type", type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                    }
                }
                else
                {
                    Writer.WriteAttributeString("type", type.ToString());
                }
            }
            if (!String.IsNullOrEmpty(property.Default))
            {
                Writer.WriteAttributeString("default", property.Default);
            }
            if (forceOptional)
            {
                Writer.WriteAttributeString("use", "optional");
            }
            else
            {
                if (!useOccurs)
                {
                    if (property.Lower == 0 || property.Lower == null)
                    {
                        Writer.WriteAttributeString("use", "optional");
                        if (property.Upper > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                    }
                    else
                    {
                        if (property.Upper > 1 || property.Lower > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                        if (String.IsNullOrEmpty(property.Default))
                        {
                            Writer.WriteAttributeString("use", "required");
                        }
                    }
                }
                else
                {
                    MultiplicityAttributes(property.Lower, property.Upper);
                }
            }
            IsEmpty = false;
            AfterWriteDebug();
        }
コード例 #4
0
ファイル: PSM_ClassController.cs プロジェクト: mff-uk/xcase
        public void ModifyAttribute(PSMAttribute attribute, string name, string alias, uint?lower, UnlimitedNatural upper, DataType type, string @default)
        {
            ModifyPSMClassAttributeCommand c = (ModifyPSMClassAttributeCommand)ModifyPSMClassAttributeCommandFactory.Factory().Create(DiagramController);

            c.PSMAttribute = attribute;
            c.Alias        = alias;
            c.Name         = name;
            c.Lower        = lower;
            c.Upper        = upper;
            c.Type         = type;
            c.Default      = @default;
            c.Execute();
        }
コード例 #5
0
ファイル: PSM_ClassController.cs プロジェクト: mff-uk/xcase
        public PSMAttribute AddAttribute(Property representedAttribute, string name, string alias, uint?lower, UnlimitedNatural upper, DataType type, string @default, IEnumerable <string> names)
        {
            AddPSMClassAttributeCommand c = (AddPSMClassAttributeCommand)AddPSMClassAttributeCommandFactory.Factory().Create(DiagramController);

            c.PSMClass             = Class;
            c.Alias                = alias;
            c.Name                 = name;
            c.Lower                = lower;
            c.Upper                = upper;
            c.Type                 = type;
            c.Default              = @default;
            c.RepresentedAttribute = representedAttribute;
            c.UsedAliasesOrNames   = names;
            c.Execute();

            return(c.CreatedAttribute);
        }
コード例 #6
0
ファイル: XsdDocument.cs プロジェクト: mff-uk/xcase
        public void typeAttribute(Property property, XmlElement targetElement, bool useOccurs, bool forceOptional)
        {
            DataType type = property.Type;

            if (type == null)
            {
                targetElement.SetAttribute("type", "xs:string");
                Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property));
            }
            else
            {
                SimpleDataType simpleType = type as SimpleDataType;
                if (simpleType != null)
                {
                    if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation))
                    {
                        if (simpleType.Parent != null)
                        {
                            //todo: simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType);
                            targetElement.SetAttribute("type", simpleType.Name);
                        }
                        else
                        {
                            targetElement.SetAttribute("type", "xs" + ":" + simpleType.DefaultXSDImplementation);
                        }
                    }
                    else
                    {
                        if (type is SimpleDataType)
                        {
                            targetElement.SetAttribute("type", "xs" + ":" + type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                        else
                        {
                            targetElement.SetAttribute("type", type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                    }
                }
                else
                {
                    targetElement.SetAttribute("type", type.ToString());
                }
            }
            if (!String.IsNullOrEmpty(property.Default))
            {
                targetElement.SetAttribute("default", property.Default);
            }
            if (forceOptional)
            {
                targetElement.SetAttribute("use", "optional");
            }
            else
            {
                if (!useOccurs)
                {
                    if (property.Lower == 0 || property.Lower == null)
                    {
                        targetElement.SetAttribute("use", "optional");
                        if (property.Upper > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                    }
                    else
                    {
                        if (property.Upper > 1 || property.Lower > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                        if (String.IsNullOrEmpty(property.Default))
                        {
                            targetElement.SetAttribute("use", "required");
                        }
                    }
                }
                else
                {
                    this.multiplicityAttributes(targetElement, property.Lower, property.Upper);
                }
            }
        }