Class ModelUtil
java.lang.Object
gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A extends Annotation>
AgetAnnotation
(Class<?> clazz, Class<A> annotationClass) Get the requested annotation from the provided Java class.static <A extends Annotation>
AgetAnnotation
(Field javaField, Class<A> annotationClass) Get the requested annotation from the provided Java field.static IDataTypeAdapter<?>
getDataTypeAdapter
(Class<? extends IDataTypeAdapter<?>> adapterClass, IBindingContext bindingContext) Get the data type adapter instance of the provided adapter class.static IGroupAs
resolveDefaultGroupAs
(GroupAs groupAs, IModule module) Resolves aGroupAs
annotation determining if an actual value is provided or if the value is the default, which indicates that no actual GroupAs was provided.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.static Object
resolveDefaultValue
(String defaultValue, IDataTypeAdapter<?> adapter) Given a provided default value string, get the data type specific default value using the provided data type adapter.static String
resolveNoneOrDefault
(String value, String defaultValue) Resolves a string value.static String
resolveNoneOrValue
(String value) Get the processed value of a string.static MarkupLine
resolveToMarkupLine
(String value) Get the markup value of a markdown string.static MarkupMultiline
resolveToMarkupMultiline
(String value) Get the markup value of a markdown string.static String
toLocation
(IBoundObject obj) static String
toLocation
(IBoundObject obj, URI uri) static Map.Entry<IAttributable.Key,
Set<String>> toPropertyEntry
(Property property)
-
Field Details
-
NO_STRING_VALUE
- See Also:
-
DEFAULT_STRING_VALUE
- See Also:
-
NULL_VALUE
A placeholder for anull
value for use in annotations, which cannot be null by default.Use of
" "
simple substitute fornull
to allow implementations to recognize the "no default value" state.- See Also:
-
-
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 fromannotationClass
- 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 fromannotationClass
- 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 isnull
or "##default", then the provided default value will be used instead. If the value is "##none", then the value will benull
. Otherwise, the value is returned.- Parameters:
value
- the requested valuedefaultValue
- the default value- Returns:
- the resolved value or
null
-
resolveNoneOrValue
Get the processed value of a string. If the value is "##none", then the value will benull
. Otherwise the value is returned.- Parameters:
value
- text or"##none"
if no text is provided- Returns:
- the resolved value or
null
-
resolveToMarkupLine
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
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 forbindingContext
- 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 anull
value.- Parameters:
defaultValue
- the string representation of the default valueadapter
- 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 wasNULL_VALUE
-
resolveDefaultInteger
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 aGroupAs
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 resolvemodule
- the containing module instance- Returns:
- a new
IGroupAs
instance or a singleton group as if the provided value was the default value
-
toLocation
-
toLocation
-
toPropertyEntry
-