[EMAIL PROTECTED] wrote:

Author: craigmcc
Date: Sat Mar 19 23:18:50 2005
New Revision: 158315

URL: http://svn.apache.org/viewcvs?view=rev&rev=158315
Log:
Initial integration with the Spring Framework (version 1.1.5 or later).

If you include shale-spring.jar (along with spring-{core,context,web}.jar
from a Spring distribution) in your web application, you will receive the
following benefits from this integration:

* Spring's JSF variable resolver (which will use a SpringBeanFactory to create
 a bean if the standard managed bean facility does not do so) is
 registered automatically, with no extra action required by the application.

* An additional variable resolvers maps the name "webApplicationContext"
 to Spring's WebApplicationContext instance for the current application
 (if any).

Compilation of "core-library" now depends on appropriate properties pointing
at a distribution directory of Spring 1.1.5 or later (earlier versions will
likely work; this is the one I have been testing with).  Lack of a Spring
Framework distribution will not fail the build, but shale-spring.jar will
be incomplete.




Wow. I must find time to get back to Shale. Please announce when Shale + Tile is ready. Before JavaOne?

BaTien
DBGROUPS

Added:
   struts/shale/trunk/core-library/src/java/org/apache/shale/spring/
   
struts/shale/trunk/core-library/src/java/org/apache/shale/spring/WebApplicationContextVariableResolver.java
   
struts/shale/trunk/core-library/src/java/org/apache/shale/spring/faces-config.xml
   struts/shale/trunk/core-library/src/java/org/apache/shale/spring/package.html
Modified:
   struts/shale/trunk/core-library/build.properties.sample
   struts/shale/trunk/core-library/build.xml

Modified: struts/shale/trunk/core-library/build.properties.sample
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/build.properties.sample?view=diff&r1=158314&r2=158315
==============================================================================
--- struts/shale/trunk/core-library/build.properties.sample (original)
+++ struts/shale/trunk/core-library/build.properties.sample Sat Mar 19 23:18:50 
2005
@@ -37,6 +37,13 @@
# Jakarta Commons Digester library
digester.home = /usr/local/commons-digester-1.6

+# The absolute or relative pathname of the JavaServer Faces +# implementation
+jsf.home = /usr/local/jsf-1_1_01
+
+# The absolute or relative pathname of the JUnit 3.8.1 JAR
+junit.home = /usr/local/junit-3.8.1
+
# The absolute or relative pathname of the directory containing the
# Jakarta Commons Logging library
logging.home = /usr/local/commons-logging-1.0.4
@@ -45,13 +52,11 @@
# Servlet API classes JAR file (servlet.jar)
server.home = /usr/local/jakarta-tomcat-5.0.28


-# The absolute or relative pathname of the JavaServer Faces -# implementation
-jsf.home = /usr/local/jsf-1_1_01
+# (OPTIONAL) The absolute or relative pathname to the "dist" directory
+# of the Spring Framework distribution (version 1.1.5 or later)
+spring.home=/usr/local/spring-framework-1.1.5/dist


# The absolute or relative pathname of the Apache Struts # distribution
struts.home = /usr/local/jakarta-struts


-# The absolute or relative pathname of the JUnit 3.8.1 JAR
-junit.home = /usr/local/junit-3.8.1

Modified: struts/shale/trunk/core-library/build.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/build.xml?view=diff&r1=158314&r2=158315
==============================================================================
--- struts/shale/trunk/core-library/build.xml (original)
+++ struts/shale/trunk/core-library/build.xml Sat Mar 19 23:18:50 2005
@@ -41,7 +41,7 @@
  <property name="logging.home"     value="/usr/local/commons-logging-1.0.4"/>
  <property name="server.home"      value="/usr/local/jakarta-tomcat-5.0.28"/>
  <property name="shale-test.home"  
value="${basedir}/../struts-shale-test/dist"/>
-
+  <property name="spring.home"      
value="/usr/local/spring-framework-1.1.5/dist"/>

  <!-- Dependency library defaults -->
  <property name="commons-beanutils.jar"
@@ -66,16 +66,10 @@
  <property name="junit.jar"        value="${junit.home}/junit.jar"/>
  <property name="servlet-api.jar"  
value="${server.home}/common/lib/servlet-api.jar"/>
  <property name="shale-test.jar"   
value="${shale-test.home}/lib/shale-test.jar"/>
-
-
-  <!-- Conditional Processing Flags -->
-  <available                     property="jsfri.present"
-                                classname="com.sun.faces.RIConstants"
-                                classpath="${jsf-impl.jar}"/>
-  <available                     property="myfaces.present"
-                                
classname="net.sourceforge.myfaces.config.MyfacesConfig"
-                                classpath="${jsf-impl.jar}"/>
-
+  <property name="spring-context.jar"
+                                    value="${spring.home}/spring-context.jar"/>
+  <property name="spring-core.jar"  value="${spring.home}/spring-core.jar"/>
+  <property name="spring-web.jar"   value="${spring.home}/spring-web.jar"/>

  <!-- Build Defaults -->
  <property name="build.home"      value="${basedir}/target"/>
@@ -112,6 +106,9 @@
    <pathelement location="${jsf-api.jar}"/>
    <pathelement location="${jsp-api.jar}"/>
    <pathelement location="${servlet-api.jar}"/>
+    <pathelement location="${spring-context.jar}"/>
+    <pathelement location="${spring-core.jar}"/>
+    <pathelement location="${spring-web.jar}"/>
    <pathelement location="${build.home}/classes"/>
  </path>

@@ -133,10 +130,31 @@
    <pathelement location="${junit.jar}"/>
    <pathelement location="${servlet-api.jar}"/>
    <pathelement location="${shale-test.jar}"/>
+    <pathelement location="${spring-context.jar}"/>
+    <pathelement location="${spring-core.jar}"/>
+    <pathelement location="${spring-web.jar}"/>
    <pathelement location="${build.home}/classes"/>
    <pathelement location="${build.home}/test-classes"/>
  </path>

+  <!-- Conditional Processing Flags -->
+  <available                     property="jsfri.present"
+                                classname="com.sun.faces.RIConstants"
+                             classpathref="compile.classpath"/>
+  <available                     property="myfaces.present"
+                                
classname="net.sourceforge.myfaces.config.MyfacesConfig"
+                             classpathref="compile.classpath"/>
+  <condition                     property="spring.present">
+    <and>
+      <available                classname="org.springframework.core.Constants"
+                             classpathref="compile.classpath"/>
+      <available                
classname="org.springframework.context.ApplicationContext"
+                             classpathref="compile.classpath"/>
+      <available                
classname="org.springframework.web.jsf.DelegatingVariableResolver"
+                             classpathref="compile.classpath"/>
+    </and>
+  </condition>
+

  <!-- ==================== Maintenance Targets ============================ -->

@@ -164,6 +182,7 @@
    <echo  message="servlet-api.jar =        ${servlet-api.jar}"/>
    <echo  message="jsfri.present =  ${jsfri.present}"/>
    <echo  message="myfaces.present= ${myfaces.present}"/>
+    <echo  message="spring.present=  ${spring.present}"/>
  </target>


@@ -206,12 +225,16 @@ deprecation="${compile.deprecation}" optimize="${compile.optimize}"> <classpath refid="compile.classpath" /> + <exclude name="src/java/org/apache/shale/spring/**" + unless="spring.present"/> </javac>

    <!-- Copy non-Java Sources -->
    <copy        todir="${build.home}/classes">
      <fileset     dir="src/java">
        <exclude  name="**/*.java"/>
+        <exclude  name="src/java/org/apache/shale/spring/**"
+                unless="spring.present"/>
      </fileset>
    </copy>

@@ -224,14 +247,35 @@
  </target>


- <target name="library" depends="compile" + <target name="library-core" depends="compile" description="Package core library">

    <jar       jarfile="${build.home}/lib/shale.jar"
               basedir="${build.home}/classes"
-              manifest="${build.home}/conf/MANIFEST.MF"/>
+              manifest="${build.home}/conf/MANIFEST.MF"
+              excludes="org/apache/shale/spring/** **/package.html"/>

  </target>
+
+
+  <target        name="library-spring" depends="compile" if="spring.present"
+          description="Package Spring integration library">
+    <mkdir        dir="${build.home}/shale-spring"/>
+    <mkdir        dir="${build.home}/shale-spring/META-INF"/>
+    <copy       todir="${build.home}/shale-spring/META-INF"
+                 file="src/java/org/apache/shale/spring/faces-config.xml"/>
+    <jar      jarfile="${build.home}/lib/shale-spring.jar"
+             manifest="${build.home}/conf/MANIFEST.MF">
+      <fileset    dir="${build.home}/shale-spring"/>
+      <fileset    dir="${build.home}/classes"
+             includes="org/apache/shale/spring/**"
+             excludes="**/faces-config.xml **/package.html"/>
+    </jar>
+  </target>
+
+
+  <target        name="library" depends="library-core,library-spring"
+          description="Package all libraries"/>


<!-- ===================== Generate Documentation ======================== -->

Added: struts/shale/trunk/core-library/src/java/org/apache/shale/spring/WebApplicationContextVariableResolver.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/spring/WebApplicationContextVariableResolver.java?view=auto&rev=158315
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/spring/WebApplicationContextVariableResolver.java (added)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/spring/WebApplicationContextVariableResolver.java Sat Mar 19 23:18:50 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * + * Licensed 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.spring;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.VariableResolver;
+import org.springframework.web.jsf.FacesContextUtils;
+
+/**
+ * <p>Extended <code>VariableResolver</code> that exposes the Spring
+ * <code>WebApplicationContext</code> instance under a variable named
+ * with the specified manifest constant.</p>
+ *
+ * $Id$
+ */
+public class WebApplicationContextVariableResolver extends VariableResolver {
+ +
+ // ------------------------------------------------------------- Constructor
+
+
+ /**
+ * <p>Construct a new [EMAIL PROTECTED] WebApplicationContextVariableResolver}
+ * instance.</p>
+ *
+ * @param original Original resolver to delegate to.
+ */
+ public WebApplicationContextVariableResolver(VariableResolver original) {
+
+ this.original = original;
+
+ }
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ /**
+ * <p>The original <code>VariableResolver</code> passed to our constructor.</p>
+ */
+ private VariableResolver original = null;
+
+
+ // ------------------------------------------------------ Manifest Constants
+
+
+ /**
+ * <p>Variable name to be resoved to our web application context.</p>
+ */
+ private static final String WEB_APPLICATION_CONTEXT_VARIABLE_NAME =
+ "webApplicationContext";
+
+
+
+
+ // ------------------------------------------------ VariableResolver Methods
+
+
+ /**
+ * <p>Resolve variable names known to this resolver; otherwise, delegate to
+ * the original resolver passed to our constructor.</p>
+ *
+ * @param name Variable name to be resolved
+ */
+ public Object resolveVariable(FacesContext context, String name)
+ throws EvaluationException {
+
+ if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(name)) {
+ return FacesContextUtils.getWebApplicationContext(context);
+ } else {
+ return original.resolveVariable(context, name);
+ }
+
+ }
+
+
+}


Added: struts/shale/trunk/core-library/src/java/org/apache/shale/spring/faces-config.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/spring/faces-config.xml?view=auto&rev=158315
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/spring/faces-config.xml (added)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/spring/faces-config.xml Sat Mar 19 23:18:50 2005
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+
+
+<!DOCTYPE faces-config PUBLIC
+ "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
+ "http://java.sun.com/dtd/web-facesconfig_1_1.dtd";>
+
+
+<!--
+
+ Copyright 2004-2005 The Apache Software Foundation.
+ + Licensed 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$
+
+-->
+
+
+<faces-config>
+
+ <application>
+ <!-- Spring Framework Integration -->
+ <variable-resolver>
+ org.springframework.web.context.WebApplicationContext
+ </variable-resolver>
+ <!-- Extended "webApplicationContext" resolver -->
+ <variable-resolver>
+ org.apache.shale.spring.WebApplicationContextVariableResolver
+ </variable-resolver>
+ </application>
+
+</faces-config>


Added: struts/shale/trunk/core-library/src/java/org/apache/shale/spring/package.html
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/spring/package.html?view=auto&rev=158315
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/spring/package.html (added)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/spring/package.html Sat Mar 19 23:18:50 2005
@@ -0,0 +1,46 @@
+<!--
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * + * Licensed 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$ -->
+
+<body>
+
+<p>The package contains an optional integration layer connecting Shale with
+the <a href="http://sourceforge.net/projects/springframework";>Spring Framework</a>.
+The following capabilities are enabled by this integration:</p>
+<ul>
+<li>Spring's <code>DelegatingVariableResolver</code> is automatically
+ enabled, which will utilize Spring's standard facilities to create a
+ new bean if the standard JavaServer Faces managed bean facility does
+ not recognize this variable name.</li>
+<li>An additional resolver is added that maps the (configurable) variable
+ name <code>webApplicationContext</code> to the instance of
+ <code>org.springframework.web.context.WebApplicationContext</code>
+ that Spring has established for this web application.</li>
+</ul>
+
+<p>To enable this integration in applications based on Shale, simply include
+the following JAR files in your application's <code>/WEB-INF/lib</code>
+directory, in addition to <code>shale.jar</code>:</p>
+<ul>
+<li>From the Shale Core Library distribution: <code>shale-spring.jar</code>.
+<li>From the Spring Framework distribution (version 1.1.5 or later):
+ <code>spring-context.jar</code>, <code>spring-core.jar</code>, and
+ <code>spring-web.jar</code> (alternatively, include <code>spring.jar</code>
+ which includes all of the above)</li>
+</ul>
+
+</body>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to