Class ValidationSupport


  • public final class ValidationSupport
    extends java.lang.Object
    Static helper methods for validating model objects during construction
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkCode​(java.lang.String s)
      A string which has at least one character and no leading or trailing whitespace and where there is no whitespace other than single spaces in the contents.
      static void checkId​(java.lang.String s)
      Any combination of letters, numerals, "-" and ".", with a length limit of 64 characters.
      static <T> java.util.List<T> checkList​(java.util.List<T> elements, java.lang.String elementName, java.lang.Class<T> type)  
      static void checkMaxLength​(java.lang.String value)  
      static void checkMinLength​(java.lang.String value)  
      static <T> java.util.List<T> checkNonEmptyList​(java.util.List<T> elements, java.lang.String elementName, java.lang.Class<T> type)  
      static void checkReferenceType​(java.util.List<Reference> reference, java.lang.String elementName, java.lang.String... referenceTypes)  
      static void checkReferenceType​(Element choiceElement, java.lang.String elementName, java.lang.String... referenceTypes)  
      static void checkReferenceType​(Reference reference, java.lang.String elementName, java.lang.String... referenceTypes)
      Checks that the reference contains valid resource type values.
      static void checkString​(java.lang.String s)
      A sequence of Unicode characters
      static void checkUri​(java.lang.String s)
      String of characters used to identify a name or a resource
      static void checkValue​(java.lang.Integer value, int minValue)  
      static void checkValue​(java.lang.String value, java.util.regex.Pattern pattern)  
      static void checkValueSetBinding​(java.util.List<? extends Element> elements, java.lang.String elementName, java.lang.String valueSet, java.lang.String system, java.lang.String... valueSetCodes)
      Check that the specified list of elements contain a code that is a member of the specified value set.
      static void checkValueSetBinding​(Element element, java.lang.String elementName, java.lang.String valueSet, java.lang.String system, java.lang.String... codes)
      Check that the specified element contains a code that is a member of the specified value set.
      static <T> T checkValueType​(T value, java.lang.Class<?>... types)  
      static void checkXHTMLContent​(java.lang.String value)  
      static <T extends Element>
      T
      choiceElement​(T element, java.lang.String elementName, java.lang.Class<?>... types)  
      static boolean hasOnlyDataAbsentReasonExtension​(Element element)  
      static <T extends Element>
      void
      prohibited​(java.util.List<T> elements, java.lang.String elementName)  
      static void prohibited​(Element element, java.lang.String elementName)  
      static <T extends Element>
      T
      requireChoiceElement​(T element, java.lang.String elementName, java.lang.Class<?>... types)  
      static <T> T requireNonNull​(T element, java.lang.String elementName)  
      static void requireValueOrChildren​(Element element)  
      static void validateBase64EncodedString​(java.lang.String value)  
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ALL_LANG_VALUE_SET_URL

        public static final java.lang.String ALL_LANG_VALUE_SET_URL
        See Also:
        Constant Field Values
      • UCUM_UNITS_VALUE_SET_URL

        public static final java.lang.String UCUM_UNITS_VALUE_SET_URL
        See Also:
        Constant Field Values
      • UCUM_CODE_SYSTEM_URL

        public static final java.lang.String UCUM_CODE_SYSTEM_URL
        See Also:
        Constant Field Values
      • DATA_ABSENT_REASON_EXTENSION_URL

        public static final java.lang.String DATA_ABSENT_REASON_EXTENSION_URL
        See Also:
        Constant Field Values
    • Method Detail

      • checkString

        public static void checkString​(java.lang.String s)
        A sequence of Unicode characters
         pattern:  [ \r\n\t\S]+
         
        Throws:
        java.lang.IllegalStateException - if the passed String is not a valid FHIR String value
      • checkCode

        public static void checkCode​(java.lang.String s)
        A string which has at least one character and no leading or trailing whitespace and where there is no whitespace other than single spaces in the contents.
         pattern:  [^\s]+(\s[^\s]+)*
         
        Throws:
        java.lang.IllegalStateException - if the passed String is not a valid FHIR Code value
      • checkId

        public static void checkId​(java.lang.String s)
        Any combination of letters, numerals, "-" and ".", with a length limit of 64 characters. (This might be an integer, an unprefixed OID, UUID or any other identifier pattern that meets these constraints.) Ids are case-insensitive.
         pattern:  [A-Za-z0-9\-\.]{1,64}
         
        Throws:
        java.lang.IllegalStateException - if the passed String is not a valid FHIR Id value
      • checkUri

        public static void checkUri​(java.lang.String s)
        String of characters used to identify a name or a resource
         pattern:  \S*
         
        Throws:
        java.lang.IllegalStateException - if the passed String is not a valid FHIR uri value
      • checkMaxLength

        public static void checkMaxLength​(java.lang.String value)
        Throws:
        java.lang.IllegalStateException - if the passed String is longer than the maximum string length
      • checkMinLength

        public static void checkMinLength​(java.lang.String value)
        Throws:
        java.lang.IllegalStateException - if the passed String is shorter than the minimum string length
      • checkValue

        public static void checkValue​(java.lang.Integer value,
                                      int minValue)
        Throws:
        java.lang.IllegalStateException - if the passed Integer value is less than the passed minValue
      • checkValue

        public static void checkValue​(java.lang.String value,
                                      java.util.regex.Pattern pattern)
        Throws:
        java.lang.IllegalStateException - if the passed String value does not match the passed pattern
      • checkValueType

        public static <T> T checkValueType​(T value,
                                           java.lang.Class<?>... types)
        Throws:
        java.lang.IllegalStateException - if the type of the passed value is not one of the passed types
      • choiceElement

        public static <T extends Element> T choiceElement​(T element,
                                                          java.lang.String elementName,
                                                          java.lang.Class<?>... types)
        Throws:
        java.lang.IllegalStateException - if the type of the passed element is not one of the passed types
      • checkXHTMLContent

        public static void checkXHTMLContent​(java.lang.String value)
        Throws:
        java.lang.IllegalStateException - if the passed String value is not valid XHTML
      • requireChoiceElement

        public static <T extends Element> T requireChoiceElement​(T element,
                                                                 java.lang.String elementName,
                                                                 java.lang.Class<?>... types)
        Throws:
        java.lang.IllegalStateException - if the passed element is null or if its type is not one of the passed types
      • requireNonNull

        public static <T> T requireNonNull​(T element,
                                           java.lang.String elementName)
        Throws:
        java.lang.IllegalStateException - if the passed element is null
      • checkNonEmptyList

        public static <T> java.util.List<T> checkNonEmptyList​(java.util.List<T> elements,
                                                              java.lang.String elementName,
                                                              java.lang.Class<T> type)
        Returns:
        the same list that was passed
        Throws:
        java.lang.IllegalStateException - if the passed list is empty or contains any null objects or objects of an incompatible type
      • checkList

        public static <T> java.util.List<T> checkList​(java.util.List<T> elements,
                                                      java.lang.String elementName,
                                                      java.lang.Class<T> type)
        Returns:
        the same list that was passed
        Throws:
        java.lang.IllegalStateException - if the passed list contains any null objects or objects of an incompatible type
      • requireValueOrChildren

        public static void requireValueOrChildren​(Element element)
        Throws:
        java.lang.IllegalStateException - if the passed element has no value and no children
      • prohibited

        public static void prohibited​(Element element,
                                      java.lang.String elementName)
        Throws:
        java.lang.IllegalStateException - if the passed element is not null
      • prohibited

        public static <T extends Element> void prohibited​(java.util.List<T> elements,
                                                          java.lang.String elementName)
        Throws:
        java.lang.IllegalStateException - if the passed list is not empty
      • checkValueSetBinding

        public static void checkValueSetBinding​(java.util.List<? extends Element> elements,
                                                java.lang.String elementName,
                                                java.lang.String valueSet,
                                                java.lang.String system,
                                                java.lang.String... valueSetCodes)
        Check that the specified list of elements contain a code that is a member of the specified value set.
        Parameters:
        elements - the list of elements for which to check codes
        elementName - the name of the element
        valueSet - the URL of the value set to check membership against
        system - the value set system
        codes - the value set codes
        Throws:
        IllegalStateExeption - if each element in the list does not include a code from the required value set
      • checkValueSetBinding

        public static void checkValueSetBinding​(Element element,
                                                java.lang.String elementName,
                                                java.lang.String valueSet,
                                                java.lang.String system,
                                                java.lang.String... codes)
        Check that the specified element contains a code that is a member of the specified value set.
        Parameters:
        element - the element for which to check codes
        elementName - the name of the element
        valueSet - the URL of the value set to check membership against
        system - the value set system
        codes - the value set codes
        Throws:
        IllegalStateExeption - if the element does not include a code from the required value set
      • checkReferenceType

        public static void checkReferenceType​(java.util.List<Reference> reference,
                                              java.lang.String elementName,
                                              java.lang.String... referenceTypes)
        Throws:
        java.lang.IllegalStateException - if the resource type found in one or more reference values does not match the specified Reference.type value or is not one of the allowed reference types for that element
      • checkReferenceType

        public static void checkReferenceType​(Element choiceElement,
                                              java.lang.String elementName,
                                              java.lang.String... referenceTypes)
        Throws:
        java.lang.IllegalStateException - if the choiceElement is a Reference and the reference value does not match the specified Reference.type value or is not one of the allowed reference types for that element
      • checkReferenceType

        public static void checkReferenceType​(Reference reference,
                                              java.lang.String elementName,
                                              java.lang.String... referenceTypes)
        Checks that the reference contains valid resource type values.
        Parameters:
        reference - the reference
        elementName - the element name
        referenceTypes - the valid resource types for the reference
        Throws:
        java.lang.IllegalStateException - if the resource type found in the reference value does not match the specified Reference.type value or is not one of the allowed reference types for that element
      • validateBase64EncodedString

        public static void validateBase64EncodedString​(java.lang.String value)
      • hasOnlyDataAbsentReasonExtension

        public static boolean hasOnlyDataAbsentReasonExtension​(Element element)