001package org.andromda.cartridges.meta.metafacades;
002
003import java.util.Collection;
004import org.andromda.cartridges.meta.MetaProfile;
005import org.andromda.metafacades.uml.GeneralizableElementFacade;
006import org.apache.commons.lang.ObjectUtils;
007import org.apache.commons.lang.StringUtils;
008
009/**
010 * MetafacadeLogic implementation for org.andromda.cartridges.meta.metafacades.MetafacadeGeneralization.
011 *
012 * @see org.andromda.cartridges.meta.metafacades.MetafacadeGeneralization
013 * @author Bob Fields
014 */
015public class MetafacadeGeneralizationLogicImpl
016    extends MetafacadeGeneralizationLogic
017{
018    private static final long serialVersionUID = 34L;
019    /**
020     * @param metaObjectIn
021     * @param context
022     */
023    public MetafacadeGeneralizationLogicImpl(
024        Object metaObjectIn,
025        String context)
026    {
027        super(metaObjectIn, context);
028    }
029
030    /**
031     * @see org.andromda.cartridges.meta.metafacades.MetafacadeGeneralization#getPrecedence()
032     */
033    @Override
034    protected Integer handleGetPrecedence()
035    {
036        Integer precedence = Integer.valueOf(999999999);
037        String value =
038            ObjectUtils.toString(
039                this.findTaggedValue(MetaProfile.TAGGEDVALUE_GENERALIZATION_PRECEDENCE));
040        if (StringUtils.isNotBlank(value))
041        {
042            try
043            {
044                precedence = Integer.valueOf(value);
045            }
046            catch (NumberFormatException ex)
047            {
048                // ignore since we'll just take the large default.
049            }
050        }
051        return precedence;
052    }
053
054    /**
055     * @see org.andromda.cartridges.meta.metafacades.MetafacadeGeneralization#getGetterName()
056     */
057    @Override
058    protected String handleGetGetterName()
059    {
060        String name = this.getName();
061        if (StringUtils.isBlank(name))
062        {
063            if (this.getParent() != null)
064            {
065                name = this.getParent().getName();
066            }
067        }
068        name = StringUtils.capitalize(name);
069        return "get" + name;
070    }
071
072    /**
073     * @see org.andromda.cartridges.meta.metafacades.MetafacadeGeneralization#getGetterNameVisibility()
074     */
075    @Override
076    protected String handleGetGetterNameVisibility()
077    {
078        String visibility = "private";
079        GeneralizableElementFacade child = this.getChild();
080        if (child != null)
081        {
082            // if we have more than one generalization for the metafacade
083            // then we expose the super facade accessors.
084            Collection<GeneralizableElementFacade> generalizations = child.getGeneralizations();
085            if ((generalizations != null) && (generalizations.size() > 1))
086            {
087                visibility = "protected";
088            }
089        }
090        return visibility;
091    }
092
093    /**
094     * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
095     */
096    @Override
097    public String getName()
098    {
099        String name = super.getName();
100        if (StringUtils.isBlank(name) && (this.getParent() != null))
101        {
102            name = this.getParent().getName();
103        }
104        return ObjectUtils.toString(
105            this.getConfiguredProperty(MetaGlobals.PROPERTY_GENERALIZATION_NAME_PATTERN))
106                          .replaceAll("\\{0\\}", name);
107    }
108}