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.Role;
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.Transformer;
015import org.apache.log4j.Logger;
016import org.omg.uml.behavioralelements.usecases.Actor;
017
018/**
019 * Represents a role a user may play within a system.  Provides access to things such as services
020 * and service operations.
021 * MetafacadeLogic for Role
022 *
023 * @see Role
024 */
025public abstract class RoleLogic
026    extends ActorFacadeLogicImpl
027    implements Role
028{
029    /**
030     * The underlying UML object
031     * @see Object
032     */
033    protected Object metaObject;
034
035    /** Create Metafacade implementation instance using the MetafacadeFactory from the context
036     * @param metaObjectIn
037     * @param context
038     */
039    protected RoleLogic(Object metaObjectIn, String context)
040    {
041        super((Actor)metaObjectIn, getContext(context));
042        this.metaObject = metaObjectIn;
043    }
044
045    /**
046     * The logger instance.
047     */
048    private static final Logger logger = Logger.getLogger(RoleLogic.class);
049
050    /**
051     * Gets the context for this metafacade logic instance.
052     * @param context String. Set to Role if null
053     * @return context String
054     */
055    private static String getContext(String context)
056    {
057        if (context == null)
058        {
059            context = "org.andromda.metafacades.uml.Role";
060        }
061        return context;
062    }
063
064    /** Reset context only for non-root metafacades
065     * @param context
066     */
067    @Override
068    public void resetMetafacadeContext(String context)
069    {
070        if (!this.contextRoot) // reset context only for non-root metafacades
071        {
072            context = getContext(context);  // to have same value as in original constructor call
073            setMetafacadeContext (context);
074        }
075    }
076
077    /**
078     * @return boolean true always
079     * @see Role
080     */
081    public boolean isRoleMetaType()
082    {
083        return true;
084    }
085
086    // --------------- attributes ---------------------
087
088   /**
089    * @see Role#isReferencesPresent()
090    * @return boolean
091    */
092    protected abstract boolean handleIsReferencesPresent();
093
094    private boolean __referencesPresent1a;
095    private boolean __referencesPresent1aSet = false;
096
097    /**
098     * Indicates if the necessary references are present for the Role.  This include any references
099     * to a service, service operation or use case.
100     * @return (boolean)handleIsReferencesPresent()
101     */
102    public final boolean isReferencesPresent()
103    {
104        boolean referencesPresent1a = this.__referencesPresent1a;
105        if (!this.__referencesPresent1aSet)
106        {
107            // referencesPresent has no pre constraints
108            referencesPresent1a = handleIsReferencesPresent();
109            // referencesPresent has no post constraints
110            this.__referencesPresent1a = referencesPresent1a;
111            if (isMetafacadePropertyCachingEnabled())
112            {
113                this.__referencesPresent1aSet = true;
114            }
115        }
116        return referencesPresent1a;
117    }
118
119    // ------------- associations ------------------
120
121    /**
122     * <p><b>Constraint:</b> org::andromda::metafacades::uml::Role::non-empty unique role name</p>
123     * <p><b>Error:</b> Each role must have a non-empty name that is unique among all other roles.</p>
124     * <p><b>OCL:</b> context Role inv: name->notEmpty() and model.allActors->isUnique(name)</p>
125     * @param validationMessages Collection<ModelValidationMessage>
126     * @see ActorFacadeLogicImpl#validateInvariants(Collection validationMessages)
127     */
128    @Override
129    public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
130    {
131        super.validateInvariants(validationMessages);
132        try
133        {
134            final Object contextElement = this.THIS();
135            boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name"))&&OCLCollections.isUnique(OCLIntrospector.invoke(contextElement,"model.allActors"),new Transformer(){public Object transform(Object object){return OCLIntrospector.invoke(object,"name");}}));
136            if (!constraintValid)
137            {
138                validationMessages.add(
139                    new ModelValidationMessage(
140                        (MetafacadeBase)contextElement ,
141                        "org::andromda::metafacades::uml::Role::non-empty unique role name",
142                        "Each role must have a non-empty name that is unique among all other roles."));
143            }
144        }
145        catch (Throwable th)
146        {
147            Throwable cause = th.getCause();
148            int depth = 0; // Some throwables have infinite recursion
149            while (cause != null && depth < 7)
150            {
151                th = cause;
152                depth++;
153            }
154            logger.error("Error validating constraint 'org::andromda::metafacades::uml::Role::non-empty unique role name' ON "
155                + this.THIS().toString() + ": " + th.getMessage(), th);
156        }
157    }
158}