Search in sources :

Example 21 with LocatableProperties

use of com.opensymphony.xwork2.util.location.LocatableProperties 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));
    }
}
Also used : Context(com.opensymphony.xwork2.inject.Context) ActionContext(com.opensymphony.xwork2.ActionContext) ValueStack(com.opensymphony.xwork2.util.ValueStack) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) Foo(com.opensymphony.xwork2.util.Foo) Factory(com.opensymphony.xwork2.inject.Factory) MockObjectTypeDeterminer(com.opensymphony.xwork2.mock.MockObjectTypeDeterminer) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) ObjectTypeDeterminer(com.opensymphony.xwork2.conversion.ObjectTypeDeterminer) MockObjectTypeDeterminer(com.opensymphony.xwork2.mock.MockObjectTypeDeterminer) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) Cat(com.opensymphony.xwork2.util.Cat)

Example 22 with LocatableProperties

use of com.opensymphony.xwork2.util.location.LocatableProperties in project struts by apache.

the class DefaultPropertiesProvider method register.

public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
    try {
        PropertiesSettings defaultSettings = new PropertiesSettings("org/apache/struts2/default");
        loadSettings(props, defaultSettings);
    } catch (Exception e) {
        throw new ConfigurationException("Could not find or error in org/apache/struts2/default.properties", e);
    }
}
Also used : ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Example 23 with LocatableProperties

use of com.opensymphony.xwork2.util.location.LocatableProperties 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;
        }
    });
}
Also used : Context(com.opensymphony.xwork2.inject.Context) ApplicationContext(org.springframework.context.ApplicationContext) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Aggregations

LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)19 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)18 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)15 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)10 Container (com.opensymphony.xwork2.inject.Container)4 Context (com.opensymphony.xwork2.inject.Context)4 Configuration (com.opensymphony.xwork2.config.Configuration)3 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)3 StrutsDefaultConfigurationProvider (com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)3 Factory (com.opensymphony.xwork2.inject.Factory)3 ActionContext (com.opensymphony.xwork2.ActionContext)2 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)2 BeanSelectionProvider (com.opensymphony.xwork2.config.BeanSelectionProvider)2 UnknownHandlerConfig (com.opensymphony.xwork2.config.entities.UnknownHandlerConfig)2 ObjectTypeDeterminer (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)2 MockObjectTypeDeterminer (com.opensymphony.xwork2.mock.MockObjectTypeDeterminer)2 Foo (com.opensymphony.xwork2.util.Foo)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 Location (com.opensymphony.xwork2.util.location.Location)2 ArrayList (java.util.ArrayList)2