001package org.andromda.metafacades.emf.uml22;
002
003import java.util.ArrayList;
004import java.util.Collection;
005import java.util.List;
006import org.andromda.metafacades.uml.OperationFacade;
007import org.eclipse.uml2.uml.Activity;
008import org.eclipse.uml2.uml.ActivityNode;
009import org.eclipse.uml2.uml.CallOperationAction;
010import org.eclipse.uml2.uml.Operation;
011
012/**
013 * MetafacadeLogic implementation for
014 * org.andromda.metafacades.uml.CallEventFacade. UML1.4 Event is mapped to UML2
015 * Activity (because UML2 Event doesn't contain parameters)
016 *
017 * @see org.andromda.metafacades.uml.CallEventFacade
018 */
019public class CallEventFacadeLogicImpl extends CallEventFacadeLogic
020{
021    private static final long serialVersionUID = 7223650138117667366L;
022
023    /**
024     * @param metaObject
025     * @param context
026     */
027    public CallEventFacadeLogicImpl(final Activity metaObject,
028            final String context)
029    {
030        super(metaObject, context);
031    }
032
033    /**
034     * @see org.andromda.metafacades.uml.CallEventFacade#getOperation()
035     */
036    @Override
037    protected OperationFacade handleGetOperation()
038    {
039        final Collection<OperationFacade> operations = this.getOperations();
040        return operations.isEmpty() ? null : operations.iterator().next();
041    }
042
043    /**
044     * @see org.andromda.metafacades.uml.CallEventFacade#getOperations()
045     */
046    @Override
047    public List<Operation> handleGetOperations()
048    {
049        // We get every operation from each CallOperationAction instance.
050        final List<Operation> operations = new ArrayList<Operation>();
051        Collection<ActivityNode> nodes = this.metaObject.getNodes();
052        // UML2 v3: What previously was in getNodes is now in getOwnedNodes, while getNodes returns null
053        // This causes JSF cartridge to fail unless getOwnedNodes exists in UML2 metamodel.
054        // Activity Node operation parameters will have the incorrect owner type.
055        if (nodes==null || nodes.isEmpty())
056        {
057            nodes = this.metaObject.getOwnedNodes();
058        }
059        for (final ActivityNode nextNode : nodes)
060        {
061            if (nextNode instanceof CallOperationAction)
062            {
063                final Operation operation = ((CallOperationAction) nextNode).getOperation();
064                if (operation != null)
065                {
066                    operations.add(operation);
067                }
068            }
069        }
070        return operations;
071    }
072
073}