import org.wamblee.security.authorization.AuthorizationService;
import org.wamblee.security.authorization.hibernate.AuthorizationMappingFiles;
import org.wamblee.system.adapters.DefaultContainer;
+import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.ORMappingConfig;
import org.wamblee.system.core.Component;
import org.wamblee.system.core.DefaultProvidedInterface;
throws IOException {
super(aName);
- addComponent("mappingFiles", new AuthorizationMappingFiles());
+ ObjectConfiguration authConfig = new ObjectConfiguration(AuthorizationMappingFiles.class);
+ authConfig.getSetterConfig().initAllSetters();
+ addComponent("mappingFiles", new AuthorizationMappingFiles(), authConfig);
Component<?> hibernate = new HibernateComponent("hibernate");
addComponent(hibernate);
import org.springframework.transaction.PlatformTransactionManager;
import org.wamblee.cache.EhCache;
import org.wamblee.system.adapters.DefaultContainer;
+import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.ORMappingConfig;
import org.wamblee.system.core.Component;
import org.wamblee.system.core.DefaultProvidedInterface;
throws IOException {
super(aName);
- addComponent("mappingFiles", new UsermgtHibernateMappingFiles());
+ ObjectConfiguration mappingFilesConfig = new ObjectConfiguration(UsermgtHibernateMappingFiles.class);
+ mappingFilesConfig.getSetterConfig().initAllSetters();
+ addComponent("mappingFiles", new UsermgtHibernateMappingFiles(), mappingFilesConfig);
Component<?> _hibernate = new HibernateComponent("hibernate");
addComponent(_hibernate);
import org.wamblee.security.authorization.AuthorizationService;
import org.wamblee.security.authorization.AuthorizationServiceTest;
import org.wamblee.security.authorization.TestUserAccessor;
+import org.wamblee.system.adapters.ClassConfiguration;
+import org.wamblee.system.adapters.ClassConfigurationTest;
import org.wamblee.system.adapters.DefaultContainer;
import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.DatabaseComponentFactory;
_container = new DefaultContainer("top");
DatabaseComponentFactory.addDatabaseConfig(_container);
_container.addComponent(new DatasourceComponent("datasource"));
- _container.addComponent("userAccessor", TestUserAccessor.class);
+ ClassConfiguration useraccessorConfig = new ClassConfiguration(TestUserAccessor.class);
+ useraccessorConfig.getObjectConfig().getSetterConfig().initAllSetters();
+ _container.addComponent("userAccessor", useraccessorConfig);
_container.addComponent(new AuthorizationComponent("authorization",
true));
+
+ ClassConfiguration dbtesterConfig = new ClassConfiguration(DatabaseTesterComponent.class);
+ dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
_container
- .addComponent("databaseTester", DatabaseTesterComponent.class);
+ .addComponent("databaseTester", dbtesterConfig);
ObjectConfiguration config = new ObjectConfiguration(
PersistentAuthorizationServiceTest.class);
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wamblee.cache.EhCache;
+import org.wamblee.system.adapters.ClassConfiguration;
import org.wamblee.system.adapters.DefaultContainer;
import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.DatabaseComponentFactory;
_container.addComponent(new DatasourceComponent("datasource"));
_container.addComponent(new UserAdministrationComponent("admin", true));
- _container.addComponent("databaseTester", DatabaseTesterComponent.class);
+ ClassConfiguration dbtesterConfig = new ClassConfiguration(DatabaseTesterComponent.class);
+ dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
+ _container.addComponent("databaseTester", dbtesterConfig);
ObjectConfiguration config = new ObjectConfiguration(
HibernateUserAdministrationTest.class);
import java.io.IOException;
-import org.wamblee.io.ClassPathResource;
+import org.wamblee.system.adapters.ClassConfiguration;
import org.wamblee.system.adapters.DefaultContainer;
+import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.DatabaseComponentFactory;
-import org.wamblee.system.components.PropertyComponent;
import org.wamblee.system.spring.component.DatabaseTesterComponent;
import org.wamblee.system.spring.component.DatasourceComponent;
import org.wamblee.system.spring.component.HibernateComponent;
super(aName);
DatabaseComponentFactory.addDatabaseConfig(this);
addComponent(new DatasourceComponent("datasource"));
- addComponent("mappingFiles", new UsermgtHibernateMappingFiles());
+
+ ObjectConfiguration mappingFilesConfig = new ObjectConfiguration(UsermgtHibernateMappingFiles.class);
+ mappingFilesConfig.getSetterConfig().initAllSetters();
+ addComponent("mappingFiles", new UsermgtHibernateMappingFiles(), mappingFilesConfig);
addComponent(new HibernateComponent("hibernate"));
addComponent(new UserGroupRepositoryComponent("usersgroups"));
- addComponent("databaseTester", DatabaseTesterComponent.class);
+ ClassConfiguration dbtesterConfig = new ClassConfiguration(DatabaseTesterComponent.class);
+ dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
+ addComponent("databaseTester", dbtesterConfig);
}
super.addComponent(aComponent);
return this;
}
-
- public DefaultContainer addComponent(String aName, Class aClass) {
- return addComponent(new ClassAdapter(aName, new ClassConfiguration(
- aClass)));
- }
public DefaultContainer addComponent(String aName, ClassConfiguration aConfiguration) {
return addComponent(new ClassAdapter(aName, aConfiguration));
}
- public DefaultContainer addComponent(String aName, Object aObject) {
- return addComponent(new ObjectAdapter(aName, aObject, new ObjectConfiguration(
- aObject.getClass())));
- }
-
public DefaultContainer addComponent(String aName, Object aObject, ObjectConfiguration aConfiguration) {
if ( !aConfiguration.appliesTo(aObject) ) {
throw new IllegalArgumentException("Configuration '" + aConfiguration + "' does nto applu to '" +
private Map<Method, ParameterValues> _setters;
/**
- * Constructs the setter configuration. By default all setters are added.
+ * Constructs the setter configuration. By default no setters are added.
*
* @param aClass
* Class which is being configured.
public SetterConfiguration(Class aClass) {
_class = aClass;
_publicOnly = true;
- initSetters();
+ _setters = new HashMap<Method, ParameterValues>();
}
- private void initSetters() {
- _setters = new HashMap<Method, ParameterValues>();
+ /**
+ * Makes sure that all available setters are used.
+ */
+ public SetterConfiguration initAllSetters() {
+ _setters.clear();
for (Method method: getAllSetters(_class, _publicOnly) ) {
_setters.put(method, createParameterValues(method));
}
+ return this;
}
/**
* Called to set whether non-public setters are also used. By default only
- * public setters are used. This resets all changes made and selects all
- * public setters if non-public is false and all setters if it is true.
+ * public setters are used. The currently selected setters remain chosen.
*
* @param aIsNonPublic
* Non public flag.
*/
- public void setNonPublic(boolean aIsNonPublic) {
+ public SetterConfiguration setNonPublic(boolean aIsNonPublic) {
_publicOnly = !aIsNonPublic;
- initSetters();
+ return this;
}
/**
*
* @return List of all setters.
*/
- private static List<Method> getAllSetters(Class aClass,
+ public static List<Method> getAllSetters(Class aClass,
boolean aPublicOnly) {
List<Method> result = new ArrayList<Method>();
for (Method method : getAllMethods(aClass)) {
public void testSimpleConstructorInjection() {
ClassConfiguration x1Config = new ClassConfiguration(X1.class);
+ x1Config.getObjectConfig().getSetterConfig().initAllSetters();
x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
- ClassConfiguration x4Config = new ClassConfiguration(X4.class);
+ ClassConfiguration x4Config = new ClassConfiguration(X4.class);
+ x4Config.getObjectConfig().getSetterConfig().initAllSetters();
ClassAdapter x1Adapter = new ClassAdapter("x1", x1Config);
ClassAdapter x4Adapter = new ClassAdapter("x4", x4Config);
public void testConstructorAndSetterInjection() {
ClassConfiguration x1Config = new ClassConfiguration(X1.class);
+ x1Config.getObjectConfig().getSetterConfig().initAllSetters();
x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
ClassConfiguration x4Config = new ClassConfiguration(X4.class);
+ x4Config.getObjectConfig().getSetterConfig().initAllSetters();
ClassConfiguration x8Config = new ClassConfiguration(X8.class);
+ x8Config.getObjectConfig().getSetterConfig().initAllSetters();
ClassAdapter x1Adapter = new ClassAdapter("x1", x1Config);
ClassAdapter x4Adapter = new ClassAdapter("x4", x4Config);
ConstructorConfiguration config = classConfig.getConstructorConfig()
.greedy();
+
ProvidedInterface provided = new DefaultProvidedInterface("arg",
String.class);
List<RequiredInterface> required = classConfig.getRequiredInterfaces();
ClassConfiguration classConfig = new ClassConfiguration(X7.class);
classConfig.getConstructorConfig().select(Boolean.class);
- classConfig.getObjectConfig().getSetterConfig().values("port").setValue(0, 10);
+ classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("port").setValue(0, 10);
ProvidedInterface providedBoolean = new DefaultProvidedInterface("boolean",
Boolean.class);
public void testConstructorInjection() {
ClassConfiguration x1Config = new ClassConfiguration(X1.class);
x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
+ x1Config.getObjectConfig().getSetterConfig().initAllSetters();
+
+ ClassConfiguration x4Config = new ClassConfiguration(X4.class);
+ x4Config.getObjectConfig().getSetterConfig().initAllSetters();
DefaultContainer container = new DefaultContainer("top").addComponent(
- "x1", x1Config).addComponent("x4", X4.class);
+ "x1", x1Config).addComponent("x4", x4Config);
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)" },
public void testConstructorInjectionAndSetterInjection() {
ClassConfiguration x1Config = new ClassConfiguration(X1.class);
x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
+ x1Config.getObjectConfig().getSetterConfig().initAllSetters();
X8 x8 = new X8(null);
EVENT_TRACKER.clear();
+ ClassConfiguration x4Config = new ClassConfiguration(X4.class);
+ x4Config.getObjectConfig().getSetterConfig().initAllSetters();
+
+ ObjectConfiguration x8Config = new ObjectConfiguration(X8.class);
+ x8Config.getSetterConfig().initAllSetters();
+
DefaultContainer container = new DefaultContainer("top").addComponent(
- "x1", x1Config).addComponent("x4", X4.class).addComponent("x8", x8);
+ "x1", x1Config).addComponent("x4", x4Config).addComponent("x8", x8, x8Config);
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)",
public void testSetterInjection() {
ClassConfiguration x1Config = new ClassConfiguration(X1.class);
+ x1Config.getObjectConfig().getSetterConfig().initAllSetters();
x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
ClassConfiguration x4Config = new ClassConfiguration(X4.class);
+ x4Config.getObjectConfig().getSetterConfig().initAllSetters();
ObjectConfiguration x8Config = new ObjectConfiguration(X8.class);
+ x8Config.getSetterConfig().initAllSetters();
X1 x1 = new X1();
X8 x8 = new X8(x1);
public void testOneSetter() {
SetterConfiguration config = new SetterConfiguration(X5.class);
+ config.initAllSetters();
List<RequiredInterface> required = config.getRequiredInterfaces();
assertEquals(1, required.size());
assertEquals("value", required.get(0).getName());
public void testPrivateSetter() {
SetterConfiguration config = new SetterConfiguration(X5.class);
config.setNonPublic(true);
+ config.initAllSetters();
List<RequiredInterface> required = new ArrayList<RequiredInterface>(
config.getRequiredInterfaces());
Collections.sort(required, new Comparator<RequiredInterface>() {
public void testInheritance() {
SetterConfiguration config = new SetterConfiguration(X9.class);
config.setNonPublic(true);
+ config.initAllSetters();
List<RequiredInterface> required = new ArrayList<RequiredInterface>(
config.getRequiredInterfaces());
Collections.sort(required, new Comparator<RequiredInterface>() {
}
public void testMultipleSetters() {
- SetterConfiguration config = new SetterConfiguration(X6.class);
+ SetterConfiguration config = new SetterConfiguration(X6.class).initAllSetters();
List<RequiredInterface> required = config.getRequiredInterfaces();
Collections.sort(required, new RequiredInterfaceComparator());
assertEquals(2, required.size());
}
public void testInvokeWrongType() {
- final SetterConfiguration config = new SetterConfiguration(X5.class);
+ final SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters();
List<RequiredInterface> required = config.getRequiredInterfaces();
assertEquals(1, required.size());
assertEquals("value", required.get(0).getName());
}
public void testSetExplicitValue() {
- SetterConfiguration config = new SetterConfiguration(X5.class);
+ SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters();
config.values("value").setValue(0, "bladibla");
List<RequiredInterface> required = config.getRequiredInterfaces();
}
public void testRemove() {
- SetterConfiguration config = new SetterConfiguration(X6.class);
+ SetterConfiguration config = new SetterConfiguration(X6.class).initAllSetters();
config.remove("port");
List<RequiredInterface> required = config.getRequiredInterfaces();
Collections.sort(required, new RequiredInterfaceComparator());
}
public void testOverridingSetters() {
- SetterConfiguration config = new SetterConfiguration(X10.class);
+ SetterConfiguration config = new SetterConfiguration(X10.class).initAllSetters();
assertEquals(2, config.getRequiredInterfaces().size());
List<Method> methods = config.getSetters();
assertEquals(2, methods.size());