You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/08/11 22:25:25 UTC

svn commit: r984569 - in /myfaces/extensions/cdi/trunk/jee-modules/jsf-module: api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/

Author: gpetracek
Date: Wed Aug 11 20:25:24 2010
New Revision: 984569

URL: http://svn.apache.org/viewvc?rev=984569&view=rev
Log:
config refactoring (intermediate result)

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/BooleanConfigValueParser.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/ConfigValueParser.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/IntegerConfigValueParser.java
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java?rev=984569&r1=984568&r2=984569&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java Wed Aug 11 20:25:24 2010
@@ -40,10 +40,10 @@ public interface ConfigParameter
 
     static final boolean DISABLE_INITIAL_REDIRECT_DEFAULT = false;
 
-    static final String GROUPED_CONVERSATION_TIMEOUT =
-            CoreCodiConfigParameter.BASE_NAME + "GROUPED_CONVERSATION_TIMEOUT";
+    static final String CONVERSATION_TIMEOUT =
+            CoreCodiConfigParameter.BASE_NAME + "CONVERSATION_TIMEOUT";
 
-    static final int GROUPED_CONVERSATION_TIMEOUT_DEFAULT = 30;
+    static final int CONVERSATION_TIMEOUT_DEFAULT = 30;
 
     static final String WINDOW_CONTEXT_TIMEOUT =
             CoreCodiConfigParameter.BASE_NAME + "WINDOW_CONTEXT_TIMEOUT";

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/BooleanConfigValueParser.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/BooleanConfigValueParser.java?rev=984569&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/BooleanConfigValueParser.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/BooleanConfigValueParser.java Wed Aug 11 20:25:24 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.config;
+
+/**
+ * @author Gerhard Petracek
+ */
+class BooleanConfigValueParser implements ConfigValueParser<Boolean>
+{
+    public Boolean parse(String value)
+    {
+        return Boolean.parseBoolean(value);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/ConfigValueParser.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/ConfigValueParser.java?rev=984569&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/ConfigValueParser.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/ConfigValueParser.java Wed Aug 11 20:25:24 2010
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.config;
+
+/**
+ * @author Gerhard Petracek
+ */
+interface ConfigValueParser<T>
+{
+    T parse(String value);
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java?rev=984569&r1=984568&r2=984569&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java Wed Aug 11 20:25:24 2010
@@ -91,7 +91,7 @@ public class DefaultWindowContextConfig 
     public int getConversationTimeoutInMinutes()
     {
         lazyInit();
-        return getAttribute(GROUPED_CONVERSATION_TIMEOUT, Integer.class);
+        return getAttribute(CONVERSATION_TIMEOUT, Integer.class);
     }
 
     public boolean isScopeBeanEventEnable()
@@ -162,131 +162,43 @@ public class DefaultWindowContextConfig 
         initUrlParameterEnabled(facesContext);
         initMaxWindowContextCount(facesContext, ProjectStage.SystemTest.equals(currentProjectStage));
         initWindowContextTimeout(facesContext);
-        initGroupedConversationTimeout(facesContext);
+        initConversationTimeout(facesContext);
         initDisableInitialRedirect(facesContext);
         initConversatonEvents(facesContext);
     }
 
     private void initUrlParameterEnabled(FacesContext facesContext)
     {
-        boolean requestParameterEnabled = URL_PARAMETER_ENABLED_DEFAULT;
-
-        String requestParameterEnabledString =
-                facesContext.getExternalContext().getInitParameter(URL_PARAMETER_ENABLED);
-
-        if (requestParameterEnabledString == null)
-        {
-            setAttribute(URL_PARAMETER_ENABLED, requestParameterEnabled);
-            return;
-        }
-
-        requestParameterEnabledString = requestParameterEnabledString.trim();
-
-        if ("".equals(requestParameterEnabledString))
-        {
-            setAttribute(URL_PARAMETER_ENABLED, requestParameterEnabled);
-            return;
-        }
-
-        setAttribute(URL_PARAMETER_ENABLED, Boolean.parseBoolean(requestParameterEnabledString));
+        initConfig(facesContext, URL_PARAMETER_ENABLED, new BooleanConfigValueParser(), URL_PARAMETER_ENABLED_DEFAULT);
     }
 
     private void initMaxWindowContextCount(FacesContext facesContext, boolean inProjectStageSystemTest)
     {
-        int maxCount = MAX_WINDOW_CONTEXT_COUNT_DEFAULT;
+        int defaultMaxCount = MAX_WINDOW_CONTEXT_COUNT_DEFAULT;
 
         if(inProjectStageSystemTest)
         {
-            maxCount = Integer.MAX_VALUE;
-        }
-
-        String maxCountString = facesContext.getExternalContext().getInitParameter(MAX_WINDOW_CONTEXT_COUNT);
-
-        if (maxCountString == null)
-        {
-            setAttribute(MAX_WINDOW_CONTEXT_COUNT, maxCount);
-            return;
-        }
-
-        maxCountString = maxCountString.trim();
-
-        if ("".equals(maxCountString))
-        {
-            setAttribute(MAX_WINDOW_CONTEXT_COUNT, maxCount);
-            return;
+            defaultMaxCount = Integer.MAX_VALUE;
         }
 
-        setAttribute(MAX_WINDOW_CONTEXT_COUNT, Integer.parseInt(maxCountString));
+        initConfig(facesContext, MAX_WINDOW_CONTEXT_COUNT, new IntegerConfigValueParser(), defaultMaxCount);
     }
 
     private void initWindowContextTimeout(FacesContext facesContext)
     {
-        int timeoutInMinutes = WINDOW_CONTEXT_TIMEOUT_DEFAULT;
-
-        String timeoutString = facesContext.getExternalContext().getInitParameter(WINDOW_CONTEXT_TIMEOUT);
-
-        if (timeoutString == null)
-        {
-            setAttribute(WINDOW_CONTEXT_TIMEOUT, timeoutInMinutes);
-            return;
-        }
-
-        timeoutString = timeoutString.trim();
-
-        if ("".equals(timeoutString))
-        {
-            setAttribute(WINDOW_CONTEXT_TIMEOUT, timeoutInMinutes);
-            return;
-        }
-
-        setAttribute(WINDOW_CONTEXT_TIMEOUT, Integer.parseInt(timeoutString));
+        initConfig(facesContext,
+                WINDOW_CONTEXT_TIMEOUT, new IntegerConfigValueParser(), WINDOW_CONTEXT_TIMEOUT_DEFAULT);
     }
 
-    private void initGroupedConversationTimeout(FacesContext facesContext)
+    private void initConversationTimeout(FacesContext facesContext)
     {
-        int timeoutInMinutes = GROUPED_CONVERSATION_TIMEOUT_DEFAULT;
-
-        String timeoutString = facesContext.getExternalContext().getInitParameter(GROUPED_CONVERSATION_TIMEOUT);
-
-        if (timeoutString == null)
-        {
-            setAttribute(GROUPED_CONVERSATION_TIMEOUT, timeoutInMinutes);
-            return;
-        }
-
-        timeoutString = timeoutString.trim();
-
-        if ("".equals(timeoutString))
-        {
-            setAttribute(GROUPED_CONVERSATION_TIMEOUT, timeoutInMinutes);
-            return;
-        }
-
-        setAttribute(GROUPED_CONVERSATION_TIMEOUT, Integer.parseInt(timeoutString));
+        initConfig(facesContext, CONVERSATION_TIMEOUT, new IntegerConfigValueParser(), CONVERSATION_TIMEOUT_DEFAULT);
     }
 
     private void initDisableInitialRedirect(FacesContext facesContext)
     {
-        boolean disableInitialRedirect = DISABLE_INITIAL_REDIRECT_DEFAULT;
-
-        String disableInitialRedirectString =
-                facesContext.getExternalContext().getInitParameter(DISABLE_INITIAL_REDIRECT);
-
-        if (disableInitialRedirectString == null)
-        {
-            setAttribute(DISABLE_INITIAL_REDIRECT, disableInitialRedirect);
-            return;
-        }
-
-        disableInitialRedirectString = disableInitialRedirectString.trim();
-
-        if ("".equals(disableInitialRedirectString))
-        {
-            setAttribute(DISABLE_INITIAL_REDIRECT, disableInitialRedirect);
-            return;
-        }
-
-        setAttribute(DISABLE_INITIAL_REDIRECT, Boolean.parseBoolean(disableInitialRedirectString));
+        initConfig(facesContext,
+                DISABLE_INITIAL_REDIRECT, new BooleanConfigValueParser(), DISABLE_INITIAL_REDIRECT_DEFAULT);
     }
 
     private void initConversatonEvents(FacesContext facesContext)
@@ -298,73 +210,50 @@ public class DefaultWindowContextConfig 
 
     private void initScopeBeanEvent(FacesContext facesContext)
     {
-        boolean disableInitialRedirect = ENABLE_SCOPE_BEAN_EVENT_DEFAULT;
-
-        String disableInitialRedirectString =
-                facesContext.getExternalContext().getInitParameter(ENABLE_SCOPE_BEAN_EVENT);
-
-        if (disableInitialRedirectString == null)
-        {
-            setAttribute(ENABLE_SCOPE_BEAN_EVENT, disableInitialRedirect);
-            return;
-        }
-
-        disableInitialRedirectString = disableInitialRedirectString.trim();
-
-        if ("".equals(disableInitialRedirectString))
-        {
-            setAttribute(ENABLE_SCOPE_BEAN_EVENT, disableInitialRedirect);
-            return;
-        }
-
-        setAttribute(ENABLE_SCOPE_BEAN_EVENT, Boolean.parseBoolean(disableInitialRedirectString));
+        initConfig(facesContext,
+                ENABLE_SCOPE_BEAN_EVENT, new BooleanConfigValueParser(), ENABLE_SCOPE_BEAN_EVENT_DEFAULT);
     }
 
     private void initBeanAccessEvent(FacesContext facesContext)
     {
-        boolean disableInitialRedirect = ENABLE_BEAN_ACCESS_EVENT_DEFAULT;
-
-        String disableInitialRedirectString =
-                facesContext.getExternalContext().getInitParameter(ENABLE_BEAN_ACCESS_EVENT);
-
-        if (disableInitialRedirectString == null)
-        {
-            setAttribute(ENABLE_BEAN_ACCESS_EVENT, disableInitialRedirect);
-            return;
-        }
-
-        disableInitialRedirectString = disableInitialRedirectString.trim();
-
-        if ("".equals(disableInitialRedirectString))
-        {
-            setAttribute(ENABLE_BEAN_ACCESS_EVENT, disableInitialRedirect);
-            return;
-        }
-
-        setAttribute(ENABLE_BEAN_ACCESS_EVENT, Boolean.parseBoolean(disableInitialRedirectString));
+        initConfig(facesContext,
+                ENABLE_BEAN_ACCESS_EVENT, new BooleanConfigValueParser(), ENABLE_BEAN_ACCESS_EVENT_DEFAULT);
     }
 
     private void initUnscopeBeanEvent(FacesContext facesContext)
     {
-        boolean disableInitialRedirect = ENABLE_UNSCOPE_BEAN_EVENT_DEFAULT;
+        initConfig(facesContext,
+                ENABLE_UNSCOPE_BEAN_EVENT, new BooleanConfigValueParser(), ENABLE_UNSCOPE_BEAN_EVENT_DEFAULT);
+    }
 
-        String disableInitialRedirectString =
-                facesContext.getExternalContext().getInitParameter(ENABLE_UNSCOPE_BEAN_EVENT);
+    protected <T> void initConfig(FacesContext facesContext,
+                                  String configKey,
+                                  ConfigValueParser<T> configValueParser,
+                                  T defaultValue)
+    {
+        String customValue = facesContext.getExternalContext().getInitParameter(configKey);
 
-        if (disableInitialRedirectString == null)
+        if (customValue == null)
         {
-            setAttribute(ENABLE_UNSCOPE_BEAN_EVENT, disableInitialRedirect);
+            setAttribute(configKey, defaultValue);
             return;
         }
 
-        disableInitialRedirectString = disableInitialRedirectString.trim();
+        customValue = customValue.trim();
 
-        if ("".equals(disableInitialRedirectString))
+        if ("".equals(customValue))
         {
-            setAttribute(ENABLE_UNSCOPE_BEAN_EVENT, disableInitialRedirect);
+            setAttribute(configKey, defaultValue);
             return;
         }
 
-        setAttribute(ENABLE_UNSCOPE_BEAN_EVENT, Boolean.parseBoolean(disableInitialRedirectString));
+        if(configValueParser == null)
+        {
+            setAttribute(configKey, customValue);
+        }
+        else
+        {
+            setAttribute(configKey, configValueParser.parse(customValue));
+        }
     }
 }
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/IntegerConfigValueParser.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/IntegerConfigValueParser.java?rev=984569&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/IntegerConfigValueParser.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/IntegerConfigValueParser.java Wed Aug 11 20:25:24 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.config;
+
+/**
+ * @author Gerhard Petracek
+ */
+class IntegerConfigValueParser implements ConfigValueParser<Integer>
+{
+    public Integer parse(String value)
+    {
+        return Integer.parseInt(value);
+    }
+}
\ No newline at end of file