You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/01/29 21:08:38 UTC
qpid-jms git commit: Return a Map of unapplied values from the given Properties object which
contains all the values that could not be applied to the target object.
Repository: qpid-jms
Updated Branches:
refs/heads/master e16ea04a9 -> 4f380e2a5
Return a Map<String, Object> of unapplied values from the given
Properties object which contains all the values that could not be
applied to the target object.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/4f380e2a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/4f380e2a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/4f380e2a
Branch: refs/heads/master
Commit: 4f380e2a520e593484b89a3cc845d68cab448cd5
Parents: e16ea04
Author: Timothy Bish <ta...@gmail.com>
Authored: Thu Jan 29 15:08:25 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Thu Jan 29 15:08:25 2015 -0500
----------------------------------------------------------------------
.../org/apache/qpid/jms/util/FactoryFinder.java | 2 +-
.../org/apache/qpid/jms/util/PropertyUtil.java | 44 +++++++++++++-------
.../apache/qpid/jms/util/PropertyUtilTest.java | 7 +++-
3 files changed, 35 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/4f380e2a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
index 2678188..3c26559 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
@@ -169,7 +169,7 @@ public class FactoryFinder<T extends Object> {
Object factory = clazz.newInstance();
- if (!PropertyUtil.setProperties(factory, properties)) {
+ if (!PropertyUtil.setProperties(factory, properties).isEmpty()) {
String msg = ""
+ " Not all provider options could be set on the found factory."
+ " Check the options are spelled correctly."
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/4f380e2a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java
index 8cd436c..ecc3fd5 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java
@@ -310,10 +310,10 @@ public class PropertyUtil {
*/
public static boolean setProperties(Object target, Map<String, String> props) {
if (target == null) {
- throw new IllegalArgumentException("target was null.");
+ throw new IllegalArgumentException("target object cannot be null");
}
if (props == null) {
- throw new IllegalArgumentException("props was null.");
+ throw new IllegalArgumentException("Given Properties object cannot be null");
}
int setCounter = 0;
@@ -338,23 +338,23 @@ public class PropertyUtil {
*
* @return true if all values in the props map were applied to the target object.
*/
- public static boolean setProperties(Object target, Properties props) {
+ public static Map<String, Object> setProperties(Object target, Properties props) {
if (target == null) {
- throw new IllegalArgumentException("target was null.");
+ throw new IllegalArgumentException("target object cannot be null");
}
if (props == null) {
- throw new IllegalArgumentException("props was null.");
+ throw new IllegalArgumentException("Given Properties object cannot be null");
}
- int setCounter = 0;
+ Map<String, Object> unmatched = new HashMap<String, Object>();
for (Map.Entry<Object, Object> entry : props.entrySet()) {
- if (setProperty(target, (String) entry.getKey(), entry.getValue())) {
- setCounter++;
+ if (!setProperty(target, (String) entry.getKey(), entry.getValue())) {
+ unmatched.put((String) entry.getKey(), entry.getValue());
}
}
- return setCounter == props.size();
+ return Collections.<String, Object>unmodifiableMap(unmatched);
}
/**
@@ -427,12 +427,20 @@ public class PropertyUtil {
}
/**
- * Set a property
+ * Set a property named property on a given Object.
+ * <p>
+ * The object is searched for an set method that would match the given named
+ * property and if one is found. If necessary an attempt will be made to convert
+ * the new value to an acceptable type.
*
* @param target
+ * The object whose property is to be set.
* @param name
+ * The name of the property to set.
* @param value
- * @return true if set
+ * The new value to set for the named property.
+ *
+ * @return true if the property was able to be set on the target object.
*/
public static boolean setProperty(Object target, String name, Object value) {
try {
@@ -454,7 +462,6 @@ public class PropertyUtil {
if (value == null || value.getClass() == setter.getParameterTypes()[0]) {
setter.invoke(target, new Object[] { value });
} else {
- // We need to convert it
setter.invoke(target, new Object[] { convert(value, setter.getParameterTypes()[0]) });
}
return true;
@@ -482,11 +489,15 @@ public class PropertyUtil {
}
/**
- * Return a String from to a character
+ * Return a portion of a String value by looking beyond the given
+ * character.
*
* @param value
+ * The string value to split
* @param c
- * @return stripped
+ * The character that marks the split point.
+ *
+ * @return the sub-string value starting beyond the given character.
*/
public static String stripUpto(String value, char c) {
String result = null;
@@ -503,8 +514,11 @@ public class PropertyUtil {
* Return a String up to and including character
*
* @param value
+ * The string value to split
* @param c
- * @return stripped
+ * The character that marks the start of split point.
+ *
+ * @return the sub-string value starting from the given character.
*/
public static String stripBefore(String value, char c) {
String result = value;
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/4f380e2a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
index 348d34a..c75914c 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
@@ -438,7 +438,7 @@ public class PropertyUtilTest {
properties.put("firstName", "foo");
properties.put("lastName", "bar");
- assertTrue(PropertyUtil.setProperties(configObject, properties));
+ assertTrue(PropertyUtil.setProperties(configObject, properties).isEmpty());
assertEquals("foo", configObject.getFirstName());
assertEquals("bar", configObject.getLastName());
@@ -468,7 +468,10 @@ public class PropertyUtilTest {
properties.put("lastName", "bar");
properties.put("unused", "absent");
- assertFalse(PropertyUtil.setProperties(configObject, properties));
+ Map<String, Object> result = PropertyUtil.setProperties(configObject, properties);
+
+ assertFalse(result.isEmpty());
+ assertTrue(result.containsKey("unused"));
assertEquals("foo", configObject.getFirstName());
assertEquals("bar", configObject.getLastName());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org