internal void TranslateMembers(PSMBridge bridge, bool translateAsOldVersion = false) { // property if (PSMSource is PSMClass) { PSMClass sourceClass = (PSMClass)PSMSource; foreach (var pr in sourceClass.PSMAttributes) { if (pr.AttributeType == null) { throw new ExolutioException(string.Format("Type of attribute `{0}` is not specified. ", pr)) { ExceptionTitle = "OCL parsing can not continue" } } ; Classifier baseType = TypeTable.Library.RootNamespace.NestedClassifier[pr.AttributeType.Name]; Classifier propType = BridgeHelpers.GetTypeByCardinality(TypeTable, pr, baseType); PSMBridgeAttribute newProp = new PSMBridgeAttribute(pr, PropertyType.One, propType); Properties.Add(newProp); //Registred to FindProperty PSMAttribute.Add(pr, newProp); //Hack newProp.Tag = pr; } } // allInstances { CollectionType allInstancesReturn = TypeTable.Library.CreateCollection(CollectionKind.Set, this); Operation allInstancesOp = new Operation(@"allInstances", true, allInstancesReturn); Operations.Add(allInstancesOp); } // oclAsType //{ // Operation oclAsTypeOp = new Operation(@"oclAsType", true, this.TypeTable.Library.Any, // new Parameter[] { new Parameter("type", this.TypeTable.Library.Type) }); // oclAsTypeOp.ReturnTypeDependsOnArguments = true; // Operations.Add(oclAsTypeOp); //} //skip if (PSMSource is PSMClass && PSMSource.Interpretation != null) { PSMClass sourceClass = (PSMClass)PSMSource; IEnumerable <PSMComponent> components = ((Exolutio.Model.PIM.PIMClass)sourceClass.Interpretation).GetInterpretedComponents().Where(ic => ic != sourceClass && ic.PSMSchema == sourceClass.PSMSchema); foreach (PSMClass targetClass in components) { SkipOperationTag tag = new SkipOperationTag { Source = this, Target = bridge.PSMAssociationMembers[targetClass] }; Operation skipOp = new Operation(string.Format(@"to{0}", targetClass.Name), true, tag.Target); skipOp.Tag = tag; Operations.Add(skipOp); } } // J.M.: 20.4.2012 - update, there may be other incoming associations besides parent, // - non tree associations. These are treated the same as parent associations. List <PSMAssociation> incomingAssociations = new List <PSMAssociation>(); //parent if (PSMSource.ParentAssociation != null) { incomingAssociations.Add(PSMSource.ParentAssociation); } if (PSMSource is PSMClass) { incomingAssociations.AddRange(((PSMClass)PSMSource).GetIncomingNonTreeAssociations().Where(a => a.IsNonTreeAssociation)); } foreach (PSMAssociation incomingAssociation in incomingAssociations) { string parentName = null; string defaultName = null; List <string> namesInOcl = new List <string>(); if (incomingAssociation.Parent is PSM.PSMClass) { parentName = incomingAssociation.Parent.Name; defaultName = parentName; namesInOcl.Add(parentName); } else if (incomingAssociation.Parent is PSM.PSMContentModel) { parentName = GetContentModelOCLName((PSM.PSMContentModel)incomingAssociation.Parent); defaultName = PSMBridgeAssociation.PARENT_STEP; } if (incomingAssociation.IsNamed) { namesInOcl.Add(incomingAssociation.Name); } namesInOcl.Add(PSMBridgeAssociation.PARENT_STEP); if (parentName != null) { Classifier propType = TypeTable.Library.RootNamespace.NestedClassifier[parentName]; PSMBridgeAssociation newProp = new PSMBridgeAssociation(defaultName, namesInOcl, incomingAssociation, PSMBridgeAssociation.AssociationDirection.Up, PropertyType.One, propType); //Properties.Add(newProp); namesInOcl.ForEach(name => Properties.Add(newProp, name)); //Hack newProp.Tag = incomingAssociation.Parent; this.Parent = newProp; } } int childCount = 0; Dictionary <PSM.PSMContentModelType, int> childContentModelCount = new Dictionary <PSM.PSMContentModelType, int>(); childContentModelCount[PSM.PSMContentModelType.Choice] = 0; childContentModelCount[PSM.PSMContentModelType.Sequence] = 0; childContentModelCount[PSM.PSMContentModelType.Set] = 0; //child foreach (var ass in PSMSource.ChildPSMAssociations) { string childClassName; string defaultName; // Association can have more than one name in OCL List <string> namesInOcl = new List <string>(); // Resolve association end type name if (ass.Child is PSM.PSMClass) { childClassName = ass.Child.Name; if (translateAsOldVersion) { childClassName += @"_old"; } namesInOcl.Add(childClassName); defaultName = childClassName; } else if (ass.Child is PSM.PSMContentModel) { var cM = (PSM.PSMContentModel)ass.Child; childClassName = GetContentModelOCLName((PSM.PSMContentModel)ass.Child); childClassName += @"_old"; childContentModelCount[cM.Type] = childContentModelCount[cM.Type] + 1; string cmName = String.Format("{0}_{1}", cM.Type.ToString().ToLower(), childContentModelCount[cM.Type]); namesInOcl.Add(cmName); defaultName = cmName; } else { System.Diagnostics.Debug.Fail("Nepodporovany typ v PSM."); continue; } if (ass.IsNamed) { namesInOcl.Add(ass.Name); defaultName = ass.Name; } // Other naming format // child_{type} namesInOcl.Add(String.Format(PSMBridgeAssociation.CHILD_N_STEP, childClassName)); // child_{order} namesInOcl.Add(string.Format(PSMBridgeAssociation.CHILD_N_STEP, ++childCount)); Classifier assType = TypeTable.Library.RootNamespace.NestedClassifier[childClassName]; Classifier propType = BridgeHelpers.GetTypeByCardinality(TypeTable, ass, assType); PSMBridgeAssociation newAss = new PSMBridgeAssociation(defaultName, namesInOcl, ass, PSMBridgeAssociation.AssociationDirection.Down, PropertyType.One, propType); //hack newAss.Tag = ass; //Registre to find PSMChildMembers.Add(ass, newAss); //Registred all name in tables foreach (string name in namesInOcl.Distinct()) { Properties.Add(newAss, name); } } }
internal void TranslateMembers() { //Attributy foreach (var pr in SourceClass.PIMAttributes) { Classifier baseType = pr.AttributeType != null ? TypeTable.Library.RootNamespace.NestedClassifier[pr.AttributeType.Name] : TypeTable.Library.Any; Classifier propType = BridgeHelpers.GetTypeByCardinality(TypeTable, pr, baseType); PIMBridgeAttribute newProp = new PIMBridgeAttribute(pr, PropertyType.One, propType); Properties.Add(newProp); //Hack newProp.Tag = pr; //Registration to find PIMAttribute.Add(pr, newProp); } //Associace foreach (var ass in SourceClass.PIMAssociationEnds) { var end = ass.PIMAssociation.PIMAssociationEnds.Where(a => a.ID != ass.ID).First(); Classifier assType = TypeTable.Library.RootNamespace.NestedClassifier[end.PIMClass.Name]; string name; if (string.IsNullOrEmpty(end.Name)) { name = assType.Name; } else { name = end.Name; } Classifier propType = BridgeHelpers.GetTypeByCardinality(TypeTable, end, assType); TypeTable.RegisterType(propType); PIMBridgeAssociation newass = new PIMBridgeAssociation(name, ass.PIMAssociation, end, PropertyType.One, propType); Properties.Add(newass); //hack newass.Tag = end; //Registration to find PIMAssociations.Add(end, newass); } //Operation foreach (var op in SourceClass.PIMOperations) { Operation newOp = new Operation(op.Name, true, op.ResultType != null ? TypeTable.Library.RootNamespace.NestedClassifier[op.ResultType.Name] : TypeTable.Library.Void, op.Parameters.Select(p => new Parameter(p.Name, TypeTable.Library.RootNamespace.NestedClassifier[p.Type.Name]))); Operations.Add(newOp); //hack newOp.Tag = op; // Registration to find PIMOperations.Add(op, newOp); } // allInstances { Operation allInstancesOp = new Operation(@"allInstances", true, this); Operations.Add(allInstancesOp); } }