setterconfiguration now by default does not add all the setters.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 12 Nov 2009 20:28:45 +0000 (20:28 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 12 Nov 2009 20:28:45 +0000 (20:28 +0000)
12 files changed:
trunk/security/src/main/java/org/wamblee/usermgt/hibernate/AuthorizationComponent.java
trunk/security/src/main/java/org/wamblee/usermgt/hibernate/UserAdministrationComponent.java
trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/UserMgtRepositoryTestContainer.java
trunk/system/general/src/main/java/org/wamblee/system/adapters/DefaultContainer.java
trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassAdapterTest.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/DefaultContainerTest.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/ObjectAdapterTest.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java

index b0d77e784ce37e2b94cd379d5c06a6138314a563..150a84470cf56c9435bf94b3f0fb1db17cb54345 100644 (file)
@@ -25,6 +25,7 @@ import org.wamblee.cache.EhCache;
 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;
@@ -49,7 +50,9 @@ public class AuthorizationComponent extends DefaultContainer {
             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);
index 8904c797227cb927609de099ddceddd857f6ec75..66e3850f2fa2501580f03a46b1b3c3febcbb00ee 100644 (file)
@@ -23,6 +23,7 @@ import org.springframework.orm.hibernate3.HibernateTemplate;
 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;
@@ -48,7 +49,9 @@ public class UserAdministrationComponent extends DefaultContainer {
             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);
index ce415cabe03c5a36792c36dd64d959f7fca8c242..9afece0081f8efe2170fc403f72f9000383e6934 100644 (file)
@@ -24,6 +24,8 @@ import org.wamblee.general.BeanKernel;
 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;
@@ -67,12 +69,17 @@ public class PersistentAuthorizationServiceTest extends
         _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);
index bef27d2c765b980e0faa765ec15585aa5a170839..5d604fc074f5e9f774450f8c5c563b29465bde6d 100644 (file)
@@ -23,6 +23,7 @@ import java.sql.SQLException;
 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;
@@ -64,7 +65,9 @@ public class HibernateUserAdministrationTest extends UserAdministrationImplTest
         _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);
index 22ae86cb43fc996c21542eeaa0946f945df8860e..dd4439167761a026981245057ad383c9ae41f6c5 100644 (file)
@@ -17,10 +17,10 @@ package org.wamblee.usermgt.hibernate;
 
 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;
@@ -38,10 +38,15 @@ public class UserMgtRepositoryTestContainer extends DefaultContainer {
         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);
 
     }
 
index 7f630105ac32cba5641432af7ffd65eb813e7798..823b7c0d4951b53210c251292156db82e7cb8f87 100644 (file)
@@ -31,21 +31,11 @@ public class DefaultContainer extends Container {
         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 '"  + 
index b2ab5f6d7044745182393717b2809d3a5b5c018b..649e008fae1f7f1ff0f17eff1b0c3923cd906db9 100644 (file)
@@ -52,7 +52,7 @@ public class SetterConfiguration {
        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.
@@ -60,27 +60,30 @@ public class SetterConfiguration {
        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; 
        }
 
        /**
@@ -201,7 +204,7 @@ public class SetterConfiguration {
         * 
         * @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)) {
index 113fe74e44fc2cab568e96d5a3942a261d3cc97d..e08190e9ca8b72ae29e5aa337562ddfa84e282f0 100644 (file)
@@ -32,8 +32,10 @@ public class ClassAdapterTest extends AdapterTestCase {
 
        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);
@@ -59,9 +61,12 @@ public class ClassAdapterTest extends AdapterTestCase {
        
        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);
index c0fc039815aab0d7963c30ce055128686a941d20..aee3216604103966b953f0c8cce935616366960e 100644 (file)
@@ -31,6 +31,7 @@ public class ClassConfigurationTest extends AdapterTestCase {
 
         ConstructorConfiguration config = classConfig.getConstructorConfig()
                 .greedy();
+        
         ProvidedInterface provided = new DefaultProvidedInterface("arg",
                 String.class);
         List<RequiredInterface> required = classConfig.getRequiredInterfaces();
@@ -52,7 +53,7 @@ public class ClassConfigurationTest extends AdapterTestCase {
         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);
index 07143e3eeee14371cf7f5f31ff3e7aade2c288fc..938a12228763493b6596d13a832e6a7c1bc9e98c 100644 (file)
@@ -23,9 +23,13 @@ public class DefaultContainerTest extends AdapterTestCase {
     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)" },
@@ -40,12 +44,19 @@ public class DefaultContainerTest extends AdapterTestCase {
     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)",
index 6d5a3359186dd908b04d0c7bd9c8f82cecd385e6..0c6825e78e5605049ee76b1eb3063ba4155bbbd0 100644 (file)
@@ -32,10 +32,13 @@ public class ObjectAdapterTest extends AdapterTestCase {
        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);
index 730dfe6d84329d2d284999a72ccdaf386385af8d..e13c9fc03a49f29bc913231a372dd765d14288c9 100644 (file)
@@ -33,6 +33,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
 
        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());
@@ -51,6 +52,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        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>() {
@@ -86,6 +88,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        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>() {
@@ -128,7 +131,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        }
 
        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());
@@ -155,7 +158,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        }
 
        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());
@@ -175,7 +178,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        }
 
        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();
@@ -294,7 +297,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        }
 
        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());
@@ -327,7 +330,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
        }
        
        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());