Author: rahul
Date: Tue Sep 12 13:45:31 2006
New Revision: 442696
URL: http://svn.apache.org/viewvc?view=rev&rev=442696
Log:
A straight port of r439885 from the shale-dialog2-legacy module. Improves
parsing of dialog-config.xml files and adds logging.
Currently the SCXML and Legacy dialogs use the same default file name for
dialog descriptions (WEB-INF/dialog-config.xml). We had discussed (a while ago)
the possibility of being able to use both dialog schemes in a Shale app, we can
look at that in round two (round one would be to get the SCXML bits up and
running). Also, while we may come up with such a scheme to enable both in the
same app if there is interest, subdialogs will need to use homogeneous schemes
as the parent dialog.
Modified:
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
Modified:
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java?view=diff&rev=442696&r1=442695&r2=442696
==============================================================================
---
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
(original)
+++
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
Tue Sep 12 13:45:31 2006
@@ -17,12 +17,16 @@
package org.apache.shale.dialog2.scxml;
import java.io.Serializable;
+import java.net.URL;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.commons.scxml.model.SCXML;
import org.apache.shale.dialog2.Constants;
import org.apache.shale.dialog2.DialogContext;
@@ -38,7 +42,23 @@
public final class SCXMLDialogManager implements DialogContextManager,
Serializable {
- // ------------------------------------------------------ DialogContext
Variables
+ // ------------------------------------------------------
SCXMLDialogManager Variables
+
+
+ /**
+ * <p>The default configuration resource we will process (if present),
+ * even if it is not explicitly configured.</p>
+ */
+ private static final String DEFAULT_CONFIGURATION_RESOURCE =
+ "/WEB-INF/dialog-config.xml";
+
+
+ /**
+ * <p>Resource name for dialog configuration resource(s) embedded in
+ * JAR files inside the application.</p>
+ */
+ private static final String EMBEDDED_CONFIGURATION_RESOURCE =
+ "META-INF/dialog-config.xml";
/**
@@ -56,6 +76,13 @@
/**
+ * <p>The <code>Log</code> instance for this class. This value is lazily
+ * instantiated, and is also transient and may need to be regenerated.</p>
+ */
+ private transient Log log = null;
+
+
+ /**
* <p>Serial number used to generate dialog instance identifiers.</p>
*/
private int serial = 0;
@@ -128,9 +155,34 @@
return this.dialogs;
}
- // Parse our configuration resources and cache the results
+ // Set up to parse our specified configuration resources and cache the
results
+ boolean didDefault = false;
ConfigurationParser parser = new ConfigurationParser();
parser.setDialogs(new HashMap());
+
+ // Parse implicitly specified resources embedded in JAR files
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = this.getClass().getClassLoader();
+ }
+ try {
+ Enumeration resources =
loader.getResources(EMBEDDED_CONFIGURATION_RESOURCE);
+ while (resources.hasMoreElements()) {
+ URL resource = (URL) resources.nextElement();
+ if (log().isDebugEnabled()) {
+ log().debug("Parsing configuration resource '"
+ + resource + "'");
+ }
+ parser.setResource(resource);
+ parser.parse();
+ }
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ // Parse explicitly specified resources
String resources =
context.getExternalContext().getInitParameter(Globals.CONFIGURATION);
if (resources == null) {
@@ -151,8 +203,16 @@
if (path.length() < 1) {
break;
}
-
parser.setResource(context.getExternalContext().getResource(path));
+ URL resource = (URL)
context.getExternalContext().getResource(path);
+ if (log().isDebugEnabled()) {
+ log().debug("Parsing configuration resource '"
+ + resource + "'");
+ }
+ parser.setResource(resource);
parser.parse();
+ if (DEFAULT_CONFIGURATION_RESOURCE.equals(path)) {
+ didDefault = true;
+ }
}
} catch (RuntimeException e) {
throw e;
@@ -160,8 +220,38 @@
throw new FacesException(e);
}
+ // Parse the default configuration resource if it exists and has not
+ // already been parsed
+ if (!didDefault) {
+ try {
+ URL resource =
+
context.getExternalContext().getResource(DEFAULT_CONFIGURATION_RESOURCE);
+ if (resource != null) {
+ if (log().isDebugEnabled()) {
+ log().debug("Parsing configuration resource '"
+ + resource + "'");
+ }
+ parser.setResource(resource);
+ 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();
+
+ if (this.dialogs.size() == 0) {
+ if (log().isWarnEnabled()) {
+ log.warn("No dialog configuration information present. No
default configuration found at: " +
+ DEFAULT_CONFIGURATION_RESOURCE + ". No embedded
configuration found at: " +
+ EMBEDDED_CONFIGURATION_RESOURCE);
+ }
+ }
+
context.getExternalContext().getApplicationMap().put(Globals.DIALOGS,
this.dialogs);
return this.dialogs;
@@ -177,4 +267,15 @@
}
+ /**
+ * <p>Return the <code>Log</code> instance for this instance.</p>
+ */
+ private Log log() {
+ if (this.log == null) {
+ this.log = LogFactory.getLog(SCXMLDialogManager.class);
+ }
+ return this.log;
+ }
+
}
+