com.ca.commons.datamodel
Interface HasMetadata

All Known Subinterfaces:
DataModelClass, DataModelItem, DataModelNamespace, DataModelProperty
All Known Implementing Classes:
ConcurrentModelClass, ConcurrentNamespace

public interface HasMetadata

A standard interface implemented by classes that have metadata attached to their instances. This provides methods to retrieve the values of attached metadata items. The methods on this interface are designed so that the do not fail with an exception if metadata is missing, or does not match the expected type. If such problems do occur, implementations should log the problem and fall back to returning the default value.


Method Summary
 Object mdObject(String mdName, Object defaultValue)
          Returns the untyped value of a metadata item.
 String mdString(String mdName, String defaultValue)
          Returns the string value of a metadata item.
 com.ca.commons.functional.Option<DataModelValue> mdValue(String mdName)
           
<T> T
mdValue(String mdName, T defaultValue)
          Tries to retrieve the value of the metadata item as a particular type.
<T> T
mdValue(String mdName, T defaultValue, Class<? extends T> type)
          Tries to retrieve the value of a metadata item as a particular type.
 

Method Detail

mdObject

@Nullable
Object mdObject(@NotNull
                         String mdName,
                         @Nullable
                         Object defaultValue)
Returns the untyped value of a metadata item. This is a shortcut for mdValue(mdName, defaultValue, Object.class).

Parameters:
mdName - The name of the metadata item.
defaultValue - A default value to return if the named item is not found.
Returns:
The metadata item's value, or the default value if no matching item was found.
See Also:
mdValue(String, Object, Class)

mdString

@Nullable
String mdString(@NotNull
                         String mdName,
                         @Nullable
                         String defaultValue)
Returns the string value of a metadata item. This is a shortcut for mdValue(mdName, defaultValue, String.class).

Parameters:
mdName - The name of the metadata item.
defaultValue - A default value to return if the named item is not found, or its value is not a string.
Returns:
The metadata item's value, or the default value if no matching item was found.
See Also:
mdValue(String, Object, Class)

mdValue

@NotNull
<T> T mdValue(@NotNull
                      String mdName,
                      @NotNull
                      T defaultValue)
Tries to retrieve the value of the metadata item as a particular type. This method requires a non-null default, and uses the class of the default value to determine the type of value expected by the caller. It is roughly equivalent to mdValue(mdName, defaultValue, defaultValue.getClass()).

Parameters:
mdName - The name of the metadata item to retrieve.
defaultValue - The default value to return if the metadata item cannot be retrieved. Also indicates the type of value expected by the caller.
Returns:
The metadata value, or the default value if no matching item was found, or the value had a different type.
See Also:
mdValue(String, Object, Class)

mdValue

@Nullable
<T> T mdValue(@NotNull
                       String mdName,
                       @Nullable
                       T defaultValue,
                       @NotNull
                       Class<? extends T> type)
Tries to retrieve the value of a metadata item as a particular type. If the metadata item does not exist, or is not of a type compatible with the expected type, then the default value (possibly null) is returned.

Parameters:
mdName - The name of the metadata item to retrieve.
defaultValue - The default value to return if the metadata item cannot be retrieved.
type - A class object indicating the type of the value that is expected.
Returns:
The metadata value, or the default value if no matching item was found, or the value had a different type. If the returned value is not null, type.isInstance(returnedValue) is always true.

mdValue

@NotNull
com.ca.commons.functional.Option<DataModelValue> mdValue(@NotNull
                                                                 String mdName)


Created 2011-07-14 13:27 EST