Issue Details (XML | Word | Printable)

Key: XOP-3
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Rodrigo Urubatan Ferreira Jardim
Votes: 2
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
XWork Optional

in xwork-optional package - I could not use the webwork/xwork validation with this XWork integration to Spring, so I created a litle patch for the SpringObjectFactory class, I think it is not the best wat to do this, but it works :-)

Created: 10/Aug/04 10:31 AM   Updated: 19/Feb/10 11:48 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. File SpringObjectFactory.diff (2 kB)



 Description  « Hide
Index: SpringObjectFactory.java
===================================================================
RCS file: /cvs/xwork-optional/xwork-spring/src/java/com/opensymphony/xwork/spring/SpringObjectFactory.java,v
retrieving revision 1.3
diff -u -r1.3 SpringObjectFactory.java
--- SpringObjectFactory.java 29 Jun 2004 10:05:24 -0000 1.3
+++ SpringObjectFactory.java 10 Aug 2004 14:51:06 -0000
@@ -4,6 +4,9 @@
  * Copyright (c) 2002-2003 by OpenSymphony
  * All rights reserved.
  */
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeansException;
@@ -14,58 +17,91 @@
 import com.opensymphony.xwork.ObjectFactory;
 
 /**
- * Simple implementation of the ObjectFactory that makes use of Spring's application
- * context if one has been configured, before falling back on the default mechanism of
- * instantiating a new class using the class name.
- *
- * In order to use this class in your application, you will need to instantiate a
- * copy of this class and set it as XWork's ObjectFactory before the xwork.xml file
- * is parsed. In a servlet environment, this could be done using a ServletContextListener.
- *
+ * Simple implementation of the ObjectFactory that makes use of Spring's
+ * application context if one has been configured, before falling back on the
+ * default mechanism of instantiating a new class using the class name.
+ *
+ * In order to use this class in your application, you will need to instantiate
+ * a copy of this class and set it as XWork's ObjectFactory before the xwork.xml
+ * file is parsed. In a servlet environment, this could be done using a
+ * ServletContextListener.
+ *
  * @author Simon Stewart (sms@lateral.net)
  */
-public class SpringObjectFactory extends ObjectFactory implements ApplicationContextAware {
- //~ Static fields/initializers /////////////////////////////////////////////
-
- private static final Log log = LogFactory.getLog(SpringObjectFactory.class);
-
- //~ Instance fields ////////////////////////////////////////////////////////
-
- private ApplicationContext appContext;
-
- //~ Methods ////////////////////////////////////////////////////////////////
-
- /**
- * Set the Spring ApplicationContext that should be used to look beans up with.
- *
- * @param appContext The Spring ApplicationContext that should be used to look beans up with.
- */
- public void setApplicationContext(ApplicationContext appContext) throws BeansException {
- this.appContext = appContext;
- }
-
- /**
- * Looks up beans using Spring's application context before falling back to
- * the method defined in the {@link ObjectFactory}.
- *
- * @param beanName The name of the bean to look up in the application context
- * @return A bean from Spring or the result of calling the overridden method.
- */
- public Object buildBean(String beanName) throws Exception {
- try {
- return appContext.getBean(beanName);
- } catch (NoSuchBeanDefinitionException e) {
- return super.buildBean(beanName);
- }
- }
-
- /**
- * This method sets the ObjectFactory used by XWork to this object. It's
- * best used as the "init-method" of a Spring bean definition in order to
- * hook Spring and XWork together properly (as an alternative to the
- * {@link SpringObjectFactoryListener}
- */
- public void initObjectFactory() {
- ObjectFactory.setObjectFactory(this);
- }
-}
+public class SpringObjectFactory extends ObjectFactory implements
+ ApplicationContextAware {
+ private Map classMap = new HashMap();
+ //~ Static fields/initializers
+ // /////////////////////////////////////////////
+
+ private static final Log log = LogFactory.getLog(SpringObjectFactory.class);
+
+ //~ Instance fields
+ // ////////////////////////////////////////////////////////
+
+ private ApplicationContext appContext;
+
+ //~ Methods
+ // ////////////////////////////////////////////////////////////////
+
+ /**
+ * Set the Spring ApplicationContext that should be used to look beans up
+ * with.
+ *
+ * @param appContext
+ * The Spring ApplicationContext that should be used to look
+ * beans up with.
+ */
+ public void setApplicationContext(ApplicationContext appContext)
+ throws BeansException {
+ this.appContext = appContext;
+ }
+
+ /**
+ * Looks up beans using Spring's application context before falling back to
+ * the method defined in the {@link ObjectFactory}.
+ *
+ * @param beanName
+ * The name of the bean to look up in the application context
+ * @return A bean from Spring or the result of calling the overridden
+ * method.
+ */
+ public Object buildBean(String beanName) throws Exception {
+ try {
+ return appContext.getBean(beanName);
+ } catch (NoSuchBeanDefinitionException e) {
+ return super.buildBean(beanName);
+ }
+ }
+
+ /**
+ * This method sets the ObjectFactory used by XWork to this object. It's
+ * best used as the "init-method" of a Spring bean definition in order to
+ * hook Spring and XWork together properly (as an alternative to the
+ * {@link SpringObjectFactoryListener}
+ */
+ public void initObjectFactory() {
+ ObjectFactory.setObjectFactory(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.opensymphony.xwork.ObjectFactory#getClassInstance(java.lang.String)
+ */
+ public Class getClassInstance(String className) throws ClassNotFoundException {
+ Class c = (Class) classMap.get(className);
+ if(c!=null)
+ return c;
+ if (appContext == null)
+ return super.getClassInstance(className);
+ if (!appContext.containsBeanDefinition(className))
+ return super.getClassInstance(className);
+ Object o = appContext.getBean(className);
+ if (o == null)
+ return super.getClassInstance(className);
+ c = o.getClass();
+ classMap.put(className,c);
+ return c;
+ }
+}
\ No newline at end of file


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Matt Raible added a comment - 27/Sep/04 10:02 AM
Here's a patch that does essentially the same thing. The one thing I couldn't get working was client-side visitor validation.

Simon Stewart added a comment - 05/Nov/04 08:21 PM
I've added a fix similar to Matt's to the SpringObjectFactory. Have yet to try the Javascript visitor validation, so I am unsure how much work this will take to fix (if any :)

Razan Abbass added a comment - 19/Feb/10 11:48 AM
[buy cheap tramadol online inurl|http://thoughtmesh.net/meshes.php?group=33]
[buy tramadol online|http://thoughtmesh.net/meshes.php?group=34]
[buy cheap tramadol online inurl|http://thoughtmesh.net/meshes.php?group=35]
[cheap tramadol|http://thoughtmesh.net/meshes.php?group=36]
[cheapest tramadol without prescription|http://thoughtmesh.net/meshes.php?group=37]
[tramadol cod online|http://thoughtmesh.net/meshes.php?group=38]
[discount tramadol|http://thoughtmesh.net/meshes.php?group=39]
[drugs that work in conjunction with tramadol |http://thoughtmesh.net/meshes.php?group=40]
[ingredients in tramadol|http://thoughtmesh.net/meshes.php?group=41]
[tramadol next day|http://thoughtmesh.net/meshes.php?group=42]
[order tramadol online cd|http://thoughtmesh.net/meshes.php?group=43]
[side effects tramadol|http://thoughtmesh.net/meshes.php?group=44]
[tramadol 50|http://thoughtmesh.net/meshes.php?group=45]
[tramadol 50mg tablets|http://thoughtmesh.net/meshes.php?group=46]
[buy tramadol|http://thoughtmesh.net/meshes.php?group=47]
[cheapest tramadol on line|http://thoughtmesh.net/meshes.php?group=48]
[tramadol hydrochloride|http://thoughtmesh.net/meshes.php?group=49]
[dosage tramadol|http://thoughtmesh.net/meshes.php?group=50]
[tramadol veterinary dose|http://thoughtmesh.net/meshes.php?group=51]
[does tramadol show in a drug screen|http://thoughtmesh.net/meshes.php?group=52]
[side effects of tramadol in canines|http://thoughtmesh.net/meshes.php?group=53]
[tramadol side effects|http://thoughtmesh.net/meshes.php?group=54]
[tramadol hcl online|http://thoughtmesh.net/meshes.php?group=55]
[tramadol hydrochloride picture|http://thoughtmesh.net/meshes.php?group=56]
[information about tramadol|http://thoughtmesh.net/meshes.php?group=57]
[tramadol hydrochloride 100mg|http://thoughtmesh.net/meshes.php?group=58]
[what is tramadol|http://thoughtmesh.net/meshes.php?group=59]
[tramadol hcl 50 mg tab|http://thoughtmesh.net/meshes.php?group=60]
[tramadol no prescription overnight|http://thoughtmesh.net/meshes.php?group=61]
[buy tramadol on line|http://thoughtmesh.net/meshes.php?group=62]
[order tramadol online|http://thoughtmesh.net/meshes.php?group=63]
[order tramadol online|http://thoughtmesh.net/meshes.php?group=64]
[overdose tramadol|http://thoughtmesh.net/meshes.php?group=65]
[overnight tramadol|http://thoughtmesh.net/meshes.php?group=66]
[tramadol slow release in burn pain|http://thoughtmesh.net/meshes.php?group=67]
[canadian pharmacy that sells tramadol without a prescription|http://thoughtmesh.net/meshes.php?group=68]
[tramadol 50mg 180 pills|http://thoughtmesh.net/meshes.php?group=69]
[low price tramadol|http://thoughtmesh.net/meshes.php?group=70]
[prescription tramadol|http://thoughtmesh.net/meshes.php?group=71]
[tramadol hcl|http://thoughtmesh.net/meshes.php?group=72]
[tramadol cheapest price|http://thoughtmesh.net/meshes.php?group=73]
[tramadol cheap no rx overnight|http://thoughtmesh.net/meshes.php?group=74]
[tramadol for sale|http://thoughtmesh.net/meshes.php?group=75]
[tramadol 50mg tablets |http://thoughtmesh.net/meshes.php?group=76]
[buy tramadol cheap medication inurl|http://thoughtmesh.net/meshes.php?group=77]
[tramadol withdrawals|http://thoughtmesh.net/meshes.php?group=78]
[cheap tramadol|http://thoughtmesh.net/meshes.php?group=79]
[order ultram online|http://thoughtmesh.net/meshes.php?group=80]
[buy cheap tramadol online inurl|http://thoughtmesh.net/meshes.php?group=81]