FrontEndViewLogic.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.FrontEndAction;
import org.andromda.metafacades.uml.FrontEndParameter;
import org.andromda.metafacades.uml.FrontEndUseCase;
import org.andromda.metafacades.uml.FrontEndView;
import org.andromda.translation.ocl.validation.OCLCollections;
import org.andromda.translation.ocl.validation.OCLExpressions;
import org.andromda.translation.ocl.validation.OCLIntrospector;
import org.andromda.translation.ocl.validation.OCLResultEnsurer;
import org.apache.commons.collections.Transformer;
import org.apache.log4j.Logger;

/**
 * Represents a view within a front end application.
 * MetafacadeLogic for FrontEndView
 *
 * @see FrontEndView
 */
public abstract class FrontEndViewLogic
    extends FrontEndActionStateLogicImpl
    implements FrontEndView
{
    /**
     * The underlying UML object
     * @see Object
     */
    protected Object metaObject;

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

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

    /**
     * Gets the context for this metafacade logic instance.
     * @param context String. Set to FrontEndView if null
     * @return context String
     */
    private static String getContext(String context)
    {
        if (context == null)
        {
            context = "org.andromda.metafacades.uml.FrontEndView";
        }
        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 FrontEndView
     */
    public boolean isFrontEndViewMetaType()
    {
        return true;
    }

    // --------------- attributes ---------------------

   /**
    * @see FrontEndView#isFrontEndView()
    * @return boolean
    */
    protected abstract boolean handleIsFrontEndView();

    private boolean __frontEndView1a;
    private boolean __frontEndView1aSet = false;

    /**
     * True if this element carries the FrontEndView stereotype.
     * @return (boolean)handleIsFrontEndView()
     */
    public final boolean isFrontEndView()
    {
        boolean frontEndView1a = this.__frontEndView1a;
        if (!this.__frontEndView1aSet)
        {
            // frontEndView has no pre constraints
            frontEndView1a = handleIsFrontEndView();
            // frontEndView has no post constraints
            this.__frontEndView1a = frontEndView1a;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__frontEndView1aSet = true;
            }
        }
        return frontEndView1a;
    }

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

    private List<FrontEndParameter> __getAllActionParameters1r;
    private boolean __getAllActionParameters1rSet = false;

    /**
     * Represents a view within a front end application.
     * @return (List<FrontEndParameter>)handleGetAllActionParameters()
     */
    public final List<FrontEndParameter> getAllActionParameters()
    {
        List<FrontEndParameter> getAllActionParameters1r = this.__getAllActionParameters1r;
        if (!this.__getAllActionParameters1rSet)
        {
            // frontEndView has no pre constraints
            List result = handleGetAllActionParameters();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getAllActionParameters1r = (List<FrontEndParameter>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndViewLogic.logger.warn("incorrect metafacade cast for FrontEndViewLogic.getAllActionParameters List<FrontEndParameter> " + result + ": " + shieldedResult);
            }
            // frontEndView has no post constraints
            this.__getAllActionParameters1r = getAllActionParameters1r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getAllActionParameters1rSet = true;
            }
        }
        return getAllActionParameters1r;
    }

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

    private List<FrontEndParameter> __getAllFormFields2r;
    private boolean __getAllFormFields2rSet = false;

    /**
     * Represents a view within a front end application.
     * @return (List<FrontEndParameter>)handleGetAllFormFields()
     */
    public final List<FrontEndParameter> getAllFormFields()
    {
        List<FrontEndParameter> getAllFormFields2r = this.__getAllFormFields2r;
        if (!this.__getAllFormFields2rSet)
        {
            // frontEndView has no pre constraints
            List result = handleGetAllFormFields();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getAllFormFields2r = (List<FrontEndParameter>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndViewLogic.logger.warn("incorrect metafacade cast for FrontEndViewLogic.getAllFormFields List<FrontEndParameter> " + result + ": " + shieldedResult);
            }
            // frontEndView has no post constraints
            this.__getAllFormFields2r = getAllFormFields2r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getAllFormFields2rSet = true;
            }
        }
        return getAllFormFields2r;
    }

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

    private List<FrontEndParameter> __getVariables3r;
    private boolean __getVariables3rSet = false;

    /**
     * Represents the view in which this parameter will be used.
     * @return (List<FrontEndParameter>)handleGetVariables()
     */
    public final List<FrontEndParameter> getVariables()
    {
        List<FrontEndParameter> getVariables3r = this.__getVariables3r;
        if (!this.__getVariables3rSet)
        {
            // view has no pre constraints
            List result = handleGetVariables();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getVariables3r = (List<FrontEndParameter>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndViewLogic.logger.warn("incorrect metafacade cast for FrontEndViewLogic.getVariables List<FrontEndParameter> " + result + ": " + shieldedResult);
            }
            // view has no post constraints
            this.__getVariables3r = getVariables3r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getVariables3rSet = true;
            }
        }
        return getVariables3r;
    }

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

    private FrontEndUseCase __getUseCase4r;
    private boolean __getUseCase4rSet = false;

    /**
     * All views that are part of this use case.
     * @return (FrontEndUseCase)handleGetUseCase()
     */
    public final FrontEndUseCase getUseCase()
    {
        FrontEndUseCase getUseCase4r = this.__getUseCase4r;
        if (!this.__getUseCase4rSet)
        {
            // views has no pre constraints
            Object result = handleGetUseCase();
            MetafacadeBase shieldedResult = this.shieldedElement(result);
            try
            {
                getUseCase4r = (FrontEndUseCase)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndViewLogic.logger.warn("incorrect metafacade cast for FrontEndViewLogic.getUseCase FrontEndUseCase " + result + ": " + shieldedResult);
            }
            // views has no post constraints
            this.__getUseCase4r = getUseCase4r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getUseCase4rSet = true;
            }
        }
        return getUseCase4r;
    }

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

    private List<FrontEndParameter> __getTables5r;
    private boolean __getTables5rSet = false;

    /**
     * Represents a view within a front end application.
     * @return (List<FrontEndParameter>)handleGetTables()
     */
    public final List<FrontEndParameter> getTables()
    {
        List<FrontEndParameter> getTables5r = this.__getTables5r;
        if (!this.__getTables5rSet)
        {
            // frontEndView has no pre constraints
            List result = handleGetTables();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getTables5r = (List<FrontEndParameter>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndViewLogic.logger.warn("incorrect metafacade cast for FrontEndViewLogic.getTables List<FrontEndParameter> " + result + ": " + shieldedResult);
            }
            // frontEndView has no post constraints
            this.__getTables5r = getTables5r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getTables5rSet = true;
            }
        }
        return getTables5r;
    }

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

    private List<FrontEndAction> __getActions6r;
    private boolean __getActions6rSet = false;

    /**
     * The StateVertex (FrontEndView or PseudostateFacade) on which this action can be triggered.
     * @return (List<FrontEndAction>)handleGetActions()
     */
    public final List<FrontEndAction> getActions()
    {
        List<FrontEndAction> getActions6r = this.__getActions6r;
        if (!this.__getActions6rSet)
        {
            // input has no pre constraints
            List result = handleGetActions();
            List shieldedResult = this.shieldedElements(result);
            try
            {
                getActions6r = (List<FrontEndAction>)shieldedResult;
            }
            catch (ClassCastException ex)
            {
                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
                FrontEndViewLogic.logger.warn("incorrect metafacade cast for FrontEndViewLogic.getActions List<FrontEndAction> " + result + ": " + shieldedResult);
            }
            // input has no post constraints
            this.__getActions6r = getActions6r;
            if (isMetafacadePropertyCachingEnabled())
            {
                this.__getActions6rSet = true;
            }
        }
        return getActions6r;
    }

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

    /**
     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndView::unique view name per usecase</p>
     * <p><b>Error:</b> Each name of a view action state must be unique in the namespace of a front-end use-case.</p>
     * <p><b>OCL:</b> context FrontEndView inv: useCase.views->isUnique(name)</p>
     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndView::view variables must have unique names</p>
     * <p><b>Error:</b> Each view-variable should have a unique name within the context of a view.</p>
     * <p><b>OCL:</b> context FrontEndView inv : variables->isUnique(name)</p>
     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndView::front-end views cannot defer operations</p>
     * <p><b>Error:</b> Views cannot defer to operations. All deferrable events modeled on a front-end view will be ignored.</p>
     * <p><b>OCL:</b> context FrontEndView inv: controllerCalls->size() = 0</p>
     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndView::each action going out of a front-end view must be unique</p>
     * <p><b>Error:</b> Each view must contain actions which each have a unique name, this view has actions with duplicate names.</p>
     * <p><b>OCL:</b> context FrontEndView inv: actions->isUnique(name)</p>
     * @param validationMessages Collection<ModelValidationMessage>
     * @see FrontEndActionStateLogicImpl#validateInvariants(Collection validationMessages)
     */
    @Override
    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
    {
        super.validateInvariants(validationMessages);
        try
        {
            final Object contextElement = this.THIS();
            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.isUnique(OCLIntrospector.invoke(contextElement,"useCase.views"),new Transformer(){public Object transform(Object object){return OCLIntrospector.invoke(object,"name");}}));
            if (!constraintValid)
            {
                validationMessages.add(
                    new ModelValidationMessage(
                        (MetafacadeBase)contextElement ,
                        "org::andromda::metafacades::uml::FrontEndView::unique view name per usecase",
                        "Each name of a view action state must be unique in the namespace of a front-end use-case."));
            }
        }
        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::FrontEndView::unique view name per usecase' ON "
                + this.THIS().toString() + ": " + th.getMessage(), th);
        }
        try
        {
            final Object contextElement = this.THIS();
            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.isUnique(OCLIntrospector.invoke(contextElement,"variables"),new Transformer(){public Object transform(Object object){return OCLIntrospector.invoke(object,"name");}}));
            if (!constraintValid)
            {
                validationMessages.add(
                    new ModelValidationMessage(
                        (MetafacadeBase)contextElement ,
                        "org::andromda::metafacades::uml::FrontEndView::view variables must have unique names",
                        "Each view-variable should have a unique name within the context of a view."));
            }
        }
        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::FrontEndView::view variables must have unique names' ON "
                + this.THIS().toString() + ": " + th.getMessage(), th);
        }
        try
        {
            final Object contextElement = this.THIS();
            boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.equal(OCLCollections.size(OCLIntrospector.invoke(contextElement,"controllerCalls")),0));
            if (!constraintValid)
            {
                validationMessages.add(
                    new ModelValidationMessage(
                        (MetafacadeBase)contextElement ,
                        "org::andromda::metafacades::uml::FrontEndView::front-end views cannot defer operations",
                        "Views cannot defer to operations. All deferrable events modeled on a front-end view will be ignored."));
            }
        }
        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::FrontEndView::front-end views cannot defer operations' ON "
                + this.THIS().toString() + ": " + th.getMessage(), th);
        }
        try
        {
            final Object contextElement = this.THIS();
            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.isUnique(OCLIntrospector.invoke(contextElement,"actions"),new Transformer(){public Object transform(Object object){return OCLIntrospector.invoke(object,"name");}}));
            if (!constraintValid)
            {
                validationMessages.add(
                    new ModelValidationMessage(
                        (MetafacadeBase)contextElement ,
                        "org::andromda::metafacades::uml::FrontEndView::each action going out of a front-end view must be unique",
                        "Each view must contain actions which each have a unique name, this view has actions with duplicate names."));
            }
        }
        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::FrontEndView::each action going out of a front-end view must be unique' ON "
                + this.THIS().toString() + ": " + th.getMessage(), th);
        }
    }
}