001package org.andromda.cartridges.ejb.metafacades;
002
003import java.util.Collection;
004import org.andromda.cartridges.ejb.EJBProfile;
005import org.andromda.metafacades.uml.AttributeFacade;
006
007/**
008 * Metaclass facade implementation.
009 */
010public class EJBPrimaryKeyFacadeLogicImpl
011        extends EJBPrimaryKeyFacadeLogic
012{
013    private static final long serialVersionUID = 34L;
014    // ---------------- constructor -------------------------------
015
016    /**
017     * @param metaObject
018     * @param context
019     */
020    public EJBPrimaryKeyFacadeLogicImpl(Object metaObject, String context)
021    {
022        super(metaObject, context);
023    }
024
025    /**
026     * @see org.andromda.cartridges.ejb.metafacades.EJBPrimaryKeyFacadeLogic#handleIsComplex()
027     */
028    protected boolean handleIsComplex()
029    {
030        return getSimplePkField() == null;
031    }
032
033    /**
034     * If this <code>object</code> does not have a complex primary key, get the (unqiue) attribute that is used as the
035     * primary key.
036     *
037     * @return the attribute used as primary key, or <code>null</code> if there is none or the class has a complex
038     *         primary key.
039     */
040    private AttributeFacade getSimplePkField()
041    {
042        AttributeFacade primaryKey = null;
043        Collection primaryKeys = ((EJBEntityFacade)this.getOwner()).getIdentifiers();
044        if (primaryKeys.size() == 1)
045        {
046            AttributeFacade pkField = (AttributeFacade)primaryKeys.iterator().next();
047            if (pkField.hasStereotype(EJBProfile.STEREOTYPE_IDENTIFIER))
048            {
049                primaryKey = pkField;
050            }
051        }
052        return primaryKey;
053    }
054
055    // ------------- relations ------------------
056
057}