From: erik Date: Sun, 15 Nov 2009 10:38:08 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2@603~52 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=82224dd7a3b0203af9bc240da850caedf01c1532;p=utils --- diff --git a/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java b/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java index 9afece00..2dcefee7 100644 --- a/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java +++ b/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java @@ -83,9 +83,9 @@ public class PersistentAuthorizationServiceTest extends ObjectConfiguration config = new ObjectConfiguration( PersistentAuthorizationServiceTest.class); - config.getSetterConfig().clear().add("userAccessor").add( - "databaseTester").add("hibernateTemplate").add( - "authorizationService"); + config.getSetterConfig().clear().add("setUserAccessor").add( + "setDatabaseTester").add("setHibernateTemplate").add( + "setAuthorizationService"); _container.addComponent("testcase", this, config); _scope = _container.start(); diff --git a/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java b/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java index f1f5d18b..fa80b1a4 100644 --- a/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java +++ b/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java @@ -54,7 +54,7 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest { ObjectConfiguration config = new ObjectConfiguration( HibernateGroupSetTest.class); config.getSetterConfig().clear().add( - "groupSet").add("databaseTester"); + "setGroupSet").add("setDatabaseTester"); _container.addComponent("testcase", this, config); _scope = _container.start(); diff --git a/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java b/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java index 5d604fc0..f707dba0 100644 --- a/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java +++ b/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java @@ -72,7 +72,7 @@ public class HibernateUserAdministrationTest extends UserAdministrationImplTest ObjectConfiguration config = new ObjectConfiguration( HibernateUserAdministrationTest.class); config.getSetterConfig().clear().add( - "userCache").add("databaseTester").add("userAdmin"); + "setUserCache").add("setDatabaseTester").add("setUserAdmin"); _container.addComponent("testcase", this, config); _scope = _container.start(); diff --git a/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java b/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java index 6b7dc38a..82588b3b 100644 --- a/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java +++ b/trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java @@ -68,8 +68,8 @@ public class HibernateUserSetTest extends InMemoryUserSetTest { ObjectConfiguration config = new ObjectConfiguration( HibernateUserSetTest.class); - config.getSetterConfig().clear().add("userset").add( - "groupset").add("databaseTester").add("userCache"); + config.getSetterConfig().clear().add("setUserset").add( + "setGroupset").add("setDatabaseTester").add("setUserCache"); _container.addComponent("testcase", this, config); _scope = _container.start(); diff --git a/trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java b/trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java index 649e008f..f81c4a4b 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java @@ -100,21 +100,40 @@ public class SetterConfiguration { * Removes a setter from the set of methods. * * @param aName - * Name of the setter to remove (without the "set" prefix). + * Name of the setter to remove. * @return Reference to the current object to allow call chaining. */ public SetterConfiguration remove(String aName) { - final String name = createSetterName(aName); - Map setters = new HashMap(); for (Method method : _setters.keySet()) { - if (method.getName().equals(name)) { + if (method.getName().equals(aName)) { _setters.remove(method); return this; } } throw new IllegalArgumentException( - "No setter configured by the name of '" + aName + "'"); + "No method configured by the name of '" + aName + "'"); } + + /** + * Removes the method from the set of methods. + * @param aMethod Method to remove. + * @return + */ + public SetterConfiguration remove(Method aMethod) { + if ( !aMethod.getDeclaringClass().isAssignableFrom(_class) ) { + throw new RuntimeException("Method " + aMethod + " not found in class " + _class + " or its superclasses"); + } + for (Method method : _setters.keySet()) { + if (method.equals(aMethod)) { + _setters.remove(method); + return this; + } + } + throw new IllegalArgumentException( + "Method '" + aMethod + "' was not configured. "); + } + + /** * Creates the name of a setter based on the name of the setter without the @@ -124,31 +143,30 @@ public class SetterConfiguration { * Setter name. * @return Setter name. */ - private String createSetterName(String aName) { + private String createxSetterName(String aName) { return "set" + aName.substring(0, 1).toUpperCase() + aName.substring(1); } /** * Adds a given setter name to the setters. * - * @param aName + * @param aName Name of a setter method. * @return Reference to the current object to allow call chaining. */ - public SetterConfiguration add(String aName) { - final String name = createSetterName(aName); + public SetterConfiguration add(final String aName) { int oldlen = _setters.size(); List methods = new ArrayList(); CollectionFilter.filter(getAllSetters(_class, _publicOnly), methods, new Condition() { @Override public boolean matches(Method aObject) { - return aObject.getName().equals(name); + return aObject.getName().equals(aName); } }); if (methods.size() == 0 ) { - throw new IllegalArgumentException("No setter found for '" + aName - + "' in " + _class.getName()); + throw new IllegalArgumentException("Method '" + aName + + "' not found in " + _class.getName()); } // TODO is it possible to get more than one setter here in case the subclass overrides // the baseclass method? @@ -220,8 +238,9 @@ public class SetterConfiguration { } private static ParameterValues createParameterValues(Method method) { + // TODO generalize to multiple parameters. return new ParameterValues( - new String[] { getSetterName(method) }, new Class[] { method + new String[] { method.getName() }, new Class[] { method .getParameterTypes()[0] }); } @@ -280,13 +299,12 @@ public class SetterConfiguration { * @return Parameter values. */ public ParameterValues values(String aMethod) { - String name = createSetterName(aMethod); for (Method method : _setters.keySet()) { - if (method.getName().equals(name)) { + if (method.getName().equals(aMethod)) { return _setters.get(method); } } - throw new IllegalArgumentException("No setter method '" + name + throw new IllegalArgumentException("No setter method '" + aMethod + "' found"); } @@ -299,7 +317,7 @@ public class SetterConfiguration { * Method. * @return Setter name. */ - private static String getSetterName(Method aMethod) { + private static String getxSetterName(Method aMethod) { String result = aMethod.getName().substring(3); return result.substring(0, 1).toLowerCase() + result.substring(1); } diff --git a/trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java b/trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java index a5cd1a09..8d5703dd 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java @@ -53,7 +53,7 @@ public class ClassConfigurationTest extends AdapterTestCase { ClassConfiguration classConfig = new ClassConfiguration(X7.class); classConfig.getConstructorConfig().select(Boolean.class); - classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("port").setValue(0, 10); + classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("setPort").setValue(0, 10); ProvidedInterface providedBoolean = new DefaultProvidedInterface("boolean", Boolean.class); diff --git a/trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java b/trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java index 1d7ec75e..382beb36 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java @@ -36,7 +36,7 @@ public class SetterConfigurationTest extends AdapterTestCase { config.initAllSetters(); List required = config.getRequiredInterfaces(); assertEquals(1, required.size()); - assertEquals("value", required.get(0).getName()); + assertEquals("setValue", required.get(0).getName()); ProvidedInterface provided = new DefaultProvidedInterface("janse", String.class); @@ -62,8 +62,8 @@ public class SetterConfigurationTest extends AdapterTestCase { } }); assertEquals(2, required.size()); - assertEquals("value", required.get(0).getName()); - assertEquals("xyz", required.get(1).getName()); + assertEquals("setValue", required.get(0).getName()); + assertEquals("setXyz", required.get(1).getName()); ProvidedInterface providedString = new DefaultProvidedInterface( "janse", String.class); @@ -98,9 +98,9 @@ public class SetterConfigurationTest extends AdapterTestCase { } }); assertEquals(3, required.size()); - assertEquals("flag", required.get(0).getName()); - assertEquals("value", required.get(1).getName()); - assertEquals("xyz", required.get(2).getName()); + assertEquals("setFlag", required.get(0).getName()); + assertEquals("setValue", required.get(1).getName()); + assertEquals("setXyz", required.get(2).getName()); ProvidedInterface providedBoolean = new DefaultProvidedInterface( "janse", Boolean.class); @@ -135,8 +135,8 @@ public class SetterConfigurationTest extends AdapterTestCase { List required = config.getRequiredInterfaces(); Collections.sort(required, new RequiredInterfaceComparator()); assertEquals(2, required.size()); - assertEquals("host", required.get(0).getName()); - assertEquals("port", required.get(1).getName()); + assertEquals("setHost", required.get(0).getName()); + assertEquals("setPort", required.get(1).getName()); ProvidedInterface provided0 = new DefaultProvidedInterface("janse", String.class); @@ -161,7 +161,7 @@ public class SetterConfigurationTest extends AdapterTestCase { final SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters(); List required = config.getRequiredInterfaces(); assertEquals(1, required.size()); - assertEquals("value", required.get(0).getName()); + assertEquals("setValue", required.get(0).getName()); ProvidedInterface provided = new DefaultProvidedInterface("janse", String.class); @@ -179,7 +179,7 @@ public class SetterConfigurationTest extends AdapterTestCase { public void testSetExplicitValue() { SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters(); - config.values("value").setValue(0, "bladibla"); + config.values("setValue").setValue(0, "bladibla"); List required = config.getRequiredInterfaces(); assertEquals(0, required.size()); @@ -209,11 +209,11 @@ public class SetterConfigurationTest extends AdapterTestCase { public void testAddByName() { SetterConfiguration config = new SetterConfiguration(X6.class); - config.clear().add("host"); + config.clear().add("setHost"); List required = config.getRequiredInterfaces(); Collections.sort(required, new RequiredInterfaceComparator()); assertEquals(1, required.size()); - assertEquals("host", required.get(0).getName()); + assertEquals("setHost", required.get(0).getName()); ProvidedInterface provided0 = new DefaultProvidedInterface("janse", String.class); @@ -235,7 +235,7 @@ public class SetterConfigurationTest extends AdapterTestCase { List required = config.getRequiredInterfaces(); Collections.sort(required, new RequiredInterfaceComparator()); assertEquals(1, required.size()); - assertEquals("host", required.get(0).getName()); + assertEquals("setHost", required.get(0).getName()); ProvidedInterface provided0 = new DefaultProvidedInterface("janse", String.class); @@ -263,7 +263,7 @@ public class SetterConfigurationTest extends AdapterTestCase { config.setNonPublic(true); config.clear(); - config.add("xyz"); + config.add("setXyz"); assertEquals(1, config.getRequiredInterfaces().size()); } @@ -298,11 +298,11 @@ public class SetterConfigurationTest extends AdapterTestCase { public void testRemove() { SetterConfiguration config = new SetterConfiguration(X6.class).initAllSetters(); - config.remove("port"); + config.remove("setPort"); List required = config.getRequiredInterfaces(); Collections.sort(required, new RequiredInterfaceComparator()); assertEquals(1, required.size()); - assertEquals("host", required.get(0).getName()); + assertEquals("setHost", required.get(0).getName()); ProvidedInterface provided0 = new DefaultProvidedInterface("janse", String.class);