Author: craigmcc
Date: Mon Aug 28 17:54:39 2006
New Revision: 437894

URL: http://svn.apache.org/viewvc?rev=437894&view=rev
Log:
Refactor the reading of the configuration files from LegacyContext to
LegacyContexts, because that is where it's going to get encountered first
(in the create() method).

SHALE-10 SHALE-48 SHALE-61

Modified:
    
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContext.java
    
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContexts.java

Modified: 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContext.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContext.java?rev=437894&r1=437893&r2=437894&view=diff
==============================================================================
--- 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContext.java
 (original)
+++ 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContext.java
 Mon Aug 28 17:54:39 2006
@@ -291,42 +291,9 @@
             return this.dialogs;
         }
 
-        // Parse our configuration resources and cache the results
-        ConfigurationParser parser = new ConfigurationParser();
-        parser.setDialogs(new HashMap());
-        String resources =
-          context.getExternalContext().getInitParameter(Globals.CONFIGURATION);
-        if (resources == null) {
-            resources = "";
-        }
-        int comma = 0;
-        String path = null;
-        try {
-            while (true) {
-                comma = resources.indexOf(",");
-                if (comma < 0) {
-                    path = resources.trim();
-                    resources = "";
-                } else {
-                    path = resources.substring(0, comma).trim();
-                    resources = resources.substring(comma + 1);
-                }
-                if (path.length() < 1) {
-                    break;
-                }
-                
parser.setResource(context.getExternalContext().getResource(path));
-                parser.parse();
-            }
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new FacesException(e);
-        }
-
-        // Cache the results both locally and in application scope
-        this.dialogs = parser.getDialogs();
-        context.getExternalContext().getApplicationMap().put(Globals.DIALOGS, 
this.dialogs);
-        return this.dialogs;
+        // Throw an exception if dialog configuration resources have not
+        // been processed yet
+        throw new IllegalStateException("Dialog configuration resources have 
not yet been processed");
 
     }
 

Modified: 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContexts.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContexts.java?rev=437894&r1=437893&r2=437894&view=diff
==============================================================================
--- 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContexts.java
 (original)
+++ 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyContexts.java
 Mon Aug 28 17:54:39 2006
@@ -19,10 +19,12 @@
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import javax.faces.FacesException;
 import javax.faces.context.FacesContext;
 import org.apache.shale.dialog2.Constants;
 import org.apache.shale.dialog2.Context;
 import org.apache.shale.dialog2.Contexts;
+import org.apache.shale.dialog2.legacy.config.ConfigurationParser;
 import org.apache.shale.dialog2.legacy.model.Dialog;
 
 /**
@@ -38,6 +40,13 @@
 
 
     /**
+     * <p><code>Map</code> of [EMAIL PROTECTED] Dialog} configurations, keyed
+     * by dialog name.  This value is lazily instantiated.</p>
+     */
+    private Map dialogs = null;
+
+
+    /**
      * <p>Map containing all currently active [EMAIL PROTECTED] Context} 
instances for
      * the current user.</p>
      */
@@ -57,12 +66,7 @@
     public Context create(FacesContext context, String name) {
 
         // Look up the specified dialog configuration
-        Map dialogs = (Map)
-          context.getApplication().getVariableResolver().
-          resolveVariable(context, Globals.DIALOGS);
-        if (dialogs == null) {
-            throw new IllegalStateException("Dialog definitions have not been 
configured");
-        }
+        Map dialogs = dialogs(context);
         Dialog dialog = (Dialog) dialogs.get(name);
         if (dialog == null) {
             throw new IllegalArgumentException("No definition for dialog name 
'"
@@ -94,6 +98,67 @@
 
 
     // --------------------------------------------------------- Private 
Methods
+
+
+    /**
+     * <p>Return a <code>Map</code> of the configured [EMAIL PROTECTED] 
Dialog}s, keyed
+     * by logical dialog name.  Upon the first request, the configuration
+     * resources will be processed.</p>
+     *
+     * @param context FacesContext for the current request
+     */
+    private Map dialogs(FacesContext context) {
+
+        // Return the cached instance (if any)
+        if (this.dialogs != null) {
+            return this.dialogs;
+        }
+
+        // Return the previously configured application scope instance (if any)
+        this.dialogs = (Map)
+          
context.getExternalContext().getApplicationMap().get(Globals.DIALOGS);
+        if (this.dialogs != null) {
+            return this.dialogs;
+        }
+
+        // Parse our configuration resources and cache the results
+        ConfigurationParser parser = new ConfigurationParser();
+        parser.setDialogs(new HashMap());
+        String resources =
+          context.getExternalContext().getInitParameter(Globals.CONFIGURATION);
+        if (resources == null) {
+            resources = "";
+        }
+        int comma = 0;
+        String path = null;
+        try {
+            while (true) {
+                comma = resources.indexOf(",");
+                if (comma < 0) {
+                    path = resources.trim();
+                    resources = "";
+                } else {
+                    path = resources.substring(0, comma).trim();
+                    resources = resources.substring(comma + 1);
+                }
+                if (path.length() < 1) {
+                    break;
+                }
+                
parser.setResource(context.getExternalContext().getResource(path));
+                parser.parse();
+            }
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+        // Cache the results both locally and in application scope
+        this.dialogs = parser.getDialogs();
+        context.getExternalContext().getApplicationMap().put(Globals.DIALOGS, 
this.dialogs);
+        return this.dialogs;
+
+    }
 
 
     /**


Reply via email to