mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-3414 removes ObjectFactory as a field and uses ActionContext to retrieve instance of ObjectFactory to allow serialize instances of XWorkList
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1364910 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+2
-2
@@ -89,9 +89,9 @@ public class CollectionConverter extends DefaultTypeConverter {
|
||||
result = new TreeSet();
|
||||
} else {
|
||||
if (size > 0) {
|
||||
result = new XWorkList(objectFactory, memberType, size);
|
||||
result = new XWorkList(memberType, size);
|
||||
} else {
|
||||
result = new XWorkList(objectFactory, memberType);
|
||||
result = new XWorkList(memberType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,17 +42,13 @@ public class XWorkList extends ArrayList {
|
||||
|
||||
private Class clazz;
|
||||
|
||||
private ObjectFactory objectFactory;
|
||||
|
||||
public XWorkList(ObjectFactory fac, Class clazz) {
|
||||
public XWorkList(Class clazz) {
|
||||
this.clazz = clazz;
|
||||
this.objectFactory = fac;
|
||||
}
|
||||
|
||||
public XWorkList(ObjectFactory fac, Class clazz, int initialCapacity) {
|
||||
public XWorkList(Class clazz, int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
this.clazz = clazz;
|
||||
this.objectFactory = fac;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,8 +165,7 @@ public class XWorkList extends ArrayList {
|
||||
public synchronized Object get(int index) {
|
||||
while (index >= this.size()) {
|
||||
try {
|
||||
//todo
|
||||
this.add(objectFactory.buildBean(clazz, null)); //ActionContext.getContext().getContextMap()));
|
||||
this.add(getObjectFactory().buildBean(clazz, ActionContext.getContext().getContextMap()));
|
||||
} catch (Exception e) {
|
||||
throw new XWorkException(e);
|
||||
}
|
||||
@@ -179,6 +174,10 @@ public class XWorkList extends ArrayList {
|
||||
return super.get(index);
|
||||
}
|
||||
|
||||
private ObjectFactory getObjectFactory() {
|
||||
return ActionContext.getContext().getInstance(ObjectFactory.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the element at the specified position in this list with the specified element.
|
||||
* <p/>
|
||||
@@ -207,7 +206,7 @@ public class XWorkList extends ArrayList {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Converting from " + element.getClass().getName() + " to " + clazz.getName());
|
||||
}
|
||||
TypeConverter conv = objectFactory.buildConverter(XWorkConverter.class);
|
||||
TypeConverter conv = getObjectFactory().buildConverter(XWorkConverter.class);
|
||||
Map<String, Object> context = ActionContext.getContext().getContextMap();
|
||||
element = conv.convertValue(context, null, null, null, element, clazz);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.util;
|
||||
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.XWorkTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -29,8 +28,7 @@ import java.util.ArrayList;
|
||||
public class XWorkListTest extends XWorkTestCase {
|
||||
|
||||
public void testAddAllIndex() {
|
||||
ObjectFactory of = container.getInstance(ObjectFactory.class);
|
||||
XWorkList xworkList = new XWorkList(of, String.class);
|
||||
XWorkList xworkList = new XWorkList(String.class);
|
||||
xworkList.add(new String[]{"a"});
|
||||
xworkList.add("b");
|
||||
|
||||
@@ -50,7 +48,7 @@ public class XWorkListTest extends XWorkTestCase {
|
||||
assertEquals("3", xworkList.get(5));
|
||||
|
||||
// take 2, no trim
|
||||
xworkList = new XWorkList(of, String.class);
|
||||
xworkList = new XWorkList(String.class);
|
||||
xworkList.add(new String[]{"a"});
|
||||
xworkList.add("b");
|
||||
|
||||
@@ -68,7 +66,7 @@ public class XWorkListTest extends XWorkTestCase {
|
||||
assertEquals("3", xworkList.get(4));
|
||||
|
||||
// take 3, insert
|
||||
xworkList = new XWorkList(of, String.class);
|
||||
xworkList = new XWorkList(String.class);
|
||||
xworkList.add(new String[]{"a"});
|
||||
xworkList.add("b");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user