< prev index next >
src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlElementRef.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 55,66 ****
* schema using substitution groups. Schema derived code provides
* support for substitution groups using an <i>element property</i>,
* (section 5.5.5, "Element Property" of JAXB 2.0 specification). An
* element property method signature is of the form:
* <pre>
! * public void setTerm(JAXBElement<? extends Operator>);
! * public JAXBElement<? extends Operator> getTerm();
* </pre>
* <p>
* An element factory method annotated with {@link XmlElementDecl} is
* used to create a <tt>JAXBElement</tt> instance, containing an XML
* element name. The presence of @XmlElementRef annotation on an
--- 55,66 ----
* schema using substitution groups. Schema derived code provides
* support for substitution groups using an <i>element property</i>,
* (section 5.5.5, "Element Property" of JAXB 2.0 specification). An
* element property method signature is of the form:
* <pre>
! * public void setTerm(JAXBElement<? extends Operator>);
! * public JAXBElement<? extends Operator> getTerm();
* </pre>
* <p>
* An element factory method annotated with {@link XmlElementDecl} is
* used to create a <tt>JAXBElement</tt> instance, containing an XML
* element name. The presence of @XmlElementRef annotation on an
*** 104,114 ****
* class Target {
* // The presence of @XmlElementRef indicates that the XML
* // element name will be derived from the @XmlRootElement
* // annotation on the type (for e.g. "jar" for JarTask).
* @XmlElementRef
! * List<Task> tasks;
* }
*
* abstract class Task {
* }
*
--- 104,114 ----
* class Target {
* // The presence of @XmlElementRef indicates that the XML
* // element name will be derived from the @XmlRootElement
* // annotation on the type (for e.g. "jar" for JarTask).
* @XmlElementRef
! * List<Task> tasks;
* }
*
* abstract class Task {
* }
*
*** 120,139 ****
* @XmlRootElement(name="javac")
* class JavacTask extends Task {
* ...
* }
*
! * <!-- XML Schema fragment -->
! * <xs:element name="target" type="Target">
! * <xs:complexType name="Target">
! * <xs:sequence>
! * <xs:choice maxOccurs="unbounded">
! * <xs:element ref="jar">
! * <xs:element ref="javac">
! * </xs:choice>
! * </xs:sequence>
! * </xs:complexType>
*
* </pre>
* <p>
* Thus the following code fragment:
* <pre>
--- 120,139 ----
* @XmlRootElement(name="javac")
* class JavacTask extends Task {
* ...
* }
*
! * <!-- XML Schema fragment -->
! * <xs:element name="target" type="Target">
! * <xs:complexType name="Target">
! * <xs:sequence>
! * <xs:choice maxOccurs="unbounded">
! * <xs:element ref="jar">
! * <xs:element ref="javac">
! * </xs:choice>
! * </xs:sequence>
! * </xs:complexType>
*
* </pre>
* <p>
* Thus the following code fragment:
* <pre>
*** 142,159 ****
* target.tasks.add(new JavacTask());
* marshal(target);
* </pre>
* will produce the following XML output:
* <pre>
! * <target>
! * <jar>
* ....
! * </jar>
! * <javac>
* ....
! * </javac>
! * </target>
* </pre>
* <p>
* It is not an error to have a class that extends <tt>Task</tt>
* that doesn't have {@link XmlRootElement}. But they can't show up in an
* XML instance (because they don't have XML element names).
--- 142,159 ----
* target.tasks.add(new JavacTask());
* marshal(target);
* </pre>
* will produce the following XML output:
* <pre>
! * <target>
! * <jar>
* ....
! * </jar>
! * <javac>
* ....
! * </javac>
! * </target>
* </pre>
* <p>
* It is not an error to have a class that extends <tt>Task</tt>
* that doesn't have {@link XmlRootElement}. But they can't show up in an
* XML instance (because they don't have XML element names).
*** 180,200 ****
* // elements "add" or "sub". At runtime, JAXBElement
* // instance contains the element name that has been
* // substituted in the XML document.
* //
* @XmlElementRef(type=JAXBElement.class,name="operator")
! * JAXBElement<? extends Operator> term;
* }
*
* @XmlRegistry
* class ObjectFactory {
* @XmlElementDecl(name="operator")
! * JAXBElement<Operator> createOperator(Operator o) {...}
* @XmlElementDecl(name="add",substitutionHeadName="operator")
! * JAXBElement<Operator> createAdd(Operator o) {...}
* @XmlElementDecl(name="sub",substitutionHeadName="operator")
! * JAXBElement<Operator> createSub(Operator o) {...}
* }
*
* class Operator {
* ...
* }
--- 180,200 ----
* // elements "add" or "sub". At runtime, JAXBElement
* // instance contains the element name that has been
* // substituted in the XML document.
* //
* @XmlElementRef(type=JAXBElement.class,name="operator")
! * JAXBElement<? extends Operator> term;
* }
*
* @XmlRegistry
* class ObjectFactory {
* @XmlElementDecl(name="operator")
! * JAXBElement<Operator> createOperator(Operator o) {...}
* @XmlElementDecl(name="add",substitutionHeadName="operator")
! * JAXBElement<Operator> createAdd(Operator o) {...}
* @XmlElementDecl(name="sub",substitutionHeadName="operator")
! * JAXBElement<Operator> createSub(Operator o) {...}
* }
*
* class Operator {
* ...
* }
*** 206,218 ****
* m.term = new ObjectFactory().createAdd(new Operator());
* marshal(m);
* </pre>
* will produce the following XML output:
* <pre>
! * <math>
! * <add>...</add>
! * </math>
* </pre>
*
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems,Inc. </li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlElementRefs
--- 206,218 ----
* m.term = new ObjectFactory().createAdd(new Operator());
* marshal(m);
* </pre>
* will produce the following XML output:
* <pre>
! * <math>
! * <add>...</add>
! * </math>
* </pre>
*
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems,Inc. </li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlElementRefs
< prev index next >