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.metafacade.MetafacadeBase;
009import org.andromda.core.metafacade.ModelValidationMessage;
010import org.andromda.metafacades.uml.EntityAssociationEnd;
011import org.andromda.translation.ocl.validation.OCLCollections;
012import org.andromda.translation.ocl.validation.OCLIntrospector;
013import org.andromda.translation.ocl.validation.OCLResultEnsurer;
014import org.apache.commons.collections.Predicate;
015import org.apache.log4j.Logger;
016import org.omg.uml.foundation.core.AssociationEnd;
017
018/**
019 * Represents an association end of an entity.
020 * MetafacadeLogic for EntityAssociationEnd
021 *
022 * @see EntityAssociationEnd
023 */
024public abstract class EntityAssociationEndLogic
025    extends AssociationEndFacadeLogicImpl
026    implements EntityAssociationEnd
027{
028    /**
029     * The underlying UML object
030     * @see Object
031     */
032    protected Object metaObject;
033
034    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
035     * @param metaObjectIn
036     * @param context
037     */
038    protected EntityAssociationEndLogic(Object metaObjectIn, String context)
039    {
040        super((AssociationEnd)metaObjectIn, getContext(context));
041        this.metaObject = metaObjectIn;
042    }
043
044    /**
045     * The logger instance.
046     */
047    private static final Logger logger = Logger.getLogger(EntityAssociationEndLogic.class);
048
049    /**
050     * Gets the context for this metafacade logic instance.
051     * @param context String. Set to EntityAssociationEnd if null
052     * @return context String
053     */
054    private static String getContext(String context)
055    {
056        if (context == null)
057        {
058            context = "org.andromda.metafacades.uml.EntityAssociationEnd";
059        }
060        return context;
061    }
062
063    /** Reset context only for non-root metafacades
064     * @param context
065     */
066    @Override
067    public void resetMetafacadeContext(String context)
068    {
069        if (!this.contextRoot) // reset context only for non-root metafacades
070        {
071            context = getContext(context);  // to have same value as in original constructor call
072            setMetafacadeContext (context);
073        }
074    }
075
076    /**
077     * @return boolean true always
078     * @see EntityAssociationEnd
079     */
080    public boolean isEntityAssociationEndMetaType()
081    {
082        return true;
083    }
084
085    // --------------- attributes ---------------------
086
087   /**
088    * @see EntityAssociationEnd#getColumnName()
089    * @return String
090    */
091    protected abstract String handleGetColumnName();
092
093    private String __columnName1a;
094    private boolean __columnName1aSet = false;
095
096    /**
097     * The name of the column that makes up the foreign key.
098     * @return (String)handleGetColumnName()
099     */
100    public final String getColumnName()
101    {
102        String columnName1a = this.__columnName1a;
103        if (!this.__columnName1aSet)
104        {
105            // columnName has no pre constraints
106            columnName1a = handleGetColumnName();
107            // columnName has no post constraints
108            this.__columnName1a = columnName1a;
109            if (isMetafacadePropertyCachingEnabled())
110            {
111                this.__columnName1aSet = true;
112            }
113        }
114        return columnName1a;
115    }
116
117   /**
118    * @see EntityAssociationEnd#getForeignKeySuffix()
119    * @return String
120    */
121    protected abstract String handleGetForeignKeySuffix();
122
123    private String __foreignKeySuffix2a;
124    private boolean __foreignKeySuffix2aSet = false;
125
126    /**
127     * The current foreign key suffix specified for this entity association end facade.
128     * @return (String)handleGetForeignKeySuffix()
129     */
130    public final String getForeignKeySuffix()
131    {
132        String foreignKeySuffix2a = this.__foreignKeySuffix2a;
133        if (!this.__foreignKeySuffix2aSet)
134        {
135            // foreignKeySuffix has no pre constraints
136            foreignKeySuffix2a = handleGetForeignKeySuffix();
137            // foreignKeySuffix has no post constraints
138            this.__foreignKeySuffix2a = foreignKeySuffix2a;
139            if (isMetafacadePropertyCachingEnabled())
140            {
141                this.__foreignKeySuffix2aSet = true;
142            }
143        }
144        return foreignKeySuffix2a;
145    }
146
147   /**
148    * @see EntityAssociationEnd#isForeignIdentifier()
149    * @return boolean
150    */
151    protected abstract boolean handleIsForeignIdentifier();
152
153    private boolean __foreignIdentifier3a;
154    private boolean __foreignIdentifier3aSet = false;
155
156    /**
157     * Indicates whether or not a foreign identifier should be used for the entity that owns this
158     * association end.  This would only make sense in the case of a child in a one-to-one
159     * parent-child association.  If this flag is true, then the identifier of this entity should
160     * also be used as the foreign key to the related parent entity.
161     * @return (boolean)handleIsForeignIdentifier()
162     */
163    public final boolean isForeignIdentifier()
164    {
165        boolean foreignIdentifier3a = this.__foreignIdentifier3a;
166        if (!this.__foreignIdentifier3aSet)
167        {
168            // foreignIdentifier has no pre constraints
169            foreignIdentifier3a = handleIsForeignIdentifier();
170            // foreignIdentifier has no post constraints
171            this.__foreignIdentifier3a = foreignIdentifier3a;
172            if (isMetafacadePropertyCachingEnabled())
173            {
174                this.__foreignIdentifier3aSet = true;
175            }
176        }
177        return foreignIdentifier3a;
178    }
179
180   /**
181    * @see EntityAssociationEnd#getForeignKeyConstraintName()
182    * @return String
183    */
184    protected abstract String handleGetForeignKeyConstraintName();
185
186    private String __foreignKeyConstraintName4a;
187    private boolean __foreignKeyConstraintName4aSet = false;
188
189    /**
190     * The name of the foreign key constraint to use for databases.
191     * @return (String)handleGetForeignKeyConstraintName()
192     */
193    public final String getForeignKeyConstraintName()
194    {
195        String foreignKeyConstraintName4a = this.__foreignKeyConstraintName4a;
196        if (!this.__foreignKeyConstraintName4aSet)
197        {
198            // foreignKeyConstraintName has no pre constraints
199            foreignKeyConstraintName4a = handleGetForeignKeyConstraintName();
200            // foreignKeyConstraintName has no post constraints
201            this.__foreignKeyConstraintName4a = foreignKeyConstraintName4a;
202            if (isMetafacadePropertyCachingEnabled())
203            {
204                this.__foreignKeyConstraintName4aSet = true;
205            }
206        }
207        return foreignKeyConstraintName4a;
208    }
209
210   /**
211    * @see EntityAssociationEnd#getColumnIndex()
212    * @return String
213    */
214    protected abstract String handleGetColumnIndex();
215
216    private String __columnIndex5a;
217    private boolean __columnIndex5aSet = false;
218
219    /**
220     * The name of the index to create on a column that persists the foreign key attribute.
221     * @return (String)handleGetColumnIndex()
222     */
223    public final String getColumnIndex()
224    {
225        String columnIndex5a = this.__columnIndex5a;
226        if (!this.__columnIndex5aSet)
227        {
228            // columnIndex has no pre constraints
229            columnIndex5a = handleGetColumnIndex();
230            // columnIndex has no post constraints
231            this.__columnIndex5a = columnIndex5a;
232            if (isMetafacadePropertyCachingEnabled())
233            {
234                this.__columnIndex5aSet = true;
235            }
236        }
237        return columnIndex5a;
238    }
239
240   /**
241    * @see EntityAssociationEnd#getSqlType()
242    * @return String
243    */
244    protected abstract String handleGetSqlType();
245
246    private String __sqlType6a;
247    private boolean __sqlType6aSet = false;
248
249    /**
250     * The SQL type for this the foreign key column of this association end.
251     * @return (String)handleGetSqlType()
252     */
253    public final String getSqlType()
254    {
255        String sqlType6a = this.__sqlType6a;
256        if (!this.__sqlType6aSet)
257        {
258            // sqlType has no pre constraints
259            sqlType6a = handleGetSqlType();
260            // sqlType has no post constraints
261            this.__sqlType6a = sqlType6a;
262            if (isMetafacadePropertyCachingEnabled())
263            {
264                this.__sqlType6aSet = true;
265            }
266        }
267        return sqlType6a;
268    }
269
270   /**
271    * @see EntityAssociationEnd#isTransient()
272    * @return boolean
273    */
274    protected abstract boolean handleIsTransient();
275
276    private boolean __transient7a;
277    private boolean __transient7aSet = false;
278
279    /**
280     * Indicates this association end should be ignored by the persistence layer.
281     * @return (boolean)handleIsTransient()
282     */
283    public final boolean isTransient()
284    {
285        boolean transient7a = this.__transient7a;
286        if (!this.__transient7aSet)
287        {
288            // transient has no pre constraints
289            transient7a = handleIsTransient();
290            // transient has no post constraints
291            this.__transient7a = transient7a;
292            if (isMetafacadePropertyCachingEnabled())
293            {
294                this.__transient7aSet = true;
295            }
296        }
297        return transient7a;
298    }
299
300   /**
301    * @see EntityAssociationEnd#isIdentifiersPresent()
302    * @return boolean
303    */
304    protected abstract boolean handleIsIdentifiersPresent();
305
306    private boolean __identifiersPresent8a;
307    private boolean __identifiersPresent8aSet = false;
308
309    /**
310     * True if the associationEnd is marked with identifiers stereotype, false otherwise.
311     * @return (boolean)handleIsIdentifiersPresent()
312     */
313    public final boolean isIdentifiersPresent()
314    {
315        boolean identifiersPresent8a = this.__identifiersPresent8a;
316        if (!this.__identifiersPresent8aSet)
317        {
318            // identifiersPresent has no pre constraints
319            identifiersPresent8a = handleIsIdentifiersPresent();
320            // identifiersPresent has no post constraints
321            this.__identifiersPresent8a = identifiersPresent8a;
322            if (isMetafacadePropertyCachingEnabled())
323            {
324                this.__identifiersPresent8aSet = true;
325            }
326        }
327        return identifiersPresent8a;
328    }
329
330   /**
331    * @see EntityAssociationEnd#getUniqueGroup()
332    * @return String
333    */
334    protected abstract String handleGetUniqueGroup();
335
336    private String __uniqueGroup9a;
337    private boolean __uniqueGroup9aSet = false;
338
339    /**
340     * The name of the unique-key that this unique association end belongs
341     * @return (String)handleGetUniqueGroup()
342     */
343    public final String getUniqueGroup()
344    {
345        String uniqueGroup9a = this.__uniqueGroup9a;
346        if (!this.__uniqueGroup9aSet)
347        {
348            // uniqueGroup has no pre constraints
349            uniqueGroup9a = handleGetUniqueGroup();
350            // uniqueGroup has no post constraints
351            this.__uniqueGroup9a = uniqueGroup9a;
352            if (isMetafacadePropertyCachingEnabled())
353            {
354                this.__uniqueGroup9aSet = true;
355            }
356        }
357        return uniqueGroup9a;
358    }
359
360   /**
361    * @see EntityAssociationEnd#isIdentifier()
362    * @return boolean
363    */
364    protected abstract boolean handleIsIdentifier();
365
366    private boolean __identifier10a;
367    private boolean __identifier10aSet = false;
368
369    /**
370     * True if this association is an identifier for its entity.
371     * @return (boolean)handleIsIdentifier()
372     */
373    public final boolean isIdentifier()
374    {
375        boolean identifier10a = this.__identifier10a;
376        if (!this.__identifier10aSet)
377        {
378            // identifier has no pre constraints
379            identifier10a = handleIsIdentifier();
380            // identifier has no post constraints
381            this.__identifier10a = identifier10a;
382            if (isMetafacadePropertyCachingEnabled())
383            {
384                this.__identifier10aSet = true;
385            }
386        }
387        return identifier10a;
388    }
389
390    // ------------- associations ------------------
391
392    /**
393     * <p><b>Constraint:</b> org::andromda::metafacades::uml::EntityAssociationEnd::valid foreign identifiers.</p>
394     * <p><b>Error:</b> Only ONE association end on an entity can be flagged as having a foreign identifier at any given time.  It also MUST be the child end (the other side is flagged as having composite aggregation) of a one-to-one association.</p>
395     * <p><b>OCL:</b> context EntityAssociationEndFacade 
396inv : foreignIdentifier implies (one2One and child and type.associationEnds -> one (foreignIdentifier))</p>
397     * @param validationMessages Collection<ModelValidationMessage>
398     * @see AssociationEndFacadeLogicImpl#validateInvariants(Collection validationMessages)
399     */
400    @Override
401    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
402    {
403        super.validateInvariants(validationMessages);
404        try
405        {
406            final Object contextElement = this.THIS();
407            boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"foreignIdentifier"))).booleanValue()?(Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"one2One"))).booleanValue()&&Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"child"))).booleanValue()&&OCLCollections.one(OCLIntrospector.invoke(contextElement,"type.associationEnds"),new Predicate(){public boolean evaluate(Object object){return Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(object,"foreignIdentifier"))).booleanValue();}})):true));
408            if (!constraintValid)
409            {
410                validationMessages.add(
411                    new ModelValidationMessage(
412                        (MetafacadeBase)contextElement ,
413                        "org::andromda::metafacades::uml::EntityAssociationEnd::valid foreign identifiers.",
414                        "Only ONE association end on an entity can be flagged as having a foreign identifier at any given time.  It also MUST be the child end (the other side is flagged as having composite aggregation) of a one-to-one association."));
415            }
416        }
417        catch (Throwable th)
418        {
419            Throwable cause = th.getCause();
420            int depth = 0; // Some throwables have infinite recursion
421            while (cause != null && depth < 7)
422            {
423                th = cause;
424                depth++;
425            }
426            logger.error("Error validating constraint 'org::andromda::metafacades::uml::EntityAssociationEnd::valid foreign identifiers.' ON "
427                + this.THIS().toString() + ": " + th.getMessage(), th);
428        }
429    }
430}