Class MandatoryIfOtherFieldEmpty

java.lang.Object
com.apgar.common.lib.constraint.BundledConstraint
com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty
All Implemented Interfaces:
com.orchestranetworks.schema.Constraint<Object>, com.orchestranetworks.schema.ConstraintOnNull, com.orchestranetworks.schema.JavaBeanVersion

public class MandatoryIfOtherFieldEmpty extends BundledConstraint implements com.orchestranetworks.schema.Constraint<Object>, com.orchestranetworks.schema.ConstraintOnNull
Constraint that checks if one field is filled, the other field should be empty. Both fields cannot be empty.

The error message and/or information message created in the error.properties and text.properties files respectively will be displayed if the constraint is not verified.

  • error.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty You must either enter field '{0}' or '{1}' but not both
  • text.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty You must either enter field '{0}' or '{1}' but not both
  • error.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty.nullCase Field '{0}' and '{1}' cannot both be empty
  • text.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty.nullCase Field '{0}' and '{1}' cannot both be empty

This constraint is defined in the XSD under the field and takes for argument the path of the second field to be compared to.

 <xs:element name="sampleField" minOccurs="0" maxOccurs="1">
     <xs:annotation>
         <xs:documentation xml:lang="en-US">
             <osd:label>Sample Field</osd:label>
         </xs:documentation>
         <xs:appinfo>
             <osd:otherFacets>
             <osd:constraint class="com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty">
                 <otherFieldPath>../otherField</otherFieldPath>
                 <bothNullEndKeysProperty>nullCase</bothNullEndKeysProperty>
             </osd:constraint>
             </osd:otherFacets>
         </xs:appinfo>
     </xs:annotation>
 </xs:element>
 
Author:
APGAR Consulting
  • Constructor Details

    • MandatoryIfOtherFieldEmpty

      public MandatoryIfOtherFieldEmpty()
  • Method Details

    • checkOccurrence

      public void checkOccurrence(Object field, com.orchestranetworks.instance.ValueContextForValidation valueContext) throws com.orchestranetworks.schema.InvalidSchemaException
      Checks if field is empty and raise warnings/errors accordingly
      Specified by:
      checkOccurrence in interface com.orchestranetworks.schema.Constraint<Object>
      Throws:
      com.orchestranetworks.schema.InvalidSchemaException
    • checkNull

      public void checkNull(com.orchestranetworks.instance.ValueContextForValidation valueContext) throws com.orchestranetworks.schema.InvalidSchemaException
      Checks if both fields are null and raise warnings/errors accordingly
      Specified by:
      checkNull in interface com.orchestranetworks.schema.ConstraintOnNull
      Throws:
      com.orchestranetworks.schema.InvalidSchemaException
    • setup

      public void setup(com.orchestranetworks.schema.ConstraintContext context)
      Specified by:
      setup in interface com.orchestranetworks.schema.Constraint<Object>
    • toUserDocumentation

      public String toUserDocumentation(Locale locale, com.orchestranetworks.instance.ValueContext valueContext) throws com.orchestranetworks.schema.InvalidSchemaException
      Returns constraint message
      Specified by:
      toUserDocumentation in interface com.orchestranetworks.schema.Constraint<Object>
      Throws:
      com.orchestranetworks.schema.InvalidSchemaException
    • setOtherFieldPath

      public void setOtherFieldPath(String otherFieldPath)
      Sets the setOtherFieldPath field
      Parameters:
      otherFieldPath - Other field checked by constraint
    • setBothNullEndKeysProperty

      public void setBothNullEndKeysProperty(String bothNullEndKeysProperty)
      Sets the setBothNullEndKeysProperty field
      Parameters:
      bothNullEndKeysProperty - property for both fields null
    • setEndKeysProperty

      public void setEndKeysProperty(String endKeysProperty)
      Sets the endKeysProperty
      Parameters:
      endKeysProperty - endKeysProperty
    • getOtherFieldPath

      public String getOtherFieldPath()
      Gets the other field path
      Returns:
      String the other field path
    • getBothNullEndKeysProperty

      public String getBothNullEndKeysProperty()
      Gets the bothNullEndKeysProperty field
      Returns:
      String bothNullEndKeysProperty field
    • getEndKeysProperty

      public String getEndKeysProperty()
      Gets the endKeysProperty field
      Returns:
      String endKeysProperty field