001package org.andromda.metafacades.uml14;
002
003import java.util.Collection;
004import org.andromda.metafacades.uml.AssociationEndFacade;
005import org.andromda.metafacades.uml.Entity;
006import org.andromda.metafacades.uml.EntityMetafacadeUtils;
007import org.andromda.metafacades.uml.UMLMetafacadeProperties;
008import org.andromda.metafacades.uml.UMLProfile;
009import org.apache.commons.lang.ObjectUtils;
010import org.apache.commons.lang.StringUtils;
011
012/**
013 * MetafacadeLogic implementation for org.andromda.metafacades.uml.EntityAssociationFacade.
014 *
015 * @see org.andromda.metafacades.uml.EntityAssociation
016 * @author Bob Fields
017 */
018public class EntityAssociationLogicImpl
019    extends EntityAssociationLogic
020{
021    private static final long serialVersionUID = -908730666308510791L;
022
023    /**
024     * @param metaObject
025     * @param context
026     */
027    public EntityAssociationLogicImpl(
028        Object metaObject,
029        String context)
030    {
031        super(metaObject, context);
032    }
033
034    /**
035     * @see org.andromda.metafacades.uml.EntityAssociation#getTableName()
036     */
037    @Override
038    public String handleGetTableName()
039    {
040        String tableName = null;
041        final Collection<AssociationEndFacade> ends = this.getAssociationEnds();
042        if (ends != null && !ends.isEmpty())
043        {
044            final AssociationEndFacade end = ends.iterator().next();
045            // prevent ClassCastException if the association isn't an
046            // Entity
047            if (Entity.class.isAssignableFrom(end.getType().getClass()))
048            {
049                final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;
050                final String tableNamePrefix =
051                    this.isConfiguredProperty(prefixProperty)
052                    ? ObjectUtils.toString(this.getConfiguredProperty(prefixProperty)) : null;
053                tableName =
054                    EntityMetafacadeUtils.getSqlNameFromTaggedValue(
055                        tableNamePrefix,
056                        this,
057                        UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,
058                        ((Entity)end.getType()).getMaxSqlNameLength(),
059                        this.getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR),
060                        this.getConfiguredProperty(UMLMetafacadeProperties.SHORTEN_SQL_NAMES_METHOD));
061            }
062        }
063        return tableName;
064    }
065
066    /**
067     * @see org.andromda.metafacades.uml.EntityAssociation#getSchema()
068     */
069    @Override
070    protected String handleGetSchema()
071    {
072        String schemaName = ObjectUtils.toString(this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_SCHEMA));
073        if (StringUtils.isBlank(schemaName))
074        {
075            schemaName = ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.SCHEMA_NAME));
076        }
077        return schemaName;
078    }
079
080    /**
081     *  @see org.andromda.metafacades.uml.EntityAssociation#isEntityAssociation()
082     */
083    @Override
084    protected boolean handleIsEntityAssociation()
085    {
086        boolean isEntityAssociation = false;
087        if (getAssociationEndA().isAssociationEndFacadeMetaType())
088        {
089            isEntityAssociation = true;
090        }
091        return isEntityAssociation;
092    }
093}