incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1304387 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
Date Fri, 23 Mar 2012 14:52:52 GMT
Author: justin
Date: Fri Mar 23 14:52:52 2012
New Revision: 1304387

URL: http://svn.apache.org/viewvc?rev=1304387&view=rev
Log:
SLING-2446 - adding BigDecimal property support to JcrPropertyResource

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=1304387&r1=1304386&r2=1304387&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
Fri Mar 23 14:52:52 2012
@@ -19,6 +19,7 @@
 package org.apache.sling.jcr.resource.internal.helper.jcr;
 
 import java.io.InputStream;
+import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Iterator;
 
@@ -39,8 +40,8 @@ import org.slf4j.LoggerFactory;
 
 @Adaptable(adaptableClass = Resource.class, adapters = {
         @Adapter(value = { Item.class, Property.class, Value.class, String.class, Boolean.class,
Long.class,
-                Double.class, Calendar.class, InputStream.class, Value[].class, String[].class,
-                Boolean[].class, Long[].class, Double[].class }),
+                Double.class, BigDecimal.class, Calendar.class, InputStream.class, Value[].class,
String[].class,
+                Boolean[].class, Long[].class, Double[].class, BigDecimal[].class }),
         @Adapter(value = Node.class, condition = "If the resource is a JcrPropertyResource
and the property is a reference or weak reference property.") })
 public class JcrPropertyResource extends JcrItemResource {
 
@@ -103,6 +104,9 @@ public class JcrPropertyResource extends
             } else if (type == Double.class) {
                 return (AdapterType) new Double(getProperty().getDouble());
 
+            } else if (type == BigDecimal.class) {
+                return (AdapterType) getProperty().getDecimal();
+
             } else if (type == Calendar.class) {
                 return (AdapterType) getProperty().getDate();
 
@@ -161,6 +165,17 @@ public class JcrPropertyResource extends
                 }
                 return (AdapterType)new Double[] {getProperty().getDouble()};
 
+            } else if (type == BigDecimal[].class) {
+                if ( getProperty().getDefinition().isMultiple() ) {
+                    final Value[] values = getProperty().getValues();
+                    final BigDecimal[] result = new BigDecimal[values.length];
+                    for(int i=0; i<values.length; i++) {
+                        result[i] = values[i].getDecimal();
+                    }
+                    return (AdapterType)result;
+                }
+                return (AdapterType)new BigDecimal[] {getProperty().getDecimal()};
+
             } else if (type == Calendar[].class) {
                 if ( getProperty().getDefinition().isMultiple() ) {
                     final Value[] values = getProperty().getValues();

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java?rev=1304387&r1=1304386&r2=1304387&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
Fri Mar 23 14:52:52 2012
@@ -21,6 +21,7 @@ package org.apache.sling.jcr.resource.in
 import static org.junit.Assert.assertEquals;
 
 import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.Map.Entry;
 
@@ -53,6 +54,7 @@ public class JcrPropertyResourceTest {
             put("string with ümlaut", PropertyType.STRING);
             put(true, PropertyType.BOOLEAN);
             put(1000L, PropertyType.LONG);
+            put(BigDecimal.TEN, PropertyType.DECIMAL);
         }};
 
         final ResourceResolver resolver = this.context.mock(ResourceResolver.class);



Mime
View raw message