All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.andromda.metafacades.uml14.FrontEndActionStateLogicImpl Maven / Gradle / Ivy

Go to download

The UML 1.4 metafacades. This is the set of UML 1.4 metafacades implementations. These implement the common UML metafacades.

The newest version!
package org.andromda.metafacades.uml14;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.andromda.metafacades.uml.ActivityGraphFacade;
import org.andromda.metafacades.uml.CallEventFacade;
import org.andromda.metafacades.uml.EventFacade;
import org.andromda.metafacades.uml.FrontEndAction;
import org.andromda.metafacades.uml.FrontEndActivityGraph;
import org.andromda.metafacades.uml.FrontEndControllerOperation;
import org.andromda.metafacades.uml.FrontEndEvent;
import org.andromda.metafacades.uml.FrontEndExceptionHandler;
import org.andromda.metafacades.uml.FrontEndUseCase;
import org.andromda.metafacades.uml.FrontEndView;
import org.andromda.metafacades.uml.OperationFacade;
import org.andromda.metafacades.uml.ServiceOperation;
import org.andromda.metafacades.uml.StateMachineFacade;
import org.andromda.metafacades.uml.TransitionFacade;
import org.andromda.metafacades.uml.UseCaseFacade;
import org.andromda.utils.StringUtilsHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;

/**
 * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndActionState.
 *
 * @see org.andromda.metafacades.uml.FrontEndActionState
 * @author Bob Fields
 */
public class FrontEndActionStateLogicImpl
    extends FrontEndActionStateLogic
{
    private static final long serialVersionUID = 34L;
    /**
     * @param metaObject
     * @param context
     */
    public FrontEndActionStateLogicImpl(
        Object metaObject,
        String context)
    {
        super(metaObject, context);
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#isServerSide()
     */
    @Override
    protected boolean handleIsServerSide()
    {
        return !(this.THIS() instanceof FrontEndView);
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#getActionMethodName()
     */
    @Override
    protected String handleGetActionMethodName()
    {
        return '_' + StringUtilsHelper.lowerCamelCaseName(getName());
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#isContainedInFrontEndUseCase()
     */
    @Override
    protected boolean handleIsContainedInFrontEndUseCase()
    {
        return this.getStateMachine() instanceof FrontEndActivityGraph;
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#getForward()
     */
    @Override
    protected TransitionFacade handleGetForward()
    {
        TransitionFacade forward = null;

        for (final Iterator iterator = this.getOutgoings().iterator(); iterator.hasNext() && forward == null;)
        {
            final TransitionFacade transition = (TransitionFacade)iterator.next();
            if (!(transition instanceof FrontEndExceptionHandler))
            {
                forward = transition;
            }
        }
        return forward;
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#getServiceCalls()
     */
    @Override
    protected List handleGetServiceCalls()
    {
        final List serviceCallsList = new ArrayList();
        final Collection deferrableEvents = this.getDeferrableEvents();
        for (final Iterator iterator = deferrableEvents.iterator(); iterator
                .hasNext();)
        {
            final EventFacade event = iterator.next();
            if (event instanceof CallEventFacade)
            {
                serviceCallsList.addAll(((CallEventFacade)event).getOperations());
            }
            else if (event instanceof FrontEndEvent)
            {
                serviceCallsList.addAll(((FrontEndEvent)event).getControllerCalls());
            }
        }
        //removing the controller calls
        CollectionUtils.filter(serviceCallsList, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                final OperationFacade operation=(OperationFacade)object;
                return operation instanceof ServiceOperation;
            }
        });
        return serviceCallsList;
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#getControllerCalls()
     */
    @Override
    protected List handleGetControllerCalls()
    {
        final List controllerCallsList = new ArrayList();
        final Collection  deferrableEvents = this.getDeferrableEvents();
        for (final Iterator  iterator = deferrableEvents.iterator(); iterator.hasNext();)
        {
            final EventFacade event = iterator.next();
            if (event instanceof CallEventFacade)
            {
                final OperationFacade operationObject = ((CallEventFacade)event).getOperation();
                if (operationObject != null)
                {
                    controllerCallsList.add(operationObject);
                }
            }
            else if (event instanceof FrontEndEvent)
            {
                final FrontEndControllerOperation callObject = ((FrontEndEvent)event).getControllerCall();
                if (callObject != null)
                {
                    controllerCallsList.add(callObject);
                }
            }
        }
        //removing the direct service calls
        CollectionUtils.filter(controllerCallsList, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                final OperationFacade operation=(OperationFacade)object;
                return operation instanceof FrontEndControllerOperation;
            }
        });
        return controllerCallsList;
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#getExceptions()
     */
    @Override
    protected List handleGetExceptions()
    {
        final Set exceptions = new LinkedHashSet();
        final Collection outgoing = getOutgoings();
        for (final Iterator iterator = outgoing.iterator(); iterator.hasNext();)
        {
            final TransitionFacade transition = iterator.next();
            if (transition instanceof FrontEndExceptionHandler)
            {
                exceptions.add((FrontEndExceptionHandler)transition);
            }
        }
        return new ArrayList(exceptions);
    }

    /**
     * @see org.andromda.metafacades.uml.FrontEndActionState#getContainerActions()
     */
    @Override
    protected List handleGetContainerActions()
    {
        final Collection actionSet = new LinkedHashSet();

        final StateMachineFacade stateMachineFacade = this.getStateMachine();
        if (stateMachineFacade instanceof ActivityGraphFacade)
        {
            final ActivityGraphFacade activityGraph = (ActivityGraphFacade)stateMachineFacade;
            final UseCaseFacade useCase = activityGraph.getUseCase();

            if (useCase instanceof FrontEndUseCase)
            {
                final Collection actions = ((FrontEndUseCase)useCase).getActions();
                for (final Iterator actionIterator = actions.iterator(); actionIterator.hasNext();)
                {
                    final FrontEndAction action = actionIterator.next();
                    if (action.getActionStates().contains(this))
                    {
                        actionSet.add(action);
                    }
                }
            }
        }
        return new ArrayList(actionSet);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy