The payloadSchema.xml also supports the switch and the case tags. These tags provide support for separate schemas that are based upon a property value, and allow you to work with sub-classes or repository subtypes. For example:

<schema id="switching-schema">
  <bean class="atg.my.TestBean"/>
  <switch property="stringOne">
    <case value="a">
      <bean class="atg.my.SubClassAOfTestBean"/>
      <property name="booleanObject" required="true"/>
      <bean-property name="childTestBean" required="false">
        <property name="stringTwo" required="true"/>
      </bean-property>
    </case>
    <case value="b">
      <bean class="atg.my.SubClassBOfTestBean"/>
      <property name="stringTwo" required="true" />
      <bean-property name="childTestBean" required="false">
        <property name="booleanObject" required="true"/>
      </bean-property>
    </case>
  </switch>
</schema>
Separating Schemas

You can use the switch tags to define bean or item-descriptor tags, which allows you to specify sub-classes or repository item subtypes. These switch tags inherit the include-all-simple setting from their containing schema or bean-property tag. The following example includes all of the simple properties of TestBean in the top-level validator, and the ‘a’ and ‘b’ cases include all of the additional simple properties of SubClassAOfTestBean and SubClassBOfTestBean:

<schema id="switching-schema" include-all-simple="true">
  <bean class="atg.my.TestBean"/>
  <switch property="stringOne">
    <case value="a">
      <bean class="atg.my.SubClassAOfTestBean"/>
    </case>
    <case value="b">
      <bean class="atg.my.SubClassBOfTestBean"/>
    </case>
  </switch>
</switching-schema>

When the include-all-simple attribute is inherited from the containing schema or bean-property, simple properties that the schema or bean-property do not already mention are included.

In the above example, the simple properties of TestBean would be included at the top level and those simple properties would not be repeated for the two case tags.

When the schema or bean-property tag references a repository and the include-all-simple attribute is set to true, subtypes are automatically generated, supporting automatic validation of dynamically added subtypes and their simple properties. For example:

<schema id="repo-dyn-subtype-validator" include-all-simple="true">
  <item-descriptor repository="/atg/dynamo/service/validator/TestRepository"
      item-type="testItemBase"/>
  <switch property="type">
    <case value="dynType1">
      <item-descriptor repository="/atg/dynamo/service/validator/TestRepository"
          item-type="testItemDynSub1"/>
      <property name="dynType1Boolean" required="true"/>
    </case>
    <case value="dynType2">
      <item-descriptor repository="/atg/dynamo/service/validator/TestRepository"
          item-type="testItemDynSub2"/>
      <property name="dynType2StringOne" required="true"/>
    </case>
  </switch>
</schema>

In preceding example, testItemBase is the base item descriptor and testItemDynType1 and testItemDynType2 are the dynamic subtypes with dynType1Boolean and dynType2StringOne corresponding to dynamic properties.

The switch tag also supports an option-to-subtype-map attribute. This attribute specifies the Nucleus path to a map that maps an option value to a RepositoryItemDescriptor, class or string containing the name of a class. The option-to-subtype-map also creates automatic case tags for subclasses, and can be useful where such configurations already exist in Nucleus. For example:

<schema id="commerceItemValidator" include-all-simple="true">
  <bean class="atg.commerce.order.CommerceItemImpl"/>
  <switch property="commerceItemClassType" option-to-subtype-map=
      "/atg/commerce/order/OrderTools.commerceItemTypeClassMap">
     ...
  </switch>
</schema>

Copyright © 1997, 2017 Oracle and/or its affiliates. All rights reserved. Legal Notices