|
Oracle® Fusion Middleware Java API Reference for EclipseLink 11g Release 1 (11.1.1) E26376-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface XmlElementDecl
Maps a factory method to a XML element.
Usage
The annotation creates a mapping between an XML schema element declaration and a element factory method that returns a JAXBElement instance representing the element declaration. Typically, the element factory method is generated (and annotated) from a schema into the ObjectFactory class in a Java package that represents the binding of the element declaration's target namespace. Thus, while the annotation syntax allows @XmlElementDecl to be used on any method, semantically its use is restricted to annotation of element factory method. The usage is subject to the following constraints:
XmlRegistry
.Object
.Example 1: Annotation on a factory method
// Example: code fragment @XmlRegistry class ObjectFactory { @XmlElementDecl(name="foo") JAXBElement<String> createFoo(String s) { ... } }
<xmp> <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" <xs:element name="foo" type="xs:string"/> </xmp>
Example 2: Element declaration with non local scope
The following example illustrates the use of scope annotation parameter in binding of element declaration in schema derived code.
The following example may be replaced in a future revision of this javadoc.
<xmp> <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> </xmp>
// Example: expected default binding class Pea { @XmlElementRefs({ @XmlElementRef(,type=JAXBElement.class) @XmlElementRef(name="bar",type=JAXBElement.class) }) List<JAXBElement<String>> fooOrBar; } @XmlRegistry class ObjectFactory { @XmlElementDecl(scope=Pea.class,name="foo") JAXBElement<String> createPeaFoo(String s); @XmlElementDecl(scope=Pea.class,name="bar") JAXBElement<String> createPeaBar(String s); @XmlElementDecl(name="foo") JAXBElement<Integer> createFoo(Integer i); }
Without scope createFoo and createPeaFoo would become ambiguous since both of them map to a XML schema element with the same local name "foo".
XmlRegistry
Required Element Summary | |
---|---|
java.lang.String |
name local name of the XML element. |
Optional Element Summary | |
---|---|
java.lang.String |
defaultValue Default value of this element. |
java.lang.String |
namespace namespace name of the XML element. |
java.lang.Class |
scope scope of the mapping. |
java.lang.String |
substitutionHeadName XML local name of a substitution group's head element. |
java.lang.String |
substitutionHeadNamespace namespace name of a substitution group's head XML element. |
Element Detail |
---|
public abstract java.lang.String name
Note to reviewers: There is no default name; since the annotation is on a factory method, it is not clear that the method name can be derived from the factory method name.
namespace()
public abstract java.lang.Class scope
If this is not XmlElementDecl.GLOBAL
, then this element declaration mapping is only active within the specified class.
public abstract java.lang.String namespace
If the value is "##default", then the value is the namespace name for the package of the class containing this factory method.
name()
public abstract java.lang.String substitutionHeadNamespace
This specifies the namespace name of the XML element whose local name is specified by substitutionHeadName().
If susbtitutionHeadName() is "", then this value can only be "##default". But the value is ignored since since this element is not part of susbtitution group when the value of susbstitutionHeadName() is "".
If susbtitutionHeadName() is not "" and the value is "##default", then the namespace name is the namespace name to which the package of the containing class, marked with XmlRegistry
, is mapped.
If susbtitutionHeadName() is not "" and the value is not "##default", then the value is the namespace name.
substitutionHeadName()
public abstract java.lang.String substitutionHeadName
If the value is "", then this element is not part of any substitution group.
substitutionHeadNamespace()
public abstract java.lang.String defaultValue
The '' value specified as a default of this annotation element is used as a poor-man's substitute for null to allow implementations to recognize the 'no default value' state.
|
Oracle® Fusion Middleware Java API Reference for EclipseLink 11g Release 1 (11.1.1) E26376-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |