You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ke...@apache.org on 2005/02/11 01:41:55 UTC
svn commit: r153307 - in incubator/beehive/trunk/controls:
src/api/org/apache/beehive/controls/api/bean/
src/runtime/org/apache/beehive/controls/runtime/bean/
test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/
Author: kentam
Date: Thu Feb 10 16:41:53 2005
New Revision: 153307
URL: http://svn.apache.org/viewcvs?view=rev&rev=153307
Log:
Allow the AnnotationMemberTypes.Decimal to be applied to members that return float, double or String. Resolves BEEHIVE-203.
Contributor: Hoi Lam
Modified:
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
Modified: incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java?view=diff&r1=153306&r2=153307
==============================================================================
--- incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java (original)
+++ incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java Thu Feb 10 16:41:53 2005
@@ -88,16 +88,15 @@
/**
* Member is a Decimal Value.
- * Member must be a String
- * REVIEW: should allow floats
+ * Can be applied to a member that returns float, double or String.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Decimal
{
int places() default 0;
- String minValue() default "";
- String maxValue() default "";
+ double minValue() default OPTIONAL_DOUBLE;
+ double maxValue() default OPTIONAL_DOUBLE;
}
/**
Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java?view=diff&r1=153306&r2=153307
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java (original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java Thu Feb 10 16:41:53 2005
@@ -404,8 +404,9 @@
boolean optional)
{
if (optional
- && (value == null || value
- .equals(AnnotationMemberTypes.OPTIONAL_INT)))
+ && (value == null ||
+ value.equals(AnnotationMemberTypes.OPTIONAL_STRING) ||
+ value.equals(AnnotationMemberTypes.OPTIONAL_INT)))
return;
int intValue = 0;
@@ -450,47 +451,56 @@
Object value, boolean optional)
{
if (optional
- && (value == null || value
- .equals(AnnotationMemberTypes.OPTIONAL_STRING)))
+ && (value == null ||
+ value.equals(AnnotationMemberTypes.OPTIONAL_STRING) ||
+ value.equals(AnnotationMemberTypes.OPTIONAL_FLOAT) ||
+ value.equals(AnnotationMemberTypes.OPTIONAL_DOUBLE)))
return;
- if (!(value instanceof String))
+ double doubleValue = 0;
+ String doubleString = null;
+
+ if (value instanceof String)
{
- error("Value assigned to a decimal property must be of type java.lang.String.");
+ doubleValue = Double.parseDouble((String)value);
+ doubleString = (String)value;
}
-
- String str = (String) value;
-
- try
+ else if (value instanceof Float)
{
- long num = Long.parseLong(str);
-
- if (num < Long.parseLong(a.minValue()))
- error("The value, "
- + num
- + ", assigned to a decimal property is less than the the minimum value allowed: "
- + a.minValue() + ".");
-
- if (num > Long.parseLong(a.maxValue()))
- error("The value, "
- + num
- + ", assigned to a decimal property exceeds the maximum value allowed: "
- + a.maxValue() + ".");
+ doubleValue = ((Float)value).doubleValue();
+ doubleString = ((Float)value).toString();
+ }
+ else if (value instanceof Double)
+ {
+ doubleValue = ((Double)value).doubleValue();
+ doubleString = ((Double)value).toString();
}
- catch (NumberFormatException nfe)
+ else
{
error("The value, "
- + str
- + ", assigned to a decimal property does not represent a number.");
+ + value
+ + ", assigned to a decimal property must be of type float, double, or java.lang.String.");
}
- int decimalPos = str.indexOf('.');
+ if (doubleValue < a.minValue())
+ error("The value, "
+ + doubleValue
+ + ", assigned to a decimal property is less than the the minimum value allowed: "
+ + a.minValue() + ".");
+
+ if (doubleValue > a.maxValue())
+ error("The value, "
+ + doubleValue
+ + ", assigned to a decimal property exceeds the maximum value allowed: "
+ + a.maxValue() + ".");
+
+ int decimalPos = doubleString.indexOf('.');
if (decimalPos == -1)
return;
- if (str.length() - decimalPos - 1 > a.places())
- error("The decimal places in the value, " + str
+ if (doubleString.length() - decimalPos - 1 > a.places())
+ error("The decimal places in the value, " + doubleString
+ ", assigned to a decimal property exceeds " + a.places()
+ ", the number of decimal places allowed.");
Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java?view=diff&r1=153306&r2=153307
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java (original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java Thu Feb 10 16:41:53 2005
@@ -24,11 +24,11 @@
@AnnotationConstraints.MembershipRule(AnnotationConstraints.MembershipRuleValues.AT_LEAST_ONE)
public @interface Price
{
- @AnnotationMemberTypes.Decimal(minValue="10")
+ @AnnotationMemberTypes.Decimal(minValue=10)
public String us_price();
- @AnnotationMemberTypes.Decimal(minValue="10")
+ @AnnotationMemberTypes.Decimal(minValue=10)
public String ca_price();
- @AnnotationMemberTypes.Decimal(minValue="10")
+ @AnnotationMemberTypes.Decimal(minValue=10)
public String eu_price();
}
Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java?view=diff&r1=153306&r2=153307
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java (original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java Thu Feb 10 16:41:53 2005
@@ -18,7 +18,7 @@
public interface PersonControl
{
- public final static String SAVINGS_MIN_VALUE="100";
+ public final static double SAVINGS_MIN_VALUE=100;
public final static String ISSUEDATE_MAXVALUE="2007/01/31";
public final static String EXPIRYDATE_MINVALUE="2007/01/32";
//public final static String ISSUEDATE_MAXVALUE=null;
@@ -50,7 +50,7 @@
public @interface Assets
{
//JIRA-203 AnnotationMemberTypes.Decimal should support float
- @AnnotationMemberTypes.Decimal(places=2, minValue=SAVINGS_MIN_VALUE, maxValue="10000")
+ @AnnotationMemberTypes.Decimal(places=2, minValue=SAVINGS_MIN_VALUE, maxValue=10000)
public String savings() default "0";
}