Author: mrdon
Date: Sun Dec 18 17:13:39 2005
New Revision: 357600

URL: http://svn.apache.org/viewcvs?rev=357600&view=rev
Log:
Adding an interceptor that supports Struts Action 1.x-style PlugIn
classes, adding an object factory that passes the servlet context to
interested interceptors

Added:
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/LegacyObjectFactory.java
   (with props)
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java
   (with props)

Added: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/LegacyObjectFactory.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/LegacyObjectFactory.java?rev=357600&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/LegacyObjectFactory.java
 (added)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/LegacyObjectFactory.java
 Sun Dec 18 17:13:39 2005
@@ -0,0 +1,67 @@
+/*
+ * $Id: Action.java 240373 2005-08-27 01:58:39Z jmitchell $
+ *
+ * Copyright 2000-2004 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.ti.legacy;
+
+import com.opensymphony.webwork.config.Configuration;
+import com.opensymphony.webwork.util.ObjectFactoryInitializable;
+import com.opensymphony.webwork.util.ServletContextAware;
+import com.opensymphony.xwork.config.entities.*;
+import com.opensymphony.xwork.config.ConfigurationException;
+import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.interceptor.Interceptor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Adds support for interceptors that want the ServletContext
+ */
+public class LegacyObjectFactory extends ObjectFactory implements 
ObjectFactoryInitializable {
+    private static final Log log = 
LogFactory.getLog(LegacyObjectFactory.class);
+
+    private ServletContext servletContext;
+    
+    public void init(ServletContext servletContext) {
+        
+        log.info("Initializing legacy integration...");
+        this.servletContext = servletContext;
+    }
+    
+    /**
+     * Builds an Interceptor from the InterceptorConfig and the Map of
+     * parameters from the interceptor reference. Implementations of this 
method
+     * should ensure that the Interceptor is parameterized with both the
+     * parameters from the Interceptor config and the interceptor ref Map (the
+     * interceptor ref params take precedence), and that the Interceptor.init()
+     * method is called on the Interceptor instance before it is returned.
+     *
+     * @param interceptorConfig    the InterceptorConfig from the configuration
+     * @param interceptorRefParams a Map of params provided in the Interceptor 
reference in the
+     *                             Action mapping or InterceptorStack 
definition
+     */
+    public Interceptor buildInterceptor(InterceptorConfig interceptorConfig, 
Map interceptorRefParams) throws ConfigurationException {
+        Interceptor interceptor = super.buildInterceptor(interceptorConfig, 
interceptorRefParams);
+        if (interceptor != null && interceptor instanceof ServletContextAware) 
{
+            
((ServletContextAware)interceptor).setServletContext(servletContext);
+        }
+        return interceptor;
+    }
+}

Propchange: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/LegacyObjectFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java?rev=357600&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java
 (added)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java
 Sun Dec 18 17:13:39 2005
@@ -0,0 +1,93 @@
+/*
+ * $Id: Action.java 240373 2005-08-27 01:58:39Z jmitchell $
+ *
+ * Copyright 2000-2004 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.ti.legacy;
+
+import com.opensymphony.xwork.interceptor.ModelDrivenInterceptor;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.interceptor.AroundInterceptor;
+import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.util.OgnlUtil;
+import com.opensymphony.webwork.util.ServletContextAware;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.*;
+import org.apache.struts.config.*;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.commons.logging.*;
+
+/**
+ *  Supports Struts Action 1.x-style PlugIn classes by wrapping them in this
+ *  no-op interceptor.
+ */
+public class PlugInInterceptor extends AroundInterceptor 
+        implements ServletContextAware{
+
+    private String className;
+    private Map params = new HashMap();
+    private PlugIn plugin = null;
+    private static final Log LOG = LogFactory.getLog(PlugInInterceptor.class);
+
+    public void setClassName(String name) {
+        this.className = name;
+    }    
+
+    public void setParams(Map params) {
+        this.params = params;
+    }
+
+    public Map getParams() {
+        return params;
+    }    
+    
+    public void setServletContext(final ServletContext servletContext) {
+        ActionServlet servlet = new ActionServlet() {
+            public ServletContext getServletContext() {
+                return servletContext;
+            }
+        };
+
+        ModuleConfig modConfig = 
StrutsFactory.getStrutsFactory().createModuleConfig();
+
+        try {
+            plugin = (PlugIn) 
ObjectFactory.getObjectFactory().buildBean(className, null);
+            plugin.init(servlet, modConfig);
+        } catch (Exception ex) {
+            LOG.error("Unable to create or init plugin "+className, ex);
+            return;
+        }    
+        if (params != null) {
+            OgnlUtil.setProperties(params, plugin);
+        }
+    }
+    
+    public void destroy() {
+        plugin.destroy();
+    }
+
+    protected void after(ActionInvocation dispatcher, String result) throws 
Exception {
+    }
+
+    protected void before(ActionInvocation invocation) throws Exception {
+    }
+}

Propchange: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java
------------------------------------------------------------------------------
    svn:executable = *



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

Reply via email to