JavaTM Platform
Standard Ed. 6

javax.xml.bind.annotation
주석형 XmlElementDecl



@Retention (value =RUNTIME )
@Target (value =METHOD )
public @interface XmlElementDecl

팩토리 메소드를 XML 요소에 맵 합니다.

사용법

이 주석은, XML schema 요소 선언과 그 요소 선언을 표현하는 JAXBElement 인스턴스를 돌려주는 「요소 팩토리 메소드」의 사이의 매핑을 작성합니다. 일반적으로, schema로부터, 요소 선언의 타겟 이름 공간의 바인딩을 표현하는 Java 패키지내의 ObjectFactory 클래스내에, 요소 팩토리 메소드가 생성 ( 및 주석)됩니다. 그 때문에, 주석의 구문상에서는 @XmlElementDecl 는 임의의 메소드로 사용 가능합니다만, 시멘틱스적으로는 이것의 사용은 요소 팩토리 메소드의 주석으로 한정됩니다. 사용에는 다음의 제약이 있습니다.

예 1:팩토리 메소드에의 주석

     //Example:code fragment
     @XmlRegistry
     class ObjectFactory {
         @XmlElementDecl(name="foo")
         JAXBElement<String> createFoo(String s) { ... }
     }
 
 
     <!-- XML input -->
       <foo>string</foo>

     //Example:code fragment corresponding to XML input
     JAXBElement<String> o =
     (JAXBElement<String>) unmarshaller.unmarshal(aboveDocument);
     // print JAXBElement instance to show values
     System.out.println(o.getName());   // prints  "{}foo"
     System.out.println(o.getValue());  // prints  "string"
     System.out.println(o.getValue(). getClass()); // prints "java.lang.String"

     <!-- Example: XML schema definition -->
     <xs:element name="foo" type="xs:string"/>
 

예 2: 로컬 스코프를 가지지 않는 요소 선언

다음의 예는, schema 파생 코드내의 요소 선언의 바인딩에 있어서의 스코프 주석 파라미터의 사용을 나타냅니다.

다음의 예는, 장래 이 javadoc 의 개정판으로 옮겨놓을 수 있을 가능성이 있습니다.


     <!-- Example: XML schema definition -->
     <xs:schema>
       <xs:complexType name="pea">
         <xs:choice maxOccurs="unbounded">
           <xs:element name="foo" type="xs:string"/>
           <xs:element name="bar" type="xs:string"/>
         </xs:choice>
       </xs:complexType> 
       <xs:element name="foo" type="xs:int"/>
     </xs:schema>
 
     //Example:expected default binding
     class Pea {
         @XmlElementRefs({
             @XmlElementRef(name="foo", type=JAXBElement.class)
             @XmlElementRef(name="bar", type=JAXBElement.class)
         })
         List<JAXBElement<String>> fooOrBar;
     }
 
     @XmlRegistry
     class ObjectFactory {
         @XmlElementDecl(scope=Pea.class, name="foo")
         JAXBElement createPeaFoo(String s);
 
         @XmlElementDecl(scope=Pea.class, name="bar")
         JAXBElement createPeaBar(String s);
 
         @XmlElementDecl(name="foo")
         JAXBElement createFoo(Integer i);
     }
 
 
스코프가 없으면, createFoo 와 createPeaFoo 는 양쪽 모두 같은 로컬명 「foo」를 가지는 XML schema 요소에 맵 되기 (위해)때문에, 불명료하게 됩니다.

도입된 버젼:
JAXB 2.0
관련 항목:
XmlRegistry

필수 요소의 개요
 String name
          XML 요소의 로컬명입니다.
 
임의 요소의 개요
 String defaultValue
          이 요소의 디폴트 값입니다.
 String namespace
          XML 요소의 이름 공간명입니다.
 Class scope
          매핑의 스코프입니다.
 String substitutionHeadName
          치환 그룹의 선두 요소의 XML 로컬명입니다.
 String substitutionHeadNamespace
          치환 그룹의 선두 XML 요소의 이름 공간명입니다.
 

요소의 상세

name

public abstract String  name
XML 요소의 로컬명입니다.

레뷰아에의 주의: 디폴트명은 없습니다. 주석은 팩토리 메소드에 대하는 것이기 (위해)때문에, 메소드명을 팩토리 메소드명으로부터 파생할 수 있을까 아키라등인가이지 않습니다.

관련 항목:
namespace()

scope

public abstract Class  scope
매핑의 스코프입니다.

이것이 XmlElementDecl.GLOBAL 이외의 경우, 이 요소 선언 매핑은 지정된 클래스내에서만 액티브하게 됩니다.

디폴트:
javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class

namespace

public abstract String  namespace
XML 요소의 이름 공간명입니다.

값이 「##default」의 경우, 값은, 이 팩토리 메소드를 포함한 클래스의 패키지의 이름 공간명입니다.

관련 항목:
name()
디폴트:
"##default"

substitutionHeadNamespace

public abstract String  substitutionHeadNamespace
치환 그룹의 선두 XML 요소의 이름 공간명입니다.

이것은, 로컬명이 substitutionHeadName() 에 의해 지정되는 XML 요소의 이름 공간명을 지정합니다.

substitutionHeadName() 가 「」의 경우, 이 값은 「##default」밖에 할 수 없습니다. substitutionHeadName() 의 값이 「」의 경우, 이 요소는 치환 그룹이 일부에서 없기 때문에, 값은 무시됩니다.

subtitutionHeadName() 가 「」이외로, 값이 「##default」의 경우, 이름 공간명은,XmlRegistry 로 마크 된 이것을 포함한 클래스의 패키지가 맵 되는 이름 공간명입니다.

substitutionHeadName() 가 「」이 아니고, 값이 「##default」이외의 경우, 값은 이름 공간명입니다.

관련 항목:
substitutionHeadName()
디폴트:
"##default"

substitutionHeadName

public abstract String  substitutionHeadName
치환 그룹의 선두 요소의 XML 로컬명입니다.

값이 「」의 경우, 이 요소는 치환 그룹의 일부에서는 없습니다.

관련 항목:
substitutionHeadNamespace()
디폴트:
""

defaultValue

public abstract String  defaultValue
이 요소의 디폴트 값입니다.

이 주석 요소의 디폴트로서 지정되고 있는 「」값은, null 대신에 사용해 구현이 비디폴트 값 상태를 인식할 수 있도록(듯이) 하는 경제적인 대체품입니다.

디폴트:
"\u0000"

JavaTM Platform
Standard Ed. 6

버그의 보고와 기능의 요청
한층 더 자세한 API 레퍼런스 및 개발자 문서에 대해서는,Java SE 개발자용 문서를 참조해 주세요. 개발자전용의 상세한 해설, 개념의 개요, 용어의 정의, 버그의 회피책, 및 코드 실례가 포함되어 있습니다.

Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.