description 규칙 속성

각 규칙 클래스는 궁극적으로 CER "루트 규칙 클래스"에서 상속합니다. 이 규칙 클래스에는 기본(그러나 특별히 유용하지는 않은) 구현이 있는 description 규칙 속성이 포함되어 있습니다.

규칙 오브젝트의 description 값은 RuleDoc의 결과이며 RuleObject에 대한 toString 메소드의 결과이기도 합니다(변수를 "클릭하면" 여러 Java IDE가 사용함). 이와 같이 규칙 세트의 동작을 이해하는 데 있어 의미있는 description은 반드시 필요할 수 있습니다.

각 규칙 클래스에서 description 속성을 명시적으로 작성하여 기본 description 계산을 대체해야 합니다. 규칙 클래스에서 일반 속성을 작성하는 방식과 동일하게 CER 편집기를 사용하여 description 속성을 작성할 수 있습니다. description 규칙 속성을 정의(또는 정의된 다른 규칙 클래스에서 상속)하지 않은 규칙 클래스가 있으면 CER 규칙 세트 유효성 검증기가 경고를 발행합니다.

description 속성은 자국어 지원 가능 메시지이며 (기타 규칙 속성과 마찬가지로) 계산은 필요에 따라 단순하거나 복잡해질 수 있습니다.

다음은 일부 규칙 클래스가 description 구현을 제공하는 예제 규칙 세트입니다.

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

    <Attribute name="firstName">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="lastName">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- 기본 설명 대체 -->
    <Attribute name="description">
      <type>
        <javaclass name="curam.creole.value.Message"/>
      </type>
      <derivation>
        <!-- 개인의 이름과 성을 연결 -->
        <concat>
          <fixedlist>
            <listof>
              <javaclass name="Object"/>
            </listof>
            <members>

              <reference attribute="firstName"/>
              <String value=" "/>
              <reference attribute="lastName"/>
            </members>
          </fixedlist>
        </concat>
      </derivation>
    </Attribute>

  </Class>

  <Class name="Income">
    <!-- 이 수입 레코드가 관련되는
         사람입니다. -->
    <Attribute name="person">
      <type>
        <ruleclass name="Person"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>
    <Attribute name="startDate">
      <type>
        <javaclass name="curam.util.type.Date"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>
    <Attribute name="amount">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- 기본 설명 대체 -->
    <Attribute name="description">
      <type>
        <javaclass name="curam.creole.value.Message"/>
      </type>
      <derivation>
        <!-- 개인의 설명과 시작 날짜를
 연결-->
        <concat>
          <fixedlist>
            <listof>
              <javaclass name="Object"/>
            </listof>
            <members>

              <reference attribute="description">
                <reference attribute="person"/>
              </reference>
              <!-- 실제 규칙 세트에서 이 설명은
                   <ResourceMessage>를 사용하여 단일 언어
                   문자열이 하드 코딩되지 않도록 합니다. -->
              <String value="'s income, starting on "/>
              <reference attribute="startDate"/>
            </members>
          </fixedlist>
        </concat>
      </derivation>
    </Attribute>

  </Class>

  <Class name="Benefit">
    <!-- NB <description>을 대체하지 않습니다. CER 규칙 세트 유효성 검증기가
         경고를 발행하고 RuleDoc이나 Java IDE에서
         이 클래스의 규칙 오브젝트를 이해하기가 더욱
         어렵습니다. -->
    <!-- 이 혜택 레코드가 관련되는
         사람입니다. -->
    <Attribute name="person">
      <type>
        <ruleclass name="Person"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="amount">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>
  </Class>

</RuleSet>

다음은 일부 규칙 오브젝트(Person, IncomeBenefit)를 작성하는 테스트 케이스입니다.

package curam.creole.example;

import java.io.File;

import junit.framework.TestCase;
import curam.creole.execution.session.RecalculationsProhibited;
import curam.creole.execution.session.Session;
import curam.creole.execution.session.SessionDoc;
import curam.creole.execution.session.Session_Factory;
import
 curam.creole.execution.session.StronglyTypedRuleObjectFactory;
import curam.creole.ruleclass.Example_description.impl.Benefit;
import
 curam.creole.ruleclass.Example_description.impl.Benefit_Factory;
import curam.creole.ruleclass.Example_description.impl.Income;
import
 curam.creole.ruleclass.Example_description.impl.Income_Factory;
import curam.creole.ruleclass.Example_description.impl.Person;
import
 curam.creole.ruleclass.Example_description.impl.Person_Factory;
import curam.creole.storage.inmemory.InMemoryDataStorage;
import curam.util.type.Date;

/**
 * 설명 규칙 속성을 테스트합니다.
 */
public class TestDescription extends TestCase {

  /**
   * 설명 규칙 속성을 테스트합니다.
   */
  public void testDescriptions() {

    /**
     * 새 세션을 작성합니다.
     */
    final Session session =
        Session_Factory.getFactory().newInstance(
            new RecalculationsProhibited(),
            new InMemoryDataStorage(
                new StronglyTypedRuleObjectFactory()));

    /**
     * 규칙 오브젝트에 대해 보고하도록 SessionDoc을 작성합니다.
     */
    final SessionDoc sessionDoc = new SessionDoc(session);

    /*
     * Person 규칙 오브젝트를 작성합니다.
     */
    final Person person =
        Person_Factory.getFactory().newInstance(session);
    person.firstName().specifyValue("John");
    person.lastName().specifyValue("Smith");

    /*
     * Income 규칙 오브젝트를 작성합니다.
     */
    final Income income =
        Income_Factory.getFactory().newInstance(session);
    income.person().specifyValue(person);
    income.amount().specifyValue(123);
    income.startDate().specifyValue(Date.fromISO8601("20070101"));

    /*
     * Benefit 규칙 오브젝트를 작성합니다.
     */
    final Benefit benefit =
        Benefit_Factory.getFactory().newInstance(session);
    benefit.person().specifyValue(person);
    benefit.amount().specifyValue(234);

    /*
     * .toString 메소드는 설명 규칙 속성을
     * 평가합니다.
     */
    System.out.println(person.toString());

    /*
     * println이 오브젝트의 toString 메소드를 호출하여 인쇄합니다.
     */
    System.out.println(income);

    /*
     * 혜택 규칙 클래스는 설명 규칙 속성을 구현하지
     * 않습니다. 따라서 여기에서는 기본 설명을
     * 얻습니다.
     */
    System.out.println(benefit);

    /*
     * 이 세션의 SessionDoc을 작성합니다.
     */
    sessionDoc.write(new File("./gen/sessiondoc"));
>
  }

}

테스트를 실행하면 다음 결과가 작성되어 규칙 오브젝트 설명을 표시합니다.

John Smith
07/01/01 00:00부터 시작된 John Smith의 수입입니다.
'Benefit' 규칙 클래스, id '3'의 설명되지 않은 인스턴스입니다. 

테스트 마지막에 세션의 규칙 오브젝트가 SessionDoc에 출력됩니다. 상위 레벨 SessionDoc 요약은 작성된 규칙 오브젝트를 표시하며 각 규칙 오브젝트의 설명을 나열합니다.

그림 1. 규칙 오브젝트 description 값을 표시하는 SessionDoc생성된 세션 문서의 예.

Benefit 규칙 오브젝트의 설명은 기본 설명입니다. description이 잘 구현되어 있지 않으면 SessionDoc을 읽는 사람이 해당 규칙 오브젝트를 이해하기 위해 Benefit 규칙 오브젝트의 SessionDoc으로 이동해야 할 수도 있습니다.

그림 2. description이 대체되지 않은 규칙 오브젝트의 SessionDoc생성된 세션 문서의 예.

마지막으로 이 스크린 샷은 디버깅 시 IDE(표시된 Eclipse와 같은)에서 오브젝트의 toString 메소드를 사용하여 (규칙 오브젝트에 대해) description을 계산하는 방식을 표시합니다.

그림 3. IDE에서 description 사용Eclipse 예제.
팁: description의 목적은 규칙 클래스 자체가 아니라 규칙 오브젝트 인스턴스를 설명하는 데 있습니다.

특히 description 규칙 속성 계산 시 데이터가 포함되어야 합니다. 즉, 규칙 클래스의 서로 다른 규칙 오브젝트 인스턴스를 쉽게 구분할 수 있게 됩니다.