Book a Demo

Author Topic: Connector Tagged value  (Read 5489 times)

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Connector Tagged value
« on: April 18, 2013, 09:01:35 pm »
Hi,

i'm about to manipulate the taggedvalue of a connector with the API.

To create an Taggedvalue it is really easy, but i cannot retrieve the information of existing ones.


Code: [Select]
EA.connector connector = <<Connector has been definied and is working!
EA.ConnectorTag contag = null;

try
{
    contag = connector.TaggedValues.GetByName("Mytagvalue");
    if (contag.Value.ToLower().Contains("content"))
    {
         tagvalue = false;
    }
}

I never could get my taggedvalue retrieved from the model.

Any idea about it?

Regards

STefan
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Connector Tagged value
« Reply #1 on: April 18, 2013, 09:13:40 pm »
Stefan,

I never use the GetByName function, and It might be possible that is it not supported for a collection of tagged values.

I just loop the tagged values and query their name.
Here's the code I use at a client, which works somewhat similar to the principles of my EA addin framework.

Code: [Select]
      /// <summary>
        /// returns the tagged values with the specified name
        /// </summary>
        /// <param name="tagName">the name of the tagged values to return</param>
        /// <returns>tagged values with the specified name</returns>
        public List<UMLTaggedValue> getTaggedValues(string tagName)
        {
            List<EATaggedValue> tags = EAWrapperFactory.createEAWrappers(this.model, this.wrappedConnector.TaggedValues).Cast<EATaggedValue>().ToList();
            List<UMLTaggedValue> returnedTags = new List<UMLTaggedValue>();
            foreach (EATaggedValue tag in tags )
            {
                if (tag.name == tagName)
                {
                    returnedTags.Add(tag);
                }
            }
            return returnedTags;
        }

Geert

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Connector Tagged value
« Reply #2 on: April 18, 2013, 10:17:16 pm »
ah, i see.

This makes it able to retrieve the content.

How is the solution to get the tag directly. if "GetByname" ist not working?

Possible would be with GUID or ID, and i didn't find a way to call it by API, only with the database...

Any idea?
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Connector Tagged value
« Reply #3 on: April 18, 2013, 10:21:05 pm »
No you can't.
GetByName() probably also loops the collection, so you won't win much using that.
Tagged values are one of those things you cannot GetByID, so you have no choice bu to iterate the collection.

Geert

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Connector Tagged value
« Reply #4 on: April 18, 2013, 10:24:13 pm »
Ok,

Code: [Select]
       public static EA.ConnectorTag getconntag(EA.Connector con, string tagName)
        {
            List<EA.ConnectorTag> list = con.TaggedValues.Cast<EA.ConnectorTag>().ToList();
            EA.ConnectorTag contag = null;
            foreach (EA.ConnectorTag tag in list)
            {
                if (tag.Name == tagName)
                {
                    contag = tag;
                }
            }
            return contag;
        }

That should do the trick
« Last Edit: April 18, 2013, 10:31:06 pm by sethordefaye »
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Connector Tagged value
« Reply #5 on: April 18, 2013, 10:30:16 pm »
Sure it does.
You can do a foreach on a EA.Collection.
To complete my code example here's the createEAWrappers operation
Code: [Select]
       /// <summary>
        /// creates a list of EAwrappers who wrap the objects in the given collection
        /// </summary>
        /// <param name="model">the model where elements are located</param>
        /// <param name="wrappedItems">the collection of items to be wrapped</param>
        /// <returns>list of EAWrappers</returns>
        public static List<object> createEAWrappers(EAModel model,EA.Collection wrappedItems)
        {
            List<object> returnList = new List<object>();
            //loop the returned ea collection
            foreach (object item in wrappedItems)
            {
                object eaWrapper = createEAWrapper(model, item);
                // only add the wrappers that are not null
                if (eaWrapper != null)
                {
                    returnList.Add(eaWrapper);
                }
            }
            return returnList;
        }

And here's part of the the code that actually creates the wrapper based on the EA object "item"
Code: [Select]
/// <summary>
        /// create an EAWrapper object from the given object from the EA API
        /// </summary>
        /// <param name="model">The model that where the object is located</param>
        /// <param name="wrappedItem">the object from the EA API to be wrapped</param>
        /// <returns>an EAWrapper that wraps the given wrappedItem</returns>
        public static object createEAWrapper(EAModel model, object wrappedItem)
        {
            object eaWrapper = null;
            if (wrappedItem is EA.Element)
            {
                EA.Element element = wrappedItem as EA.Element;
                //object is an element, figure out wich element this is
                if (element.Type == "Class")
                {
                    if (element.StereotypeEx.Contains("enumeration"))
                    {
                        //create new EA enumeration
                        eaWrapper = new EAEnumeration(model,element);
                    }else
                    {
                        // create new EAclass
                        eaWrapper = new EAClass(model, element);
                    }
                }
                else if (element.Type == "Activity")
                {
                    //create new activity
                    eaWrapper = new EAActivity(model, element);
                }
                else if (element.Type == "Package")
                {
                    //create new package
                    eaWrapper = new EAPackage(model, element);
                }
                else if (element.Type == "GUIElement")
                {
                    eaWrapper = new EAScreenElement(model, element);
                }
                else if (element.Type == "Screen")
                {
                    eaWrapper = new EAScreen(model, element);
                }
                else if (element.Type == "Action")
                {
                    eaWrapper = new EAAction(model, element);
                }
                else if (element.Type == "Collaboration")
                {
                    eaWrapper = new EACollaboration(model, element);
                }
                else if (element.Type == "Interface")
                {
                    eaWrapper = new EAInterface(model, element);
                }
                else if (element.Type == "State")
                {
                    eaWrapper = new EAState(model, element);
                }
                else if (element.Type == "UseCase")
                {
                    eaWrapper = new EAUseCase(model, element);
                }
                else if (element.Type == "InformationItem")
                {
                    eaWrapper = new EAInformationItem(model, element);
                }

                else
                {
                    // TODO: add other types when needed
                    eaWrapper = new EAElement(model, element);
                    //throw new Exception("element of type " + element.Type + " cannot be wrapped in an EAElement");
                }
            }
            else if (wrappedItem is EA.Attribute)

Geert
      

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Connector Tagged value
« Reply #6 on: April 18, 2013, 10:32:15 pm »
Sorry, i edited my last post

Code: [Select]
       public static EA.ConnectorTag getconntag(EA.Connector con, string tagName)
        {
            List<EA.ConnectorTag> list = con.TaggedValues.Cast<EA.ConnectorTag>().ToList();
            EA.ConnectorTag contag = null;
            foreach (EA.ConnectorTag tag in list)
            {
                if (tag.Name == tagName)
                {
                    contag = tag;
                }
            }
            return contag;
        }

This solves my issue about it  :)

Thank you Geert
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Connector Tagged value
« Reply #7 on: April 19, 2013, 04:54:27 am »
Beware that tags can appear more than once under the same name. The way you implemented it you get the last one - where the definition of "last" is not clear from EA's side.

q.