dev@javaserverfaces.java.net

Re: [REVIEW] Make reduced verbosity the default when bootstrapping JSF

From: Roger Kitain <Roger.Kitain_at_Sun.COM>
Date: Fri, 16 Jun 2006 15:29:21 -0400

r=rogerk

Ryan Lubke wrote:

>
>------------------------------------------------------------------------
>
>Reduce verbosity of context startup processing.
>
>
>
>SECTION: Modified Files
>----------------------------
>M src/com/sun/faces/config/WebConfiguration.java
> - Refactored various processing sections from ctor
> into private methods
> - Added new context param 'com.sun.faces.displayConfiguration'
> which is false by default. For development
> purposes, it can be switched to true to obtain the
> old behavior.
>
>M src/com/sun/faces/spi/InjectionProviderFactory.java
> - Switched the configuration message from INFO to FINE.
> - Switched from INFO to WARNING for the case where
> no injection is available.
>
>
>SECTION: Diffs
>----------------------------
>Index: src/com/sun/faces/config/WebConfiguration.java
>===================================================================
>RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/config/WebConfiguration.java,v
>retrieving revision 1.7
>diff -u -r1.7 WebConfiguration.java
>--- src/com/sun/faces/config/WebConfiguration.java 31 May 2006 21:13:05 -0000 1.7
>+++ src/com/sun/faces/config/WebConfiguration.java 16 Jun 2006 17:43:44 -0000
>@@ -56,6 +56,9 @@
> // Key under which we store our WebConfiguration instance.
> private static final String WEB_CONFIG_KEY =
> "com.sun.faces.config.WebConfiguration";
>+
>+ // Logging level. Defaults to FINE
>+ private Level loggingLevel = Level.FINE;
>
> private Map<BooleanWebContextInitParameter, Boolean> booleanContextParameters =
> new HashMap<BooleanWebContextInitParameter, Boolean>(
>@@ -80,169 +83,10 @@
> this.servletContext = servletContext;
>
> String contextName = getServletContextName();
>-
>- // process non-boolean context parameters
>- for (WebContextInitParameter param : WebContextInitParameter.values()) {
>- String value =
>- servletContext.getInitParameter(param.getQualifiedName());
>-
>- if (value != null && value.length() > 0 && param.isDeprecated()) {
>- WebContextInitParameter alternate = param.getAlternate();
>- if (LOGGER.isLoggable(Level.WARNING)) {
>- LOGGER.log(Level.WARNING,
>- "jsf.config.webconfig.param.deprecated",
>- new Object[]{
>- contextName,
>- param.getQualifiedName(),
>- alternate.getQualifiedName()});
>- }
>-
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- "jsf.config.webconfig.configinfo.reset",
>- new Object[]{contextName,
>- alternate.getQualifiedName(),
>- value});
>- }
>-
>- contextParameters.put(alternate, value);
>- continue;
>- }
>-
>- if ((value == null || value.length() == 0) && !param.isDeprecated()) {
>- value = param.getDefaultValue();
>- }
>- if (value == null || value.length() == 0) {
>- continue;
>- }
>-
>- if (value.length() > 0) {
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- "jsf.config.webconfig.configinfo",
>- new Object[]{contextName,
>- param.getQualifiedName(),
>- value});
>-
>- }
>- contextParameters.put(param, value);
>- } else {
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- "jsf.config.webconfig.option.notconfigured",
>- new Object[]{contextName,
>- param.getQualifiedName()});
>- }
>- }
>-
>- }
>-
>- // process boolean contxt parameters
>- for (BooleanWebContextInitParameter param : BooleanWebContextInitParameter
>- .values()) {
>- String strValue =
>- servletContext.getInitParameter(param.getQualifiedName());
>- boolean value;
>-
>- if (strValue != null && strValue.length() > 0 && param.isDeprecated()) {
>- BooleanWebContextInitParameter alternate = param.getAlternate();
>- if (LOGGER.isLoggable(Level.WARNING)) {
>- LOGGER.log(Level.WARNING,
>- "jsf.config.webconfig.param.deprecated",
>- new Object[]{
>- contextName,
>- param.getQualifiedName(),
>- alternate.getQualifiedName()});
>- }
>-
>- if (isValueValid(param, strValue)) {
>- value = Boolean.valueOf(strValue);
>- } else {
>- value = param.getDefaultValue();
>- }
>-
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- ((value)
>- ? "jsf.config.webconfig.configinfo.reset.enabled"
>- : "jsf.config.webconfig.configinfo.reset.disabled"),
>- new Object[]{contextName,
>- alternate.getQualifiedName()});
>- }
>-
>- booleanContextParameters.put(alternate, value);
>- continue;
>- }
>-
>- if (!param.isDeprecated()) {
>- if (strValue == null) {
>- value = param.getDefaultValue();
>- } else {
>- if (isValueValid(param, strValue)) {
>- value = Boolean.valueOf(strValue);
>- } else {
>- value = param.getDefaultValue();
>- }
>- }
>-
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- ((value)
>- ? "jsf.config.webconfig.boolconfiginfo.enabled"
>- : "jsf.config.webconfig.boolconfiginfo.disabled"),
>- new Object[]{contextName,
>- param.getQualifiedName()});
>- }
>-
>- booleanContextParameters.put(param, value);
>- }
>-
>- }
>-
>- InitialContext initialContext = null;
>- try {
>- initialContext = new InitialContext();
>- } catch (NamingException ne) {
>- // log WARNING - unable to get JNDI initial context
>- }
>-
>- if (initialContext != null) {
>- // process environment entries
>- for (WebEnvironmentEntry entry : WebEnvironmentEntry.values()) {
>- String entryName = entry.getQualifiedName();
>-
>- try {
>- String value = (String) initialContext.lookup(entryName);
>- if (value != null) {
>- if (LOGGER.isLoggable(Level.INFO)) {
>- // special logic for ClientStateSavingPassword
>- if (!entry
>- .equals(WebEnvironmentEntry.ClientStateSavingPassword))
>- {
>- if (LOGGER
>- .isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- "jsf.config.webconfig.enventryinfo",
>- new Object[]{contextName,
>- entryName,
>- value});
>- }
>- } else {
>- if (LOGGER
>- .isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>- "jsf.config.webconfig.enventry.clientencrypt",
>- contextName);
>- }
>- }
>- }
>- envEntries.put(entry, value);
>- }
>- } catch (NamingException ne) {
>- // log WARNING - unable to lookup value
>- }
>- }
>- }
>+
>+ processBooleanParameters(servletContext, contextName);
>+ processInitParameters(servletContext, contextName);
>+ processJndiEntries(contextName);
>
> }
>
>@@ -295,19 +139,6 @@
>
>
> /**
>- * @return the name of this application
>- */
>- public String getServletContextName() {
>- if (servletContext.getMajorVersion() == 2
>- && servletContext.getMinorVersion() <= 4) {
>- return servletContext.getServletContextName();
>- } else {
>- return servletContext.getContextPath();
>- }
>- }
>-
>-
>- /**
> * Obtain the value of the specified boolean parameter
> * @param param the parameter of interest
> * @return the value of the specified boolean parameter
>@@ -325,6 +156,18 @@
>
>
> /**
>+ * Obtain the value of the specified parameter
>+ * @param param the parameter of interest
>+ * @return the value of the specified parameter
>+ */
>+ public String getContextInitParameter(WebContextInitParameter param) {
>+
>+ return contextParameters.get(param);
>+
>+ }
>+
>+
>+ /**
> * Obtain the value of the specified env-entry
> * @param entry the env-entry of interest
> * @return the value of the specified env-entry
>@@ -337,29 +180,38 @@
>
>
> /**
>- * Obtain the value of the specified parameter
>- * @param param the parameter of interest
>- * @return the value of the specified parameter
>+ * @return the name of this application
> */
>- public String getContextInitParameter(WebContextInitParameter param) {
>+ public String getServletContextName() {
>
>- return contextParameters.get(param);
>+ if (servletContext.getMajorVersion() == 2
>+ && servletContext.getMinorVersion() <= 4) {
>+ return servletContext.getServletContextName();
>+ } else {
>+ return servletContext.getContextPath();
>+ }
>
> }
>
>
>- public void overrideContextInitParameter(WebContextInitParameter param) {
>+ public void overrideContextInitParameter(BooleanWebContextInitParameter param) {
>+
> // no-op for now
>+
> }
>
>
>- public void overrideContextInitParameter(BooleanWebContextInitParameter param) {
>+ public void overrideContextInitParameter(WebContextInitParameter param) {
>+
> // no-op for now
>+
> }
>
>
> public void overrideEnvEntry(WebEnvironmentEntry entry) {
>+
> // no-op for now
>+
> }
>
>
>@@ -390,6 +242,13 @@
> // --------------------------------------------------------- Private Methods
>
>
>+ /**
>+ * <p>Is the configured value valid against the default boolean pattern.</p>
>+ * @param param the boolean parameter
>+ * @param value the configured value
>+ * @return <code>true</code> if the value is valid,
>+ * otherwise <code>false</code>
>+ */
> private boolean isValueValid(BooleanWebContextInitParameter param,
> String value) {
>
>@@ -411,6 +270,206 @@
> }
>
>
>+ /**
>+ * <p>Process all boolean context initialization parameters.</p>
>+ * @param servletContext the ServletContext of interest
>+ * @param contextName the context name
>+ */
>+ private void processBooleanParameters(ServletContext servletContext,
>+ String contextName) {
>+
>+ // process boolean contxt parameters
>+ for (BooleanWebContextInitParameter param : BooleanWebContextInitParameter
>+ .values()) {
>+ String strValue =
>+ servletContext.getInitParameter(param.getQualifiedName());
>+ boolean value;
>+
>+ if (strValue != null && strValue.length() > 0 && param.isDeprecated()) {
>+ BooleanWebContextInitParameter alternate = param.getAlternate();
>+ if (LOGGER.isLoggable(Level.WARNING)) {
>+ LOGGER.log(Level.WARNING,
>+ "jsf.config.webconfig.param.deprecated",
>+ new Object[]{
>+ contextName,
>+ param.getQualifiedName(),
>+ alternate.getQualifiedName()});
>+ }
>+
>+ if (isValueValid(param, strValue)) {
>+ value = Boolean.valueOf(strValue);
>+ } else {
>+ value = param.getDefaultValue();
>+ }
>+
>+ if (LOGGER.isLoggable(Level.INFO)) {
>+ LOGGER.log(Level.INFO,
>+ ((value)
>+ ? "jsf.config.webconfig.configinfo.reset.enabled"
>+ : "jsf.config.webconfig.configinfo.reset.disabled"),
>+ new Object[]{contextName,
>+ alternate.getQualifiedName()});
>+ }
>+
>+ booleanContextParameters.put(alternate, value);
>+ continue;
>+ }
>+
>+ if (!param.isDeprecated()) {
>+ if (strValue == null) {
>+ value = param.getDefaultValue();
>+ } else {
>+ if (isValueValid(param, strValue)) {
>+ value = Boolean.valueOf(strValue);
>+ } else {
>+ value = param.getDefaultValue();
>+ }
>+ }
>+
>+ // first param processed should be
>+ // com.sun.faces.displayConfiguration
>+ if (BooleanWebContextInitParameter.DisplayConfiguration
>+ .equals(param) && value) {
>+ loggingLevel = Level.INFO;
>+ }
>+
>+ if (LOGGER.isLoggable(loggingLevel)) {
>+ LOGGER.log(loggingLevel,
>+ ((value)
>+ ? "jsf.config.webconfig.boolconfiginfo.enabled"
>+ : "jsf.config.webconfig.boolconfiginfo.disabled"),
>+ new Object[]{contextName,
>+ param.getQualifiedName()});
>+ }
>+
>+ booleanContextParameters.put(param, value);
>+ }
>+
>+ }
>+
>+ }
>+
>+
>+ /**
>+ * <p>Process all non-boolean context initialization parameters.</p>
>+ * @param servletContext the ServletContext of interest
>+ * @param contextName the context name
>+ */
>+ private void processInitParameters(ServletContext servletContext,
>+ String contextName) {
>+
>+ for (WebContextInitParameter param : WebContextInitParameter.values()) {
>+ String value =
>+ servletContext.getInitParameter(param.getQualifiedName());
>+
>+ if (value != null && value.length() > 0 && param.isDeprecated()) {
>+ WebContextInitParameter alternate = param.getAlternate();
>+ if (LOGGER.isLoggable(Level.WARNING)) {
>+ LOGGER.log(Level.WARNING,
>+ "jsf.config.webconfig.param.deprecated",
>+ new Object[]{
>+ contextName,
>+ param.getQualifiedName(),
>+ alternate.getQualifiedName()});
>+ }
>+
>+ if (LOGGER.isLoggable(Level.INFO)) {
>+ LOGGER.log(Level.INFO,
>+ "jsf.config.webconfig.configinfo.reset",
>+ new Object[]{contextName,
>+ alternate.getQualifiedName(),
>+ value});
>+ }
>+
>+ contextParameters.put(alternate, value);
>+ continue;
>+ }
>+
>+ if ((value == null || value.length() == 0) && !param.isDeprecated()) {
>+ value = param.getDefaultValue();
>+ }
>+ if (value == null || value.length() == 0) {
>+ continue;
>+ }
>+
>+ if (value.length() > 0) {
>+ if (LOGGER.isLoggable(loggingLevel)) {
>+ LOGGER.log(loggingLevel,
>+ "jsf.config.webconfig.configinfo",
>+ new Object[]{contextName,
>+ param.getQualifiedName(),
>+ value});
>+
>+ }
>+ contextParameters.put(param, value);
>+ } else {
>+ if (LOGGER.isLoggable(loggingLevel)) {
>+ LOGGER.log(loggingLevel,
>+ "jsf.config.webconfig.option.notconfigured",
>+ new Object[]{contextName,
>+ param.getQualifiedName()});
>+ }
>+ }
>+
>+ }
>+
>+ }
>+
>+
>+ /**
>+ * <p>Process all JNDI entries.</p>
>+ * @param contextName the context name
>+ */
>+ private void processJndiEntries(String contextName) {
>+
>+ InitialContext initialContext = null;
>+ try {
>+ initialContext = new InitialContext();
>+ } catch (NamingException ne) {
>+ // log WARNING - unable to get JNDI initial context
>+ }
>+
>+ if (initialContext != null) {
>+ // process environment entries
>+ for (WebEnvironmentEntry entry : WebEnvironmentEntry.values()) {
>+ String entryName = entry.getQualifiedName();
>+
>+ try {
>+ String value = (String) initialContext.lookup(entryName);
>+ if (value != null) {
>+ if (LOGGER.isLoggable(Level.INFO)) {
>+ // special logic for ClientStateSavingPassword
>+ if (!entry
>+ .equals(WebEnvironmentEntry.ClientStateSavingPassword))
>+ {
>+ if (LOGGER
>+ .isLoggable(loggingLevel)) {
>+ LOGGER.log(loggingLevel,
>+ "jsf.config.webconfig.enventryinfo",
>+ new Object[]{contextName,
>+ entryName,
>+ value});
>+ }
>+ } else {
>+ if (LOGGER
>+ .isLoggable(loggingLevel)) {
>+ LOGGER.log(loggingLevel,
>+ "jsf.config.webconfig.enventry.clientencrypt",
>+ contextName);
>+ }
>+ }
>+ }
>+ envEntries.put(entry, value);
>+ }
>+ } catch (NamingException ne) {
>+ // log WARNING - unable to lookup value
>+ }
>+ }
>+ }
>+
>+ }
>+
>+
> // ------------------------------------------------------------------- Enums
>
>
>@@ -420,6 +479,7 @@
> */
> public enum WebContextInitParameter {
>
>+
> // implementation note:
> // if a parameter is to be deprecated,
> // then the <name>Deprecated enum element
>@@ -479,43 +539,43 @@
> private boolean deprecated;
>
>
>- // ------------------------------------------------------------ Constructors
>+ // ---------------------------------------------------------- Public Methods
>
>
>- WebContextInitParameter(String qualifiedName,
>- String defaultValue) {
>+ public String getDefaultValue() {
>
>- this(qualifiedName, defaultValue, false, null);
>+ return defaultValue;
>
> }
>
>
>- WebContextInitParameter(String qualifiedName,
>- String defaultValue,
>- boolean deprecated,
>- WebContextInitParameter alternate) {
>+ public String getQualifiedName() {
>
>- this.qualifiedName = qualifiedName;
>- this.defaultValue = defaultValue;
>- this.deprecated = deprecated;
>- this.alternate = alternate;
>+ return qualifiedName;
>
> }
>
>
>- // ---------------------------------------------------------- Public Methods
>+ // ------------------------------------------------- Package Private Methods
>
>
>- public String getDefaultValue() {
>+ WebContextInitParameter(String qualifiedName,
>+ String defaultValue) {
>
>- return defaultValue;
>+ this(qualifiedName, defaultValue, false, null);
>
> }
>
>
>- public String getQualifiedName() {
>+ WebContextInitParameter(String qualifiedName,
>+ String defaultValue,
>+ boolean deprecated,
>+ WebContextInitParameter alternate) {
>
>- return qualifiedName;
>+ this.qualifiedName = qualifiedName;
>+ this.defaultValue = defaultValue;
>+ this.deprecated = deprecated;
>+ this.alternate = alternate;
>
> }
>
>@@ -544,12 +604,16 @@
> */
> public enum BooleanWebContextInitParameter {
>
>+
> // implementation note:
> // if a parameter is to be deprecated,
> // then the <name>Deprecated enum element
> // *must* appear after the one that is taking
> // its place. The reporting logic depends on this
>
>+ DisplayConfiguration(
>+ "com.sun.faces.displayConfiguration",
>+ false),
> ValidateFacesConfigFiles(
> "com.sun.faces.validateXml",
> false),
>@@ -578,11 +642,11 @@
> ),
> CompressViewState(
> "com.sun.faces.compressViewState",
>- false
>+ true
> ),
> CompressViewStateDeprecated(
> "com.sun.faces.COMPRESS_STATE",
>- false,
>+ true,
> true,
> CompressViewState
> );
>@@ -593,43 +657,43 @@
> private boolean deprecated;
>
>
>- // ------------------------------------------------------------ Constructors
>+ // ---------------------------------------------------------- Public Methods
>
>
>- BooleanWebContextInitParameter(String qualifiedName,
>- boolean defaultValue) {
>+ public boolean getDefaultValue() {
>
>- this(qualifiedName, defaultValue, false, null);
>+ return defaultValue;
>
> }
>
>
>- BooleanWebContextInitParameter(String qualifiedName,
>- boolean defaultValue,
>- boolean deprecated,
>- BooleanWebContextInitParameter alternate) {
>+ public String getQualifiedName() {
>
>- this.qualifiedName = qualifiedName;
>- this.defaultValue = defaultValue;
>- this.deprecated = deprecated;
>- this.alternate = alternate;
>+ return qualifiedName;
>
> }
>
>
>- // ---------------------------------------------------------- Public Methods
>+ // ------------------------------------------------- Package Private Methods
>
>
>- public boolean getDefaultValue() {
>+ BooleanWebContextInitParameter(String qualifiedName,
>+ boolean defaultValue) {
>
>- return defaultValue;
>+ this(qualifiedName, defaultValue, false, null);
>
> }
>
>
>- public String getQualifiedName() {
>+ BooleanWebContextInitParameter(String qualifiedName,
>+ boolean defaultValue,
>+ boolean deprecated,
>+ BooleanWebContextInitParameter alternate) {
>
>- return qualifiedName;
>+ this.qualifiedName = qualifiedName;
>+ this.defaultValue = defaultValue;
>+ this.deprecated = deprecated;
>+ this.alternate = alternate;
>
> }
>
>@@ -665,24 +729,24 @@
> private String qualifiedName;
>
>
>- // ------------------------------------------------------------ Constructors
>+ // ---------------------------------------------------------- Public Methods
>
>
>- WebEnvironmentEntry(String qualifiedName) {
>+ public String getQualifiedName() {
>
>- this.qualifiedName = JNDI_PREFIX
>- + RIConstants.FACES_PREFIX
>- + qualifiedName;
>+ return qualifiedName;
>
> }
>
>
>- // ---------------------------------------------------------- Public Methods
>+ // ------------------------------------------------- Package Private Methods
>
>
>- public String getQualifiedName() {
>+ WebEnvironmentEntry(String qualifiedName) {
>
>- return qualifiedName;
>+ this.qualifiedName = JNDI_PREFIX
>+ + RIConstants.FACES_PREFIX
>+ + qualifiedName;
>
> }
>
>Index: src/com/sun/faces/spi/InjectionProviderFactory.java
>===================================================================
>RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/spi/InjectionProviderFactory.java,v
>retrieving revision 1.4
>diff -u -r1.4 InjectionProviderFactory.java
>--- src/com/sun/faces/spi/InjectionProviderFactory.java 31 May 2006 17:22:29 -0000 1.4
>+++ src/com/sun/faces/spi/InjectionProviderFactory.java 16 Jun 2006 17:43:44 -0000
>@@ -73,14 +73,14 @@
> InjectionProvider provider = getProviderInstance(providerClass);
>
> if (provider.getClass() != NoopInjectionProvider.class) {
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO,
>+ if (LOGGER.isLoggable(Level.FINE)) {
>+ LOGGER.log(Level.FINE,
> "jsf.spi.injection.provider_configured",
> new Object[]{provider.getClass().getName()});
> }
> } else {
>- if (LOGGER.isLoggable(Level.INFO)) {
>- LOGGER.log(Level.INFO, "jsf.spi.injection.no_injection");
>+ if (LOGGER.isLoggable(Level.WARNING)) {
>+ LOGGER.log(Level.WARNING, "jsf.spi.injection.no_injection");
> }
> }
> return provider;
>
>
>
>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
>For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net
>
>