Author: aco
Date: Tue Jul 4 02:38:58 2006
New Revision: 418964
URL: http://svn.apache.org/viewvc?rev=418964&view=rev
Log:
Fix bug in ReflectionUtil in recognizing ReflectionConfigurable nested objects
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/ReflectionUtil.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/test/java/org/apache/activemq/tool/ReflectionUtilTest.java
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/ReflectionUtil.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/ReflectionUtil.java?rev=418964&r1=418963&r2=418964&view=diff
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/ReflectionUtil.java
(original)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/ReflectionUtil.java
Tue Jul 4 02:38:58 2006
@@ -44,25 +44,38 @@
debugInfo = "Invoking: " + targetClass.getName();
StringTokenizer tokenizer = new StringTokenizer(key, ".");
+ String keySubString = key;
int tokenCount = tokenizer.countTokens();
// For nested settings, get the object first. -1, do not count the
last token
for (int j=0; j<tokenCount-1; j++) {
// Find getter method first
String name = tokenizer.nextToken();
+
+ // Check if the target object will accept the settings
+ if (target instanceof ReflectionConfigurable &&
!((ReflectionConfigurable)target).acceptConfig(keySubString, val)) {
+ return;
+ } else {
+ // This will reduce the key, so that it will be recognize
by the next object. i.e.
+ // Property name: factory.prefetchPolicy.queuePrefetch
+ // Calling order:
this.getFactory().prefetchPolicy().queuePrefetch();
+ // If factory does not accept the config, it should be
given prefetchPolicy.queuePrefetch as the key
+ keySubString = keySubString.substring(name.length() + 1);
// +1 to account for the '.'
+ }
+
String getMethod = "get" + name.substring(0,1).toUpperCase() +
name.substring(1);
Method method = targetClass.getMethod(getMethod, new Class[]
{});
target = method.invoke(target, null);
targetClass = target.getClass();
+
debugInfo += ("." + getMethod + "()");
}
// Property name
String property = tokenizer.nextToken();
-
// Check if the target object will accept the settings
- if (obj instanceof ReflectionConfigurable &&
!((ReflectionConfigurable)target).acceptConfig(property, val)) {
+ if (target instanceof ReflectionConfigurable &&
!((ReflectionConfigurable)target).acceptConfig(property, val)) {
return;
}
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/test/java/org/apache/activemq/tool/ReflectionUtilTest.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/test/java/org/apache/activemq/tool/ReflectionUtilTest.java?rev=418964&r1=418963&r2=418964&view=diff
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/test/java/org/apache/activemq/tool/ReflectionUtilTest.java
(original)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/test/java/org/apache/activemq/tool/ReflectionUtilTest.java
Tue Jul 4 02:38:58 2006
@@ -22,8 +22,45 @@
import java.io.File;
import org.apache.activemq.tool.properties.ReflectionUtil;
+import org.apache.activemq.tool.properties.ReflectionConfigurable;
public class ReflectionUtilTest extends TestCase {
+ public void testConfigurableOption() {
+ TestClass5 data = new TestClass5();
+
+ data.willIntercept = true;
+ ReflectionUtil.configureClass(data, "this-should-not-matter",
"this-should-not-matter");
+ assertTrue(data.intercepted);
+
+ data.willIntercept = false;
+ data.nest = new TestClass5();
+ data.nest.willIntercept = true;
+ ReflectionUtil.configureClass(data, "nest.this-should-not-matter",
"this-should-not-matter");
+ assertTrue(data.intercepted);
+ assertTrue(data.nest.intercepted);
+
+ data.willIntercept = false;
+ data.nest = new TestClass5();
+ data.nest.willIntercept = false;
+ data.nest.nest = new TestClass5();
+ data.nest.nest.willIntercept = true;
+ ReflectionUtil.configureClass(data,
"nest.nest.this-should-not-matter", "this-should-not-matter");
+ assertTrue(data.intercepted);
+ assertTrue(data.nest.intercepted);
+ assertTrue(data.nest.nest.intercepted);
+
+ TestClass6 data2 = new TestClass6();
+ data2.nestConfig = new TestClass5();
+ data2.nestConfig.willIntercept = true;
+ ReflectionUtil.configureClass(data2,
"nestConfig.this-should-not-matter", "this-should-not-matter");
+ assertTrue(data2.nestConfig.intercepted);
+
+ data2.nestNotConfig = new TestClass6();
+ data2.nestNotConfig.nestConfig = new TestClass5();
+ data2.nestNotConfig.nestConfig.willIntercept = true;
+ ReflectionUtil.configureClass(data2,
"nestNotConfig.nestConfig.this-should-not-matter", "this-should-not-matter");
+ assertTrue(data2.nestNotConfig.nestConfig.intercepted);
+ }
public void testDataTypeConfig() {
TestClass3 targetObj = new TestClass3();
@@ -255,6 +292,55 @@
public void setTestFile(String testFile) {
this.testFile = new File(testFile);
+ }
+ }
+
+ public class TestClass5 implements ReflectionConfigurable {
+ public boolean intercepted = false;
+ public boolean willIntercept = true;
+ public TestClass5 nest = null;
+
+ public void configureProperties(Properties props) {
+ // Do nothing
+ }
+
+ public Properties retrieveProperties(Properties props) {
+ return null;
+ }
+
+ public boolean acceptConfig(String key, String val) {
+ intercepted = true;
+
+ return !willIntercept;
+ }
+
+ public TestClass5 getNest() {
+ return nest;
+ }
+
+ public void setNest(TestClass5 nest) {
+ this.nest = nest;
+ }
+ }
+
+ public class TestClass6 {
+ public TestClass6 nestNotConfig = null;
+ public TestClass5 nestConfig = null;
+
+ public TestClass6 getNestNotConfig() {
+ return nestNotConfig;
+ }
+
+ public void setNestNotConfig(TestClass6 nestNotConfig) {
+ this.nestNotConfig = nestNotConfig;
+ }
+
+ public TestClass5 getNestConfig() {
+ return nestConfig;
+ }
+
+ public void setNestConfig(TestClass5 nestConfig) {
+ this.nestConfig = nestConfig;
}
}
}