001// license-header java merge-point
002//
003// Attention: generated code (by MetafacadeLogic.vsl) - do not modify!
004//
005package org.andromda.metafacades.uml14;
006
007import java.util.Collection;
008import java.util.List;
009import org.andromda.core.metafacade.MetafacadeBase;
010import org.andromda.core.metafacade.ModelValidationMessage;
011import org.andromda.metafacades.uml.DependencyFacade;
012import org.andromda.metafacades.uml.FrontEndAction;
013import org.andromda.metafacades.uml.FrontEndController;
014import org.andromda.metafacades.uml.FrontEndUseCase;
015import org.andromda.translation.ocl.validation.OCLCollections;
016import org.andromda.translation.ocl.validation.OCLIntrospector;
017import org.andromda.translation.ocl.validation.OCLResultEnsurer;
018import org.apache.log4j.Logger;
019import org.omg.uml.foundation.core.Classifier;
020
021/**
022 * A front end controller is assigned as the context of a use-case. The controller provides the
023 * "controlling" of the use case's activity.
024 * MetafacadeLogic for FrontEndController
025 *
026 * @see FrontEndController
027 */
028public abstract class FrontEndControllerLogic
029    extends ClassifierFacadeLogicImpl
030    implements FrontEndController
031{
032    /**
033     * The underlying UML object
034     * @see Object
035     */
036    protected Object metaObject;
037
038    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
039     * @param metaObjectIn
040     * @param context
041     */
042    protected FrontEndControllerLogic(Object metaObjectIn, String context)
043    {
044        super((Classifier)metaObjectIn, getContext(context));
045        this.metaObject = metaObjectIn;
046    }
047
048    /**
049     * The logger instance.
050     */
051    private static final Logger logger = Logger.getLogger(FrontEndControllerLogic.class);
052
053    /**
054     * Gets the context for this metafacade logic instance.
055     * @param context String. Set to FrontEndController if null
056     * @return context String
057     */
058    private static String getContext(String context)
059    {
060        if (context == null)
061        {
062            context = "org.andromda.metafacades.uml.FrontEndController";
063        }
064        return context;
065    }
066
067    /** Reset context only for non-root metafacades
068     * @param context
069     */
070    @Override
071    public void resetMetafacadeContext(String context)
072    {
073        if (!this.contextRoot) // reset context only for non-root metafacades
074        {
075            context = getContext(context);  // to have same value as in original constructor call
076            setMetafacadeContext (context);
077        }
078    }
079
080    /**
081     * @return boolean true always
082     * @see FrontEndController
083     */
084    public boolean isFrontEndControllerMetaType()
085    {
086        return true;
087    }
088
089    // ------------- associations ------------------
090
091    private FrontEndUseCase __getUseCase1r;
092    private boolean __getUseCase1rSet = false;
093
094    /**
095     * Returns the controller for this use-case.
096     * @return (FrontEndUseCase)handleGetUseCase()
097     */
098    public final FrontEndUseCase getUseCase()
099    {
100        FrontEndUseCase getUseCase1r = this.__getUseCase1r;
101        if (!this.__getUseCase1rSet)
102        {
103            // controller has no pre constraints
104            Object result = handleGetUseCase();
105            MetafacadeBase shieldedResult = this.shieldedElement(result);
106            try
107            {
108                getUseCase1r = (FrontEndUseCase)shieldedResult;
109            }
110            catch (ClassCastException ex)
111            {
112                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
113                FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getUseCase FrontEndUseCase " + result + ": " + shieldedResult);
114            }
115            // controller has no post constraints
116            this.__getUseCase1r = getUseCase1r;
117            if (isMetafacadePropertyCachingEnabled())
118            {
119                this.__getUseCase1rSet = true;
120            }
121        }
122        return getUseCase1r;
123    }
124
125    /**
126     * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
127     * @return Object
128     */
129    protected abstract Object handleGetUseCase();
130
131    private List<DependencyFacade> __getServiceReferences2r;
132    private boolean __getServiceReferences2rSet = false;
133
134    /**
135     * A front end controller is assigned as the context of a use-case. The controller provides the
136     * "controlling" of the use case's activity.
137     * @return (List<DependencyFacade>)handleGetServiceReferences()
138     */
139    public final List<DependencyFacade> getServiceReferences()
140    {
141        List<DependencyFacade> getServiceReferences2r = this.__getServiceReferences2r;
142        if (!this.__getServiceReferences2rSet)
143        {
144            // frontEndController has no pre constraints
145            List result = handleGetServiceReferences();
146            List shieldedResult = this.shieldedElements(result);
147            try
148            {
149                getServiceReferences2r = (List<DependencyFacade>)shieldedResult;
150            }
151            catch (ClassCastException ex)
152            {
153                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
154                FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getServiceReferences List<DependencyFacade> " + result + ": " + shieldedResult);
155            }
156            // frontEndController has no post constraints
157            this.__getServiceReferences2r = getServiceReferences2r;
158            if (isMetafacadePropertyCachingEnabled())
159            {
160                this.__getServiceReferences2rSet = true;
161            }
162        }
163        return getServiceReferences2r;
164    }
165
166    /**
167     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
168     * @return  List
169     */
170    protected abstract List handleGetServiceReferences();
171
172    private List<FrontEndAction> __getDeferringActions3r;
173    private boolean __getDeferringActions3rSet = false;
174
175    /**
176     * The controller that will handle the execution of this front-end action. This controller is
177     * set as the context of the activity graph (and therefore also of the use-case).
178     * @return (List<FrontEndAction>)handleGetDeferringActions()
179     */
180    public final List<FrontEndAction> getDeferringActions()
181    {
182        List<FrontEndAction> getDeferringActions3r = this.__getDeferringActions3r;
183        if (!this.__getDeferringActions3rSet)
184        {
185            // controller has no pre constraints
186            List result = handleGetDeferringActions();
187            List shieldedResult = this.shieldedElements(result);
188            try
189            {
190                getDeferringActions3r = (List<FrontEndAction>)shieldedResult;
191            }
192            catch (ClassCastException ex)
193            {
194                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
195                FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getDeferringActions List<FrontEndAction> " + result + ": " + shieldedResult);
196            }
197            // controller has no post constraints
198            this.__getDeferringActions3r = getDeferringActions3r;
199            if (isMetafacadePropertyCachingEnabled())
200            {
201                this.__getDeferringActions3rSet = true;
202            }
203        }
204        return getDeferringActions3r;
205    }
206
207    /**
208     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
209     * @return  List
210     */
211    protected abstract List handleGetDeferringActions();
212
213    /**
214     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package</p>
215     * <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>
216     * <p><b>OCL:</b> context FrontEndController inv: packageName->notEmpty()</p>
217     * @param validationMessages Collection<ModelValidationMessage>
218     * @see ClassifierFacadeLogicImpl#validateInvariants(Collection validationMessages)
219     */
220    @Override
221    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
222    {
223        super.validateInvariants(validationMessages);
224        try
225        {
226            final Object contextElement = this.THIS();
227            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"packageName")));
228            if (!constraintValid)
229            {
230                validationMessages.add(
231                    new ModelValidationMessage(
232                        (MetafacadeBase)contextElement ,
233                        "org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package",
234                        "Each front-end controller is required to be modeled in a package, doing otherwise will result in uncompileable code due to filename collisions."));
235            }
236        }
237        catch (Throwable th)
238        {
239            Throwable cause = th.getCause();
240            int depth = 0; // Some throwables have infinite recursion
241            while (cause != null && depth < 7)
242            {
243                th = cause;
244                depth++;
245            }
246            logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package' ON "
247                + this.THIS().toString() + ": " + th.getMessage(), th);
248        }
249    }
250}