001package org.andromda.metafacades.uml14;
002
003import java.util.Collection;
004import java.util.Iterator;
005import org.omg.uml.behavioralelements.activitygraphs.ActionState;
006import org.omg.uml.behavioralelements.commonbehavior.Action;
007import org.omg.uml.behavioralelements.statemachines.Transition;
008
009/**
010 * MetafacadeLogic implementation.
011 *
012 * @see org.andromda.metafacades.uml.ActionFacade
013 * @author Bob Fields
014 */
015public class ActionFacadeLogicImpl
016        extends ActionFacadeLogic
017{
018    private static final long serialVersionUID = 161746442702442292L;
019
020    /**
021     * @param metaObject
022     * @param context
023     */
024    public ActionFacadeLogicImpl(Action metaObject,
025                                 String context)
026    {
027        super(metaObject, context);
028    }
029
030    /**
031     * @see org.andromda.metafacades.uml14.ActionFacadeLogic#handleGetTransition()
032     */
033    protected Transition handleGetTransition()
034    {
035        Transition effectTransition = null;
036
037        final Collection allTransitions = UML14MetafacadeUtils.getModel().getStateMachines().getTransition().refAllOfType();
038        for (final Iterator iterator = allTransitions.iterator(); iterator.hasNext() && effectTransition == null;)
039        {
040            Transition transition = (Transition)iterator.next();
041            if (metaObject.equals(transition.getEffect()))
042            {
043                effectTransition = transition;
044            }
045        }
046
047        return effectTransition;
048    }
049
050    /**
051     * @see org.andromda.metafacades.uml14.ActionFacadeLogic#handleGetActionState()
052     */
053    protected ActionState handleGetActionState()
054    {
055        ActionState entryState = null;
056
057        final Collection allActionStates = UML14MetafacadeUtils.getModel().getActivityGraphs().getActionState().refAllOfType();
058        for (final Iterator iterator = allActionStates.iterator(); iterator.hasNext() && entryState == null;)
059        {
060            final ActionState actionState = (ActionState)iterator.next();
061            if (metaObject.equals(actionState.getEntry()))
062            {
063                entryState = actionState;
064            }
065        }
066
067        return entryState;
068    }
069
070    /**
071     * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
072     */
073    public Object getValidationOwner()
074    {
075        Object validationOwner = getTransition();
076
077        if (validationOwner == null)
078        {
079            validationOwner = getActionState();
080        }
081
082        return validationOwner;
083    }
084}