35.3. 간단한 형식에서 복합 유형 파생

35.3.1. 개요

Apache CXF는 간단한 유형에서 복잡한 유형의 파생을 지원합니다. 간단한 유형은 sub-elements 및 attributes 둘 다 정의로 구성됩니다. 따라서 간단한 유형에서 복잡한 유형을 파생하는 주된 이유 중 하나는 간단한 유형에 특성을 추가하는 것입니다.

간단한 유형에서 복잡한 유형을 파생하는 두 가지 방법이 있습니다.

35.3.2. 확장의 파생

예 35.12. “Simple Type by Extension에서 Complex 유형 파생” 통화 특성을 포함하는 xsd:decimal primitive 유형에서 확장에 의해 파생되는 복잡한 type인 International Price 의 예를 보여줍니다.

예 35.12. Simple Type by Extension에서 Complex 유형 파생

<complexType name="internationalPrice">
    <simpleContent>
        <extension base="xsd:decimal">
            <attribute name="currency" type="xsd:string"/>
        </extension>
    </simpleContent>
    </complexType>

simpleContent 요소는 새 형식에 하위 요소가 포함되어 있지 않음을 나타냅니다. extension 요소는 새 유형이 xsd:decimal 을 확장하도록 지정합니다.

35.3.3. 제한별 유도

예 35.13. “단순 유형에서 제한으로 복합 유형 파생” xsd:string 에서 제한으로 파생되는 복잡한 유형 idType 의 예를 보여줍니다. 정의된 형식은 xsd:string의 가능한 값을 10자 길이의 값으로 제한합니다. 또한 형식에 특성을 추가합니다.

예 35.13. 단순 유형에서 제한으로 복합 유형 파생

<complexType name="idType">
  <simpleContent>
    <restriction base="xsd:string">
     <length value="10" />
     <attribute name="expires" type="xsd:dateTime" />
    </restriction>
  </simpleContent>
</complexType>

예 35.12. “Simple Type by Extension에서 Complex 유형 파생” 에서와 같이 새 유형에 자식이 포함되지 않은 simpleContent 요소 신호입니다. 이 예제에서는 제한 요소를 사용하여 새 형식에 사용되는 가능한 값을 제한합니다. 특성 요소는 새 형식에 요소를 추가합니다.The attribute element adds the element to the new type.

35.3.4. Java로의 매핑

간단한 유형에서 파생된 복잡한 유형은 @XmlType 주석으로 장식되는 Java 클래스에 매핑됩니다. 생성된 클래스에는 복잡한 형식이 파생되는 단순 형식의 멤버 변수 값이 포함됩니다.The generated class contains a member variable, value, of the simple type from which the complex type is derived. 멤버 변수는 @XmlValue 주석으로 장식됩니다. 클래스에도 getValue() 메서드와 setValue() 메서드가 있습니다. 또한 생성된 클래스에는 단순 유형을 확장하는 각 속성에 대해 멤버 변수와 연결된 getter 및 setter 메서드가 있습니다.

예 35.14. “idType Java Class”예 35.13. “단순 유형에서 제한으로 복합 유형 파생” 에 정의된 idType 유형에 대해 생성된 Java 클래스를 보여줍니다.

예 35.14. idType Java Class

@XmlType(name = "idType", propOrder = {
    "value"
})
public class IdType {

    @XmlValue
    protected String value;
    @XmlAttribute
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar expires;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public XMLGregorianCalendar getExpires() {
        return expires;
    }

    public void setExpires(XMLGregorianCalendar value) {
        this.expires = value;
    }

}