/// <summary>
        /// Adds a constructor based on the gSOAP proxy to a given Energistics class
        /// </summary>
        /// <param name="energisticsClass">An Energistics class</param>
        /// <param name="fesapiBaseClass">Correspondinf fesapi base class if exists else null</param>
        private void addFromGsoapConstructor(EA.Element energisticsClass, EA.Element fesapiBaseClass)
        {
            // adding a new constructor, basically a method named whith the Energistics class name
            EA.Method fesapiConstructor = energisticsClass.Methods.AddNew(energisticsClass.Name, "");
            if (!(fesapiConstructor.Update()))
            {
                Tool.showMessageBox(repository, fesapiConstructor.GetLastError());
            }
            energisticsClass.Methods.Refresh();

            // adding the gSOAP proxy parameter
            string fesapiConstructorParamType = "gsoap_resqml2_0_1::resqml2__" + energisticsClass.Name + "*";

            EA.Parameter fesapiConstructParam = fesapiConstructor.Parameters.AddNew("fromGsoap", fesapiConstructorParamType);
            if (!(fesapiConstructParam.Update()))
            {
                Tool.showMessageBox(repository, fesapiConstructParam.GetLastError());
            }
            fesapiConstructor.Parameters.Refresh();

            // adding a tag sepcifying that the body will be located into the class declaration
            EA.MethodTag fesapiConstructorBodyLocationTag = fesapiConstructor.TaggedValues.AddNew("bodyLocation", "classDec");
            if (!(fesapiConstructorBodyLocationTag.Update()))
            {
                Tool.showMessageBox(repository, fesapiConstructorBodyLocationTag.GetLastError());
            }

            // if there exists a correspondinf fesapi base class, we add the proper initialization directive
            if (fesapiBaseClass != null)
            {
                string       initializerTagValue = fesapiBaseClass.Name + "(fromGsoap)";
                EA.MethodTag initializerTag      = fesapiConstructor.TaggedValues.AddNew("initializer", initializerTagValue);
                if (!(initializerTag.Update()))
                {
                    Tool.showMessageBox(repository, initializerTag.GetLastError());
                }
            }
            fesapiConstructor.TaggedValues.Refresh();

            // adding constructor notes
            fesapiConstructor.Notes = "Creates an instance of this class by wrapping a gsoap instance.";
            if (!(fesapiConstructor.Update()))
            {
                Tool.showMessageBox(repository, fesapiConstructor.GetLastError());
            }
        }
        /// <summary>
        /// This method basically copy the content of a fesapi class into an Energistics class.
        /// Attributes, methods, tags and notes are handled.
        /// Important notes:
        /// - common attributes and tags (according to their name) existing content will be erased
        /// - existing notes will be erased during this process
        /// </summary>
        /// <param name="fesapiClass">A source fesapi class</param>
        /// <param name="energisticsClass">A target Energistics class</param>
        private void copyClassContent(EA.Element fesapiClass, EA.Element energisticsClass)
        {
            // -------------------
            // -------------------
            // attributes handling

            // for each fesapi attribute, if a corresponding Energistics attritute exists
            // (that is to say if the Energistics class contains an attribute with the same name)
            // we copy the fesapi attribute content into the Energistics attribute content else we create from scratch
            // an Energistics attribute
            foreach (EA.Attribute fesapiAttribute in fesapiClass.Attributes)
            {
                EA.Attribute correspondingEnergisticsAttribute = null;
                foreach (EA.Attribute a in energisticsClass.Attributes)
                {
                    if (a.Name == fesapiAttribute.Name)
                    {
                        correspondingEnergisticsAttribute = a;
                        break;
                    }
                }

                // if there is no corresponding target attribute, we create one
                if (correspondingEnergisticsAttribute == null)
                {
                    correspondingEnergisticsAttribute = energisticsClass.Attributes.AddNew(fesapiAttribute.Name, fesapiAttribute.Type);
                    if (!(correspondingEnergisticsAttribute.Update()))
                    {
                        Tool.showMessageBox(repository, correspondingEnergisticsAttribute.GetLastError());
                        continue;
                    }
                    energisticsClass.Attributes.Refresh();
                }

                correspondingEnergisticsAttribute.Alias             = fesapiAttribute.Alias;
                correspondingEnergisticsAttribute.AllowDuplicates   = fesapiAttribute.AllowDuplicates;
                correspondingEnergisticsAttribute.ClassifierID      = fesapiAttribute.ClassifierID;
                correspondingEnergisticsAttribute.Container         = fesapiAttribute.Container;
                correspondingEnergisticsAttribute.Containment       = fesapiAttribute.Containment;
                correspondingEnergisticsAttribute.Default           = fesapiAttribute.Default;
                correspondingEnergisticsAttribute.IsCollection      = fesapiAttribute.IsCollection;
                correspondingEnergisticsAttribute.IsConst           = fesapiAttribute.IsConst;
                correspondingEnergisticsAttribute.IsDerived         = fesapiAttribute.IsDerived;
                correspondingEnergisticsAttribute.IsID              = fesapiAttribute.IsID;
                correspondingEnergisticsAttribute.IsOrdered         = fesapiAttribute.IsOrdered;
                correspondingEnergisticsAttribute.IsStatic          = fesapiAttribute.IsStatic;
                correspondingEnergisticsAttribute.Length            = fesapiAttribute.Length;
                correspondingEnergisticsAttribute.LowerBound        = fesapiAttribute.LowerBound;
                correspondingEnergisticsAttribute.Notes             = fesapiAttribute.Notes;
                correspondingEnergisticsAttribute.Precision         = fesapiAttribute.Precision;
                correspondingEnergisticsAttribute.RedefinedProperty = fesapiAttribute.RedefinedProperty;
                correspondingEnergisticsAttribute.Scale             = fesapiAttribute.Scale;
                correspondingEnergisticsAttribute.Stereotype        = fesapiAttribute.Stereotype;
                correspondingEnergisticsAttribute.StereotypeEx      = fesapiAttribute.StereotypeEx;
                correspondingEnergisticsAttribute.Style             = fesapiAttribute.Style;
                correspondingEnergisticsAttribute.StyleEx           = fesapiAttribute.StyleEx;
                correspondingEnergisticsAttribute.SubsettedProperty = fesapiAttribute.SubsettedProperty;
                correspondingEnergisticsAttribute.Type              = fesapiAttribute.Type;
                correspondingEnergisticsAttribute.UpperBound        = fesapiAttribute.UpperBound;
                correspondingEnergisticsAttribute.Visibility        = fesapiAttribute.Visibility;
                if (!(correspondingEnergisticsAttribute.Update()))
                {
                    Tool.showMessageBox(repository, correspondingEnergisticsAttribute.GetLastError());
                    continue;
                }

                foreach (EA.AttributeTag fesapiAttributeTag in fesapiAttribute.TaggedValues)
                {
                    EA.AttributeTag energisticsAttributeTag = correspondingEnergisticsAttribute.TaggedValues.AddNew(fesapiAttributeTag.Name, fesapiAttributeTag.Value);
                    if (!(energisticsAttributeTag.Update()))
                    {
                        Tool.showMessageBox(repository, energisticsAttributeTag.GetLastError());
                    }
                }
                correspondingEnergisticsAttribute.TaggedValues.Refresh();
            }

            // ----------------
            // ----------------
            // methods handling

            // we assume that the Energistics model does not contain methods. So, for each fesapi class method
            // a copy is created into the energistics class
            foreach (EA.Method fesapiMethod in fesapiClass.Methods)
            {
                EA.Method energisticsMethod = energisticsClass.Methods.AddNew(fesapiMethod.Name, fesapiMethod.ReturnType);
                energisticsMethod.Abstract       = fesapiMethod.Abstract;
                energisticsMethod.Behavior       = fesapiMethod.Behavior;
                energisticsMethod.ClassifierID   = fesapiMethod.ClassifierID;
                energisticsMethod.Code           = fesapiMethod.Code;
                energisticsMethod.Concurrency    = fesapiMethod.Concurrency;
                energisticsMethod.IsConst        = fesapiMethod.IsConst;
                energisticsMethod.IsLeaf         = fesapiMethod.IsLeaf;
                energisticsMethod.IsPure         = fesapiMethod.IsPure;
                energisticsMethod.IsQuery        = fesapiMethod.IsQuery;
                energisticsMethod.IsRoot         = fesapiMethod.IsRoot;
                energisticsMethod.IsStatic       = fesapiMethod.IsStatic;
                energisticsMethod.IsSynchronized = fesapiMethod.IsSynchronized;
                energisticsMethod.Notes          = fesapiMethod.Notes;
                energisticsMethod.ReturnIsArray  = fesapiMethod.ReturnIsArray;
                energisticsMethod.StateFlags     = fesapiMethod.StateFlags;
                energisticsMethod.Stereotype     = fesapiMethod.Stereotype;
                energisticsMethod.StereotypeEx   = fesapiMethod.StereotypeEx;
                energisticsMethod.Style          = fesapiMethod.Style;
                energisticsMethod.StyleEx        = fesapiMethod.StyleEx;
                energisticsMethod.Throws         = fesapiMethod.Throws;
                energisticsMethod.Visibility     = fesapiMethod.Visibility;
                if (!(energisticsMethod.Update()))
                {
                    Tool.showMessageBox(repository, energisticsMethod.GetLastError());
                }
                energisticsClass.Methods.Refresh();

                foreach (EA.MethodTag fesapiMethodTag in fesapiMethod.TaggedValues)
                {
                    EA.MethodTag energisticsMethodTag = energisticsMethod.TaggedValues.AddNew(fesapiMethodTag.Name, fesapiMethodTag.Value);
                    if (!(energisticsMethodTag.Update()))
                    {
                        Tool.showMessageBox(repository, energisticsMethodTag.GetLastError());
                    }
                }
                energisticsMethod.TaggedValues.Refresh();

                foreach (EA.Parameter fesapiMethodParameter in fesapiMethod.Parameters)
                {
                    EA.Parameter energisticsMethodParameter = energisticsMethod.Parameters.AddNew(fesapiMethodParameter.Name, fesapiMethodParameter.Type);
                    energisticsMethodParameter.Alias        = fesapiMethodParameter.Alias;
                    energisticsMethodParameter.ClassifierID = fesapiMethodParameter.ClassifierID;
                    energisticsMethodParameter.Default      = fesapiMethodParameter.Default;
                    energisticsMethodParameter.IsConst      = fesapiMethodParameter.IsConst;
                    energisticsMethodParameter.Kind         = fesapiMethodParameter.Kind;
                    energisticsMethodParameter.Notes        = fesapiMethodParameter.Notes;
                    energisticsMethodParameter.Position     = fesapiMethodParameter.Position;
                    energisticsMethodParameter.Stereotype   = fesapiMethodParameter.Stereotype;
                    energisticsMethodParameter.StereotypeEx = fesapiMethodParameter.StereotypeEx;
                    energisticsMethodParameter.Style        = fesapiMethodParameter.Style;
                    energisticsMethodParameter.StyleEx      = fesapiMethodParameter.StyleEx;

                    if (!(energisticsMethodParameter.Update()))
                    {
                        Tool.showMessageBox(repository, energisticsMethodParameter.GetLastError());
                    }
                }
                energisticsMethod.Parameters.Refresh();
            }

            // -------------
            // -------------
            // tags handling

            foreach (EA.TaggedValue fesapiTag in fesapiClass.TaggedValues)
            {
                EA.TaggedValue energisticsTag = energisticsClass.TaggedValues.AddNew(fesapiTag.Name, fesapiTag.Value);
                if (!(energisticsTag.Update()))
                {
                    Tool.showMessageBox(repository, energisticsTag.GetLastError());
                }
                energisticsClass.TaggedValues.Refresh();
            }

            // --------------
            // --------------
            // notes handling

            // important note: Energistics class notes are deleted during this copy
            if (fesapiClass.Notes != "")
            {
                energisticsClass.Notes = fesapiClass.Notes;
                if (!(energisticsClass.Update()))
                {
                    Tool.showMessageBox(repository, energisticsClass.GetLastError());
                }
            }

            energisticsClass.Refresh();
        }
        /// <summary>
        /// Add an XML_TAG attribute with its getter to a given Energistics class. This method
        /// has no effect if the Energistics class is abstract or if the corresponding fesapi class
        /// is tagged such that no XML_TAG should be generated
        /// </summary>
        /// <param name="energisticsClass">An Energistics class</param>
        /// <param name="fesapiClass">Its corresponding fesapi class</param>
        private void addXmlTagAttributeWithGetter(EA.Element energisticsClass, EA.Element fesapiClass)
        {
            // we look for a fesapi class tag telling that no XML_TAG attribute should be generated
            string generateXmlTag = "true";

            EA.TaggedValue generateXmlTagTag = fesapiClass.TaggedValues.GetByName(Constants.fesapiGenerateXmlTagTagName);
            if (generateXmlTagTag != null)
            {
                generateXmlTag = generateXmlTagTag.Value;
            }

            if (!(fesapiClass.Name.Contains("Abstract")) && generateXmlTag == "true") // impotant note: we assume that a class is
                                                                                      // abstract if it contains "Abstract" in its
                                                                                      // name
            {
                // we add an XML_TAG attribute
                EA.Attribute xmlTagAttribute = energisticsClass.Attributes.AddNew("XML_TAG", "char*");
                xmlTagAttribute.IsStatic = true;
                xmlTagAttribute.IsConst  = true;
                if (!(xmlTagAttribute.Update()))
                {
                    Tool.showMessageBox(repository, xmlTagAttribute.GetLastError());
                }
                energisticsClass.Attributes.Refresh();

                // thanks to a tag, we tells that the XML_TAG attribute should be generated during the code generation.
                // Keep in mind that Energistics class attributes are not generated in fesapi by default since most of them
                // relies on gSOAP proxies attributes
                EA.AttributeTag generationTag = xmlTagAttribute.TaggedValues.AddNew(Constants.fesapiGenerationTagName, "true");
                if (!(generationTag.Update()))
                {
                    Tool.showMessageBox(repository, generationTag.GetLastError());
                }

                // thanks to a tag, we tells that no getter should be automatically generated during the transformation
                // of the Energistics model into a C++ model
                EA.AttributeTag getterGenerationTag = xmlTagAttribute.TaggedValues.AddNew(Constants.fesapiGetterGenerationTagName, "false");
                if (!(getterGenerationTag.Update()))
                {
                    Tool.showMessageBox(repository, getterGenerationTag.GetLastError());
                }

                // add the XML_TAG attributr getter
                EA.Method getXmlTagMethod = energisticsClass.Methods.AddNew("getXmlTag", "std::string");
                getXmlTagMethod.Stereotype = "const";
                getXmlTagMethod.Code       = "return XML_TAG;";
                getXmlTagMethod.Abstract   = true;
                if (!(getXmlTagMethod.Update()))
                {
                    Tool.showMessageBox(repository, getXmlTagMethod.GetLastError());
                }
                energisticsClass.Methods.Refresh();

                // tag the getter in order for its body to be generated into the class declaration
                EA.MethodTag getXmlTagMethodBodyLocationTag = getXmlTagMethod.TaggedValues.AddNew("bodyLocation", "classDec");
                if (!(getXmlTagMethodBodyLocationTag.Update()))
                {
                    Tool.showMessageBox(repository, getXmlTagMethodBodyLocationTag.GetLastError());
                }
                getXmlTagMethod.TaggedValues.Refresh();
            }
        }
예제 #4
0
        private void updateMethods(EA.Element sourceClass, EA.Element targetClass)
        {
            foreach (EA.Method sourceMethod in sourceClass.Methods)
            {
                EA.Method targetMethod = null;
                foreach (EA.Method currentMethod in targetClass.Methods)
                {
                    if (Tool.areEqualMethods(sourceMethod, currentMethod))
                    {
                        targetMethod = currentMethod;
                        break;
                    }
                }

                // for the time being we only consider methods which not exist in the target class
                if (targetMethod != null)
                {
                    continue;
                }

                // we create a new method based on the source one
                targetMethod                = targetClass.Methods.AddNew(sourceMethod.Name, sourceMethod.ReturnType);
                targetMethod.Abstract       = sourceMethod.Abstract;
                targetMethod.Behavior       = sourceMethod.Behavior;
                targetMethod.ClassifierID   = sourceMethod.ClassifierID;
                targetMethod.Code           = sourceMethod.Code;
                targetMethod.Concurrency    = sourceMethod.Concurrency;
                targetMethod.IsConst        = sourceMethod.IsConst;
                targetMethod.IsLeaf         = sourceMethod.IsLeaf;
                targetMethod.IsPure         = sourceMethod.IsPure;
                targetMethod.IsQuery        = sourceMethod.IsQuery;
                targetMethod.IsRoot         = sourceMethod.IsRoot;
                targetMethod.IsStatic       = sourceMethod.IsStatic;
                targetMethod.IsSynchronized = sourceMethod.IsSynchronized;
                targetMethod.Notes          = sourceMethod.Notes;
                targetMethod.ReturnIsArray  = sourceMethod.ReturnIsArray;
                targetMethod.StateFlags     = sourceMethod.StateFlags;
                targetMethod.Stereotype     = sourceMethod.Stereotype;
                targetMethod.StereotypeEx   = sourceMethod.StereotypeEx;
                targetMethod.Style          = sourceMethod.Style;
                targetMethod.StyleEx        = sourceMethod.StyleEx;
                targetMethod.Throws         = sourceMethod.Throws;
                targetMethod.Visibility     = sourceMethod.Visibility;
                if (!(targetMethod.Update()))
                {
                    Tool.showMessageBox(repository, targetMethod.GetLastError());
                }
                targetClass.Methods.Refresh();

                foreach (EA.MethodTag sourceMethodTag in sourceMethod.TaggedValues)
                {
                    EA.MethodTag targetMethodTag = targetMethod.TaggedValues.AddNew(sourceMethodTag.Name, sourceMethodTag.Value);
                    if (!(targetMethodTag.Update()))
                    {
                        Tool.showMessageBox(repository, targetMethodTag.GetLastError());
                    }
                }
                targetMethod.TaggedValues.Refresh();

                foreach (EA.Parameter sourceMethodParameter in sourceMethod.Parameters)
                {
                    EA.Parameter targetMethodParameter = targetMethod.Parameters.AddNew(sourceMethodParameter.Name, sourceMethodParameter.Type);
                    targetMethodParameter.Alias        = sourceMethodParameter.Alias;
                    targetMethodParameter.ClassifierID = sourceMethodParameter.ClassifierID;
                    targetMethodParameter.Default      = sourceMethodParameter.Default;
                    targetMethodParameter.IsConst      = sourceMethodParameter.IsConst;
                    targetMethodParameter.Kind         = sourceMethodParameter.Kind;
                    targetMethodParameter.Notes        = sourceMethodParameter.Notes;
                    targetMethodParameter.Position     = sourceMethodParameter.Position;
                    targetMethodParameter.Stereotype   = sourceMethodParameter.Stereotype;
                    targetMethodParameter.StereotypeEx = sourceMethodParameter.StereotypeEx;
                    targetMethodParameter.Style        = sourceMethodParameter.Style;
                    targetMethodParameter.StyleEx      = sourceMethodParameter.StyleEx;

                    if (!(targetMethodParameter.Update()))
                    {
                        Tool.showMessageBox(repository, targetMethodParameter.GetLastError());
                    }
                }
                targetMethod.Parameters.Refresh();
            }
        }