Return-Path: Delivered-To: apmail-struts-dev-archive@www.apache.org Received: (qmail 44503 invoked from network); 5 May 2006 19:53:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 May 2006 19:53:01 -0000 Received: (qmail 79999 invoked by uid 500); 5 May 2006 19:52:57 -0000 Delivered-To: apmail-struts-dev-archive@struts.apache.org Received: (qmail 79958 invoked by uid 500); 5 May 2006 19:52:57 -0000 Mailing-List: contact dev-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list dev@struts.apache.org Received: (qmail 79947 invoked by uid 99); 5 May 2006 19:52:57 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 May 2006 12:52:57 -0700 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=INFO_TLD,SPF_HELO_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [206.252.142.4] (HELO milhouse.priv.jgsullivan.com) (206.252.142.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 May 2006 12:52:51 -0700 Received: from [192.168.2.110] (maximus.jgsullivan.com [68.79.151.2]) by milhouse.priv.jgsullivan.com (8.12.11.20060308/8.12.11) with ESMTP id k45JqTeS028968 for ; Fri, 5 May 2006 15:52:30 -0400 Mime-Version: 1.0 Message-Id: In-Reply-To: References: <445B9944.4080303@twdata.org> Date: Fri, 5 May 2006 14:49:59 -0500 To: "Struts Developers List" From: Joe Germuska Subject: Re: Messages Round II (was Leveraging known constructs (was Public API first draft)) Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N What about a String constant representing a global warning, and then only warn(String fieldName, String key) warn(String fieldName, String key, Object...) i.e. warn(GLOBAL, "warnings.foo", 42); Joe At 12:26 PM -0700 5/5/06, Bob Lee wrote: >There's some potential overloading ambiguity. For example: > > void warn(String key, Object... arguments); > void warn(String fieldName, String key); > >Right now, if I want to add a global warning with one String argument, >I'll have to cast the argument to Object: > > messages.warn("key", (Object) "argument"); > >I think we should rename the global methods (as they're the lesser >used) or the argument methods. Here are some options: > > void formatAndWarn(String key, Object... arguments); > void warnGlobally(String key, Object... arguments); > void globalWarn(String key, Object... arguments); > void generalWarn(String key, Object... arguments); > void warnAll(String key, Object... arguments); > void warnOverall(String key, Object... arguments); > void addGlobalWarning(String key, Object... arguments); > void warnWithArguments(String key, Object... arguments); > >Preferences, more suggestions? > >Bob > >On 5/5/06, Don Brown wrote: >>I like it, Level should extend Comparable, and Global works for me. >> >>Don >> >>Bob Lee wrote: >>> - The attached version supports arbitrary levels. I used an interface >>> instead of an enum so the user can define additional levels if they >>> wish. Should Level extend Comparable? >>> >>> - It has built in support for INFO, WARN, and ERROR along with >>> respective convenience methods. >>> >>> - It provides a Map of field messages. It's not necessary for Messages >>> itself to implement both Map and List. Delegating to separate objects >>> is less confusing. >>> >>> - Adding messages and checking for the presence of messages >>> (hasErrors()) should be dead simple. Getting the messages doesn't have >>> to be as convenient (at least not through the published API). >>> >>> - "Request-scoped" is the wrong word. We're really talking about "not >>> associated with a field." Page-scoped? Form-scoped? Global? >>> >>> Thanks, >>> Bob >>> >>> >>> ------------------------------------------------------------------------ >>> >>> package org.apache.struts.action2; >>> >>> import java.util.List; >>> import java.util.Map; >>> import java.util.HashMap; >>> import java.util.Set; >>> import java.io.Serializable; >>> >>> /** >>> * Request and field-scoped messages. Uses keys instead of actual >>>messages to decouple code from messages. Messages >>> * may come from multiple actions and interceptors. >>> * >>> * @author crazybob@google.com (Bob Lee) >>> */ >>> public interface Messages { >>> >>> /** >>> * Message level. >>> */ >>> public interface Level { >>> >>> /** >>> * Informational message level. >>> */ >>> public static final Level INFO = new LevelImpl("info"); >>> >>> /** >>> * Warning message level. >>> */ >>> public static final Level WARN = new LevelImpl("warn"); >>> >>> /** >>> * Error message level. >>> */ >>> public static final Level ERROR = new LevelImpl("error"); >>> } >>> >>> /** >>> * Adds request-scoped informational message. >>> * >>> * @param key message key >>> * @see Level.INFO >>> */ >>> void info(String key); >>> >>> /** >>> * Adds request-scoped informational message. >>> * >>> * @param key message key >>> * @param arguments message arguments >>> * @see Level.INFO >>> */ >>> void info(String key, Object... arguments); >>> >>> /** >>> * Adds field-scoped informational message. >>> * >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> * @see Level.INFO >>> */ >>> void info(String fieldName, String key); >>> >>> /** >>> * Adds field-scoped informational message. >>> * >>> * @param fieldName name of field to attach message to >>> * @param key message key >> > * @param arguments message arguments >>> * @see Level.INFO >>> */ >>> void info(String fieldName, String key, Object... arguments); >>> >>> /** >>> * Adds request-scoped warning message. >>> * >>> * @param key message key >>> * @see Level.WARN >>> */ >>> void warn(String key); >>> >>> /** >>> * Adds request-scoped warning message. >>> * >>> * @param key message key >>> * @param arguments message arguments >>> * @see Level.WARN >>> */ >>> void warn(String key, Object... arguments); >>> >>> /** >>> * Adds field-scoped warning message. >>> * >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> * @see Level.WARN >>> */ >>> void warn(String fieldName, String key); >>> >>> /** >>> * Adds field-scoped warning message. >>> * >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> * @param arguments message arguments >>> * @see Level.WARN >>> */ >>> void warn(String fieldName, String key, Object... arguments); >>> >>> /** >>> * Adds request-scoped error message. >>> * >>> * @param key message key >>> * @see Level.ERROR >>> */ >>> void error(String key); >>> >>> /** >>> * Adds request-scoped error message. >>> * >>> * @param key message key >>> * @param arguments message arguments >>> * @see Level.ERROR >>> */ >>> void error(String key, Object... arguments); >>> >>> /** >>> * Adds field-scoped error message. >>> * >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> * @see Level.ERROR >>> */ >>> void error(String fieldName, String key); >>> >>> /** >>> * Adds field-scoped error message. >>> * >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> * @param arguments message arguments >>> * @see Level.ERROR >>> */ >>> void error(String fieldName, String key, Object... arguments); >>> >>> /** >>> * Adds request-scoped message. >>> * >>> * @param level message level >>> * @param key message key >>> */ >>> void add(Level level, String key); >>> >>> /** >>> * Adds request-scoped message. >>> * >>> * @param level message level >>> * @param key message key >>> * @param arguments message arguments >>> */ >>> void add(Level level, String key, Object... arguments); >>> >>> /** >>> * Adds field-scoped message. >>> * >>> * @param level message level >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> */ >>> void add(Level level, String fieldName, String key); >>> >>> /** >>> * Adds field-scoped message. >>> * >>> * @param level message level >>> * @param fieldName name of field to attach message to >>> * @param key message key >>> * @param arguments message arguments >>> */ >>> void add(Level level, String fieldName, String key, Object... >>>arguments); >>> >>> /** >>> * Gets request-scoped messages. >>> * >>> * @param level message level >>> * @return unmodifiable list of messages for this request. >>> */ >>> List forRequest(Level level); >>> >>> /** >>> * Gets field-scoped messages. >>> * >>> * @param level message level >>> * @return unmodifiable map of field names to message lists >>> */ >>> Map> forFields(Level level); >>> >>> /** >>> * Returns set of levels for which we have messages. >>> * >>> * @return unmodifiable set of levels >>> */ >>> Set levels(); >>> >>> /** >>> * Returns true if we have request or field-scoped error messages. >>> * >>> * @see Level.ERROR >>> */ >>> boolean hasErrors(); >>> >>> /** >>> * Returns true if we have request or field-scoped warning messages. >>> * >>> * @see Level.WARN >>> */ >>> boolean hasWarnings(); >>> >>> /** >>> * Returns true if we have request or field-scoped >>>informational messages. >>> * >>> * @see Level.INFO >>> */ >>> boolean hasInformation(); >> > >>> /** >>> * Returns true if no request or field-scoped messages have been added. >>> */ >>> boolean isEmpty(); >>> >>> /** >>> * Returns true if no request or field-scoped messages have >>>been added for the given level. >>> * >>> * @param level message level >>> */ >>> boolean isEmpty(Level level); >>> >>> static class LevelImpl implements Messages.Level, Serializable { >>> >>> private static final long serialVersionUID = 0; >>> >>> static Map levels = new HashMap(); >>> >>> String name; >>> >>> public LevelImpl(String name) { >>> this.name = name; >>> levels.put(name, this); >>> } >>> >>> Object readResolve() { >>> return forName(name); >>> } >>> >>> public String toString() { >>> return "Level(" + name + ")"; >>> } >>> >>> static Level forName(String name) { >>> Level level = levels.get(name); >>> if (level == null) >>> throw new NullPointerException("Invalid level: " + name); >>> return level; >>> } >>> } >>> } >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org >>> For additional commands, e-mail: dev-help@struts.apache.org >> >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org >>For additional commands, e-mail: dev-help@struts.apache.org >> > >--------------------------------------------------------------------- >To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org >For additional commands, e-mail: dev-help@struts.apache.org -- Joe Germuska Joe@Germuska.com * http://blog.germuska.com "You really can't burn anything out by trying something new, and even if you can burn it out, it can be fixed. Try something new." -- Robert Moog --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org For additional commands, e-mail: dev-help@struts.apache.org