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.FrontEndController;
013import org.andromda.metafacades.uml.FrontEndPackage;
014import org.andromda.translation.ocl.validation.OCLCollections;
015import org.andromda.translation.ocl.validation.OCLExpressions;
016import org.andromda.translation.ocl.validation.OCLIntrospector;
017import org.andromda.translation.ocl.validation.OCLResultEnsurer;
018import org.apache.log4j.Logger;
019import org.omg.uml.modelmanagement.UmlPackage;
020
021/**
022 * Represents a package storing "front-end" components.
023 * MetafacadeLogic for FrontEndPackage
024 *
025 * @see FrontEndPackage
026 */
027public abstract class FrontEndPackageLogic
028    extends PackageFacadeLogicImpl
029    implements FrontEndPackage
030{
031    /**
032     * The underlying UML object
033     * @see Object
034     */
035    protected Object metaObject;
036
037    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
038     * @param metaObjectIn
039     * @param context
040     */
041    protected FrontEndPackageLogic(Object metaObjectIn, String context)
042    {
043        super((UmlPackage)metaObjectIn, getContext(context));
044        this.metaObject = metaObjectIn;
045    }
046
047    /**
048     * The logger instance.
049     */
050    private static final Logger logger = Logger.getLogger(FrontEndPackageLogic.class);
051
052    /**
053     * Gets the context for this metafacade logic instance.
054     * @param context String. Set to FrontEndPackage if null
055     * @return context String
056     */
057    private static String getContext(String context)
058    {
059        if (context == null)
060        {
061            context = "org.andromda.metafacades.uml.FrontEndPackage";
062        }
063        return context;
064    }
065
066    /** Reset context only for non-root metafacades
067     * @param context
068     */
069    @Override
070    public void resetMetafacadeContext(String context)
071    {
072        if (!this.contextRoot) // reset context only for non-root metafacades
073        {
074            context = getContext(context);  // to have same value as in original constructor call
075            setMetafacadeContext (context);
076        }
077    }
078
079    /**
080     * @return boolean true always
081     * @see FrontEndPackage
082     */
083    public boolean isFrontEndPackageMetaType()
084    {
085        return true;
086    }
087
088    // ------------- associations ------------------
089
090    private List<FrontEndAction> __getFrontEndUseCases1r;
091    private boolean __getFrontEndUseCases1rSet = false;
092
093    /**
094     * Represents a package storing "front-end" components.
095     * @return (List<FrontEndAction>)handleGetFrontEndUseCases()
096     */
097    public final List<FrontEndAction> getFrontEndUseCases()
098    {
099        List<FrontEndAction> getFrontEndUseCases1r = this.__getFrontEndUseCases1r;
100        if (!this.__getFrontEndUseCases1rSet)
101        {
102            // frontEndPackage has no pre constraints
103            List result = handleGetFrontEndUseCases();
104            List shieldedResult = this.shieldedElements(result);
105            try
106            {
107                getFrontEndUseCases1r = (List<FrontEndAction>)shieldedResult;
108            }
109            catch (ClassCastException ex)
110            {
111                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
112                FrontEndPackageLogic.logger.warn("incorrect metafacade cast for FrontEndPackageLogic.getFrontEndUseCases List<FrontEndAction> " + result + ": " + shieldedResult);
113            }
114            // frontEndPackage has no post constraints
115            this.__getFrontEndUseCases1r = getFrontEndUseCases1r;
116            if (isMetafacadePropertyCachingEnabled())
117            {
118                this.__getFrontEndUseCases1rSet = true;
119            }
120        }
121        return getFrontEndUseCases1r;
122    }
123
124    /**
125     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
126     * @return  List
127     */
128    protected abstract List handleGetFrontEndUseCases();
129
130    private List<FrontEndController> __getFrontEndControllers2r;
131    private boolean __getFrontEndControllers2rSet = false;
132
133    /**
134     * Represents a package storing "front-end" components.
135     * @return (List<FrontEndController>)handleGetFrontEndControllers()
136     */
137    public final List<FrontEndController> getFrontEndControllers()
138    {
139        List<FrontEndController> getFrontEndControllers2r = this.__getFrontEndControllers2r;
140        if (!this.__getFrontEndControllers2rSet)
141        {
142            // frontEndPackage has no pre constraints
143            List result = handleGetFrontEndControllers();
144            List shieldedResult = this.shieldedElements(result);
145            try
146            {
147                getFrontEndControllers2r = (List<FrontEndController>)shieldedResult;
148            }
149            catch (ClassCastException ex)
150            {
151                // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
152                FrontEndPackageLogic.logger.warn("incorrect metafacade cast for FrontEndPackageLogic.getFrontEndControllers List<FrontEndController> " + result + ": " + shieldedResult);
153            }
154            // frontEndPackage has no post constraints
155            this.__getFrontEndControllers2r = getFrontEndControllers2r;
156            if (isMetafacadePropertyCachingEnabled())
157            {
158                this.__getFrontEndControllers2rSet = true;
159            }
160        }
161        return getFrontEndControllers2r;
162    }
163
164    /**
165     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
166     * @return  List
167     */
168    protected abstract List handleGetFrontEndControllers();
169
170    /**
171     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndPackage::no more than one controller per package</p>
172     * <p><b>Error:</b> In order to avoid possible naming collisions at most one controller per package is allowed. It is recommended to refactor your model.</p>
173     * <p><b>OCL:</b> context FrontEndPackage inv: frontEndControllers->size() < 2</p>
174     * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndPackage::no more than one usecase per package</p>
175     * <p><b>Error:</b> In order to avoid possible naming collisions at most one FrontEndUseCase per package is allowed. It is recommended to refactor your model.</p>
176     * <p><b>OCL:</b> context FrontEndPackage inv: frontEndUseCases->size() < 2</p>
177     * @param validationMessages Collection<ModelValidationMessage>
178     * @see PackageFacadeLogicImpl#validateInvariants(Collection validationMessages)
179     */
180    @Override
181    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
182    {
183        super.validateInvariants(validationMessages);
184        try
185        {
186            final Object contextElement = this.THIS();
187            boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.less(OCLCollections.size(OCLIntrospector.invoke(contextElement,"frontEndControllers")),2));
188            if (!constraintValid)
189            {
190                validationMessages.add(
191                    new ModelValidationMessage(
192                        (MetafacadeBase)contextElement ,
193                        "org::andromda::metafacades::uml::FrontEndPackage::no more than one controller per package",
194                        "In order to avoid possible naming collisions at most one controller per package is allowed. It is recommended to refactor your model."));
195            }
196        }
197        catch (Throwable th)
198        {
199            Throwable cause = th.getCause();
200            int depth = 0; // Some throwables have infinite recursion
201            while (cause != null && depth < 7)
202            {
203                th = cause;
204                depth++;
205            }
206            logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndPackage::no more than one controller per package' ON "
207                + this.THIS().toString() + ": " + th.getMessage(), th);
208        }
209        try
210        {
211            final Object contextElement = this.THIS();
212            boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.less(OCLCollections.size(OCLIntrospector.invoke(contextElement,"frontEndUseCases")),2));
213            if (!constraintValid)
214            {
215                validationMessages.add(
216                    new ModelValidationMessage(
217                        (MetafacadeBase)contextElement ,
218                        "org::andromda::metafacades::uml::FrontEndPackage::no more than one usecase per package",
219                        "In order to avoid possible naming collisions at most one FrontEndUseCase per package is allowed. It is recommended to refactor your model."));
220            }
221        }
222        catch (Throwable th)
223        {
224            Throwable cause = th.getCause();
225            int depth = 0; // Some throwables have infinite recursion
226            while (cause != null && depth < 7)
227            {
228                th = cause;
229                depth++;
230            }
231            logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndPackage::no more than one usecase per package' ON "
232                + this.THIS().toString() + ": " + th.getMessage(), th);
233        }
234    }
235}