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.ModelValidationMessage;
010import org.andromda.metafacades.uml.ClassifierFacade;
011import org.andromda.metafacades.uml.ModelElementFacade;
012import org.andromda.metafacades.uml.PackageFacade;
013import org.apache.log4j.Logger;
014import org.omg.uml.modelmanagement.UmlPackage;
015
016/**
017 * Used to group elements, and provides a namespace for the grouped elements. A package can have one
018 * or more profile applications to indicate which profiles have been applied. Because a profile is a
019 * package, it is possible to apply a profile not only to packages, but also to profiles. Package
020 * specializes TemplateableElement and PackageableElement specializes ParameterableElement to
021 * specify that a package can be used as a template and a PackageableElement as a template
022 * parameter.
023 * MetafacadeLogic for PackageFacade
024 *
025 * @see PackageFacade
026 */
027public abstract class PackageFacadeLogic
028    extends ModelElementFacadeLogicImpl
029    implements PackageFacade
030{
031    /**
032     * The underlying UML object
033     * @see UmlPackage
034     */
035    protected UmlPackage metaObject;
036
037    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
038     * @param metaObjectIn
039     * @param context
040     */
041    protected PackageFacadeLogic(UmlPackage metaObjectIn, String context)
042    {
043        super(metaObjectIn, getContext(context));
044        this.metaObject = metaObjectIn;
045    }
046
047    /**
048     * The logger instance.
049     */
050    private static final Logger logger = Logger.getLogger(PackageFacadeLogic.class);
051
052    /**
053     * Gets the context for this metafacade logic instance.
054     * @param context String. Set to PackageFacade 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.PackageFacade";
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 PackageFacade
082     */
083    public boolean isPackageFacadeMetaType()
084    {
085        return true;
086    }
087
088    // --------------- attributes ---------------------
089
090   /**
091    * @see PackageFacade#getTablePrefix()
092    * @return String
093    */
094    protected abstract String handleGetTablePrefix();
095
096    private String __tablePrefix1a;
097    private boolean __tablePrefix1aSet = false;
098
099    /**
100     * The Entity table prefix to be used for this package.
101     * @return (String)handleGetTablePrefix()
102     */
103    public final String getTablePrefix()
104    {
105        String tablePrefix1a = this.__tablePrefix1a;
106        if (!this.__tablePrefix1aSet)
107        {
108            // tablePrefix has no pre constraints
109            tablePrefix1a = handleGetTablePrefix();
110            // tablePrefix has no post constraints
111            this.__tablePrefix1a = tablePrefix1a;
112            if (isMetafacadePropertyCachingEnabled())
113            {
114                this.__tablePrefix1aSet = true;
115            }
116        }
117        return tablePrefix1a;
118    }
119
120    // ---------------- business methods ----------------------
121
122    /**
123     * Method to be implemented in descendants
124     * Finds the model element with the given 'fullyQualifiedName', or returns null if one can't be
125     * found with that name.
126     * @param fullyQualifiedName
127     * @return ModelElementFacade
128     */
129    protected abstract ModelElementFacade handleFindModelElement(String fullyQualifiedName);
130
131    /**
132     * Finds the model element with the given 'fullyQualifiedName', or returns null if one can't be
133     * found with that name.
134     * @param fullyQualifiedName String
135     * The fully qualified name of the model element to find.
136     * @return handleFindModelElement(fullyQualifiedName)
137     */
138    public ModelElementFacade findModelElement(String fullyQualifiedName)
139    {
140        // findModelElement has no pre constraints
141        ModelElementFacade returnValue = handleFindModelElement(fullyQualifiedName);
142        // findModelElement has no post constraints
143        return returnValue;
144    }
145
146    // ------------- associations ------------------
147
148    /**
149     * Used to group elements, and provides a namespace for the grouped elements. A package can have
150     * one or
151     * more profile applications to indicate which profiles have been applied. Because a profile is
152     * a
153     * package, it is possible to apply a profile not only to packages, but also to profiles.
154     * Package
155     * specializes TemplateableElement and PackageableElement specializes ParameterableElement to
156     * specify
157     * that a package can be used as a template and a PackageableElement as a template parameter.
158     * @return (Collection<ClassifierFacade>)handleGetClasses()
159     */
160    public final Collection<ClassifierFacade> getClasses()
161    {
162        Collection<ClassifierFacade> getClasses1r = null;
163        // packageFacade has no pre constraints
164        Collection result = handleGetClasses();
165        List shieldedResult = this.shieldedElements(result);
166        try
167        {
168            getClasses1r = (Collection<ClassifierFacade>)shieldedResult;
169        }
170        catch (ClassCastException ex)
171        {
172            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
173            PackageFacadeLogic.logger.warn("incorrect metafacade cast for PackageFacadeLogic.getClasses Collection<ClassifierFacade> " + result + ": " + shieldedResult);
174        }
175        // packageFacade has no post constraints
176        return getClasses1r;
177    }
178
179    /**
180     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
181     * @return  Collection
182     */
183    protected abstract Collection handleGetClasses();
184
185    /**
186     * Gets the root package for the model element.
187     * @return (Collection<ModelElementFacade>)handleGetModelElements()
188     */
189    public final Collection<ModelElementFacade> getModelElements()
190    {
191        Collection<ModelElementFacade> getModelElements2r = null;
192        // rootPackage has no pre constraints
193        Collection result = handleGetModelElements();
194        List shieldedResult = this.shieldedElements(result);
195        try
196        {
197            getModelElements2r = (Collection<ModelElementFacade>)shieldedResult;
198        }
199        catch (ClassCastException ex)
200        {
201            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
202            PackageFacadeLogic.logger.warn("incorrect metafacade cast for PackageFacadeLogic.getModelElements Collection<ModelElementFacade> " + result + ": " + shieldedResult);
203        }
204        // rootPackage has no post constraints
205        return getModelElements2r;
206    }
207
208    /**
209     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
210     * @return  Collection
211     */
212    protected abstract Collection handleGetModelElements();
213
214    /**
215     * Used to group elements, and provides a namespace for the grouped elements. A package can have
216     * one or
217     * more profile applications to indicate which profiles have been applied. Because a profile is
218     * a
219     * package, it is possible to apply a profile not only to packages, but also to profiles.
220     * Package
221     * specializes TemplateableElement and PackageableElement specializes ParameterableElement to
222     * specify
223     * that a package can be used as a template and a PackageableElement as a template parameter.
224     * @return (Collection<PackageFacade>)handleGetSubPackages()
225     */
226    public final Collection<PackageFacade> getSubPackages()
227    {
228        Collection<PackageFacade> getSubPackages3r = null;
229        // packageFacade has no pre constraints
230        Collection result = handleGetSubPackages();
231        List shieldedResult = this.shieldedElements(result);
232        try
233        {
234            getSubPackages3r = (Collection<PackageFacade>)shieldedResult;
235        }
236        catch (ClassCastException ex)
237        {
238            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
239            PackageFacadeLogic.logger.warn("incorrect metafacade cast for PackageFacadeLogic.getSubPackages Collection<PackageFacade> " + result + ": " + shieldedResult);
240        }
241        // packageFacade has no post constraints
242        return getSubPackages3r;
243    }
244
245    /**
246     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
247     * @return  Collection
248     */
249    protected abstract Collection handleGetSubPackages();
250
251    /**
252     * Used to group elements, and provides a namespace for the grouped elements. A package can have
253     * one or
254     * more profile applications to indicate which profiles have been applied. Because a profile is
255     * a
256     * package, it is possible to apply a profile not only to packages, but also to profiles.
257     * Package
258     * specializes TemplateableElement and PackageableElement specializes ParameterableElement to
259     * specify
260     * that a package can be used as a template and a PackageableElement as a template parameter.
261     * @return (Collection<ModelElementFacade>)handleGetOwnedElements()
262     */
263    public final Collection<ModelElementFacade> getOwnedElements()
264    {
265        Collection<ModelElementFacade> getOwnedElements4r = null;
266        // packageFacade has no pre constraints
267        Collection result = handleGetOwnedElements();
268        List shieldedResult = this.shieldedElements(result);
269        try
270        {
271            getOwnedElements4r = (Collection<ModelElementFacade>)shieldedResult;
272        }
273        catch (ClassCastException ex)
274        {
275            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
276            PackageFacadeLogic.logger.warn("incorrect metafacade cast for PackageFacadeLogic.getOwnedElements Collection<ModelElementFacade> " + result + ": " + shieldedResult);
277        }
278        // packageFacade has no post constraints
279        return getOwnedElements4r;
280    }
281
282    /**
283     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
284     * @return  Collection
285     */
286    protected abstract Collection handleGetOwnedElements();
287
288    /**
289     * @param validationMessages Collection<ModelValidationMessage>
290     * @see ModelElementFacadeLogicImpl#validateInvariants(Collection validationMessages)
291     */
292    @Override
293    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
294    {
295        super.validateInvariants(validationMessages);
296    }
297}