You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/09/19 15:16:30 UTC
svn commit: r697083 -
/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Author: fmeschbe
Date: Fri Sep 19 06:16:30 2008
New Revision: 697083
URL: http://svn.apache.org/viewvc?rev=697083&view=rev
Log:
SLING-602 Add support for well-known Java Types: byte, short, integer,
float and Date.
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=697083&r1=697082&r2=697083&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 Fri Sep 19 06:16:30 2008
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
+import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -82,6 +83,8 @@
Class<T> type = (Class<T>) defaultValue.getClass();
if (Calendar.class.isAssignableFrom(type)) {
type = (Class<T>) Calendar.class;
+ } else if (Date.class.isAssignableFrom(type)) {
+ type = (Class<T>) Date.class;
} else if (Value.class.isAssignableFrom(type)) {
type = (Class<T>) Value.class;
}
@@ -309,6 +312,16 @@
if (String.class == type) {
return (T) jcrValue.getString();
+
+ } else if (Byte.class == type) {
+ return (T) new Byte((byte) jcrValue.getLong());
+
+ } else if (Short.class == type) {
+ return (T) new Short((short) jcrValue.getLong());
+
+ } else if (Integer.class == type) {
+ return (T) new Integer((int) jcrValue.getLong());
+
} else if (Long.class == type) {
if ( jcrValue.getType() == PropertyType.BINARY ) {
if ( index == -1 ) {
@@ -317,12 +330,22 @@
return (T)new Long(p.getLengths()[index]);
}
return (T) new Long(jcrValue.getLong());
+
+ } else if (Float.class == type) {
+ return (T) new Float(jcrValue.getDouble());
+
} else if (Double.class == type) {
return (T) new Double(jcrValue.getDouble());
+
} else if (Boolean.class == type) {
return (T) Boolean.valueOf(jcrValue.getBoolean());
+
+ } else if (Date.class == type) {
+ return (T) jcrValue.getDate().getTime();
+
} else if (Calendar.class == type) {
return (T) jcrValue.getDate();
+
} else if (Value.class == type) {
return (T) jcrValue;
}