java.lang.Object
gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil

public final class ModelUtil extends Object
  • Field Details

  • Method Details

    • getAnnotation

      @NonNull public static <A extends Annotation> A getAnnotation(@NonNull Class<?> clazz, Class<A> annotationClass)
      Get the requested annotation from the provided Java class.
      Type Parameters:
      A - the annotation Java type
      Parameters:
      clazz - the Java class to get the annotation from
      annotationClass - the annotation class instance
      Returns:
      the annotation
      Throws:
      IllegalArgumentException - if the annotation was not present on the class
    • getAnnotation

      @NonNull public static <A extends Annotation> A getAnnotation(@NonNull Field javaField, Class<A> annotationClass)
      Get the requested annotation from the provided Java field.
      Type Parameters:
      A - the annotation Java type
      Parameters:
      javaField - the Java field to get the annotation from
      annotationClass - the annotation class instance
      Returns:
      the annotation
      Throws:
      IllegalArgumentException - if the annotation was not present on the field
    • resolveNoneOrDefault

      @Nullable public static String resolveNoneOrDefault(@Nullable String value, @Nullable String defaultValue)
      Resolves a string value. If the value is null or "##default", then the provided default value will be used instead. If the value is "##none", then the value will be null. Otherwise, the value is returned.
      Parameters:
      value - the requested value
      defaultValue - the default value
      Returns:
      the resolved value or null
    • resolveNoneOrValue

      @Nullable public static String resolveNoneOrValue(@NonNull String value)
      Get the processed value of a string. If the value is "##none", then the value will be null. Otherwise the value is returned.
      Parameters:
      value - text or "##none" if no text is provided
      Returns:
      the resolved value or null
    • resolveToMarkupLine

      @Nullable public static MarkupLine resolveToMarkupLine(@NonNull String value)
      Get the markup value of a markdown string.
      Parameters:
      value - markdown text or "##none" if no text is provided
      Returns:
      the markup line content or null if no markup content was provided
    • resolveToMarkupMultiline

      @Nullable public static MarkupMultiline resolveToMarkupMultiline(@NonNull String value)
      Get the markup value of a markdown string.
      Parameters:
      value - markdown text or "##none" if no text is provided
      Returns:
      the markup line content or null if no markup content was provided
    • getDataTypeAdapter

      @NonNull public static IDataTypeAdapter<?> getDataTypeAdapter(@NonNull Class<? extends IDataTypeAdapter<?>> adapterClass, @NonNull IBindingContext bindingContext)
      Get the data type adapter instance of the provided adapter class.

      If the provided adapter Java class is the NullJavaTypeAdapter class, then the default data type adapter will be returned.

      Parameters:
      adapterClass - the data type adapter class to get the data type adapter instance for
      bindingContext - the Metaschema binding context used to lookup the data type adapter
      Returns:
      the data type adapter
      Throws:
      IllegalArgumentException - if the provided adapter is not registered with the binding context
    • resolveDefaultValue

      @Nullable public static Object resolveDefaultValue(@NonNull String defaultValue, IDataTypeAdapter<?> adapter)
      Given a provided default value string, get the data type specific default value using the provided data type adapter.

      If the provided default value is NULL_VALUE, then this method will return a null value.

      Parameters:
      defaultValue - the string representation of the default value
      adapter - the data type adapter instance used to cast the default string value to a data type specific object
      Returns:
      the data type specific object or null if the provided default value was NULL_VALUE
    • resolveDefaultInteger

      public static Integer resolveDefaultInteger(int value)
      Resolves an integer value by determining if an actual value is provided or -2^31, which indicates that no actual value was provided.

      The integer value -2^31 cannot be used, since this indicates no value.

      Parameters:
      value - the integer value to resolve
      Returns:
      the integer value or null if the provided value was -2^31
    • resolveDefaultGroupAs

      @NonNull public static IGroupAs resolveDefaultGroupAs(@NonNull GroupAs groupAs, @NonNull IModule module)
      Resolves a GroupAs annotation determining if an actual value is provided or if the value is the default, which indicates that no actual GroupAs was provided.
      Parameters:
      groupAs - the GroupAs value to resolve
      module - the containing module instance
      Returns:
      a new IGroupAs instance or a singleton group as if the provided value was the default value
    • toLocation

      public static String toLocation(@NonNull IBoundObject obj)
    • toLocation

      public static String toLocation(@NonNull IBoundObject obj, @Nullable URI uri)
    • toPropertyEntry

      public static Map.Entry<IAttributable.Key,Set<String>> toPropertyEntry(@NonNull Property property)