示例#1
0
 /// <summary>
 /// Adds members included from structural representatives
 /// </summary>
 internal void IncludeSRMembers(PSMBridgeClass representedClass)
 {
     foreach (KeyValuePair <PSMAttribute, PSMBridgeAttribute> kvp in representedClass.PSMAttribute)
     {
         PSMBridgeAttribute copy = new PSMBridgeAttribute(kvp.Key, kvp.Value.PropertyType, kvp.Value.Type);
         PSMAttribute.Add(kvp.Key, copy);
         copy.Tag = kvp.Value.Tag;
         Properties.Add(copy);
     }
     foreach (KeyValuePair <PSMAssociation, PSMBridgeAssociation> kvp in PSMChildMembers)
     {
         if (kvp.Value.Direction == PSMBridgeAssociation.AssociationDirection.Down)
         {
             PSMBridgeAssociation copy = new PSMBridgeAssociation(kvp.Value.DefaultName, kvp.Value.Aliases, kvp.Value.SourceAsscociation, kvp.Value.Direction, kvp.Value.PropertyType, kvp.Value.Type);
             PSMChildMembers.Add(kvp.Key, copy);
             copy.Tag = kvp.Value.Tag;
             Properties.Add(copy, kvp.Value.Name);
         }
     }
 }
示例#2
0
        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);
                }
            }
        }