001package org.andromda.metafacades.uml14;
002
003import org.andromda.metafacades.uml.NameMasker;
004import org.andromda.metafacades.uml.UMLMetafacadeProperties;
005import org.apache.commons.lang.StringUtils;
006import org.omg.uml.foundation.core.EnumerationLiteral;
007
008/**
009 * MetafacadeLogic implementation for org.andromda.metafacades.uml.EnumerationLiteralFacade.
010 *
011 * @see org.andromda.metafacades.uml.EnumerationLiteralFacade
012 * @author Bob Fields
013 */
014public class EnumerationLiteralFacadeLogicImpl
015    extends EnumerationLiteralFacadeLogic
016{
017    private static final long serialVersionUID = 8552041173866794442L;
018
019    /**
020     * @param metaObject
021     * @param context
022     */
023    public EnumerationLiteralFacadeLogicImpl(
024        EnumerationLiteral metaObject,
025        String context)
026    {
027        super(metaObject, context);
028    }
029
030    /**
031     * @see org.andromda.metafacades.uml.EnumerationLiteralFacade#getName()
032     */
033    @Override
034    protected String handleGetName()
035    {
036        return this.getName(false);
037    }
038
039    /**
040     * @see org.andromda.metafacades.uml.EnumerationLiteralFacade#getValue()
041     */
042    @Override
043    protected String handleGetValue()
044    {
045        return this.getValue(false);
046    }
047
048    /**
049     * @see org.andromda.metafacades.uml.EnumerationLiteralFacade#getName(boolean)
050     */
051    @Override
052    protected String handleGetName(boolean modelName)
053    {
054        String name = super.handleGetName();
055        final String mask = String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.ENUMERATION_LITERAL_NAME_MASK));
056        if (!modelName && StringUtils.isNotBlank(mask))
057        {
058            name = NameMasker.mask(name, mask);
059        }
060        return name;
061    }
062
063    /**
064     * @see org.andromda.metafacades.uml.EnumerationLiteralFacade#getValue(boolean)
065     */
066    @Override
067    protected String handleGetValue(boolean modelValue)
068    {
069        return StringUtils.trimToEmpty(this.getName(modelValue));
070    }
071
072
073    /**
074     * @see org.andromda.metafacades.uml14.EnumerationLiteralFacadeLogic#handleGetEnumerationValue()
075     */
076    protected String handleGetEnumerationValue() {
077        String value = this.getValue();
078        if (StringUtils.isEmpty(value))
079        {
080            value = "\"\"";
081        }
082        if (value.indexOf('"')<0)
083        {
084            value = '\"' + value + '\"';
085        }
086        return value;
087    }
088}