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.FrontEndAction;
012import org.andromda.metafacades.uml.FrontEndActionState;
013import org.andromda.metafacades.uml.FrontEndExceptionHandler;
014import org.andromda.metafacades.uml.FrontEndForward;
015import org.andromda.metafacades.uml.OperationFacade;
016import org.andromda.translation.ocl.validation.OCLCollections;
017import org.andromda.translation.ocl.validation.OCLExpressions;
018import org.andromda.translation.ocl.validation.OCLIntrospector;
019import org.andromda.translation.ocl.validation.OCLResultEnsurer;
020import org.apache.log4j.Logger;
021import org.omg.uml.behavioralelements.activitygraphs.ActionState;
022
023/**
024 * Represents an operation on the server called by an action. Optionally may defer operations to the
025 * controller.
026 * MetafacadeLogic for FrontEndActionState
027 *
028 * @see FrontEndActionState
029 */
030public abstract class FrontEndActionStateLogic
031    extends ActionStateFacadeLogicImpl
032    implements FrontEndActionState
033{
034    /**
035     * The underlying UML object
036     * @see Object
037     */
038    protected Object metaObject;
039
040    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
041     * @param metaObjectIn
042     * @param context
043     */
044    protected FrontEndActionStateLogic(Object metaObjectIn, String context)
045    {
046        super((ActionState)metaObjectIn, getContext(context));
047        this.metaObject = metaObjectIn;
048    }
049
050    /**
051     * The logger instance.
052     */
053    private static final Logger logger = Logger.getLogger(FrontEndActionStateLogic.class);
054
055    /**
056     * Gets the context for this metafacade logic instance.
057     * @param context String. Set to FrontEndActionState if null
058     * @return context String
059     */
060    private static String getContext(String context)
061    {
062        if (context == null)
063        {
064            context = "org.andromda.metafacades.uml.FrontEndActionState";
065        }
066        return context;
067    }
068
069    /** Reset context only for non-root metafacades
070     * @param context
071     */
072    @Override
073    public void resetMetafacadeContext(String context)
074    {
075        if (!this.contextRoot) // reset context only for non-root metafacades
076        {
077            context = getContext(context);  // to have same value as in original constructor call
078            setMetafacadeContext (context);
079        }
080    }
081
082    /**
083     * @return boolean true always
084     * @see FrontEndActionState
085     */
086    public boolean isFrontEndActionStateMetaType()
087    {
088        return true;
089    }
090
091    // --------------- attributes ---------------------
092
093   /**
094    * @see FrontEndActionState#isServerSide()
095    * @return boolean
096    */
097    protected abstract boolean handleIsServerSide();
098
099    private boolean __serverSide1a;
100    private boolean __serverSide1aSet = false;
101
102    /**
103     * Indicates whether or not this front end action state is server side. Pages, for example, are
104     * also action states but they return control to the client.
105     * @return (boolean)handleIsServerSide()
106     */
107    public final boolean isServerSide()
108    {
109        boolean serverSide1a = this.__serverSide1a;
110        if (!this.__serverSide1aSet)
111        {
112            // serverSide has no pre constraints
113            serverSide1a = handleIsServerSide();
114            // serverSide has no post constraints
115            this.__serverSide1a = serverSide1a;
116            if (isMetafacadePropertyCachingEnabled())
117            {
118                this.__serverSide1aSet = true;
119            }
120        }
121        return serverSide1a;
122    }
123
124   /**
125    * @see FrontEndActionState#isContainedInFrontEndUseCase()
126    * @return boolean
127    */
128    protected abstract boolean handleIsContainedInFrontEndUseCase();
129
130    private boolean __containedInFrontEndUseCase2a;
131    private boolean __containedInFrontEndUseCase2aSet = false;
132
133    /**
134     * True if this element is contained in a FrontEndUseCase.
135     * @return (boolean)handleIsContainedInFrontEndUseCase()
136     */
137    public final boolean isContainedInFrontEndUseCase()
138    {
139        boolean containedInFrontEndUseCase2a = this.__containedInFrontEndUseCase2a;
140        if (!this.__containedInFrontEndUseCase2aSet)
141        {
142            // containedInFrontEndUseCase has no pre constraints
143            containedInFrontEndUseCase2a = handleIsContainedInFrontEndUseCase();
144            // containedInFrontEndUseCase has no post constraints
145            this.__containedInFrontEndUseCase2a = containedInFrontEndUseCase2a;
146            if (isMetafacadePropertyCachingEnabled())
147            {
148                this.__containedInFrontEndUseCase2aSet = true;
149            }
150        }
151        return containedInFrontEndUseCase2a;
152    }
153
154   /**
155    * @see FrontEndActionState#getActionMethodName()
156    * @return String
157    */
158    protected abstract String handleGetActionMethodName();
159
160    private String __actionMethodName3a;
161    private boolean __actionMethodName3aSet = false;
162
163    /**
164     * The method name representing this action state.
165     * @return (String)handleGetActionMethodName()
166     */
167    public final String getActionMethodName()
168    {
169        String actionMethodName3a = this.__actionMethodName3a;
170        if (!this.__actionMethodName3aSet)
171        {
172            // actionMethodName has no pre constraints
173            actionMethodName3a = handleGetActionMethodName();
174            // actionMethodName has no post constraints
175            this.__actionMethodName3a = actionMethodName3a;
176            if (isMetafacadePropertyCachingEnabled())
177            {
178                this.__actionMethodName3aSet = true;
179            }
180        }
181        return actionMethodName3a;
182    }
183
184   /**
185    * @see FrontEndActionState#getServiceCalls()
186    * @return List<OperationFacade>
187    */
188    protected abstract List<OperationFacade> handleGetServiceCalls();
189
190    private List<OperationFacade> __serviceCalls4a;
191    private boolean __serviceCalls4aSet = false;
192
193    /**
194     * All calls deferred to the controller by this action state.
195     * @return (List<OperationFacade>)handleGetServiceCalls()
196     */
197    public final List<OperationFacade> getServiceCalls()
198    {
199        List<OperationFacade> serviceCalls4a = this.__serviceCalls4a;
200        if (!this.__serviceCalls4aSet)
201        {
202            // serviceCalls has no pre constraints
203            serviceCalls4a = handleGetServiceCalls();
204            // serviceCalls has no post constraints
205            this.__serviceCalls4a = serviceCalls4a;
206            if (isMetafacadePropertyCachingEnabled())
207            {
208                this.__serviceCalls4aSet = true;
209            }
210        }
211        return serviceCalls4a;
212    }
213
214    // ------------- associations ------------------
215
216    private List<FrontEndAction> __getContainerActions1r;
217    private boolean __getContainerActions1rSet = false;
218
219    /**
220     * All action states visited by this action.
221     * @return (List<FrontEndAction>)handleGetContainerActions()
222     */
223    public final List<FrontEndAction> getContainerActions()
224    {
225        List<FrontEndAction> getContainerActions1r = this.__getContainerActions1r;
226        if (!this.__getContainerActions1rSet)
227        {
228            // actionStates has no pre constraints
229            List result = handleGetContainerActions();
230            List shieldedResult = this.shieldedElements(result);
231            try
232            {
233                getContainerActions1r = (List<FrontEndAction>)shieldedResult;
234            }
235            catch (ClassCastException ex)
236            {
237                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
238                FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getContainerActions List<FrontEndAction> " + result + ": " + shieldedResult);
239            }
240            // actionStates has no post constraints
241            this.__getContainerActions1r = getContainerActions1r;
242            if (isMetafacadePropertyCachingEnabled())
243            {
244                this.__getContainerActions1rSet = true;
245            }
246        }
247        return getContainerActions1r;
248    }
249
250    /**
251     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
252     * @return  List
253     */
254    protected abstract List handleGetContainerActions();
255
256    private List<OperationFacade> __getControllerCalls2r;
257    private boolean __getControllerCalls2rSet = false;
258
259    /**
260     * Represents an operation on the server called by an action. Optionally may defer operations to
261     * the
262     * controller.
263     * @return (List<OperationFacade>)handleGetControllerCalls()
264     */
265    public final List<OperationFacade> getControllerCalls()
266    {
267        List<OperationFacade> getControllerCalls2r = this.__getControllerCalls2r;
268        if (!this.__getControllerCalls2rSet)
269        {
270            // frontEndActionState has no pre constraints
271            List result = handleGetControllerCalls();
272            List shieldedResult = this.shieldedElements(result);
273            try
274            {
275                getControllerCalls2r = (List<OperationFacade>)shieldedResult;
276            }
277            catch (ClassCastException ex)
278            {
279                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
280                FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getControllerCalls List<OperationFacade> " + result + ": " + shieldedResult);
281            }
282            // frontEndActionState has no post constraints
283            this.__getControllerCalls2r = getControllerCalls2r;
284            if (isMetafacadePropertyCachingEnabled())
285            {
286                this.__getControllerCalls2rSet = true;
287            }
288        }
289        return getControllerCalls2r;
290    }
291
292    /**
293     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
294     * @return  List
295     */
296    protected abstract List handleGetControllerCalls();
297
298    private List<FrontEndExceptionHandler> __getExceptions3r;
299    private boolean __getExceptions3rSet = false;
300
301    /**
302     * Represents an operation on the server called by an action. Optionally may defer operations to
303     * the
304     * controller.
305     * @return (List<FrontEndExceptionHandler>)handleGetExceptions()
306     */
307    public final List<FrontEndExceptionHandler> getExceptions()
308    {
309        List<FrontEndExceptionHandler> getExceptions3r = this.__getExceptions3r;
310        if (!this.__getExceptions3rSet)
311        {
312            // frontEndActionState has no pre constraints
313            List result = handleGetExceptions();
314            List shieldedResult = this.shieldedElements(result);
315            try
316            {
317                getExceptions3r = (List<FrontEndExceptionHandler>)shieldedResult;
318            }
319            catch (ClassCastException ex)
320            {
321                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
322                FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getExceptions List<FrontEndExceptionHandler> " + result + ": " + shieldedResult);
323            }
324            // frontEndActionState has no post constraints
325            this.__getExceptions3r = getExceptions3r;
326            if (isMetafacadePropertyCachingEnabled())
327            {
328                this.__getExceptions3rSet = true;
329            }
330        }
331        return getExceptions3r;
332    }
333
334    /**
335     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
336     * @return  List
337     */
338    protected abstract List handleGetExceptions();
339
340    private FrontEndForward __getForward4r;
341    private boolean __getForward4rSet = false;
342
343    /**
344     * Represents an operation on the server called by an action. Optionally may defer operations to
345     * the
346     * controller.
347     * @return (FrontEndForward)handleGetForward()
348     */
349    public final FrontEndForward getForward()
350    {
351        FrontEndForward getForward4r = this.__getForward4r;
352        if (!this.__getForward4rSet)
353        {
354            // frontEndActionState has no pre constraints
355            Object result = handleGetForward();
356            MetafacadeBase shieldedResult = this.shieldedElement(result);
357            try
358            {
359                getForward4r = (FrontEndForward)shieldedResult;
360            }
361            catch (ClassCastException ex)
362            {
363                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
364                FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getForward FrontEndForward " + result + ": " + shieldedResult);
365            }
366            // frontEndActionState has no post constraints
367            this.__getForward4r = getForward4r;
368            if (isMetafacadePropertyCachingEnabled())
369            {
370                this.__getForward4rSet = true;
371            }
372        }
373        return getForward4r;
374    }
375
376    /**
377     * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
378     * @return Object
379     */
380    protected abstract Object handleGetForward();
381
382    /**
383     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndActionState::each front-end action state must have a name</p>
384     * <p><b>Error:</b> A "front-end" action state must have a non-empty name.</p>
385     * <p><b>OCL:</b> context FrontEndActionState inv: name->notEmpty()</p>
386     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndActionState::front-end action states can have at most one outgoing transition</p>
387     * <p><b>Error:</b> A "front-end" action state needs at most one outgoing transition that is not an exception-transition.</p>
388     * <p><b>OCL:</b> context FrontEndActionState inv: serverSide implies (exceptions->size() + 1 = outgoings->size() or exceptions->size() = outgoings->size())</p>
389     * @param validationMessages Collection<ModelValidationMessage>
390     * @see ActionStateFacadeLogicImpl#validateInvariants(Collection validationMessages)
391     */
392    @Override
393    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
394    {
395        super.validateInvariants(validationMessages);
396        try
397        {
398            final Object contextElement = this.THIS();
399            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name")));
400            if (!constraintValid)
401            {
402                validationMessages.add(
403                    new ModelValidationMessage(
404                        (MetafacadeBase)contextElement ,
405                        "org::andromda::metafacades::uml::FrontEndActionState::each front-end action state must have a name",
406                        "A \"front-end\" action state must have a non-empty name."));
407            }
408        }
409        catch (Throwable th)
410        {
411            Throwable cause = th.getCause();
412            int depth = 0; // Some throwables have infinite recursion
413            while (cause != null && depth < 7)
414            {
415                th = cause;
416                depth++;
417            }
418            logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndActionState::each front-end action state must have a name' ON "
419                + this.THIS().toString() + ": " + th.getMessage(), th);
420        }
421        try
422        {
423            final Object contextElement = this.THIS();
424            boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"serverSide"))).booleanValue()?(OCLExpressions.equal(OCLCollections.size(OCLIntrospector.invoke(contextElement,"exceptions"))+1,OCLCollections.size(OCLIntrospector.invoke(contextElement,"outgoings")))||OCLExpressions.equal(OCLCollections.size(OCLIntrospector.invoke(contextElement,"exceptions")),OCLCollections.size(OCLIntrospector.invoke(contextElement,"outgoings")))):true));
425            if (!constraintValid)
426            {
427                validationMessages.add(
428                    new ModelValidationMessage(
429                        (MetafacadeBase)contextElement ,
430                        "org::andromda::metafacades::uml::FrontEndActionState::front-end action states can have at most one outgoing transition",
431                        "A \"front-end\" action state needs at most one outgoing transition that is not an exception-transition."));
432            }
433        }
434        catch (Throwable th)
435        {
436            Throwable cause = th.getCause();
437            int depth = 0; // Some throwables have infinite recursion
438            while (cause != null && depth < 7)
439            {
440                th = cause;
441                depth++;
442            }
443            logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndActionState::front-end action states can have at most one outgoing transition' ON "
444                + this.THIS().toString() + ": " + th.getMessage(), th);
445        }
446    }
447}