001package org.andromda.cartridges.bpm4struts.metafacades;
002
003import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals;
004import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile;
005import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils;
006import org.andromda.metafacades.uml.ClassifierFacade;
007
008/**
009 * MetafacadeLogic implementation for org.andromda.cartridges.bpm4struts.metafacades.StrutsAttribute.
010 *
011 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAttribute
012 */
013public class StrutsAttributeLogicImpl
014    extends StrutsAttributeLogic
015{
016    private static final long serialVersionUID = 34L;
017    /**
018     * @param metaObject
019     * @param context
020     */
021    public StrutsAttributeLogicImpl(Object metaObject,
022                                    String context)
023    {
024        super(metaObject, context);
025    }
026
027    /**
028     * @return dateFormat
029     * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAttribute#getDateFormat()
030     */
031    protected String handleGetDateFormat()
032    {
033        String dateFormat = null;
034
035        if (this.getType() != null && this.getType().isDateType())
036        {
037            final Object taggedValueObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_FORMAT);
038            if (taggedValueObject == null)
039            {
040                dateFormat = (String)this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_DATEFORMAT);
041            }
042            else
043            {
044                dateFormat = taggedValueObject.toString();
045            }
046        }
047
048        return dateFormat;
049    }
050
051    /**
052     * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAttributeLogic#handleGetDummyValue(int)
053     */
054    protected String handleGetDummyValue(int seed)
055    {
056        String dummyValue = null;
057
058        final ClassifierFacade type = this.getType();
059
060        if (type == null)
061        {
062            dummyValue = "";
063        }
064        else if (type.isDateType())
065        {
066            dummyValue = "new java.util.Date()";
067        }
068        else if (type.isBooleanType())
069        {
070            dummyValue = String.valueOf(seed % 2 == 0);
071        }
072        else if (type.isPrimitive())
073        {
074            dummyValue = String.valueOf(seed);
075        }
076        else
077        {
078            dummyValue = '\"' + this.getName() + '-' + seed + '\"';
079        }
080
081        return dummyValue;
082    }
083
084    /**
085     * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAttributeLogic#handleIsSafeNamePresent()
086     */
087    protected boolean handleIsSafeNamePresent()
088    {
089        return Bpm4StrutsUtils.isSafeName(this.getName());
090    }
091}