コード例 #1
0
        void addParameter(EA.Repository r, 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;

                        EA.Parameter param = method.Parameters.AddNew(spel.Name, "");
                        param.Name = spel.Name;

                        string classifiedId = queryIAAType(r, spel.SchemaTypeName.Name);

                        param.Type         = spel.SchemaTypeName.Name;
                        param.ClassifierID = classifiedId;

                        param.Update();
                        method.Parameters.Refresh();
                    }
                }
            }
        }
コード例 #2
0
        public EA.Parameter getOrCreateParameter(EA.Method parentMethod, MocaNode attributeNode)
        {
            String oldGuid = attributeNode.getAttributeOrCreate(Main.GuidStringName).Value;

            String result = repository.SQLQuery("select * from t_operationparams where ea_guid = '" + oldGuid + "'");

            EA.Parameter rattribute = null;
            SQLParameter attribute  = new SQLParameter(sqlRep, result);

            if (attribute.ParameterGUID == "")
            {
                rattribute = parentMethod.Parameters.AddNew(attributeNode.getAttributeOrCreate("name").Value, "") as EA.Parameter;
                rattribute.Update();

                repository.Execute("update t_operationparams set ea_guid = '" + oldGuid + "' where ea_guid = '" + rattribute.ParameterGUID + "'");

                parentMethod.Parameters.Refresh();

                foreach (EA.Parameter parm in parentMethod.Parameters)
                {
                    if (parm.ParameterGUID == oldGuid)
                    {
                        return(parm);
                    }
                }
            }
            return(rattribute);
        }
コード例 #3
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
                {
                }
            }
        }
コード例 #4
0
        private bool Update(EA.Parameter prm)
        {
            bool result = prm.Update();

            if (result == false)
            {
                throw new Exception("Update Didn't work out properlly!!!");
            }
            return(result);
        }
コード例 #5
0
 protected override void Correct(IMyParameter elementToCorrect)
 {
     EA.Method    element   = Repository.GetMethodByGuid(elementToCorrect.Owner.Guid);
     EA.Parameter parameter = element.Parameters.Cast <EA.Parameter>().SingleOrDefault(p => p.ParameterGUID == elementToCorrect.Guid);
     if (parameter == null)
     {
         return;
     }
     parameter.Name = elementToCorrect.Name.FilterSpecialCharacters();
     parameter.Update();
 }
コード例 #6
0
 protected override void Correct(IMyParameter elementToCorrect)
 {
     EA.Parameter parameter =
         Repository.GetMethodByGuid(elementToCorrect.Owner.Guid)
         .Parameters.Cast <EA.Parameter>()
         .SingleOrDefault(p => p.ParameterGUID == elementToCorrect.Guid);
     if (parameter != null)
     {
         parameter.Name = elementToCorrect.Name.TrimSpacesToCamelCase();
         parameter.Update();
     }
 }
コード例 #7
0
        private void HandleParameter(EA.Parameter param, Method method)
        {
            Parameter p = new Parameter();

            p.SetName(param.Name);
            Int32 id = Int32.Parse(param.ClassifierID);

            EA.Element datatype = m_InterfaceOfInterest.GetElementByID(id);
            p.SetDatatype(FetchNamespace(datatype));
            p.SetIsConst(param.IsConst);
            p.SetPositionInArgList(param.Position);

            method.AddParameter(p);
        }
コード例 #8
0
 public EA.Parameter getRealParameter()
 {
     if (parameter == null)
     {
         EA.Method parent = repository.GetOriginalRepository().GetMethodByID(this.OperationID);
         foreach (EA.Parameter actParam in parent.Parameters)
         {
             if (actParam.Name == this.Name)
             {
                 this.parameter = actParam;
             }
         }
     }
     return(parameter);
 }
コード例 #9
0
        /// <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);
        }
コード例 #10
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);
            }
        }
コード例 #11
0
        /// <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());
            }
        }
コード例 #12
0
ファイル: WSDLTest.cs プロジェクト: xatazch/api-add-in
        public void exportWSDL()
        {
            EAMetaModel meta = new EAMetaModel();

            EA.Element component = new EAElement();
            component.Name    = "CommunicationManagement";
            component.Version = "http://usermodel.namespace";

            {
                object    obj = component.Methods.AddNew("operation1", "");
                EA.Method op1 = (EA.Method)obj;
                op1.Name = "DoSomething1";
                object       objParam = op1.Parameters.AddNew("paramString", "");
                EA.Parameter param    = (EA.Parameter)objParam;
                param.Name = "paramStringName";
                param.Type = "String";
                param.Kind = "Input";
            }
            {
                object    obj = component.Methods.AddNew("operation2", "");
                EA.Method op1 = (EA.Method)obj;
                op1.Name = "DoSomething2";
                object       objParam = op1.Parameters.AddNew("paramString", "");
                EA.Parameter param    = (EA.Parameter)objParam;
                param.Name = "paramStringName";
                param.Type = "String";
                param.Kind = "Input";
            }

            WSDLManager mgr = new WSDLManager();

            ServiceDescription sd = mgr.exportWSDL(EARepository.Repository, component);


            sd.Write(@"service.wsdl");

            Assert.IsNotNull(sd);
            Assert.AreEqual(1, sd.PortTypes.Count);
        }
コード例 #13
0
        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();
        }
コード例 #14
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();
            }
        }
コード例 #15
0
        public EClass importEClassFeatures(MocaNode eClassNode, SQLElement eclassElem)
        {
            MocaNode operationsNode = eClassNode.getChildNodeWithName(EClass.OperationsChildNodeName);
            MocaNode attributesNode = eClassNode.getChildNodeWithName(EClass.AttributesChildNodeName);
            MocaNode refsNode       = eClassNode.getChildNodeWithName(EClass.ReferencesChildNodeName);

            foreach (MocaNode eOpNode in operationsNode.Children)
            {
                EA.Method eaMethod = getOrCreateMethod(eclassElem, eOpNode);

                foreach (MocaNode eParamNode in eOpNode.getChildNodeWithName(EOperation.ParametersChildNodeName).Children)
                {
                    if (eParamNode.Name == "EParameter")
                    {
                        EA.Parameter eaParam = getOrCreateParameter(eaMethod, eParamNode);
                    }
                }
                eaMethod.Parameters.Refresh();

                MocaNode sdmActivityNode = eOpNode.getChildNodeWithName("Activity");
                if (sdmActivityNode != null)
                {
                    MainImport.getInstance().SdmImport.importSDMActivity(eclassElem, sqlRep.GetMethodByID(eaMethod.MethodID), sdmActivityNode);
                }
            }
            foreach (MocaNode eAttrNode in attributesNode.Children)
            {
                EA.Attribute eAttribute = getOrCreateAttribute(eclassElem, eAttrNode);;
                eAttribute.Update();
            }

            if (refsNode.Children.Count != 0)
            {
                MainImport.getInstance().ConnectorNodeToParent.Add(refsNode, eclassElem.getRealElement());
            }

            eclassElem.Attributes.Refresh();
            eclassElem.Methods.Refresh();

            EClass eclass = new EClass(sqlRep.GetElementByID(eclassElem.ElementID), sqlRep);

            eclass.deserializeFromMocaTree(eClassNode);
            foreach (EAttribute eattr in eclass.EAttributes)
            {
                if (eattr.typeGuid != "")
                {
                    MainImport.getInstance().ObjectToTypeGuid.Add(eattr.EaAttribute.getRealAttribute(), eattr.typeGuid);
                }
                MainImport.getInstance().OldGuidToNewGuid.Add(eattr.guid, eattr.EaAttribute.AttributeGUID);
            }

            foreach (EOperation eOp in eclass.EOperations)
            {
                if (eOp.typeGuid != "")
                {
                    MainImport.getInstance().ObjectToTypeGuid.Add(eOp.EaMethod.getRealMethod(), eOp.typeGuid);
                }
                MainImport.getInstance().OldGuidToNewGuid.Add(eOp.guid, eOp.EaMethod.MethodGUID);
                foreach (EParameter eParam in eOp.EParameters)
                {
                    if (eParam.typeGuid != "")
                    {
                        MainImport.getInstance().ObjectToTypeGuid.Add(eParam.EaParameter.getRealParameter(), eParam.typeGuid);
                    }
                    MainImport.getInstance().OldGuidToNewGuid.Add(eParam.Guid, eParam.EaParameter.ParameterGUID);
                }
            }

            if (eClassNode.getAttributeOrCreate("baseClasses").Value != "")
            {
                MainImport.getInstance().ElementToBaseClassGuids.Add(eclassElem.getRealElement(), eClassNode.getAttributeOrCreate("baseClasses").Value);
            }
            MainImport.getInstance().ElementGuidToElement.Add(eclassElem.ElementGUID, eclassElem.getRealElement());
            MainImport.getInstance().MocaTaggableElements.Add(eclass);
            MainImport.getInstance().OldGuidToNewGuid.Add(eclass.Guid, eclassElem.ElementGUID);

            return(eclass);
        }
コード例 #16
0
 public EAElementsUpdaterHandler(EA.Parameter parameter)
 {
     this.parameter = parameter;
 }
コード例 #17
0
        private void importRule(SQLPackage modelPackage, MocaNode ruleNode)
        {
            EA.Element ruleElement = MainImport.getInstance().EcoreImport.getOrCreateElement(modelPackage, ruleNode, Main.EAClassType);

            if (ruleElement.Diagrams.Count == 0)
            {
                EA.Diagram ruleDiagram = ruleElement.Diagrams.AddNew(ruleElement.Name, TGGModelingMain.TggRuleDiagramMetatype[0]) as EA.Diagram;
                ruleDiagram.Update();
                MainImport.getInstance().DiagramsToBeFilled.Add(ruleDiagram);
            }

            EA.Method mainMethod = MainImport.getInstance().EcoreImport.getOrCreateMethod(sqlRep.GetElementByID(ruleElement.ElementID), ruleNode.getAttributeOrCreate("mainMethodGuid").Value, ruleElement.Name, "");

            MocaNode parametersNode = ruleNode.getChildNodeWithName(EOperation.ParametersChildNodeName);

            if (parametersNode != null)
            {
                foreach (MocaNode paramNode in parametersNode.Children)
                {
                    EA.Parameter parameter = MainImport.getInstance().EcoreImport.getOrCreateParameter(mainMethod, paramNode);

                    MainImport.getInstance().OldGuidToNewGuid.Add(paramNode.getAttributeOrCreate(Main.GuidStringName).Value, parameter.ParameterGUID);
                }
            }

            EClass eClass = MainImport.getInstance().EcoreImport.importEClassFeatures(ruleNode, sqlRep.GetElementByID(ruleElement.ElementID));

            MainImport.getInstance().MocaTaggableElements.Remove(eClass);
            TGGRule rule = new TGGRule(sqlRep, sqlRep.GetElementByID(ruleElement.ElementID));

            rule.deserializeFromMocaTree(ruleNode);

            MainImport.getInstance().MocaTaggableElements.Add(rule);

            foreach (MocaNode ovNode in ruleNode.getChildNodeWithName(StoryPattern.ObjectVariablesChildNodeName).Children)
            {
                if (ovNode.Name == TGGModelingMain.TggObjectVariableStereotype)
                {
                    ObjectVariable ov = MainImport.getInstance().SdmImport.importObjectVariable(sqlRep.GetElementByID(ruleElement.ElementID), ovNode);
                    MainImport.getInstance().MocaTaggableElements.Remove(ov);
                    ov = new TGGObjectVariable(ov.sqlElement, sqlRep);
                    ov.deserializeFromMocaTree(ovNode);
                    MainImport.getInstance().MocaTaggableElements.Add(ov);
                }
                else if (ovNode.Name == TGGCorrespondence.CorrespondenceNodeName)
                {
                    ObjectVariable ov = MainImport.getInstance().SdmImport.importObjectVariable(sqlRep.GetElementByID(ruleElement.ElementID), ovNode);
                    MainImport.getInstance().MocaTaggableElements.Remove(ov);
                    ov = new TGGCorrespondence(ov.sqlElement, sqlRep);
                    ov.deserializeFromMocaTree(ovNode);
                    MainImport.getInstance().MocaTaggableElements.Add(ov);
                }
            }

            MocaNode cspsNode = ruleNode.getChildNodeWithName(TGGRule.CspsChildNodeName);

            if (cspsNode != null)
            {
                foreach (MocaNode cspInstanceNode in cspsNode.Children)
                {
                    importTGGCSP(sqlRep.GetElementByID(ruleElement.ElementID), cspInstanceNode);
                }
            }
            else
            {
                if (ruleNode.getAttributeOrCreate(TGGRule.CspSpecAttributeName).Value != "")
                {
                    EA.Element constraintElement = ruleElement.Elements.AddNew("", Main.EAClassType) as EA.Element;
                    constraintElement.Stereotype = TGGModelingMain.CSPConstraintStereotype;
                    constraintElement.Notes      = ruleNode.getAttributeOrCreate(TGGRule.CspSpecAttributeName).Value;
                    constraintElement.Update();

                    CSPInstance cspInstance = new CSPInstance(sqlRep, sqlRep.GetElementByID(constraintElement.ElementID));
                    cspInstance.CspStringValueFromImport = ruleNode.getAttributeOrCreate(TGGRule.CspSpecAttributeName).Value;
                    MainImport.getInstance().MocaTaggableElements.Add(cspInstance);
                }
            }
        }
コード例 #18
0
        /// <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();
        }