]> source.dussan.org Git - archiva.git/commitdiff
move plexus-webwork to spring adapter code in plexus-spring
authorNicolas De Loof <nicolas@apache.org>
Fri, 29 Feb 2008 09:31:42 +0000 (09:31 +0000)
committerNicolas De Loof <nicolas@apache.org>
Fri, 29 Feb 2008 09:31:42 +0000 (09:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@632271 13f79535-47bb-0310-9956-ffa450edef68

springy/archiva-web/archiva-webapp/src/main/resources/webwork.properties
springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml
springy/plexus-spring/pom.xml
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusWebApplicationContext.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/WebWorkPlexusInSpringObjectFactory.java [new file with mode: 0644]

index 539c9f27873815650dc602a3ca069979fb6babb7..d31964175a1f8caac2e3197df26278194af880f6 100644 (file)
@@ -19,7 +19,7 @@
 
 # define our own action mapper here
 webwork.mapper.class = org.apache.maven.archiva.web.mapper.RepositoryActionMapper
-webwork.objectFactory = org.codehaus.plexus.xwork.PlexusObjectFactory
+webwork.objectFactory = org.codehaus.plexus.spring.WebWorkPlexusInSpringObjectFactory
 webwork.url.includeParams = none
 
 # webwork.devMode = true
index a782e82a6d1117961d3526db30b972e6dff000a4..c59a0c1090795d5f48e9c522a6e7afb6b042d562 100644 (file)
     <constructor-arg ref="cache#url-failures-cache" type="org.codehaus.plexus.cache.Cache"/>
   </bean>
 
-  <bean class="org.springframework.web.context.support.ServletContextAttributeExporter"
-        lazy-init="false" >
-    <property name="attributes">
-        <map>
-            <entry key="webwork.plexus.container" value-ref="plexusContainer"/>
-        </map>
-    </property>
-  </bean>
-
 </beans>
\ No newline at end of file
index cdea479bfedcdb2c3e47846d52a1a1521c44c064..f92244eb58f5511bdfcbe91d7c928077f7bd037b 100644 (file)
       <artifactId>dom4j</artifactId>\r
       <version>1.6.1</version>\r
     </dependency>\r
+    <dependency>\r
+      <groupId>com.opensymphony</groupId>\r
+      <artifactId>webwork</artifactId>\r
+      <version>2.2.6</version>\r
+      <optional>true</optional>\r
+    </dependency>\r
+    <dependency>\r
+      <groupId>javax.servlet</groupId>\r
+      <artifactId>servlet-api</artifactId>\r
+      <version>2.3</version>\r
+      <optional>true</optional>\r
+    </dependency>\r
+\r
     <dependency>\r
       <groupId>junit</groupId>\r
       <artifactId>junit</artifactId>\r
index 0392ed38cc0764b2c7c5a67c5b4b6f986560d92b..b1595bed13d8d95d42bfdd68c012cf3179e14f48 100644 (file)
@@ -19,22 +19,11 @@ package org.codehaus.plexus.spring;
  * under the License.
  */
 
-import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
 
-import org.apache.commons.lang.ClassUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.ListableBeanFactory;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
index 5450dd933ac018c17e7d8e7d7678417a41a3704e..26b96fa0dead1ac6b0f9da496be324b28a53587e 100644 (file)
@@ -101,6 +101,11 @@ public class PlexusToSpringUtils
         return disposable;\r
     }\r
 \r
+    public static String buildSpringId( Class role, String roleHint )\r
+    {\r
+        return buildSpringId( role.getName(), roleHint );\r
+    }\r
+\r
     public static String buildSpringId( String role, String roleHint )\r
     {\r
         int i = role.lastIndexOf( '.' ) + 1;\r
index 87970a05594b21593632aa3aa6c1861f7d457dcc..d96ea1a8a32784bc912650f13955aebca5792951 100644 (file)
@@ -58,6 +58,7 @@ public class PlexusWebApplicationContext
     protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
     {
         delegate.postProcessBeanFactory( beanFactory, this );
+        getServletContext().setAttribute( "webwork.plexus.container", beanFactory.getBean( "plexusContainer" ) );
         super.postProcessBeanFactory( beanFactory );
     }
 
diff --git a/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/WebWorkPlexusInSpringObjectFactory.java b/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/WebWorkPlexusInSpringObjectFactory.java
new file mode 100644 (file)
index 0000000..57f8770
--- /dev/null
@@ -0,0 +1,70 @@
+package org.codehaus.plexus.spring;
+
+/*
+ * 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.
+ */
+
+import java.util.Map;
+
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.core.NestedRuntimeException;
+
+import com.opensymphony.webwork.spring.WebWorkSpringObjectFactory;
+import com.opensymphony.xwork.Action;
+import com.opensymphony.xwork.Result;
+import com.opensymphony.xwork.interceptor.Interceptor;
+
+/**
+ * Replacement for WebWorkSpringObjectFactory ("webwork.objectFactory = spring") to support
+ * plexus components lookup as expected by plexus-xwork integration.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class WebWorkPlexusInSpringObjectFactory
+    extends WebWorkSpringObjectFactory
+{
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see com.opensymphony.xwork.spring.SpringObjectFactory#buildBean(java.lang.String,
+     * java.util.Map)
+     */
+    public Object buildBean( String name, Map map )
+        throws Exception
+    {
+        String id = PlexusToSpringUtils.buildSpringId( Action.class, name );
+        if ( appContext.containsBean( id ) )
+        {
+            return super.buildBean( id, map );
+        }
+
+        id = PlexusToSpringUtils.buildSpringId( Result.class, name );
+        if ( appContext.containsBean( id ) )
+        {
+            return super.buildBean( id, map );
+        }
+
+        id = PlexusToSpringUtils.buildSpringId( Interceptor.class, name );
+        if ( appContext.containsBean( id ) )
+        {
+            return super.buildBean( id, map );
+        }
+        return super.buildBean( name, map );
+    }
+}