m2doc

M2DOC : How to pass a collection of objects


Is it possible to pass a list of object (PhysicalComponent) to my custom service that prevent me to iterate over all PhysicalComponent ?

Actually I iterarate like this in my M2DOC template :

{m:for pc | self.eAllContents(pa::PhysicalComponent)}
{m:pc.MatrixFlow()}
{m:endfor}

Solution

  • You can create a service with the following signatures:

    public SomeReturnType myService(List<PhysicalComponent> components) {
    ...
    }
    

    or

    public SomeReturnType myService(Set<PhysicalComponent> components) {
    ...
    }
    

    or

    public SomeReturnType myService(Collection<PhysicalComponent> components) {
    ...
    }
    

    Then you can call it this way for instance:

    {m:self.eAllContents(pa::PhysicalComponent)->myService()}
    

    The arrow tells to pass the collection to the service, the dot tell to call the service on each element of the collection.

    If you used a List of a Set as the first parameter you may need to use asSequence() or asOrderedSet():

    {m:self.eAllContents(pa::PhysicalComponent)->asSequence()->myService()}
    

    or

    {m:self.eAllContents(pa::PhysicalComponent)->asOrderedSet()->myService()}