From d479253768d296a40b4f699e1de9b03c7146a97a Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 3 Dec 2013 14:03:28 -0800 Subject: Adding javadocs and Carbonado User Guide --- .../carbonado/constraint/ConstraintDefinition.html | 288 +++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 apidocs/com/amazon/carbonado/constraint/ConstraintDefinition.html (limited to 'apidocs/com/amazon/carbonado/constraint/ConstraintDefinition.html') diff --git a/apidocs/com/amazon/carbonado/constraint/ConstraintDefinition.html b/apidocs/com/amazon/carbonado/constraint/ConstraintDefinition.html new file mode 100644 index 0000000..0b5234b --- /dev/null +++ b/apidocs/com/amazon/carbonado/constraint/ConstraintDefinition.html @@ -0,0 +1,288 @@ + + + + + + +ConstraintDefinition (Carbonado 1.2.3 API) + + + + + + + +
+ + + + + +
+ + + +
+
com.amazon.carbonado.constraint
+

Annotation Type ConstraintDefinition

+
+
+
+
    +
  • +
    +
    +
    @Documented
    +@Retention(value=RUNTIME)
    +@Target(value=ANNOTATION_TYPE)
    +public @interface ConstraintDefinition
    +
    Allows annotations to be defined that restrict property values. The + annotation is just a pointer to a constraint checking class. If the + constraint class is not explicitly provided, it defaults to a static inner + class named "Constraint" in the annotation itself. + +

    The constraint class must have a public constructor that accepts the + annotation that has the ConstraintDefinition annotation. It must also define + several "constrain" methods which perform constraint checks on specific + property types. +

    + Example integer constraint: +

    + @Documented
    + @Retention(RetentionPolicy.RUNTIME)
    + @Target(ElementType.METHOD)
    + @ConstraintDefinition
    + public @interface IntegerConstraint {
    +     int min() default Integer.MIN_VALUE;
    +
    +     int max() default Integer.MAX_VALUE;
    +
    +     public static class Constraint {
    +         private final String propertyName;
    +         private final int min;
    +         private final int max;
    +
    +         // Constructor may throw a MalformedTypeException if
    +         // params supplied by annotation are illegal.
    +
    +         /**
    +          * @param type optional type of object that contains the constrained property
    +          * @param propertyName name of property with constraint
    +          * @param annotation specific annotation that binds to this constraint class
    +          */
    +         public Constraint(Class type, String propertyName, IntegerConstraint annotation) {
    +             this.propertyName = propertyName;
    +             this.min = annotation.min();
    +             this.max = annotation.max();
    +         }
    +
    +         // Define a constrain method for each supported property type.
    +
    +         /**
    +          * @param propertyValue specific value to constrain
    +          */
    +         public void constrain(int propertyValue) throws IllegalArgumentException {
    +             if (propertyValue < min || propertyValue > max) {
    +                 throw new IllegalArgumentException
    +                     ("Value for \"" + propertyName + "\" must be in range " +
    +                      min + ".." + max + ": " + propertyValue);
    +             }
    +         }
    +     }
    + }
    + 
    + + The newly defined integer constraint can be applied to property mutators. + +
    + public interface UserInfo extends Storable {
    +     ...
    +
    +     int getAge();
    +     // Constraint is called before setting age.
    +     @IntegerConstraint(min=0, max=120)
    +     void setAge(int value);
    + }
    + 
    +
    Author:
    +
    Brian S O'Neill
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Optional Element Summary

      + + + + + + + + + + +
      Optional Elements 
      Modifier and TypeOptional Element and Description
      java.lang.Classimplementation +
      Specify class which will perform constraint checking.
      +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Element Detail

      + + + +
        +
      • +

        implementation

        +
        public abstract java.lang.Class implementation
        +
        Specify class which will perform constraint checking. Must have a public + constructor with the signature + (Class type, String propertyName, Annotation), + where Annotation refers to the annotation with the + constraint definition. + +

        The implementation class need not be explicitly specified. By + default, the constraint class must be a static inner class of the + annotation, named "Constraint".

        +
        +
        Default:
        +
        void.class
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + +
+ + + + + +
+ + +

Copyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.

+ + -- cgit v1.2.3