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.common.Introspector;
010import org.andromda.core.metafacade.MetafacadeBase;
011import org.andromda.core.metafacade.ModelValidationMessage;
012import org.andromda.metafacades.uml.ClassifierFacade;
013import org.andromda.metafacades.uml.ModelElementFacade;
014import org.andromda.metafacades.uml.TemplateParameterFacade;
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.TemplateParameter;
020
021/**
022 * Represents a UML template parameter. Exposes a parameterable element as a formal template
023 * parameter of a template. Only UML2 TemplateParameter inherits from ModelElement, so the UML14
024 * implementation cannot extend ModelElement. UML14 TemplateParameter.parameter inherits from
025 * Parameter.
026 * MetafacadeLogic for TemplateParameterFacade
027 *
028 * @see TemplateParameterFacade
029 */
030public abstract class TemplateParameterFacadeLogic
031    extends MetafacadeBase
032    implements TemplateParameterFacade
033{
034    /**
035     * The underlying UML object
036     * @see TemplateParameter
037     */
038    protected TemplateParameter metaObject;
039
040    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
041     * @param metaObjectIn
042     * @param context
043     */
044    protected TemplateParameterFacadeLogic(TemplateParameter metaObjectIn, String context)
045    {
046        super(metaObjectIn, getContext(context));
047        this.metaObject = metaObjectIn;
048    }
049
050    /**
051     * The logger instance.
052     */
053    private static final Logger logger = Logger.getLogger(TemplateParameterFacadeLogic.class);
054
055    /**
056     * Gets the context for this metafacade logic instance.
057     * @param context String. Set to TemplateParameterFacade 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.TemplateParameterFacade";
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 TemplateParameterFacade
085     */
086    public boolean isTemplateParameterFacadeMetaType()
087    {
088        return true;
089    }
090
091    // --------------- attributes ---------------------
092
093   /**
094    * @see TemplateParameterFacade#getType()
095    * @return ClassifierFacade
096    */
097    protected abstract ClassifierFacade handleGetType();
098
099    /**
100     * TemplateParameter may be of type Classifier, PackageableElement,
101     * Operation or Property. Generally a Class parameter has a name and a type of Classifier.
102     * @return (ClassifierFacade)handleGetType()
103     */
104    public final ClassifierFacade getType()
105    {
106        ClassifierFacade type1a = null;
107        // type has no pre constraints
108        type1a = handleGetType();
109        // type has no post constraints
110        return type1a;
111    }
112
113   /**
114    * @see TemplateParameterFacade#getName()
115    * @return String
116    */
117    protected abstract String handleGetName();
118
119    /**
120     * TODO: Model Documentation for TemplateParameterFacade.name
121     * @return (String)handleGetName()
122     */
123    public final String getName()
124    {
125        String name2a = null;
126        // name has no pre constraints
127        name2a = handleGetName();
128        // name has no post constraints
129        return name2a;
130    }
131
132   /**
133    * @see TemplateParameterFacade#getFullyQualifiedName()
134    * @return String
135    */
136    protected abstract String handleGetFullyQualifiedName();
137
138    /**
139     * Return the fully qualified name of the template parameter: package + class + parameter name
140     * @return (String)handleGetFullyQualifiedName()
141     */
142    public final String getFullyQualifiedName()
143    {
144        String fullyQualifiedName3a = null;
145        // fullyQualifiedName has no pre constraints
146        fullyQualifiedName3a = handleGetFullyQualifiedName();
147        // fullyQualifiedName has no post constraints
148        return fullyQualifiedName3a;
149    }
150
151   /**
152    * @see TemplateParameterFacade#getGetterSetterTypeName()
153    * @return String
154    */
155    protected abstract String handleGetGetterSetterTypeName();
156
157    /**
158     * The type of the template parameter.
159     * @return (String)handleGetGetterSetterTypeName()
160     */
161    public final String getGetterSetterTypeName()
162    {
163        String getterSetterTypeName4a = null;
164        // getterSetterTypeName has no pre constraints
165        getterSetterTypeName4a = handleGetGetterSetterTypeName();
166        // getterSetterTypeName has no post constraints
167        return getterSetterTypeName4a;
168    }
169
170   /**
171    * @see TemplateParameterFacade#getGetterName()
172    * @return String
173    */
174    protected abstract String handleGetGetterName();
175
176    /**
177     * get + capitalized parameter name
178     * @return (String)handleGetGetterName()
179     */
180    public final String getGetterName()
181    {
182        String getterName5a = null;
183        // getterName has no pre constraints
184        getterName5a = handleGetGetterName();
185        // getterName has no post constraints
186        return getterName5a;
187    }
188
189   /**
190    * @see TemplateParameterFacade#getSetterName()
191    * @return String
192    */
193    protected abstract String handleGetSetterName();
194
195    /**
196     * set + capitalized parameter name
197     * @return (String)handleGetSetterName()
198     */
199    public final String getSetterName()
200    {
201        String setterName6a = null;
202        // setterName has no pre constraints
203        setterName6a = handleGetSetterName();
204        // setterName has no post constraints
205        return setterName6a;
206    }
207
208   /**
209    * @see TemplateParameterFacade#getOwner()
210    * @return ModelElementFacade
211    */
212    protected abstract ModelElementFacade handleGetOwner();
213
214    /**
215     * The ModelElement that owns this parameter. For UML14, the classifier package. For UML2, the
216     * Classifier.
217     * @return (ModelElementFacade)handleGetOwner()
218     */
219    public final ModelElementFacade getOwner()
220    {
221        ModelElementFacade owner7a = null;
222        // owner has no pre constraints
223        owner7a = handleGetOwner();
224        // owner has no post constraints
225        return owner7a;
226    }
227
228    // ---------------- business methods ----------------------
229
230    /**
231     * Method to be implemented in descendants
232     * Gets the documentation for the model element, The indent argument is prefixed to each line.
233     * By default this method wraps lines after 64 characters.
234     * This method is equivalent to <code>getDocumentation(indent, 64)</code>.
235     * @param indent
236     * @return String
237     */
238    protected abstract String handleGetDocumentation(String indent);
239
240    /**
241     * Gets the documentation for the model element, The indent argument is prefixed to each line.
242     * By default this method wraps lines after 64 characters.
243     * This method is equivalent to <code>getDocumentation(indent, 64)</code>.
244     * @param indent String
245     * <p>Specifies the amount to indent by.</p>
246     * @return handleGetDocumentation(indent)
247     */
248    public String getDocumentation(String indent)
249    {
250        // getDocumentation has no pre constraints
251        String returnValue = handleGetDocumentation(indent);
252        // getDocumentation has no post constraints
253        return returnValue;
254    }
255
256    /**
257     * Method to be implemented in descendants
258     * This method returns the documentation for this model element, with the lines wrapped after
259     * the specified number of characters, values of less than 1 will indicate no line wrapping is
260     * required. By default paragraphs are returned as HTML.
261     * This method is equivalent to <code>getDocumentation(indent, lineLength, true)</code>.
262     * @param indent
263     * @param lineLength
264     * @return String
265     */
266    protected abstract String handleGetDocumentation(String indent, int lineLength);
267
268    /**
269     * This method returns the documentation for this model element, with the lines wrapped after
270     * the specified number of characters, values of less than 1 will indicate no line wrapping is
271     * required. By default paragraphs are returned as HTML.
272     * This method is equivalent to <code>getDocumentation(indent, lineLength, true)</code>.
273     * @param indent String
274     * TODO: Model Documentation for
275     * TemplateParameterFacade.getDocumentation(indent)
276     * @param lineLength int
277     * TODO: Model Documentation for
278     * TemplateParameterFacade.getDocumentation(lineLength)
279     * @return handleGetDocumentation(indent, lineLength)
280     */
281    public String getDocumentation(String indent, int lineLength)
282    {
283        // getDocumentation has no pre constraints
284        String returnValue = handleGetDocumentation(indent, lineLength);
285        // getDocumentation has no post constraints
286        return returnValue;
287    }
288
289    /**
290     * Method to be implemented in descendants
291     * TODO: Model Documentation for
292     * TemplateParameterFacade.getDocumentation
293     * @param indent
294     * @param lineLength
295     * @param htmlStyle
296     * @return String
297     */
298    protected abstract String handleGetDocumentation(String indent, int lineLength, boolean htmlStyle);
299
300    /**
301     * TODO: Model Documentation for
302     * TemplateParameterFacade.getDocumentation
303     * @param indent String
304     * TODO: Model Documentation for
305     * TemplateParameterFacade.getDocumentation(indent)
306     * @param lineLength int
307     * TODO: Model Documentation for
308     * TemplateParameterFacade.getDocumentation(lineLength)
309     * @param htmlStyle boolean
310     * TODO: Model Documentation for
311     * TemplateParameterFacade.getDocumentation(htmlStyle)
312     * @return handleGetDocumentation(indent, lineLength, htmlStyle)
313     */
314    public String getDocumentation(String indent, int lineLength, boolean htmlStyle)
315    {
316        // getDocumentation has no pre constraints
317        String returnValue = handleGetDocumentation(indent, lineLength, htmlStyle);
318        // getDocumentation has no post constraints
319        return returnValue;
320    }
321
322    // ------------- associations ------------------
323
324    /**
325     * Represents a UML template parameter. Exposes a parameterable element as a formal template
326     * parameter
327     * of a template. Only UML2 TemplateParameter inherits from ModelElement, so the UML14
328     * implementation
329     * cannot extend ModelElement. UML14 TemplateParameter.parameter inherits from Parameter.
330     * @return (ModelElementFacade)handleGetDefaultElement()
331     */
332    public final ModelElementFacade getDefaultElement()
333    {
334        ModelElementFacade getDefaultElement1r = null;
335        // templateParameterFacade has no pre constraints
336        Object result = handleGetDefaultElement();
337        MetafacadeBase shieldedResult = this.shieldedElement(result);
338        try
339        {
340            getDefaultElement1r = (ModelElementFacade)shieldedResult;
341        }
342        catch (ClassCastException ex)
343        {
344            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
345            TemplateParameterFacadeLogic.logger.warn("incorrect metafacade cast for TemplateParameterFacadeLogic.getDefaultElement ModelElementFacade " + result + ": " + shieldedResult);
346        }
347        // templateParameterFacade has no post constraints
348        return getDefaultElement1r;
349    }
350
351    /**
352     * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
353     * @return Object
354     */
355    protected abstract Object handleGetDefaultElement();
356
357    /**
358     * Represents a UML template parameter. Exposes a parameterable element as a formal template
359     * parameter
360     * of a template. Only UML2 TemplateParameter inherits from ModelElement, so the UML14
361     * implementation
362     * cannot extend ModelElement. UML14 TemplateParameter.parameter inherits from Parameter.
363     * @return (ModelElementFacade)handleGetParameter()
364     */
365    public final ModelElementFacade getParameter()
366    {
367        ModelElementFacade getParameter2r = null;
368        // templateParameterFacade has no pre constraints
369        Object result = handleGetParameter();
370        MetafacadeBase shieldedResult = this.shieldedElement(result);
371        try
372        {
373            getParameter2r = (ModelElementFacade)shieldedResult;
374        }
375        catch (ClassCastException ex)
376        {
377            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
378            TemplateParameterFacadeLogic.logger.warn("incorrect metafacade cast for TemplateParameterFacadeLogic.getParameter ModelElementFacade " + result + ": " + shieldedResult);
379        }
380        // templateParameterFacade has no post constraints
381        return getParameter2r;
382    }
383
384    /**
385     * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
386     * @return Object
387     */
388    protected abstract Object handleGetParameter();
389
390    /**
391     * Represents a UML template parameter. Exposes a parameterable element as a formal template
392     * parameter
393     * of a template. Only UML2 TemplateParameter inherits from ModelElement, so the UML14
394     * implementation
395     * cannot extend ModelElement. UML14 TemplateParameter.parameter inherits from Parameter.
396     * @return (Collection<ClassifierFacade>)handleGetConstrainingClassifiers()
397     */
398    public final Collection<ClassifierFacade> getConstrainingClassifiers()
399    {
400        Collection<ClassifierFacade> getConstrainingClassifiers3r = null;
401        // templateParameterFacade has no pre constraints
402        Collection result = handleGetConstrainingClassifiers();
403        List shieldedResult = this.shieldedElements(result);
404        try
405        {
406            getConstrainingClassifiers3r = (Collection<ClassifierFacade>)shieldedResult;
407        }
408        catch (ClassCastException ex)
409        {
410            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
411            TemplateParameterFacadeLogic.logger.warn("incorrect metafacade cast for TemplateParameterFacadeLogic.getConstrainingClassifiers Collection<ClassifierFacade> " + result + ": " + shieldedResult);
412        }
413        // templateParameterFacade has no post constraints
414        return getConstrainingClassifiers3r;
415    }
416
417    /**
418     * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
419     * @return  Collection
420     */
421    protected abstract Collection handleGetConstrainingClassifiers();
422
423    /**
424     * <p><b>Constraint:</b> org::andromda::metafacades::uml::TemplateParameterFacade::template parameter type must be specified</p>
425     * <p><b>Error:</b> Template Parameter type must be specified.</p>
426     * <p><b>OCL:</b> context TemplateParameterFacade inv: type.name->notEmpty()</p>
427     * @param validationMessages Collection<ModelValidationMessage>
428     * @see MetafacadeBase#validateInvariants(Collection validationMessages)
429     */
430    @Override
431    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
432    {
433        try
434        {
435            final Object contextElement = this.THIS();
436            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"type.name")));
437            if (!constraintValid)
438            {
439                validationMessages.add(
440                    new ModelValidationMessage(
441                        (MetafacadeBase)contextElement ,
442                        "org::andromda::metafacades::uml::TemplateParameterFacade::template parameter type must be specified",
443                        "Template Parameter type must be specified."));
444            }
445        }
446        catch (Throwable th)
447        {
448            Throwable cause = th.getCause();
449            int depth = 0; // Some throwables have infinite recursion
450            while (cause != null && depth < 7)
451            {
452                th = cause;
453                depth++;
454            }
455            logger.error("Error validating constraint 'org::andromda::metafacades::uml::TemplateParameterFacade::template parameter type must be specified' ON "
456                + this.THIS().toString() + ": " + th.getMessage(), th);
457        }
458    }
459
460    /**
461     * The property that stores the name of the metafacade.
462     */
463    private static final String NAME_PROPERTY = "name";
464    private static final String FQNAME_PROPERTY = "fullyQualifiedName";
465
466    /**
467     * @see Object#toString()
468     */
469    @Override
470    public String toString()
471    {
472        final StringBuilder toString = new StringBuilder(this.getClass().getName());
473        toString.append("[");
474        try
475        {
476            toString.append(Introspector.instance().getProperty(this, FQNAME_PROPERTY));
477        }
478        catch (final Throwable tryAgain)
479        {
480            try
481            {
482                toString.append(Introspector.instance().getProperty(this, NAME_PROPERTY));
483            }
484            catch (final Throwable ignore)
485            {
486                // - just ignore when the metafacade doesn't have a name or fullyQualifiedName property
487            }
488        }
489        toString.append("]");
490        return toString.toString();
491    }
492}