Author: craigmcc Date: Mon Jan 30 16:38:16 2006 New Revision: 373652 URL: http://svn.apache.org/viewcvs?rev=373652&view=rev Log: Improve the usability of the exception you get if LoadBundle.getMap() is called outside the scope of a JSF request.
Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/util/LoadBundle.java Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/util/LoadBundle.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/util/LoadBundle.java?rev=373652&r1=373651&r2=373652&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/util/LoadBundle.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/util/LoadBundle.java Mon Jan 30 16:38:16 2006 @@ -29,6 +29,7 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; +import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; @@ -137,6 +138,9 @@ * of the application resource bundle specified by the <code>basename</code> * property, localized for the <code>Locale</code> stored in the * <code>UIViewRoot</code> for the current request.</p> + * + * @exception IllegalStateException if we are not inside a Faces request, + * or if there is not a current view root with a valid locale */ public Map getMap() { @@ -148,9 +152,19 @@ throw new IllegalStateException("The 'basename' property cannot be null"); // FIXME - i18n } FacesContext context = FacesContext.getCurrentInstance(); - assert context != null; - Locale locale = context.getViewRoot().getLocale(); - assert locale != null; + UIViewRoot root = null; + Locale locale = null; + if (context != null) { + root = context.getViewRoot(); + } + if (root != null) { + locale = root.getLocale(); + } + if (locale == null) { + throw new IllegalStateException("Cannot retrieve locale-specific map if there " + + "is not a current Faces request, containing a valid view root, with" + + "a Locale instance inside."); + } // Look up the requested resource bundle final ResourceBundle bundle = getBundle(basename, locale); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]