Author: fmeschbe
Date: Wed Sep 17 06:45:47 2008
New Revision: 696291
URL: http://svn.apache.org/viewvc?rev=696291&view=rev
Log:
SLING-662 Implemented transparent support for arrays and multi-value properties
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=696291&r1=696290&r2=696291&view=diff
==============================================================================
---
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
(original)
+++
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Wed Sep 17 06:45:47 2008
@@ -237,6 +237,8 @@
@SuppressWarnings("unchecked")
private <T> T convertToType(String name, Class<T> type) {
+ T result = null;
+
try {
if (node.hasProperty(name)) {
Property prop = node.getProperty(name);
@@ -244,11 +246,33 @@
boolean multiValue = prop.getDefinition().isMultiple();
boolean array = type.isArray();
- if (array && multiValue) {
- return (T) convertToArray(prop, prop.getValues(),
- type.getComponentType());
- } else if (!array && !multiValue) {
- return convertToType(prop, -1, prop.getValue(), type);
+ if (multiValue) {
+
+ Value[] values = prop.getValues();
+ if (array) {
+
+ result = (T) convertToArray(prop, values,
+ type.getComponentType());
+
+ } else if (values.length > 0) {
+
+ result = convertToType(prop, -1, values[0], type);
+
+ }
+
+ } else {
+
+ Value value = prop.getValue();
+ if (array) {
+
+ result = (T) convertToArray(prop,
+ new Value[] { value }, type.getComponentType());
+
+ } else {
+
+ result = convertToType(prop, -1, value, type);
+
+ }
}
}
@@ -260,7 +284,7 @@
}
// fall back to nothing
- return null;
+ return result;
}
private <T> T[] convertToArray(Property p, Value[] jcrValues, Class<T>
type)