예제 #1
0
        /// <summary>
        /// AddOperation
        /// </summary>
        /// <param name="eElement"></param>
        /// <param name="strOperationName"></param>
        /// <param name="strParamType"></param>
        private static void AddOperation(EA.Element eElement, string strOperationName, string strParamType)
        {
            string strLogInfo = "Operation: " + strOperationName + ":" + strParamType;

            EAImporter.LogMsg(EAImporter.LogMsgType.Adding, strLogInfo);
            // first see if operation name already exits
            bool bFound = false;

            for (short i = 0; i < eElement.Methods.Count; i++)
            {
                Application.DoEvents();

                EA.Method eOperationTst = eElement.Methods.GetAt(i);

                for (short j = 0; j < eOperationTst.Parameters.Count; j++)
                {
                    Application.DoEvents();

                    EA.Parameter eParamTst = eOperationTst.Parameters.GetAt(j);

                    if (eParamTst.Type == strParamType)
                    {
                        EAImporter.LogMsg(EAImporter.LogMsgType.Exists, strLogInfo);
                        bFound = true;
                        return;
                    }
                }
            }

            if (!bFound)
            {
                EA.Method eOperation = eElement.Methods.AddNew(strOperationName, "");
                eOperation.Update();
                eElement.Methods.Refresh();

                EA.Parameter eParam = eOperation.Parameters.AddNew(strParamType, "");
                eParam.Name = strParamType;
                eParam.Kind = "in";
                eParam.Type = strParamType;
                eParam.Update();
                eOperation.Update();
                eElement.Update();
                eElement.Methods.Refresh();

                EAImporter.LogMsg(EAImporter.LogMsgType.Added, strLogInfo);
            }
        }
예제 #2
0
        private void setClassifierAttributes()
        {
            int counter = 0;

            foreach (Object objectToBeTyped in this.ObjectToTypeGuid.Keys)
            {
                String typeElementGuid = this.ObjectToTypeGuid[objectToBeTyped];
                if (hasGui)
                {
                    ImportWorker.ReportProgress(4, new ProgressObject(ProgressBarType.Current, "Set Classifiers", ObjectToTypeGuid.Count));
                }
                else
                {
                    Console.Out.WriteLine("SCALE:Set Classifiers for '" + typeElementGuid + "' %" + counter + "/" + ObjectToTypeGuid.Count + "#");
                    counter++;
                }


                if (OldGuidToNewGuid.ContainsKey(typeElementGuid))
                {
                    String     newTypeElementGuid = this.OldGuidToNewGuid[typeElementGuid];
                    EA.Element typeElement        = ElementGuidToElement[newTypeElementGuid];
                    if (objectToBeTyped is EA.Element)
                    {
                        EA.Element elem = objectToBeTyped as EA.Element;
                        elem.ClassifierID = typeElement.ElementID;
                        elem.Update();
                    }
                    else if (objectToBeTyped is EA.Method)
                    {
                        EA.Method meth = objectToBeTyped as EA.Method;
                        meth.ReturnType   = typeElement.Name;
                        meth.ClassifierID = typeElement.ElementID.ToString();
                        meth.Update();
                    }
                    else if (objectToBeTyped is EA.Attribute)
                    {
                        EA.Attribute attr = objectToBeTyped as EA.Attribute;
                        attr.Type         = typeElement.Name;
                        attr.ClassifierID = typeElement.ElementID;
                        attr.Update();
                    }
                    else if (objectToBeTyped is EA.Parameter)
                    {
                        EA.Parameter param = objectToBeTyped as EA.Parameter;
                        param.Type         = typeElement.Name;
                        param.ClassifierID = typeElement.ElementID.ToString();
                        param.Update();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                }
            }
        }
        /// <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());
            }
        }
        private bool Update(EA.Method mth)
        {
            bool result = mth.Update();

            if (result == false)
            {
                throw new Exception("Update Didn't work out properlly!!!");
            }
            return(result);
        }
 protected override void Correct(IMyOperation elementToCorrect)
 {
     EA.Element theClass  = Repository.GetElementByGuid(elementToCorrect.Owner.Guid);
     EA.Method  theMethod = theClass.Methods.Cast <EA.Method>().SingleOrDefault(m => m.MethodGUID == elementToCorrect.Guid);
     if (theMethod == null)
     {
         return;
     }
     theMethod.Name = elementToCorrect.Name.FilterSpecialCharacters();
     theMethod.Update();
 }
예제 #6
0
 protected override void Correct(IMyOperation elementToCorrect)
 {
     EA.Element theClass     = Repository.GetElementByGuid(elementToCorrect.Owner.Guid);
     EA.Method  theOperation = theClass.Methods.Cast <EA.Method>().SingleOrDefault(m => m.MethodGUID == elementToCorrect.Guid);
     if (theOperation == null)
     {
         return;
     }
     theOperation.Name = "_" + elementToCorrect.Name;
     theOperation.Update();
 }
예제 #7
0
 public EA.Method getOrCreateMethod(SQLElement parentClass, String oldGuid, String methodName, String returnType)
 {
     EA.Method method = repository.GetMethodByGuid(oldGuid);
     if (method == null)
     {
         method            = parentClass.getRealElement().Methods.AddNew(methodName, "") as EA.Method;
         method.ReturnType = returnType;
         method.Update();
         repository.Execute("update t_operation set ea_guid = '" + oldGuid + "' where ea_guid = '" + method.MethodGUID + "'");
         method = repository.GetMethodByGuid(oldGuid);
     }
     return(method);
 }
        /// <summary>
        /// Generate an EA-Interface into the defined package. It adds the EA Interface reference if exists.
        /// </summary>
        public int Generate(EA.Package pkg)
        {
            int newMethods = 0;

            if (El == null)
            {
                // Create Interface
                El = (EA.Element)pkg.Elements.AddNew(Name, "Interface");
                El.Update();
            }
            // Generate operations for Interface
            foreach (FunctionItem functionItem in ProvidedFunctions)
            {
                EA.Method m        = functionItem.Op;
                bool      isUpdate = true;
                if (m == null)
                {
                    isUpdate = false;
                    // new function
                    m = (EA.Method)El.Methods.AddNew(functionItem.Name, "Operation");
                    newMethods++;
                }
                m.ReturnType = functionItem.ReturnType;
                m.Update();
                if (isUpdate)
                {
                    DeleteParameter(m);
                }
                foreach (ParameterItem par in functionItem.ParameterList)
                {
                    string       parName = par.Name;
                    EA.Parameter p       = (EA.Parameter)m.Parameters.AddNew(parName, "Parameter");
                    p.Position = par.Position;
                    p.Type     = par.Type;
                    p.IsConst  = par.IsConst;
                    p.Update();
                    m.Parameters.Refresh();
                    functionItem.Op = m;
                }
                m.Parameters.Refresh();



                functionItem.Op = m;
            }
            El.Methods.Refresh();
            return(newMethods);
        }
예제 #9
0
        private void appendNewMethodAndSdm()
        {
            repository.SaveDiagram(oldSDMDiagram.DiagramID);


            EA.Element eClass = getContainingClass();
            this.newMethod = eClass.Methods.AddNew(textBoxNewSDM.Text, "void") as EA.Method;
            newMethod.Update();

            SDMModelingMain.createStoryDiagram(sqlRepository.GetMethodByID(newMethod.MethodID), sqlRepository.GetOriginalRepository(), oldSDMDiagram);
            newSdmContainer = sqlRepository.GetOriginalRepository().GetElementByID(sqlRepository.GetCurrentDiagram().ParentID);
            EA.Diagram newSdmDiagram = newSdmContainer.Diagrams.GetAt(0) as EA.Diagram;
            EA.Element newStartNode  = findNewStartNode(newSdmContainer);
            createExtractedSDMStatementNode();

            int leftMax = 10000000;
            int topMax  = -100000;

            computeLeftAndTopMin(ref leftMax, ref topMax);

            //copy elements
            foreach (EA.Element selectedElement in this.selectedActivityNodes)
            {
                selectedElement.ParentID = newSdmContainer.ElementID;
                EA.DiagramObject newPatternDiagramObject = null;
                copyDiagramObjects(leftMax - 100, topMax + 100, newSdmDiagram, selectedElement);
                EA.DiagramObject selectedDiagramObject = getDiagramObject(selectedElement.ElementID);
                if (selectedDiagramObject != null)
                {
                    newPatternDiagramObject = copyDiagramObject(leftMax - 100, topMax + 100, newSdmDiagram, selectedDiagramObject, selectedElement, 2);
                    EAUtil.deleteDiagramObject(repository, oldSDMDiagram, selectedElement);
                }

                //deleteUnselectedConnectors(selectedElement);
                selectedElement.Update();

                arrangeUnselectedConnectors(newSdmContainer, newSdmDiagram, newStartNode, selectedElement, newPatternDiagramObject.bottom, newPatternDiagramObject.left);
            }



            repository.ReloadDiagram(newSdmDiagram.DiagramID);
            repository.ReloadDiagram(oldSDMDiagram.DiagramID);
            repository.OpenDiagram(oldSDMDiagram.DiagramID);
        }
 public override void Save(EA.Repository rep, FindAndReplaceItem.FieldType fieldType)
 {
     EA.Method meth = rep.GetMethodByGuid(Guid);
     if ((fieldType & FindAndReplaceItem.FieldType.Description) > 0)
     {
         meth.Notes = Description;
     }
     if ((fieldType & FindAndReplaceItem.FieldType.Name) > 0)
     {
         meth.Name = Name;
     }
     if ((fieldType & FindAndReplaceItem.FieldType.Stereotype) > 0)
     {
         meth.StereotypeEx = Stereotype;
     }
     IsUpdated = true;
     meth.Update();
 }
예제 #11
0
        // Update Method Types
        public static bool UpdateMethod(EA.Repository rep, EA.Method m)
        {
            int id;

            // over all parameters
            foreach (EA.Parameter par in m.Parameters)
            {
                if ((par.ClassifierID == "") || (par.ClassifierID == "0"))
                {
                    // find type from type_name
                    id = GetTypeId(rep, par.Type);
                    if (id > 0)
                    {
                        par.ClassifierID = id.ToString();
                        bool error = par.Update();
                        if (!error)
                        {
                            MessageBox.Show("Error write Parameter", m.GetLastError());
                            return(false);
                            // Error occurred
                        }
                    }
                }
            }
            // no classifier defined
            if ((m.ClassifierID == "") || (m.ClassifierID == "0"))
            {
                // find type from type_name
                id = GetTypeId(rep, m.ReturnType);
                if (id > 0)
                {
                    m.ClassifierID = id.ToString();
                    bool error = m.Update();
                    if (!error)
                    {
                        MessageBox.Show("Error write Method", m.GetLastError());
                        return(false);
                        // Error occurred
                    }
                }
            }
            return(true);
        }
예제 #12
0
        /// <summary>
        /// メソッドをEAに向けて更新実行する
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="selectedMethod"></param>
        private void execUpdateMethod(EA.Repository repo, MethodVO selectedMethod)
        {
            EA.Method mth = getMethodByGuid(selectedMethod.guid);

            if (mth == null)
            {
                EA.Element elem = (EA.Element)repo.GetElementByGuid(myElement.guid);
                if (elem == null)
                {
                    return;
                }
                mth            = (EA.Method)elem.Methods.AddNew(selectedMethod.name, selectedMethod.returnType);
                mth.MethodGUID = selectedMethod.guid;
            }
//					mth.StereotypeEx = selectedMethod.stereoType;
//					mth.Notes = selectedMethod.notes;
            mth.Alias    = selectedMethod.alias;
            mth.Behavior = selectedMethod.behavior;
            mth.Update();
        }
예제 #13
0
        void addReturn(EA.Repository rep, EA.Method method, XmlQualifiedName elName, ServiceDescription wsdl)
        {
            foreach (XmlSchema sch in wsdl.Types.Schemas)
            {
                XmlSchemaObject so = findElement(sch, elName);
                if (so != null)
                {
                    XmlSchemaElement     sel         = (XmlSchemaElement)so;
                    XmlSchemaComplexType complexType = (XmlSchemaComplexType)sel.SchemaType;
                    XmlSchemaSequence    sequence    = (XmlSchemaSequence)complexType.Particle;

                    foreach (XmlSchemaObject sp in sequence.Items)
                    {
                        XmlSchemaElement spel = (XmlSchemaElement)sp;

                        method.ReturnType = spel.SchemaTypeName.Name;
                        method.Update();
                    }
                }
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            EA.Method newMethod = null;
            int       i         = 0;

            foreach (CheckBox cb in this.checkBoxToElement.Keys)
            {
                if (cb.Checked)
                {
                    if (newMethod == null)
                    {
                        String methodName = "postProcess";
                        if (rbBWD.Checked)
                        {
                            methodName += "BACKWARD";
                        }
                        else if (rbFWD.Checked)
                        {
                            methodName += "FORWARD";
                        }
                        newMethod = this.tggRuleElement.Methods.AddNew(methodName, "void") as EA.Method;
                        newMethod.Update();
                    }

                    SQLElement elementToAdd = this.checkBoxToElement[cb];
                    String     type         = elementToAdd.Name;

                    EA.Parameter parameter = newMethod.Parameters.AddNew(this.parameterNames[i], type) as EA.Parameter;
                    parameter.ClassifierID = elementToAdd.ElementID.ToString();
                    parameter.Update();
                    newMethod.Parameters.Refresh();
                }
                i++;
            }
            Close();
        }
예제 #15
0
        private void createExtractedSDMStatementNode()
        {
            Boolean thisPatternCreated = false;

            int leftMax = 0;
            int topMax  = -100000;

            computeLeftAndTopMax(ref leftMax, ref topMax);


            EA.Element thisObject = searchThisObject();
            //only create a statementNode if there exists a this object on the sdm
            //otherwise create new story node with an this variable

            if (thisObject == null)
            {
                thisOvPattern = createStoryPattern("this Activity");

                thisObject = createThisOv(thisOvPattern);

                createDiagramObject(leftMax + 50, topMax - 20, 50, 100, thisObject);

                createDiagramObject(leftMax, topMax, 100, 200, thisOvPattern);

                thisPatternCreated = true;

                leftMax += 300;
            }

            //create new story node with objectvariable bound to new sdm.
            if (checkBoxBoundOv.Checked)
            {
                EA.Element boundOvPattern = createStoryPattern("Bound new SDM");
                EA.Element boundObject2   = createThisOv(boundOvPattern);
                SQLElement boundObject    = sqlRepository.GetElementByID(boundObject2.ElementID);


                createDiagramObject(leftMax + 20, topMax - 20, 50, 100, boundObject2);
                createDiagramObject(leftMax, topMax, 100, 200, boundOvPattern);

                ObjectVariable ov = new ObjectVariable(boundObject, sqlRepository);
                ov.loadTreeFromTaggedValue();

                ov.BindingState = BindingState.BOUND;

                MethodCallExpression mcExp = new MethodCallExpression(sqlRepository.GetMethodByID(newMethod.MethodID), sqlRepository);

                ObjectVariableExpression ovExp = new ObjectVariableExpression(sqlRepository.GetElementByID(thisObject.ElementID), sqlRepository);
                mcExp.Target         = ovExp;
                ov.BindingExpression = mcExp;
                ov.Classifier        = ovClassifiersComboBox1.Classifiers[ovClassifiersComboBox1.SelectedIndex];

                ov.saveTreeToEATaggedValue(true);

                sdmCallPattern = boundOvPattern;

                EA.Method sdmMethod = repository.GetMethodByGuid(EAUtil.findTaggedValue(sqlRepository.GetElementByID(newSdmContainer.ElementID), SDMModelingMain.SDMContainerAssociatedMethodTaggedValueName).Value);
                sdmMethod.ClassifierID = "" + ov.Classifier.EaElement.ElementID;
                sdmMethod.ReturnType   = ov.Classifier.EaElement.Name;
                sdmMethod.Update();
            }
            //instead create statement node construct
            else
            {
                EA.Element           statementActivity = createStoryPattern("Call extracted method");
                StatementNode        statementNode     = new StatementNode(sqlRepository, sqlRepository.GetElementByID(statementActivity.ElementID));
                MethodCallExpression mcExp             = new MethodCallExpression(sqlRepository.GetMethodByID(newMethod.MethodID), sqlRepository);

                ObjectVariableExpression ovExp = new ObjectVariableExpression(sqlRepository.GetElementByID(thisObject.ElementID), sqlRepository);
                mcExp.Target = ovExp;
                statementNode.StatementExpression = mcExp;
                statementActivity.Notes           = thisObject.Name + "." + newMethod.Name + "()";
                EAEcoreAddin.Util.EAUtil.setTaggedValue(sqlRepository, statementActivity, "activityType", "call");
                EAEcoreAddin.Util.EAUtil.setTaggedValue(sqlRepository, statementActivity, "evacuated", "false");
                statementActivity.Update();

                createDiagramObject(leftMax, topMax, 200, 200, statementActivity);
                statementNode.saveTreeToEATaggedValue(true);

                sdmCallPattern = statementActivity;
            }

            if (thisPatternCreated)
            {
                //create edge between this pattern and statement pattern
                EA.Connector acEdge = thisOvPattern.Connectors.AddNew("", Main.EAControlFlowType) as EA.Connector;
                acEdge.SupplierID = sdmCallPattern.ElementID;
                acEdge.Update();
                ActivityEdge edge = new ActivityEdge(sqlRepository, sqlRepository.GetConnectorByID(acEdge.ConnectorID));
                edge.saveTreeToEATaggedValue(true);
            }
        }
예제 #16
0
        public void importWSDL(String filename, EA.Repository repository, EA.Diagram diagram)
        {
            logger.log("Importing: " + filename);

            EA.Package package = repository.GetPackageByID(diagram.PackageID);

            XmlTextReader reader = new XmlTextReader(filename);

            ServiceDescription wsdl = ServiceDescription.Read(reader);

            foreach (PortType pt in wsdl.PortTypes)
            {
                //logger.log("PortType: "+ pt.Name);

                EA.Element clazz = package.Elements.AddNew(pt.Name, APIAddinClass.EA_TYPE_CLASS);
                clazz.Notes   = wsdl.Documentation;
                clazz.Version = wsdl.TargetNamespace;
                package.Update();

                EA.DiagramObject diaObj = diagram.DiagramObjects.AddNew(pt.Name, "");
                diagram.Update();

                diaObj.ElementID = clazz.ElementID;

                diaObj.Update();


                foreach (Operation op in pt.Operations)
                {
                    //logger.log("\tOperation: "+ op.Name);

                    EA.Method method = clazz.Methods.AddNew(op.Name, "");

                    method.Name = op.Name;

                    method.Update();

                    clazz.Update();

                    clazz.Methods.Refresh();

                    OperationInput  oi = null;
                    OperationOutput oo = null;
                    foreach (OperationMessage msg in op.Messages)
                    {
                        if (msg is OperationInput)
                        {
                            oi = msg as OperationInput;
                        }

                        else if (msg is OperationOutput)
                        {
                            oo = msg as OperationOutput;
                        }
                        else
                        {
                        }
                    }

                    if (oi == null || oo == null)
                    {
                        return;
                    }

                    foreach (Message m in wsdl.Messages)
                    {
                        //logger.log("\n\tMessage: " + m.Name);
                        //logger.log("\tOperationInput: " + oi.Message.Name);

                        if (m.Name.Equals(oi.Message.Name))
                        {
                            foreach (MessagePart p in m.Parts)
                            {
                                if (!p.Name.Equals("Header"))
                                {
                                    addParameter(repository, method, p.Element, wsdl);
                                }
                            }
                        }
                        else if (m.Name.Equals(oo.Message.Name))
                        {
                            foreach (MessagePart p in m.Parts)
                            {
                                if (!p.Name.Equals("Header"))
                                {
                                    addReturn(repository, method, p.Element, wsdl);
                                }
                            }
                        }
                    }
                }
            }
            diagram.DiagramObjects.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();
            }
        }
예제 #18
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();
            }
        }
        /// <summary>
        /// This methods create some easy access vector attributes into an Energistics EpcDocument
        /// class. These vector are usefull to access top level Resqml objects from one EpcDocument.
        /// It also provides corresponding accessors and forward declarations.
        /// </summary>
        /// <param name="energisticsEpcDocument">An Energistics EpcDocument class</param>
        /// <param name="toUpdateClassF2E">A dictionary mapping Fesapi classes with their corresponding Energistics classes</param>
        private void createEpcDocumentEasyAccessVector(EA.Element energisticsEpcDocument,
                                                       Dictionary <EA.Element, EA.Element> toUpdateClassF2E)
        {
            // we create a dictionry for mapping a given fesapi namespace with corresponding fesapi class.
            // Usefull for handling EpcDocument forward declarations
            Dictionary <string, List <string> > importNamespace = new Dictionary <string, List <string> >();

            foreach (KeyValuePair <EA.Element, EA.Element> entry in toUpdateClassF2E)
            {
                EA.Element energisticsClass = entry.Value;

                // we assume that we do not want to provide easy access vectors to access abstract classes from
                // EpcDocument
                if (energisticsClass.Name.Contains("Abstract"))
                {
                    continue;
                }

                // getting the fesapi namespace of the current non-abstract Energistics class. It exists since
                // the EpcDocument easy access vectors creation occurs at the very end of the Energistics model
                // update
                EA.TaggedValue tag = energisticsClass.TaggedValues.GetByName(Constants.fesapiNamespaceTagName);

                // creating the EpcDocument std::vector attribute for easily access the current Energistics class
                string       attributeName = Char.ToLowerInvariant(energisticsClass.Name[0]) + energisticsClass.Name.Substring(1) + "Set";
                string       attributeType = "std::vector<" + tag.Value + "::" + energisticsClass.Name + "*>";
                EA.Attribute attribute     = attribute = energisticsEpcDocument.Attributes.AddNew(attributeName, attributeType);
                attribute.Visibility = "Private";
                if (!(attribute.Update()))
                {
                    Tool.showMessageBox(repository, attribute.GetLastError());
                    continue;
                }
                energisticsEpcDocument.Attributes.Refresh();

                // thanks to a tag, we tell to the transformation engine (transforming the Energistics model into a C++ model)
                // to preserve our easy access vector attribute in the C++ model
                EA.AttributeTag generationTag = attribute.TaggedValues.AddNew(Constants.fesapiGenerationTagName, "true");
                if (!(generationTag.Update()))
                {
                    Tool.showMessageBox(repository, generationTag.GetLastError());
                    continue;
                }
                attribute.TaggedValues.Refresh();

                // we want to generate by hand the corresponding getter. Thanks to a tag, we tell to the model
                // transformation engine (transforming the Energistics model into a C++ model) to do not automatically
                // generate a getter
                EA.AttributeTag getterGenerationTag = attribute.TaggedValues.AddNew(Constants.fesapiGetterGenerationTagName, "false");
                if (!(getterGenerationTag.Update()))
                {
                    Tool.showMessageBox(repository, getterGenerationTag.GetLastError());
                    continue;
                }

                // we create by hand the corresponding vector
                string    methodName = "get" + energisticsClass.Name + "Set";
                string    methodType = attributeType + " &";
                EA.Method method     = energisticsEpcDocument.Methods.AddNew(methodName, methodType);
                method.IsConst    = true;
                method.Stereotype = "const";
                if (!(method.Update()))
                {
                    Tool.showMessageBox(repository, method.GetLastError());
                    continue;
                }
                energisticsEpcDocument.Methods.Refresh();

                // associating the Energistics class to its fesapi namespace
                if (!(importNamespace.ContainsKey(tag.Value)))
                {
                    importNamespace.Add(tag.Value, new List <string>());
                }
                importNamespace[tag.Value].Add(energisticsClass.Name);
            }

            // converting the association between fesapi namespace and Energistics classes into a
            // EpcDocument class tag. This tag will be used during the code generation for copying
            // forward declarations corresponding to easy access vectors into EpcDocument.h
            string importNameSpaceTagValue = "";

            foreach (KeyValuePair <string, List <string> > kv in importNamespace)
            {
                importNameSpaceTagValue += "namespace " + kv.Key + " {";
                List <string> classNameList = kv.Value;
                foreach (string className in classNameList)
                {
                    importNameSpaceTagValue += "class " + className + ";";
                }
                importNameSpaceTagValue += "}";
            }
            EA.TaggedValue importNamespaceTag = energisticsEpcDocument.TaggedValues.AddNew(Constants.fesapiImportNamespaceTag, importNameSpaceTagValue);
            if (!(importNamespaceTag.Update()))
            {
                Tool.showMessageBox(repository, importNamespaceTag.GetLastError());
            }
            energisticsEpcDocument.TaggedValues.Refresh();
        }
        /// <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();
        }