SOLVED: Is there a generic way to determine... attributes?

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

SOLVED: Is there a generic way to determine... attributes?

Postby jim.thompson@pobox.com » Sun Oct 21, 2018 9:30 pm

Is it possible to query a model element for its attributes as defined in the metamodel, and the corresponding values of those attributes as defined by the model?

Example: suppose I have a model element of type Class and I want to query that element and get back some data structure, I would think it would be a dictionary with key-value pairs like this:

    Key: isAbstract, Value: true
    Key: isActive, Value: false
Of course, the returned dictionary would also include the classes NamedElement attributes:

    Key: name, Value: "MyClass"
    Key: qualifiedName, "MyModel:MyPackage:MyClass"
    Key: visibility, Value: public
Etc.

[Note, I am *not* talking about the owned attributes, which are model attributes, not metamodel attributes, and are readily available through Classifier.getAttribute().]

Also, I'm aware that there are calls such as isAbstract(), getName(), getVisibility(), etc. I am looking for a *generic* technique.
Last edited by jim.thompson@pobox.com on Fri Nov 16, 2018 7:22 pm, edited 1 time in total.
jim.thompson@pobox.com
Forum Newbie
Forum Newbie
 
Posts: 18
Posts Rating:0
Joined: Mon Mar 12, 2018 9:11 pm
Full name: Jim Thompson

Re: Is there a generic way to determine an elements attributes?

Postby mindaugas.genutis » Tue Oct 30, 2018 8:53 am

Dear Jim,

I have answered this question to you in direct customer support, jira ticket MDUMLCS-29740.

Yours Sincerely,

-- Mindaugas Genutis
User avatar
mindaugas.genutis
Customer Support
Customer Support
 
Posts: 510
Posts Rating:36
Joined: Thu Feb 04, 2010 1:57 am
Location: Kaunas

Re: Is there a generic way to determine an elements attributes?

Postby jim.thompson@pobox.com » Fri Nov 16, 2018 7:14 pm

Your answer was exactly what I needed, thanks.
jim.thompson@pobox.com
Forum Newbie
Forum Newbie
 
Posts: 18
Posts Rating:0
Joined: Mon Mar 12, 2018 9:11 pm
Full name: Jim Thompson

SOLVED: Is there a generic way to determine.... atributes?

Postby jim.thompson@pobox.com » Fri Nov 16, 2018 7:21 pm

Here's the answer the No Magic support team gave me:

Each Element implements the Eclipse Modeling Framework EObject interface, so getting an Element's metamodel attributes is as easy as:

Code: Select all
      EClass e_class = element.eClass();
      EList<EStructuralFeature> features = e_class.getEAllStructuralFeatures();


Some of those features will be instances of EAttribute, and *those* are the metamodel attributes.
jim.thompson@pobox.com
Forum Newbie
Forum Newbie
 
Posts: 18
Posts Rating:0
Joined: Mon Mar 12, 2018 9:11 pm
Full name: Jim Thompson


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests