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 org.andromda.core.common.Introspector;
009import org.andromda.core.metafacade.MetafacadeBase;
010import org.andromda.core.metafacade.ModelValidationMessage;
011import org.andromda.metafacades.uml.ModelElementFacade;
012import org.andromda.metafacades.uml.TemplateArgumentFacade;
013import org.apache.log4j.Logger;
014import org.omg.uml.foundation.core.TemplateArgument;
015
016/**
017 * Represents the model object 'Template Parameter Substitution'. Relates the actual parameter(s) to
018 * a formal template parameter as part of a template binding.
019 * MetafacadeLogic for TemplateArgumentFacade
020 *
021 * @see TemplateArgumentFacade
022 */
023public abstract class TemplateArgumentFacadeLogic
024    extends MetafacadeBase
025    implements TemplateArgumentFacade
026{
027    /**
028     * The underlying UML object
029     * @see TemplateArgument
030     */
031    protected TemplateArgument metaObject;
032
033    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
034     * @param metaObjectIn
035     * @param context
036     */
037    protected TemplateArgumentFacadeLogic(TemplateArgument metaObjectIn, String context)
038    {
039        super(metaObjectIn, getContext(context));
040        this.metaObject = metaObjectIn;
041    }
042
043    /**
044     * The logger instance.
045     */
046    private static final Logger logger = Logger.getLogger(TemplateArgumentFacadeLogic.class);
047
048    /**
049     * Gets the context for this metafacade logic instance.
050     * @param context String. Set to TemplateArgumentFacade if null
051     * @return context String
052     */
053    private static String getContext(String context)
054    {
055        if (context == null)
056        {
057            context = "org.andromda.metafacades.uml.TemplateArgumentFacade";
058        }
059        return context;
060    }
061
062    /** Reset context only for non-root metafacades
063     * @param context
064     */
065    @Override
066    public void resetMetafacadeContext(String context)
067    {
068        if (!this.contextRoot) // reset context only for non-root metafacades
069        {
070            context = getContext(context);  // to have same value as in original constructor call
071            setMetafacadeContext (context);
072        }
073    }
074
075    /**
076     * @return boolean true always
077     * @see TemplateArgumentFacade
078     */
079    public boolean isTemplateArgumentFacadeMetaType()
080    {
081        return true;
082    }
083
084    // ------------- associations ------------------
085
086    /**
087     * Represents the model object 'Template Parameter Substitution'. Relates the actual
088     * parameter(s) to a
089     * formal template parameter as part of a template binding.
090     * @return (ModelElementFacade)handleGetElement()
091     */
092    public final ModelElementFacade getElement()
093    {
094        ModelElementFacade getElement1r = null;
095        // templateArgumentFacade has no pre constraints
096        Object result = handleGetElement();
097        MetafacadeBase shieldedResult = this.shieldedElement(result);
098        try
099        {
100            getElement1r = (ModelElementFacade)shieldedResult;
101        }
102        catch (ClassCastException ex)
103        {
104            // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
105            TemplateArgumentFacadeLogic.logger.warn("incorrect metafacade cast for TemplateArgumentFacadeLogic.getElement ModelElementFacade " + result + ": " + shieldedResult);
106        }
107        // templateArgumentFacade has no post constraints
108        return getElement1r;
109    }
110
111    /**
112     * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
113     * @return Object
114     */
115    protected abstract Object handleGetElement();
116
117    /**
118     * @param validationMessages Collection<ModelValidationMessage>
119     * @see MetafacadeBase#validateInvariants(Collection validationMessages)
120     */
121    @Override
122    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
123    {
124    }
125
126    /**
127     * The property that stores the name of the metafacade.
128     */
129    private static final String NAME_PROPERTY = "name";
130    private static final String FQNAME_PROPERTY = "fullyQualifiedName";
131
132    /**
133     * @see Object#toString()
134     */
135    @Override
136    public String toString()
137    {
138        final StringBuilder toString = new StringBuilder(this.getClass().getName());
139        toString.append("[");
140        try
141        {
142            toString.append(Introspector.instance().getProperty(this, FQNAME_PROPERTY));
143        }
144        catch (final Throwable tryAgain)
145        {
146            try
147            {
148                toString.append(Introspector.instance().getProperty(this, NAME_PROPERTY));
149            }
150            catch (final Throwable ignore)
151            {
152                // - just ignore when the metafacade doesn't have a name or fullyQualifiedName property
153            }
154        }
155        toString.append("]");
156        return toString.toString();
157    }
158}