Class ModelViewer
- java.lang.Object
-
- de.aristaflow.adept2.model.common.viewer.ModelViewer
-
public class ModelViewer extends Object
Allows the creation of typed views on attribute maps.Constraints for the view:
TODO unset attributes: return default values? "not-existing-value" like e.g. INTEGER_MIN_VALUE? => define values!
TODO exception handling: external handler, default handlers... above -> default values?
TODO annotation for the interface, e.g. a description etc.
- Author:
- Kevin Goeser
-
-
Field Summary
Fields Modifier and Type Field Description protected static Set<Class<?>>
allowedConsumerTypes
The set of types which are allowed to beSystemDataConsumer
.protected static Set<Class<?>>
allowedTypes
Set of types, which are allowed as return values and parameters.static Class<?>[]
allowedTypesArray
Array of types, which are allowed as return values and parameters.
-
Constructor Summary
Constructors Constructor Description ModelViewer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V> V
createNew(Class<V> view)
Create a new, empty view for performing changes.static <V> V
createView(Map<String,String> attributes, Class<V> view)
Creates a new view on the given data, implementing the given interface.protected static <V> V
createView(Map<String,String> attributes, Class<V> view, String prefix, Locale locale)
Creates a translating view, returning the values for the given locale.static <V> V
createView(Map<String,String> attributes, Class<V> view, Locale locale)
Creates a new view on the given data, implementing the given interface.
-
-
-
Field Detail
-
allowedTypesArray
public static final Class<?>[] allowedTypesArray
Array of types, which are allowed as return values and parameters.
-
allowedTypes
protected static final Set<Class<?>> allowedTypes
Set of types, which are allowed as return values and parameters.
-
allowedConsumerTypes
protected static final Set<Class<?>> allowedConsumerTypes
The set of types which are allowed to beSystemDataConsumer
.
-
-
Method Detail
-
createView
public static <V> V createView(Map<String,String> attributes, Class<V> view)
Creates a new view on the given data, implementing the given interface.The interface needs to match the constraints provided in the class description of
ModelViewer
.- Type Parameters:
V
- The type of the view.- Parameters:
attributes
- The data for the view.view
- The view interface.- Returns:
- A view of type
view
on the attributes. The returned object must only be accessed via the designated view interface!
-
createView
public static <V> V createView(Map<String,String> attributes, Class<V> view, Locale locale)
Creates a new view on the given data, implementing the given interface.The interface needs to match the constraints provided in the class description of
ModelViewer
.- Type Parameters:
V
- The type of the view.- Parameters:
attributes
- The data for the view.view
- The view interface.locale
- The locale for a translated view.- Returns:
- A view of type
view
on the attributes. The returned object must only be accessed via the designated view interface!
-
createNew
public static <V> V createNew(Class<V> view)
Create a new, empty view for performing changes. This is useful for creating views of nested views, ie. where the view object itself is set into another view.
When connecting the created view to the parent view (calling the appropriate set-method), only a copy of the new view will be added to the parent. If you need the very same nested object, retrieve it from the parent right after connecting it and replace the created view with the retrieved one.- Type Parameters:
V
-- Parameters:
view
-- Returns:
- A new view with an empty attribute map.
-
createView
protected static <V> V createView(Map<String,String> attributes, Class<V> view, String prefix, Locale locale)
Creates a translating view, returning the values for the given locale.- Type Parameters:
V
-- Parameters:
attributes
-view
-prefix
- Prefix, if not "", it must end with a '.'.locale
-- Returns:
-
-