001package org.andromda.cartridges.jsf2.metafacades;
002
003import org.andromda.cartridges.jsf2.JSFGlobals;
004import org.andromda.utils.StringUtilsHelper;
005
006/**
007 * MetafacadeLogic implementation for org.andromda.cartridges.jsf2.metafacades.JSFEvent.
008 *
009 * @see org.andromda.cartridges.jsf2.metafacades.JSFEvent
010 */
011public class JSFEventLogicImpl
012    extends JSFEventLogic
013{
014    private static final long serialVersionUID = 34L;
015    /**
016     * @param metaObject
017     * @param context
018     */
019    public JSFEventLogicImpl(Object metaObject, String context)
020    {
021        super(metaObject, context);
022    }
023
024    /**
025     * @return triggerKey
026     * @see org.andromda.cartridges.jsf2.metafacades.JSFEvent#getMessageKey()
027     */
028    protected String handleGetMessageKey()
029    {
030        String triggerKey = StringUtilsHelper.toResourceMessageKey(getName());
031        if (!this.isNormalizeMessages())
032        {
033            final JSFAction action = (JSFAction)this.getAction();
034            if (action != null)
035            {
036                final JSFView view = (JSFView)action.getInput();
037                if (view != null)
038                {
039                    triggerKey = view.getMessageKey() + '.' + triggerKey;
040                }
041            }
042        }
043        return triggerKey;
044    }
045
046    /**
047     * @return StringUtilsHelper.toPhrase(this.getName())
048     * @see org.andromda.cartridges.jsf2.metafacades.JSFEvent#getMessageValue()
049     */
050    protected String handleGetMessageValue()
051    {
052        return StringUtilsHelper.toPhrase(this.getName());
053    }
054
055    /**
056     * @return "Reset"
057     * @see org.andromda.cartridges.jsf2.metafacades.JSFEvent#getResetMessageValue()
058     */
059    protected String handleGetResetMessageValue()
060    {
061        return "Reset";
062    }
063
064    /**
065     * @return getMessageKey() + ".reset.message"
066     * @see org.andromda.cartridges.jsf2.metafacades.JSFEvent#getResetMessageKey()
067     */
068    protected String handleGetResetMessageKey()
069    {
070        return this.getMessageKey() + ".reset.message";
071    }
072
073    /**
074     * Indicates whether or not we should normalize messages.
075     * @return normalizeMessages true/false
076     */
077    private boolean isNormalizeMessages()
078    {
079        final String normalizeMessages = (String)getConfiguredProperty(JSFGlobals.NORMALIZE_MESSAGES);
080        return Boolean.valueOf(normalizeMessages).booleanValue();
081    }
082}