shale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r476713 - in /shale/framework/trunk/shale-dialog-scxml: pom.xml src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java src/main/resources/META-INF/taglib.tld
Date Sun, 19 Nov 2006 05:10:57 GMT
Author: rahul
Date: Sat Nov 18 21:10:57 2006
New Revision: 476713

URL: http://svn.apache.org/viewvc?view=rev&rev=476713
Log:
Clean up static resources, parse dialog configs at startup/deploy rather than first access.
Same scheme as one in shale-dialog-basic from r473638.
SHALE-274

Added:
    shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java
  (with props)
    shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld   (with
props)
Modified:
    shale/framework/trunk/shale-dialog-scxml/pom.xml

Modified: shale/framework/trunk/shale-dialog-scxml/pom.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/pom.xml?view=diff&rev=476713&r1=476712&r2=476713
==============================================================================
--- shale/framework/trunk/shale-dialog-scxml/pom.xml (original)
+++ shale/framework/trunk/shale-dialog-scxml/pom.xml Sat Nov 18 21:10:57 2006
@@ -52,6 +52,11 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.shale</groupId>

Added: shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java?view=auto&rev=476713
==============================================================================
--- shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java
(added)
+++ shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java
Sat Nov 18 21:10:57 2006
@@ -0,0 +1,212 @@
+/*
+ * 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.shale.dialog.scxml;
+
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.shale.dialog.scxml.config.ConfigurationParser;
+
+/**
+ * <p>ServletContextListener that loads dialog configuration resources
+ * at application startup, and cleans up the libraries we depend on at
+ * application shutdown.</p>
+ *
+ * $Id$
+ *
+ * @since 1.0.4
+ */
+public class SCXMLLifecycleListener implements ServletContextListener {
+
+
+    // -------------------------------------------------------- Static 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";
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>The <code>Log</code> instance we will use for this listener.</p>
+     */
+    private Log log = LogFactory.getLog(SCXMLLifecycleListener.class);
+
+
+    // ------------------------------------------ ServletContextListener Methods
+
+
+    /**
+     * <p>Process the application shutdown event, cleanup resources.</p>
+     *
+     * @param event Shutdown event to be processed
+     */
+    public void contextDestroyed(ServletContextEvent event) {
+
+        if (log.isInfoEnabled()) {
+            log.info("Finalizing Dialog SCXML Implementation");
+        }
+
+        // Clean up our cache of dialog configuration information
+        event.getServletContext().removeAttribute(Globals.DIALOGS);
+
+        // Clean up dependency libraries we have used
+        PropertyUtils.clearDescriptors();
+        LogFactory.release(Thread.currentThread().getContextClassLoader());
+        log = null;
+
+    }
+
+
+    /**
+     * <p>Process the application startup event, parse dialog
+     * configurations.</p>
+     *
+     * @param event Startup event to be processed
+     */
+    public void contextInitialized(ServletContextEvent event) {
+
+        if (log.isInfoEnabled()) {
+            log.info("Initializing Dialog SCXML Implementation");
+        }
+
+        // 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 =
+          event.getServletContext().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;
+                }
+                URL resource = event.getServletContext().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;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+        // Parse the default configuration resource if it exists and has not
+        // already been parsed
+        if (!didDefault) {
+            try {
+                URL resource =
+                  event.getServletContext().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 in application scope
+        Map dialogs = parser.getDialogs();
+
+        if (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);
+            }
+        }
+        event.getServletContext().setAttribute(Globals.DIALOGS, dialogs);
+
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLLifecycleListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld?view=auto&rev=476713
==============================================================================
--- shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld (added)
+++ shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld Sat Nov
18 21:10:57 2006
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+
+ $Id$
+
+-->
+
+<!DOCTYPE taglib PUBLIC
+ "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
+ "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
+
+<taglib>
+
+
+  <tlib-version>1.0</tlib-version>
+  <jsp-version>1.2</jsp-version>
+  <short-name>s</short-name>
+  <uri>http://shale.apache.org/dialog-scxml</uri>
+  <display-name>Shale Framework SCXML Dialog Tag Library</display-name>
+  <description>
+    This tag library contains no live custom tag handlers.  It exists
+    solely to declare the lifecycle context listener without requiring
+    any entries in the application's WEB-INF/web.xml resource
+  </description>
+
+
+  <!-- ===================== Servlet Listeners ============================= -->
+
+
+  <listener>
+    <listener-class>org.apache.shale.dialog.scxml.SCXMLLifecycleListener</listener-class>
+  </listener>
+  
+
+  <!-- ================= JSF Component Tags ================================ -->
+
+
+</taglib>

Propchange: shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/taglib.tld
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message