38.5. Fixed Value Attribute Mapping

38.5.1. 개요

기본적으로 코드 생성기는 고정 값을 일반 속성에 맞게 사용하는 것으로 정의된 특성을 매핑합니다.By default, the code generators map attributes defined as having a fixed value to normal properties. 스키마 유효성 검사를 사용하는 경우 Apache CXF는 스키마 정의를 적용할 수 있습니다( 24.3.4.7절. “스키마 유효성 검사 유형 값”참조). 그러나 스키마 유효성 검사를 사용하면 메시지 처리 시간이 증가합니다.

고정 값이 있는 속성을 Java에 매핑하는 또 다른 방법은 Java 상수에 매핑하는 것입니다. globalBindings 사용자 지정 요소를 사용하여 고정 값 속성을 Java 상수에 매핑하도록 코드 생성기에 지시할 수 있습니다. property 요소를 사용하여 보다 지역화된 수준에서 Java 상수에 고정 값 속성의 매핑을 사용자 지정할 수도 있습니다.

38.5.2. 글로벌 사용자 정의

전역Binding 요소의 fixedAttributeAsConstantProperty 속성을 추가하여 이 동작을 변경할 수 있습니다. 이 속성을 true 로 설정하면 고정 특성을 사용하여 정의된 모든 속성을 Java 상수에 매핑하도록 코드 생성기가 지시합니다.

예 38.21. “in-Line Customization to Force Generation of Constants” 코드 생성기가 고정 값을 사용하여 속성에 대해 상수를 생성하도록 강제 적용하는 인라인 사용자 지정을 보여줍니다.

예 38.21. in-Line Customization to Force Generation of Constants

<schema targetNamespace="http://widget.com/types/widgetTypes"
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        jaxb:version="2.0">
  <annotation>
    <appinfo>
      <jaxb:globalBindings fixedAttributeAsConstantProperty="true" />
    </appinfo>
  </annotation>
  ...
</schema>

예 38.22. “파일의 강제 적용에 파일 바인딩” 고정 속성의 생성을 사용자 지정하는 외부 바인딩 파일을 보여줍니다.

예 38.22. 파일의 강제 적용에 파일 바인딩

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               jaxb:version="2.0">
  <jaxb:bindings schemaLocation="types.xsd">
    <jaxb:globalBindings fixedAttributeAsConstantProperty="true" />
  <jaxb:bindings>
<jaxb:bindings>

38.5.3. 로컬 매핑

속성 요소의 fixedAttributeAsConstantProperty 속성 을 사용하여 특성 매핑을 특성별로 사용자 지정할 수 있습니다. 이 속성을 true 로 설정하면 고정 특성을 사용하여 정의된 모든 속성을 Java 상수에 매핑하도록 코드 생성기가 지시합니다.

예 38.23. “in-Line Customization to Force Generation of Constants” 코드 생성기가 고정된 값으로 단일 속성에 대해 상수를 생성하도록 강제 적용하는 인라인 사용자 지정을 보여줍니다.

예 38.23. in-Line Customization to Force Generation of Constants

<schema targetNamespace="http://widget.com/types/widgetTypes"
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        jaxb:version="2.0">
  <complexType name="widgetAttr">
    <sequence>
      ...
    </sequence>
    <attribute name="fixer" type="xsd:int" fixed="7">
      <annotation> <appinfo> <jaxb:property fixedAttributeAsConstantProperty="true" /> </appinfo> </annotation>
     </attribute>
  </complexType>
  ...
</schema>

예 38.24. “파일의 강제 적용에 파일 바인딩” 고정 속성의 생성을 사용자 지정하는 외부 바인딩 파일을 표시합니다.

예 38.24. 파일의 강제 적용에 파일 바인딩

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               jaxb:version="2.0">
  <jaxb:bindings schemaLocation="types.xsd">
    <jaxb:bindings node="xsd:complexType[@name='widgetAttr']">
      <jaxb:bindings node="xsd:attribute[@name='fixer']">
            <jaxb:property fixedAttributeAsConstantProperty="true" />
        </jaxb:bindings>
    </jaxb:bindings>
  </jaxb:bindings>
<jaxb:bindings>

38.5.4. Java 매핑

기본 매핑에서 모든 속성은 getter 및 setter 메서드를 사용하여 표준 Java 속성에 매핑됩니다. 이 사용자 지정이 고정 특성을 사용하여 정의된 속성에 적용되는 경우 예 38.25. “고정 값 속성을 Java Constant에 매핑” 에서와 같이 속성이 Java 상수에 매핑됩니다.

예 38.25. 고정 값 속성을 Java Constant에 매핑

@XmlAttribute
public final static type NAME = value;

유형34.1절. “기본 유형” 에서 설명하는 매핑을 사용하여 특성의 기본 유형을 Java 유형에 매핑하여 결정됩니다.

NAME특성 요소의 name 속성 값을 모든 대문자로 변환하여 결정됩니다.

값은 특성 요소의 고정 특성 값에 따라 결정됩니다.

예를 들어 예 38.23. “in-Line Customization to Force Generation of Constants” 에 정의된 속성은 예 38.26. “고정 값 특성을 Java Constant로 매핑” 로 매핑됩니다.

예 38.26. 고정 값 특성을 Java Constant로 매핑

@XmlRootElement(name = "widgetAttr")
public class WidgetAttr {

    ...

  @XmlAttribute
  public final static int FIXER = 7;

  ...

}