singleitem

Recupera un único elemento de una lista.

La expresión singleitem puede ser útil cuando se espera que una lista sólo contenga un único elemento, por ejemplo al filtrar una lista por criterios que sólo debe seleccionar un solo elemento de la lista.

La expresión singleitem especifica:

Para recuperar un elemento de una posición específica en una lista, consulte get en Operaciones de lista útiles.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_singleitem"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Person">

    <Attribute name="dateOfBirth">
      <type>
        <javaclass name="curam.util.type.Date"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="children">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- El primer hijo nacido de esta persona -->
    <Attribute name="firstBornChild">
      <type>
        <ruleclass name="Person"/>
      </type>
      <derivation>
        <!-- obtener el primer hijo, si hay alguno
             - si no hay hijos, devolver nulo -->
        <singleitem onEmpty="returnNull" onMultiple="returnFirst">
          <!-- clasificar los hijos por orden de fecha de nacimiento -->
          <sort>
            <list alias="child">
              <reference attribute="children"/>
            </list>
            <sortorder>
              <sortitem direction="ascending">
                <reference attribute="dateOfBirth">
                  <current alias="child"/>
                </reference>
              </sortitem>
            </sortorder>
          </sort>

        </singleitem>
      </derivation>

    </Attribute>

    <!-- Recuperar el único registro de información de la unidad familiar
         del almacenamiento externo - siempre debe haber
         exactamente uno - cualquier otro valor es un error.  -->
    <Attribute name="householdInformation">
      <type>
        <ruleclass name="HouseholdInformation"/>
      </type>
      <derivation>
        <singleitem onEmpty="error" onMultiple="error">
          <readall ruleclass="HouseholdInformation"/>
        </singleitem>
      </derivation>
    </Attribute>

  </Class>

  <Class name="HouseholdInformation">

    <Attribute name="householdContainsDisabledPerson">
      <type>
        <javaclass name="Boolean"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>