Properties-default-sources construct 编辑

The properties-default-sources construct is analogous to the parameters-default-sources construct. While the parameters-default-sources construct allows the reuse of existing parameters (from other StyleBooks) in a StyleBook, properties-default-sources construct allows the user to specify properties of a component based on existing sources.

The properties of a component may be distributed across various sections of the StyleBook. For example, the properties may come from object parameters, substitutions that return an object, properties of other components, or outputs of other components. In such cases, you need to redefine the properties that occur in other sections of the StyleBook in the definition of the component. Clearly, this is redundant and can lead to errors. To deal with this problem, properties-default-sources construct can be used. The properties-default-sources construct is a list where each item identifies a source for some properties of the component.

For example, consider a component that creates an lbvserver configuration. This component should define the properties of the lbvserver as follows.

parameters:
  -
    name: lb
    type: ns::lbvserver
components:
  -
    name: lb-comp
    type: ns::lbvserver
    properties:
      name: $parameters.lb.name
      ipv46: $parameters.lb.ipv46
      port: $parameters.lb.port
      servicetype: $parameters.lb.servicetype
      lbmethod: $parameters.lb.lbmethod
<!--NeedCopy-->

In the above example, observe that the values for all properties defined in the components section are taken from $parameters.lb object. Though they are taken from a single source, the properties are again defined in the StyleBook. In addition, if a new sub-parameter to $parameters.lb object that is relevant to the configuration of the lbvserver is added, you need to update the lb-comp component to add the new property that corresponds to the new sub-parameter.

To avoid redefining properties and to fetch all relevant properties of a component without explicitly list them in the properties section, properties-default-sources construct can be used. The above example can be written as follows.

parameters:
  -
    name: lb
    type: ns::lbvserver
components:
  -
    name: lb-comp
    type: ns::lbvserver
    properties-default-sources:
      - $parameters.lb
<!--NeedCopy-->

In the above example, the use of properties-default-sources construct leads to a reduction in the size of the component definition, and this allows you to concisely define a component. In addition, each time the source of the properties of the component changes, the changes are reflected automatically. For example, when a new property, say “persistencetype,” is added in the $parameters.lb object, this property is added to the configuration of lb-comp by default since persistencetype is a property of lbvserver. Thus, properties-default-sources construct provides a dynamic interface to define the components without worrying about changes happening to the sources of the properties of the component.

Computation of the Properties of the Component

This section discusses on how the properties are fetched if properties-default-sources construct is used in a component. First, the StyleBooks compiler identifies the list of properties for a component based on its type (in the above example, lbvserver.) Next, the compiler fetches these properties from the multiple sources in the order that they are defined (in properties-default-sources section of the component). If a property exists in multiple sources then the property appearing in the last source takes precedence over others. Finally, a property fetched by using properties-default-sources construct can be overridden in the properties section of the component. It is important to note that the definition of a component section should at least have a properties-default-sources section or a properties section. It may have both.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:4 次

字数:4268

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文