Skip to content
Ruben Taelman edited this page May 9, 2018 · 2 revisions

Goals

The main goal of this small vocabulary is for describing the mapping between declarative object instantiations in the object-oriented components vocabulary and JavaScript/JSON objects, so that it can be used in a semantic dependency injection framework to instantiate objects, such as Components.js.

Design

The main requirement was that it should be able to describe JavaScript/JSON values objects. We designed the vocabulary in such a way that it can also be used for other object-oriented programming languages.

Requirements:

  1. Define an object with fields and values
  2. Define an array with values
  3. Values can either be literals, or they can refer to other mappable entries

Method

This vocabulary was created in conjunction with the development of Components.js.

We first defined om:ObjectMapping as a root mapping type, which is responsible for linking with all the mapping properties. Similarly, om:ArrayMapping is defined as a subtype to indicate the object being an array, just like in JavaScript.

A om:ObjectMapping can have multiple om:field properties, which has as range a om:ObjectMappingEntry. This entry has a om:fieldName and a value (either om:fieldValue or om:fieldValueRaw). The name identifies the final object field name, and the value indicates the final field value. If om:fieldValueRaw is used, then the literal value will be converted to a runtime value as-is. Otherwise, if om:fieldValue is used, then the referred value is the predicate of a class that can be bound to a certain value during instantiation, as defined by the Object-Oriented vocabulary. If this value is again a om:ObjectMapping, then the mapping will happen recursively.

Similarly, om:ArrayMapping can have an list of om:ArrayMappingElements, where each element can only have a value (either om:fieldValue or om:fieldValueRaw), without a name. This is then converted to a runtime JavaScript array.

Practical example can be found at http://componentsjs.readthedocs.io/en/latest/configuration/components/object_mapping/

Clone this wiki locally