How to derive a collection of objects [message #1758975] |
Tue, 04 April 2017 18:10  |
Eclipse User |
|
|
|
Dear all,
I am completly stucked trying to derive a collection from another collection. Let me summarize the problem:
- I have a Repository containing component definitions (ComponentDef). Each component definition has: (1) a name; and (2) a set of Ports. Ports only have a name.
- I want to reuse these components in different systems. Thus, I model my System as a set of components (Component). Similar to component definitions, Each Component has: (1) a name, and (2) a set of ports, but they also contain (3) a reference to one of the component definitions stored in the the Respository.
- I want to initialize each system component deriving its name and ports from the name and ports of its definition , i.e., as soon as I set the definition to a ComponentDef, I want its name and ports to be automatically obtained from the corresponding ComponentDef.
- Deriving the name of the component is trivial. However, deriving the list of ports seems absolutely impossible to me. I have managed to get the first port of the component definition (I attach the .ecore file => see the derive_ports() operation). However, I do not know how to derive the whole list of ports. In fact, I have not been able to check if the definition is empty and, in case it is not, if it contains ports or not to safely access them, i.e., to avoid runtime exceptions. As soon as I modify the body of the operation trying to check these conditions, I get an error.
Any help will be very wellcome!
Thanks in advance,
Christina
BTW: I am using Eclipse Oxygen with EMF 2.13.0 and OCL 6.3.0
|
|
|
|
Re: How to derive a collection of objects [message #1759078 is a reply to message #1759055] |
Wed, 05 April 2017 13:36  |
Eclipse User |
|
|
|
Dear Ed,
Thank you for your prompt answer. You are right; I modified the multiplicity of "ports" to try something, and then forgot to change it back again. The correct cardinality is 1..*
Anyway, the problem is not the cardinality, but the lack of an operation that allows me to iterate on the ports of the ComponentDefinition and, for each of these ports, to create a copy and to insert the copy in the list of ports of the Component. Maybe the operation/iterator exists but I do not know it, or I do not know how to use it for this purpose :-S.
All I managed to do in the example I sent yesterday was to initialize the ports of a Component with the first port of its ComponentDefinition. How can I add all the others?
I would really appreciate any hint on this issue.
Thank you in advance!
Cristina
|
|
|
Powered by
FUDForum. Page generated in 0.03125 seconds