use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class SetPropertiesTest method doTestAddingToListsWithObjects.
public void doTestAddingToListsWithObjects(final boolean allowAdditions) {
loadConfigurationProviders(new StubConfigurationProvider() {
@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.factory(ObjectTypeDeterminer.class, new Factory() {
public Object create(Context context) throws Exception {
return new MockObjectTypeDeterminer(null, Cat.class, null, allowAdditions);
}
@Override
public Class type() {
return Cat.class;
}
});
}
});
Foo foo = new Foo();
foo.setMoreCats(new ArrayList());
String spielname = "Spielen";
ValueStack vs = ActionContext.getContext().getValueStack();
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
vs.getContext().put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
vs.push(foo);
try {
vs.setValue("moreCats[2].name", spielname);
} catch (IndexOutOfBoundsException e) {
if (allowAdditions) {
throw e;
}
}
Object setCat = null;
if (allowAdditions) {
setCat = foo.getMoreCats().get(2);
assertNotNull(setCat);
assertTrue(setCat instanceof Cat);
assertTrue(((Cat) setCat).getName().equals(spielname));
} else {
assertTrue(foo.getMoreCats() == null || foo.getMoreCats().size() == 0);
}
// has been created
if (allowAdditions) {
spielname = "paws";
vs.setValue("moreCats[0].name", spielname);
setCat = foo.getMoreCats().get(0);
assertNotNull(setCat);
assertTrue(setCat instanceof Cat);
assertTrue(((Cat) setCat).getName().equals(spielname));
}
}
use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class ScopedModelDrivenInterceptorTest method testResolveModel.
public void testResolveModel() throws Exception {
ActionContext ctx = ActionContext.getContext().withSession(new HashMap<>());
ObjectFactory factory = ActionContext.getContext().getContainer().getInstance(ObjectFactory.class);
Object obj = inter.resolveModel(factory, ctx, "java.lang.String", "request", "foo");
assertNotNull(obj);
assertTrue(obj instanceof String);
assertSame(obj, ctx.get("foo"));
obj = inter.resolveModel(factory, ctx, "java.lang.String", "session", "foo");
assertNotNull(obj);
assertTrue(obj instanceof String);
assertSame(obj, ctx.getSession().get("foo"));
obj = inter.resolveModel(factory, ctx, "java.lang.String", "session", "foo");
assertNotNull(obj);
assertTrue(obj instanceof String);
assertSame(obj, ctx.getSession().get("foo"));
}
use of com.opensymphony.xwork2.inject.Factory in project onebusaway-application-modules by camsys.
the class SpringContainer method register.
@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
// Since we're about to override...
builder.setAllowDuplicates(true);
builder.factory(ObjectFactory.class, new Factory<ObjectFactory>() {
public ObjectFactory create(Context xworkContext) throws Exception {
SpringObjectFactory f = new SpringObjectFactory();
xworkContext.getContainer().inject(f);
f.setApplicationContext(_applicationContext);
f.setAutowireStrategy(_autoWireStrategy);
return f;
}
@Override
public Class<? extends ObjectFactory> type() {
return ObjectFactory.class;
}
});
}
Aggregations