001package org.andromda.metafacades.uml14;
002
003import java.util.Collection;
004import org.andromda.metafacades.uml.FrontEndController;
005import org.andromda.metafacades.uml.FrontEndUseCase;
006import org.andromda.metafacades.uml.ModelElementFacade;
007import org.andromda.metafacades.uml.PseudostateFacade;
008import org.andromda.metafacades.uml.TransitionFacade;
009import org.andromda.metafacades.uml.UMLProfile;
010import org.andromda.metafacades.uml.UseCaseFacade;
011
012
013/**
014 * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndActivityGraph.
015 *
016 * @see org.andromda.metafacades.uml.FrontEndActivityGraph
017 * @author Bob Fields
018 */
019public class FrontEndActivityGraphLogicImpl
020    extends FrontEndActivityGraphLogic
021{
022    private static final long serialVersionUID = 815773525076250652L;
023
024    /**
025     * @param metaObject
026     * @param context
027     */
028    public FrontEndActivityGraphLogicImpl (Object metaObject, String context)
029    {
030        super (metaObject, context);
031    }
032
033    /**
034     * @see org.andromda.metafacades.uml.FrontEndActivityGraph#isContainedInFrontEndUseCase()
035     */
036    @Override
037    protected boolean handleIsContainedInFrontEndUseCase()
038    {
039        return this.getUseCase() instanceof FrontEndUseCase;
040    }
041
042    /**
043     * Retrieves the usecase that owns this activity.
044     *
045     * @see org.andromda.metafacades.uml14.ActivityGraphFacadeLogic#handleGetUseCase()
046     */
047    protected Object handleGetUseCase()
048    {
049        Object useCase = super.handleGetUseCase();
050        if (useCase == null)
051        {
052            useCase = getModel().findUseCaseWithTaggedValueOrHyperlink(UMLProfile.TAGGEDVALUE_PRESENTATION_USECASE_ACTIVITY,
053                    getName());
054        }
055        return useCase;
056    }
057
058    /**
059     * @see org.andromda.metafacades.uml.FrontEndActivityGraph#getInitialAction()
060     */
061    @Override
062    protected TransitionFacade handleGetInitialAction()
063    {
064        TransitionFacade firstAction = null;
065        final Collection<PseudostateFacade> initialStates = getInitialStates();
066        if (!initialStates.isEmpty())
067        {
068            final PseudostateFacade initialState = initialStates.iterator().next();
069            final Collection<TransitionFacade> outgoings = initialState.getOutgoings();
070            firstAction = outgoings.isEmpty() ? null : outgoings.iterator().next();
071        }
072        return firstAction;
073    }
074
075    /**
076     * @see org.andromda.metafacades.uml.FrontEndActivityGraph#getController()
077     */
078    @Override
079    protected Object handleGetController()
080    {
081        Object controller = null;
082
083        final ModelElementFacade contextElement = this.getContextElement();
084        if (contextElement instanceof FrontEndController)
085        {
086            controller = contextElement;
087        }
088
089         // - for those tools not supporting setting the context of an activity graph (such as Poseidon)
090         //   an alternative is implemented: a tagged value on the controller, specifying the name of the use-case
091         //
092         // It is also allowed to set a hyperlink from the controller to the usecase
093        if (controller == null)
094        {
095            final UseCaseFacade useCase = this.getUseCase();
096            if (useCase != null)
097            {
098                final String useCaseName = useCase.getName();
099                controller = this.getModel().findClassWithTaggedValueOrHyperlink(
100                        UMLProfile.TAGGEDVALUE_PRESENTATION_CONTROLLER_USECASE, useCaseName);
101            }
102        }
103        return controller;
104    }
105}