검색

35.6. 모델 그룹 사용

download PDF

35.6.1. 개요

XML 스키마 모델 그룹은 사용자 정의 복합 형식에서 요소 그룹을 참조할 수 있는 편리한 바로 가기입니다.For example, you can define a group of elements that are common to several types in your application and then reference the group again. 모델 그룹은 그룹 요소를 사용하여 정의되며 복잡한 유형 정의와 유사합니다. 모델 그룹을 Java로 매핑하는 것도 복잡한 유형의 매핑과 유사합니다.

35.6.2. XML 스키마에서 모델 그룹 정의

name 속성이 있는 group 요소를 사용하여 XML Schema에서 모델 그룹 을 정의합니다. name 특성의 값은 스키마 전체에서 그룹을 참조하는 데 사용되는 문자열입니다. complexType 요소와 같은 group 요소에는 시퀀스 요소, 모든 요소 또는 choice 요소가 immediate 자식으로 포함될 수 있습니다.

자식 요소 내에서는 요소 요소를 사용하여 그룹의 멤버를 정의합니다.Inside the child element, you define the members of the group using element elements. 그룹의 각 멤버에 대해 하나의 요소 요소 를 지정합니다. 그룹 멤버는 minOccurs 및 maxOccurs 를 포함하여 요소 요소에 대한 표준 속성을 사용할 수 있습니다.Group members can use any of the standard attributes for the element element including minOccurs and maxOccurs. 따라서 그룹에 세 개의 요소가 있고 그 중 하나가 최대 3 번 발생할 수 있는 경우 세 가지 요소 가 있는 그룹을 정의하면 maxOccurs="3"을 사용하는 그룹을 정의합니다. 예 35.22. “XML 스키마 모델 그룹” 세 가지 요소가 있는 모델 그룹을 보여 줍니다.

예 35.22. XML 스키마 모델 그룹

<group name="passenger">
  <sequence>
    <element name="name" type="xsd:string" />
    <element name="clubNum" type="xsd:long" />
    <element name="seatPref" type="xsd:string"
             maxOccurs="3" />
  </sequence>
</group>

35.6.3. 형식 정의에서 모델 그룹 사용Using a model group in a type definition

모델 그룹을 정의한 후에는 복잡한 형식 정의의 일부로 사용할 수 있습니다.Once a model group has been defined, it can be used as part of a complex type definition. 복잡한 유형 정의에서 모델 그룹을 사용하려면 ref 속성이 있는 group 요소를 사용합니다. ref 특성의 값은 해당 특성이 정의되었을 때 그룹에 지정된 이름입니다. 예를 들어 예 35.22. “XML 스키마 모델 그룹” 에 정의된 그룹을 사용하려면 예 35.23. “모델 그룹이 있는 복합 유형” 와 같이 {ref="tns:passenger" > 을 사용합니다.

예 35.23. 모델 그룹이 있는 복합 유형

<complexType name="reservation">
  <sequence>
    <group ref="tns:passenger" />
    <element name="origin" type="xsd:string" />
    <element name="destination" type="xsd:string" />
    <element name="fltNum" type="xsd:long" />
  </sequence>
</complexType>

형식 정의에서 모델 그룹을 사용하면 그룹이 형식의 멤버가 됩니다.When a model group is used in a type definition, the group becomes a member of the type. 따라서 예약 인스턴스에는 네 개의 멤버 요소가 있습니다. 첫 번째 요소는 passenger 요소이며 예 35.22. “XML 스키마 모델 그룹” 에 표시된 그룹에서 정의한 멤버 요소를 포함합니다. 예약 인스턴스 예는 예 35.24. “모델 그룹이 있는 Type의 인스턴스” 에 표시되어 있습니다.

예 35.24. 모델 그룹이 있는 Type의 인스턴스

<reservation>
  <passenger> <name>A. Smart</name> <clubNum>99</clubNum> <seatPref>isle1</seatPref> </passenger>
  <origin>LAX</origin>
  <destination>FRA</destination>
  <fltNum>34567</fltNum>
</reservation>

35.6.4. Java로의 매핑

기본적으로 모델 그룹은 복잡한 유형 정의에 포함된 경우에만 Java 아티팩트에 매핑됩니다. 모델 그룹을 포함하는 복잡한 유형의 코드를 생성할 때 Apache CXF는 모델 그룹의 멤버 변수를 해당 유형에 대해 생성된 Java 클래스에 간단하게 포함합니다. 모델 그룹을 나타내는 멤버 변수는 모델 그룹의 정의에 따라 주석이 추가됩니다.

예 35.25. “그룹이 포함된 유형”예 35.23. “모델 그룹이 있는 복합 유형” 에 정의된 복잡한 유형에 대해 생성된 Java 클래스를 보여줍니다.

예 35.25. 그룹이 포함된 유형

@XmlType(name = "reservation", propOrder = {
    "name",
    "clubNum",
    "seatPref",
    "origin",
    "destination",
    "fltNum"
})
public class Reservation {

    @XmlElement(required = true)
    protected String name;
    protected long clubNum;
    @XmlElement(required = true)
    protected List<String> seatPref;
    @XmlElement(required = true)
    protected String origin;
    @XmlElement(required = true)
    protected String destination;
    protected long fltNum;

    public String getName() {
        return name;
    }

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

    public long getClubNum() {
        return clubNum;
    }

    public void setClubNum(long value) {
        this.clubNum = value;
    }

    public List<String> getSeatPref() {
        if (seatPref == null) {
            seatPref = new ArrayList<String>();
        }
        return this.seatPref;
    }

    public String getOrigin() {
        return origin;
    }

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

    public String getDestination() {
        return destination;
    }

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

    public long getFltNum() {
        return fltNum;
    }

    public void setFltNum(long value) {
        this.fltNum = value;
    }

35.6.5. 여러 발생

그룹 요소의 maxOccurs 속성을 둘 이상의 값으로 설정하여 모델 그룹이 두 번 이상 표시되도록 지정할 수 있습니다.You can specify that the model group appears more than once by setting the group's maxOccurs attribute to a value greater than one. 모델 그룹 Apache CXF의 여러 발생을 허용하기 위해 모델 그룹을 List<T> 오브젝트에 매핑 합니다. List<T > 오브젝트는 그룹의 첫 번째 하위 규칙에 따라 생성됩니다.

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.