FrontEndControllerLogic.java

// license-header java merge-point
//
// Attention: generated code (by MetafacadeLogic.vsl) - do not modify!
//
package org.andromda.metafacades.uml14;

import java.util.Collection;
import java.util.List;
import org.andromda.core.metafacade.MetafacadeBase;
import org.andromda.core.metafacade.ModelValidationMessage;
import org.andromda.metafacades.uml.DependencyFacade;
import org.andromda.metafacades.uml.FrontEndAction;
import org.andromda.metafacades.uml.FrontEndController;
import org.andromda.metafacades.uml.FrontEndUseCase;
import org.andromda.translation.ocl.validation.OCLCollections;
import org.andromda.translation.ocl.validation.OCLIntrospector;
import org.andromda.translation.ocl.validation.OCLResultEnsurer;
import org.apache.log4j.Logger;
import org.omg.uml.foundation.core.Classifier;

/**
 * A front end controller is assigned as the context of a use-case. The controller provides the
 * "controlling" of the use case's activity.
 * MetafacadeLogic for FrontEndController
 *
 * @see FrontEndController
 */
public abstract class FrontEndControllerLogic
    extends ClassifierFacadeLogicImpl
    implements FrontEndController
{
    /**
     * The underlying UML object
     * @see Object
     */
    protected Object metaObject;

    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
     * @param metaObjectIn
     * @param context
     */
    protected FrontEndControllerLogic(Object metaObjectIn, String context)
    {
        super((Classifier)metaObjectIn, getContext(context));
        this.metaObject = metaObjectIn;
    }

    /**
     * The logger instance.
     */
    private static final Logger logger = Logger.getLogger(FrontEndControllerLogic.class);

    /**
     * Gets the context for this metafacade logic instance.
     * @param context String. Set to FrontEndController if null
     * @return context String
     */
    private static String getContext(String context)
    {
        if (context == null)
        {
            context = "org.andromda.metafacades.uml.FrontEndController";
        }
        return context;
    }

    /** Reset context only for non-root metafacades
     * @param context
     */
    @Override
    public void resetMetafacadeContext(String context)
    {
        if (!this.contextRoot) // reset context only for non-root metafacades
        {
            context = getContext(context);  // to have same value as in original constructor call
            setMetafacadeContext (context);
        }
    }

    /**
     * @return boolean true always
     * @see FrontEndController
     */
    public boolean isFrontEndControllerMetaType()
    {
        return true;
    }

    // ------------- associations ------------------

    private FrontEndUseCase __getUseCase1r;
    private boolean __getUseCase1rSet = false;

    /**
     * Returns the controller for this use-case.
     * @return (FrontEndUseCase)handleGetUseCase()
     */
    public final FrontEndUseCase getUseCase()
    {
        FrontEndUseCase getUseCase1r = this.__getUseCase1r;
        if (!this.__getUseCase1rSet)
        {
            // controller has no pre constraints
            Object result = handleGetUseCase();
            MetafacadeBase shieldedResult = this.shieldedElement(result);
            try
            {
                getUseCase1r = (FrontEndUseCase)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getUseCase FrontEndUseCase " + result + ": " + shieldedResult);
            }
            // controller has no post constraints
            this.__getUseCase1r = getUseCase1r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getUseCase1rSet = true;
            }
        }
        return getUseCase1r;
    }

    /**
     * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
     * @return Object
     */
    protected abstract Object handleGetUseCase();

    private List<DependencyFacade> __getServiceReferences2r;
    private boolean __getServiceReferences2rSet = false;

    /**
     * A front end controller is assigned as the context of a use-case. The controller provides the
     * "controlling" of the use case's activity.
     * @return (List<DependencyFacade>)handleGetServiceReferences()
     */
    public final List<DependencyFacade> getServiceReferences()
    {
        List<DependencyFacade> getServiceReferences2r = this.__getServiceReferences2r;
        if (!this.__getServiceReferences2rSet)
        {
            // frontEndController has no pre constraints
            List result = handleGetServiceReferences();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getServiceReferences2r = (List<DependencyFacade>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getServiceReferences List<DependencyFacade> " + result + ": " + shieldedResult);
            }
            // frontEndController has no post constraints
            this.__getServiceReferences2r = getServiceReferences2r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getServiceReferences2rSet = true;
            }
        }
        return getServiceReferences2r;
    }

    /**
     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
     * @return  List
     */
    protected abstract List handleGetServiceReferences();

    private List<FrontEndAction> __getDeferringActions3r;
    private boolean __getDeferringActions3rSet = false;

    /**
     * The controller that will handle the execution of this front-end action. This controller is
     * set as the context of the activity graph (and therefore also of the use-case).
     * @return (List<FrontEndAction>)handleGetDeferringActions()
     */
    public final List<FrontEndAction> getDeferringActions()
    {
        List<FrontEndAction> getDeferringActions3r = this.__getDeferringActions3r;
        if (!this.__getDeferringActions3rSet)
        {
            // controller has no pre constraints
            List result = handleGetDeferringActions();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getDeferringActions3r = (List<FrontEndAction>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getDeferringActions List<FrontEndAction> " + result + ": " + shieldedResult);
            }
            // controller has no post constraints
            this.__getDeferringActions3r = getDeferringActions3r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getDeferringActions3rSet = true;
            }
        }
        return getDeferringActions3r;
    }

    /**
     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
     * @return  List
     */
    protected abstract List handleGetDeferringActions();

    /**
     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package</p>
     * <p><b>Error:</b> Each front-end controller is required to be modeled in a package, doing otherwise will result in uncompileable code due to filename collisions.</p>
     * <p><b>OCL:</b> context FrontEndController inv: packageName->notEmpty()</p>
     * @param validationMessages Collection<ModelValidationMessage>
     * @see ClassifierFacadeLogicImpl#validateInvariants(Collection validationMessages)
     */
    @Override
    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
    {
        super.validateInvariants(validationMessages);
        try
        {
            final Object contextElement = this.THIS();
            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"packageName")));
            if (!constraintValid)
            {
                validationMessages.add(
                    new ModelValidationMessage(
                        (MetafacadeBase)contextElement ,
                        "org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package",
                        "Each front-end controller is required to be modeled in a package, doing otherwise will result in uncompileable code due to filename collisions."));
            }
        }
        catch (Throwable th)
        {
            Throwable cause = th.getCause();
            int depth = 0; // Some throwables have infinite recursion
            while (cause != null && depth < 7)
            {
                th = cause;
                depth++;
            }
            logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package' ON "
                + this.THIS().toString() + ": " + th.getMessage(), th);
        }
    }
}