다른 단순 유형에서 파생된 단순 유형

패싯을 사용하여 단순 유형을 다른 단순 유형에서 파생시키고 제한사항을 보다 일반적인 단순 유형과 통합할 수 있습니다.

다른 단순 유형에서 단순 유형을 파생시킬지에 대한 의사결정은 제한사항 통합을 의미합니다. 이러한 제한사항을 통합하려면 패싯을 사용합니다. 패싯은 제한된 기본 제공 유형으로 새 단순 유형을 정의할 수 있는 일련의 사전 정의된 제한조건입니다.

패싯의 예제: 우편번호

패싯의 예로 우편번호가 5개의 숫자만 포함하도록 정의된 패턴을 들 수 있습니다.

다음 스키마는 단순 유형 정의를 표시합니다.

<simpleType name="myType">
    <restriction base="string">
    <pattern value="*A"/>
    </restriction>
</simpleType>
<attribute name = "typeValue" type = "myType"/>

이 예제에서 단순 유형 myType은 string의 하위 유형으로 정의됩니다. typeValue 속성은 java.lang.String 유형의 동적 클래스 필드에 맵핑됩니다.

단순 유형 정의를 동적 클래스 유형에 맵핑할 때 유형 계층 트리가 검색됩니다. 맵핑 유형을 단순 유형 정의 맵핑으로 유지하는 기본 제공 유형이 발견된 때까지 계층 트리가 가장 제한적인 유형부터 위쪽 방향으로 검색됩니다.

다음 우편번호 예제에서는 사용자 스키마 단순 유형이 XOM에 표시되는 방법과 해당 단순 유형을 조작하기 위해 생성되는 메소드를 보여줍니다. 정적 메소드 세트가 선언되었습니다. 이 메소드는 규칙에서 호출할 수 있습니다. checkFloatInInterval 및 findZipCodePattern이라는 두 개의 규칙이 ZipCode 오브젝트를 테스트하는 데 사용됩니다.

스키마는 다음과 같습니다.

<simpleType name="zip-code">
  <restriction base="string">
    <pattern value="A[0-9]{5}"/>
  </restriction>
</simpleType>
<simpleType name="Interval">
  <restriction base="float">
    <minInclusive value="1.1"/>
    <maxInclusive value="3.1"/>
  </restriction>
</simpleType>

XOM 표시는 다음과 같습니다.

class ZipCode extends IlrXmlObject
{
   static String getPattern();
   static int getMinLength();
   static int getMaxLength();
   static getLength();
   static String[] getEnumerations();
}
class Interval
{
   static String getPattern();
   static int getMinLength();
   static int getMaxLength();
   static getLength();
   static float[] getEnumerations();
   static float getMinInclusive ();
   static float getMaxInclusive ();
   static float getMinExclusive ();
   static float getMaxExclusive ();
   static int getTotalDigits();
   static int getFractionDigits();
}

규칙은 다음과 같습니다.

rule checkFloatInInterval
{
  when {
     f: Float ( i: floatValue(); Interval.getMinInclusive() <= i;
                i <= Internal.getMaxInclusive()   );
  }
  then {
     out.println ( f + " in Interval" );
  }
}
rule findZipCodePattern 
{
   when {
      s: String ( equals ZipCode.getPattern() );
   }
   then {
      out.println ( s + " equals zip code pattern" );
   }
}

단순 유형 동적 메소드는 유형 패싯 값에 대한 정보를 제공합니다.

메소드가 유형 계층에서 마지막 패싯 정의를 리턴하는 경우 다음과 같은 결과를 얻을 수 있습니다.

패싯 유형은 다음과 같습니다.

다음 표에서는 패싯이 정의되지 않은 경우의 리턴값을 보여줍니다.

표 1. 패싯이 정의되지 않은 리턴값
유형 getMinInclusive getMinExclusive GetMaxInclusive getMaxExclusive

getMinLength getMaxLength

getLength getTotalDigits getFractionDigits

getEnumerations
float -Float.MAX_VALUE Float.MAX_VALUE

IlrXmlObject.UNKNOWN_

POSITIVE_VALUE

float[0]
double -Double.MAX_VALUE Double.MAX_VALUE double[0]
byte Byte.MIN_VALUE Byte.MAX_VALUE byte[0]
int Integer.MIN_VALUE Integer.MAX_VALUE int[0]
long Long.MIN_VALUE Long.MAX_VALUE long[0]
Object null null Object[0]