Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: xhanness on March 12, 2009, 09:26:23 pm

Title: can't get tagged values into profiles
Post by: xhanness on March 12, 2009, 09:26:23 pm
Hi everybody,

I have developed a profile. Some profile's classes have attributes. I saved it into xml and imported it.

When I click on a profile element (Resources window) and drag it into the diagram, I get a element with all tagged values, corresponding to the original attributes. It works fine ...

However, when I try to generate elements via Automation interface, the tagged values do not appear...

I call the following method:
Code: [Select]
       public static EA.Element createElement(EA.Package aParentPackage, string aElementName,
string aElementType, string [highlight]aElementStereotype[/highlight])
        {
            EA.Element newElement = (EA.Element)aParentPackage.Elements.AddNew(aElementName, aElementType);                        
            newElement.Stereotype = aElementStereotype;
            newElement.Update();
            aParentPackage.Elements.Refresh();

            return newElement;
        }

and I provide the name of the class from the profile package as a "[highlight]aElementStereotype[/highlight]"

Could someone give me a hint, why tagged values do not appear in this case?

... May be the EA does not map my generated elements to the profile correctly ...



Title: Re: can't get tagged values into profiles
Post by: «Midnight» on March 12, 2009, 10:16:15 pm
I'm not sure you should be using the Resources window at all. See the documentation on profiles - or search the forum - for the newer method of loading these. It has been the default implementation since EA 7.0 came out.

Even so I think you will still have your problem with automation. Try this:

Change your code so that the profile string is in the form <profile name>::<stereotype>. Something like MyProfile::MyStereotype. You would quote the entire string of course. You are (sort of) providing a fully-qualified string in place of (just) a stereotype name.

There are some things you should be aware of. In no particular order:HTH, David

[edit]But see Frank's post below.

Note that this will take you into undocumented territory - at least as of EA 7.1. We'll see if 7.5 either documents (and stabilizes) this, or provides another way.[/edit]
Title: Re: can't get tagged values into profiles
Post by: Frank Horn on March 12, 2009, 10:31:35 pm
Haven't tried it for a while, but the situation used to be that tagged values defined in profiles would never be automatically added to elements created by API. There used to be a synchronizing method though:

http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1203483841/4#4

Title: Re: can't get tagged values into profiles
Post by: xhanness on March 12, 2009, 11:13:15 pm
Hi gyus !

thanks for your helpful answers ... I got the elements sychnronized with my profile and tagged values are present.


The right solution was THIS

Code: [Select]
aRepository.CustomCommand("Repository", "SynchProfile", "Profile=PPP;Stereotype=SSS");

The stereotype name is enough to provide without namespace.

thanks !
 :)

Title: Re: can't get tagged values into profiles
Post by: lubos on April 02, 2009, 11:00:58 pm
The problem I see is that you have to know the name of the profile, which is not very general.
We have solved this problem by this code in plugin:
Code: [Select]
oreach (FileInfo fi in di.GetFiles("*.xml"))
                {
              
                    XPathDocument xdoc = new XPathDocument(fi.FullName);
                    XPathNavigator xnav= xdoc.CreateNavigator();
                    String[] stereotypes = elem.StereotypeEx.Split(',');
                    foreach (String stereotype in stereotypes)
                    {
                  
                        XPathNodeIterator xiter = xnav.Select("/MDG.Technology/UMLProfiles/UMLProfile/Content/Stereotypes/Stereotype[@name='"+stereotype+"']/TaggedValues/Tag");
                        while (xiter.MoveNext())
                        {
                        
                            String def= xiter.Current.GetAttribute("default", "");
                            if (def == String.Empty) def = "";
                            String name = xiter.Current.GetAttribute("name", "");
                            if (name == String.Empty) name = "xxxnamexxx";
                            CommonUtils.setTaggedValue(elem, name, def);
                        }
                    }

                }

that parses the MDG xml file and looks for definitions of the given stereotype and automatically adds the requirred tagged values to the element.

The advantage I see is you can add new UML profiles without modifying the plugin.

Any other ideas?
Title: Re: can't get tagged values into profiles
Post by: KP on November 10, 2009, 10:54:13 am
Quote
Hi gyus !

thanks for your helpful answers ... I got the elements sychnronized with my profile and tagged values are present.


The right solution was THIS

Code: [Select]
aRepository.CustomCommand("Repository", "SynchProfile", "Profile=PPP;Stereotype=SSS[highlight];[/highlight]");

The stereotype name is enough to provide without namespace.

thanks !
 :)

There was a missing semi-colon, which I have highlighted. HTH
Title: Re: can't get tagged values into profiles
Post by: Timbo on October 01, 2010, 06:19:19 pm
Hi,
Is there an issue with synchronizing operations. I have the synchronize working fine with stereotypes that are classes but i have an issue with operations. When i add in code they do not synchronise. If i then go to diagram and save them as a dif stereotype then save them back to normal stereotype they do sync. Code below shows how i add it which is the same as for the elements, so im not sure how to fix this issue. Any ideas?


Code: [Select]
       
        var MatchingRuleOp as EA.Method;
        MatchingRuleOp = ResponseRuleElement.Methods.AddNew(  "MatchAll" , "");
        MatchingRuleOp.Stereotype = "DP_MatchingRule";
        MatchingRuleOp.Update();
     thePackage.Elements.Refresh();
     Repository.CustomCommand("Repository", "SynchProfile", "Profile=DataPower;Stereotype=DP_MatchingRule;");