Ejemplo n.º 1
0
        internal UML_SM.Region getContainingRegion(ElementWrapper elementWrapper)
        {
            ElementWrapper parentElement = getOwningElement(elementWrapper);

            if (parentElement is BehaviorStateMachines.StateMachine)
            {
                BehaviorStateMachines.StateMachine owningStateMachine =
                    parentElement as BehaviorStateMachines.StateMachine;
                foreach (BehaviorStateMachines.Region region in owningStateMachine.regions)
                {
                    if (region.isContainedElement(elementWrapper))
                    {
                        return(region);
                    }
                }
            }
            else if (parentElement is BehaviorStateMachines.State)
            {
                BehaviorStateMachines.State owningState =
                    parentElement as BehaviorStateMachines.State;
                foreach (BehaviorStateMachines.Region region in owningState.regions)
                {
                    if (region.isContainedElement(elementWrapper))
                    {
                        return(region);
                    }
                }
            }

            return(null);
        }
        /// creates a new EAElementWrapper based on the given EA.Element
        internal ElementWrapper createEAElementWrapper
            (global::EA.Element elementToWrap)
        {
            //first check if this element already exists in the cache
            if (this.EAModel.useCache)
            {
                var elementWrapper = this.EAModel.getElementFromCache(elementToWrap.ElementID);
                if (elementWrapper != null)
                {
                    return(elementWrapper);
                }
            }
            ElementWrapper newElementWrapper;

            switch (elementToWrap.Type)
            {
            case "Class":
                //first check if this isn't an enumeration.
                // Enumerations are stored as type Class but with the stereotype enumeration
                if (elementToWrap.StereotypeEx.Contains("enumeration"))
                {
                    newElementWrapper = new Enumeration(this.model as Model, elementToWrap);
                    break;
                }
                else
                {
                    //check if associationclass
                    //elementToWrap.IsAssocationClass() returns an exception when used in a background thread so we use our own method to figure out if its an associationClass.
                    if (this.isAssociationClass(elementToWrap))
                    {
                        newElementWrapper = new AssociationClass(this.model as Model, elementToWrap);
                        break;
                    }
                    else
                    {
                        //just a regular class
                        newElementWrapper = new Class(this.model as Model, elementToWrap);
                        break;
                    }
                }

            case "Enumeration":
                // since version 10 there are also "real" enumerations Both are still supported
                newElementWrapper = new Enumeration(this.model as Model, elementToWrap);
                break;

            case "Interface":
                newElementWrapper = new Interface(this.model as Model, elementToWrap);
                break;

            case "Note":
                newElementWrapper = new NoteComment(this.model as Model, elementToWrap);
                break;

            case "Action":
                // figure out wether this Action is a standard action or a
                // specialized action
                //elementToWrap.Properties;
                XmlDocument descriptionXml   = ((Model)this.model).SQLQuery(@"SELECT x.Description FROM t_object o
										inner join t_xref x on x.Client = o.ea_guid
										where o.Object_ID = "                                         + elementToWrap.ElementID.ToString());
                XmlNodeList descriptionNodes = descriptionXml.SelectNodes(((EA.Model) this.model).formatXPath("//Description"));
                foreach (XmlNode descriptionNode in descriptionNodes)
                {
                    if (descriptionNode.InnerText.Contains("CallOperation"))
                    {
                        newElementWrapper = new CallOperationAction(this.model as Model, elementToWrap);
                        break;
                    }
                }

                // simple Action
                newElementWrapper = new Action(this.model as Model, elementToWrap);
                break;

            case "Interaction":
                newElementWrapper = new Interaction(this.model as Model, elementToWrap);
                break;

            case "Activity":
                newElementWrapper = new Activity(this.model as Model, elementToWrap);
                break;

            case "StateMachine":
                newElementWrapper = new BehaviorStateMachines.StateMachine(this.model as Model, elementToWrap);
                break;

            case "State":
                newElementWrapper = new BehaviorStateMachines.State(this.model as Model, elementToWrap, null);
                break;

            case "StateNode":
                string metaType = elementToWrap.MetaType;
                if (metaType == "Pseudostate" ||
                    metaType == "Synchronisation")
                {
                    newElementWrapper = new BehaviorStateMachines.PseudoState(this.model as Model, elementToWrap, null);
                    break;
                }
                else if (metaType == "FinalState")
                {
                    newElementWrapper = new BehaviorStateMachines.FinalState(this.model as Model, elementToWrap, null);
                    break;
                }
                newElementWrapper = new ElementWrapper(this.model as Model, elementToWrap);
                break;

            case "Package":
                int packageID;
                if (int.TryParse(elementToWrap.MiscData[0], out packageID))
                {
                    newElementWrapper = ((Model)this.model).getElementWrapperByPackageID(packageID);
                    break;
                }
                else
                {
                    throw new Exception("WrappedElement " + elementToWrap.Name + " is not a package");
                }

            case "DataType":
            case "PrimitiveType":     //TODO: fix primitive type so it can handle this
                newElementWrapper = new DataType(this.model as Model, elementToWrap);
                break;

            case "InformationItem":
                newElementWrapper = new InformationItem(this.model as Model, elementToWrap);
                break;

            case "ProxyConnector":
                newElementWrapper = new ProxyConnector(this.model as Model, elementToWrap);
                break;

            case "Part":
                newElementWrapper = new Property(this.model as Model, elementToWrap);
                break;

            case "InteractionFragment":
                newElementWrapper = new InteractionFragment(this.model as Model, elementToWrap);
                break;

            default:
                newElementWrapper = new ElementWrapper(this.model as Model, elementToWrap);
                break;
            }
            //add the element to the cache if needed
            if (this.EAModel.useCache)
            {
                this.EAModel.addElementToCache(newElementWrapper);
            }
            return(newElementWrapper);
        }