I currently doing some model transformations using EMF-UML-Implementation.
In my model transformation I create an uml class with some attributes. The attributes are type of enumerations I also created.
Some of the attribute should get a default value. The default value should be enumeration literals.
The question now is, how do I get the enumeration literals to the defaultValue-property of the Property.
I already have found that I have to use ValueSpecification. But the UML superstructure says not much about that (page 139 f.). Which properties do I have to use for setting the defaultValue to enumeration literals?
I think the main problem I have is, that the use of ValueSpecification is unclear to me. Currently I only use default to set the default values, which is type of String.
The defaultValue-property takes a ValueSpecification argument. So in your case, you need an InstanceValue for this purpose (which derives from ValueSpecification). The InstanceValue itself has an instance-property, which takes an InstanceSpecification as argument. As EnumerationLiteral derives from InstanceSpecification, you can now simply assign one of your EnumerationLiterals to it.
Related
In a UML class diagram, the value of one of the attributes of a class is a (typed) dictionary. What is a proper UML type annotation? (Within the box; not as an association.)
For example, in Python I would annotate this attribute with Dict[A,B] or possibly Mapping[A,B]. I am not asking about Python; this is just one example of a somewhat generic attribute annotation. I am open to the possibility that UML does not offer a language agnostic equivalent to this, but I am hoping that is not true.
Comment: I am asking about generic attribute annotation, directly with the class box. I do not wish to add a separate class box for Dict to the diagram. Therefore this is not a duplicate of How can I represent a Python dictionary in UML?
In UML Dict is typically model as a template class with two template parameters for instance named key and value.
Let's say you want the class C has the attribute a being a Dict[A,B], so you have a binding having the template param substitutions key -> A and value -> B.
There are several ways to show that in a class diagram.
For instance using the class DictAB to model Dict[A,B] :
or if you prefer :
But it is also possible to not use the auxiliary class DictAB and to use the textual representation of the binding expression (see formal/2017-12-05 ยง 7.3.4 page 26) :
ReadVariableAction activity action in BoUML allows to choose a class and its attribute and returns the attribute through creation of output pin (see figure below and BoUML documentation):
But what is the semantic of that action? What does ReadVariableAction operation actually return?
According to clause 16.9.3.1 Variable Action of The Unified Modeling Language Specification Version 2.5:
A VariableAction operates on a statically-specified Variable. The Variable must be one that is defined either by an Activity (see sub clause 15.2) or a StructuredActivityNode (see sub clause 16.11) containing the VariableAction.
Clause 15.2.2 Abstract Syntax below says that Variable subsets ownedMember, so the variable should be identifiable by name.
But BoUML neither allows creation of variables for an activity nor passing a name of a variable to ReadVariableAction.
It seems that I could use ReadVariableAction as shown below
But it's wrong model from UML's point of view.
The semantic of the read/write/clear/add/remove variable actions in BoUML is ... wrong !
Clearly I misunderstood that part when I added the activities in BoUML, I didn't read well the norm to understood that concerns variable of the activity or a structured activity node. So by error the 'variable' I allow to choose is an attribute of a class. An other consequence is you cannot define variables for an activity nor structured activity node.
Mea culpa
BoUML 7.10 is available and fix the problem
In the example I made every object of the type "Folder" have an array of type "File" with the name "content" a size of "n" as a private attribute (just saying my understanding of it to make sure that I am not already wrong there). That's how I see it in most examples but I never understand what "n" now is. Is it another attribute of the "Folder" object or is it something that we specify in another part of an UML diagram or something else completely?
What I am trying to achieve is that every object of the type "Folder" has an additional attribute that specifies the size of the "content" array.
Of course, you can not only write 0..*, but use any concrete number, too. If that number has some external definition, you can use there n, as you have it.
The external definition means "not defined by class diagram elements, except notes". Everything that you need to be said on a class diagram page, but can't because of the UML limitations, should be put in a note.
So, n can be defined in appropriate note on the page or in some different document or both.
As #Kilian had mentioned, in the case of some more complicated dependencies of such variables you can use constraints. This way seems to me the most powerful.
But if n has no objective definition or dependency, but is a simple variable that can have any meaning, then it will be correct to use a rule, such as 0..*, or 1..*, or maybe 3..5, according to the reality you are working with.
I created a plain Groovy class (i.e Person class)with some properties. Now I want to get those declared attributes (which I've defined in my class) with their order, but I don't know how to do it.
I've tried to use Person.metaClass.getProperties() but it retrieves not only declared properties but also built-in Groovy ones.
Could you please help me on this: just get declared properties by its order when declaring.
Thank you so much!
I can't see a use case, but the compiler could reorder all fields declaration while creating bytecode. I'm pretty sure ordering is not a constraint on fields though it should mostly be the case for not modified/enhanced class
As per the JVM spec, generated fields should be marked SYNTHETIC (like generated methods) in the bytecode, so you can test with :
Person.getDeclaredFields().grep { !it.synthetic }
and filter the base Groovy fields like ClassInfo,metaClass and others beginning by __timestamp
But I'm not a specialist, there could be another way I don't think of
There was a question about this on the mailing list back in February of this year
The answer is, no. There is no way to get properties in the order they are declared in the class without doing some extra work.
You could parse the source file for the class, and generate an ordered list of property names from that
You could write a custom annotation, and annotate the fields with this annotation ie: #Order(1) String prop
You could make all of the classes where this matters implement an interface which forces them to have a method that returns the names of the properties in order.
Other than that, you probably want to have a re-think :-(
I am using enterprise architect for UML. I need to generate code from the model.
I need have a nullable double attribute in a class.
I am able to add a double attribute but don't know how to make it nullable.
Do anyone have any idea how to add a nullable attribute.
There is a small problems with your question, let me first answer the part about the EA, and get to it later.
In UML you denote nullable type as
+attributeName : TypeName [0..1]
+fromUser : User [0..1]
in EA this is done in the Multiplicity section Select the class->Hit F9->Select the attribute->Click detail
Lower bound and Upper bound are the fields you are looking for, if each are 1 this attribute has a single value [1] usually not depicted in the diagram
[0..1] can have a value of null.
[*] can have any amount of values.
[1..*] collection that contains at least one value
[n..m] collection that contains between n and m values. n and m are replaced by concrete numbers
in many languages double is a primitive/value type you can not make it null. If you need to, you have to use Double. Note the first letter is capital.