001package org.andromda.metafacades.uml14;
002
003import java.util.Collection;
004import java.util.Iterator;
005import org.apache.commons.collections.Predicate;
006import org.omg.uml.behavioralelements.activitygraphs.ActionState;
007import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState;
008import org.omg.uml.behavioralelements.usecases.UseCase;
009import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
010
011/**
012 * Metaclass facade implementation.
013 * @author Bob Fields
014 */
015public class ActivityGraphFacadeLogicImpl
016    extends ActivityGraphFacadeLogic
017{
018    private static final long serialVersionUID = 3098736925534206256L;
019
020    /**
021     * @param metaObject
022     * @param context
023     */
024    public ActivityGraphFacadeLogicImpl(
025        ActivityGraph metaObject,
026        String context)
027    {
028        super(metaObject, context);
029    }
030
031    /**
032     * @see org.andromda.metafacades.uml.ActivityGraphFacade#getActionStates()
033     */
034    @Override
035    public Collection handleGetActionStates()
036    {
037        final Predicate filter =
038            new Predicate()
039            {
040                public boolean evaluate(Object object)
041                {
042                    return object instanceof ActionState;
043                }
044            };
045        return getSubvertices(filter);
046    }
047
048    /**
049     * @see org.andromda.metafacades.uml.ActivityGraphFacade#getObjectFlowStates()
050     */
051    @Override
052    public Collection handleGetObjectFlowStates()
053    {
054        final Predicate filter =
055            new Predicate()
056            {
057                public boolean evaluate(Object object)
058                {
059                    return object instanceof ObjectFlowState;
060                }
061            };
062        return getSubvertices(filter);
063    }
064
065    /**
066     * @see org.andromda.metafacades.uml.ActivityGraphFacade#getUseCase()
067     */
068    @Override
069    protected Object handleGetUseCase()
070    {
071        UseCase stateMachineUseCase = null;
072
073        final Collection<UseCase> useCases = UML14MetafacadeUtils.getModel().getUseCases().getUseCase().refAllOfType();
074        for (final Iterator<UseCase> useCaseIterator = useCases.iterator();
075             useCaseIterator.hasNext() && stateMachineUseCase == null;)
076        {
077            // loop over all use-cases
078            final UseCase useCase = useCaseIterator.next();
079            if (useCase.getOwnedElement().contains(metaObject))
080            {
081                stateMachineUseCase = useCase;
082            }
083        }
084
085        return stateMachineUseCase;
086    }
087
088    /**
089     * @see org.andromda.metafacades.uml.ActivityGraphFacade#getPartitions()
090     */
091    @Override
092    protected Collection handleGetPartitions()
093    {
094        return metaObject.getPartition();
095    }
096
097    /**
098     * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
099     */
100    public Object getValidationOwner()
101    {
102        Object validationOwner = getUseCase();
103
104        if (validationOwner == null)
105        {
106            validationOwner = getStateMachineContext();
107        }
108        if (validationOwner == null)
109        {
110            validationOwner = getPackage();
111        }
112
113        return validationOwner;
114    }
115}