Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for view of Map #44

Open
ceharris opened this issue May 5, 2016 · 2 comments
Open

Support for view of Map #44

ceharris opened this issue May 5, 2016 · 2 comments

Comments

@ceharris
Copy link
Member

ceharris commented May 5, 2016

Want to be able to produce a view (or sub-view) based on a map.

@ceharris
Copy link
Member Author

The most important case is that of a map whose values are simple types, submaps, and arrays/lists; i.e. those maps that can be translated directly to JSON or XML. In this case, the view template doesn't need to specify any nodes other than a node for the map itself, and it provides no mechanism to override the behavior of including everything in the map in the view.

@ceharris
Copy link
Member Author

ceharris commented Nov 11, 2016

There are essentially two possible approaches for implementing this:

  1. Add map and arrayOfMaps methods to ViewTemplateBuilder and ViewTemplateBuilderProducer. This will require additional visitMap and visitArrayOfMaps methods on ViewNodeVisitor and all of its implementations, including the visitors used to produce view generators and applicators. And, of course, there will be new generator and applicator implementations needed.
  2. Allow a Map data type for a value node or an element in an arrayOfValues node. This is appealing in that it requires few (if any) API additions/changes, but would be fairly disruptive throughout the runtime implementation. Presently, value nodes and array-of-values nodes assume that the associated datatype(s) can be unambiguously represented as a string, number, or boolean, where as a Map is fundamentally a structure. Consequently, applicators and generators would need new conditional logic, and the necessary changes could cascade all the way down to the view event stream.

In either case, when generating a view, the values in a map will need to be recursively evaluated to determine their representation in the view event stream.

  • values of type Map will need to be represented as objects
  • values of other Collection subtypes and arrays will need to be represented as arrays (of values)
  • values of other types will be transformed to string, number, or boolean representation

When applying a view, if the (declared) data type of a the corresponding view node is a Map, the applicator needs to anticipate a sub-stream of events for an object. Within the sub-stream, the event type (object, array, value) determines what sort of object is to be constructed and injected; i.e. within the sub-stream there are no corresponding view nodes to guide what is injected.

As a map is recursively evaluated, frames will be pushed onto the view context in the same manner as when recursively evaluating the properties of a Java object. This will provide appropriate path information needed by various user-provided add-ons such as converters, URL path template resolvers, etc.

Need to explore how various listeners might be used with map nodes or value nodes with map data types. It seems like property listeners/interceptors are applicable as the "properties" of a map are traversed. The other listener types don't seem applicable. Are other listener types needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant