feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
/**
* Converts an element (and its descendants)
* from/to DOM (or similar) representation.
*
* <p>
* Implementations of this interface will be used in conjunction with
* {@link XmlAnyElement} annotation to map an element of XML into a representation
* of infoset such as W3C DOM.
*
* <p>
* Implementations hide how a portion of XML is converted into/from such
* DOM-like representation, allowing JAXB providers to work with arbitrary
* such library.
*
* <P>
* This interface is intended to be implemented by library writers
* and consumed by JAXB providers. None of those methods are intended to
* be called from applications.
*
* @author Kohsuke Kawaguchi
* @since JAXB2.0
*/
public interface DomHandler<ElementT,ResultT extends Result> {
/**
* When a JAXB provider needs to unmarshal a part of a document into an
* infoset representation, it first calls this method to create a
* {@link Result} object.
*
* <p>
* A JAXB provider will then send a portion of the XML
* into the given result. Such a portion always form a subtree
* of the whole XML document rooted at an element.
*
* @param errorHandler
* if any error happens between the invocation of this method
* and the invocation of {@link #getElement(Result)}, they
* must be reported to this handler.
*
* The caller must provide a non-null error handler.
*
* The {@link Result} object created from this method
* may hold a reference to this error handler.
*
* @return
* null if the operation fails. The error must have been reported
* to the error handler.
*/
ResultT createUnmarshaller( ValidationEventHandler errorHandler );
/**
* Once the portion is sent to the {@link Result}. This method is called
* by a JAXB provider to obtain the unmarshalled element representation.
*
* <p>
* Multiple invocations of this method may return different objects.
* This method can be invoked only when the whole sub-tree are fed
* to the {@link Result} object.
*
* @param rt
* The {@link Result} object created by {@link #createUnmarshaller(ValidationEventHandler)}.
*
* @return
* null if the operation fails. The error must have been reported
* to the error handler.
*/
ElementT getElement(ResultT rt);
/**
* This method is called when a JAXB provider needs to marshal an element
* to XML.
*
* <p>
* If non-null, the returned {@link Source} must contain a whole document
* rooted at one element, which will then be weaved into a bigger document
* that the JAXB provider is marshalling.
*
* @param errorHandler
* Receives any errors happened during the process of converting
* an element into a {@link Source}.
*
* The caller must provide a non-null error handler.
*
* @return
* null if there was an error. The error should have been reported
* to the handler.
*/
Source marshal( ElementT n, ValidationEventHandler errorHandler );
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
/**
* {@link DomHandler} implementation for W3C DOM (<code>org.w3c.dom</code> package.)
*
* @author Kohsuke Kawaguchi
* @since JAXB2.0
*/
public class W3CDomHandler implements DomHandler<Element,DOMResult> {
private DocumentBuilder builder;
/**
* Default constructor.
*
* It is up to a JAXB provider to decide which DOM implementation
* to use or how that is configured.
*/
public W3CDomHandler() {
this.builder = null;
}
/**
* Constructor that allows applications to specify which DOM implementation
* to be used.
*
* @param builder
* must not be null. JAXB uses this {@link DocumentBuilder} to create
* a new element.
*/
public W3CDomHandler(DocumentBuilder builder) {
if(builder==null)
throw new IllegalArgumentException();
this.builder = builder;
}
public DocumentBuilder getBuilder() {
return builder;
}
public void setBuilder(DocumentBuilder builder) {
this.builder = builder;
}
public DOMResult createUnmarshaller(ValidationEventHandler errorHandler) {
if(builder==null)
return new DOMResult();
else
return new DOMResult(builder.newDocument());
}
public Element getElement(DOMResult r) {
// JAXP spec is ambiguous about what really happens in this case,
// so work defensively
Node n = r.getNode();
if( n instanceof Document ) {
return ((Document)n).getDocumentElement();
}
if( n instanceof Element )
return (Element)n;
if( n instanceof DocumentFragment )
return (Element)n.getChildNodes().item(0);
// if the result object contains something strange,
// it is not a user problem, but it is a JAXB provider's problem.
// That's why we throw a runtime exception.
throw new IllegalStateException(n.toString());
}
public Source marshal(Element element, ValidationEventHandler errorHandler) {
return new DOMSource(element);
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
/**
* Used by XmlAccessorOrder to control the ordering of properties and
* fields in a JAXB bound class.
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
* @see XmlAccessorOrder
*/
public enum XmlAccessOrder {
/**
* The ordering of fields and properties in a class is undefined.
*/
UNDEFINED,
/**
* The ordering of fields and properties in a class is in
* alphabetical order as determined by the
* method java.lang.String.compareTo(String anotherString).
*/
ALPHABETICAL
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
/**
* Used by XmlAccessorType to control serialization of fields or
* properties.
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
* @see XmlAccessorType
*/
public enum XmlAccessType {
/**
* Every getter/setter pair in a JAXB-bound class will be automatically
* bound to XML, unless annotated by {@link XmlTransient}.
*
* Fields are bound to XML only when they are explicitly annotated
* by some of the JAXB annotations.
*/
PROPERTY,
/**
* Every non static, non transient field in a JAXB-bound class will be automatically
* bound to XML, unless annotated by {@link XmlTransient}.
*
* Getter/setter pairs are bound to XML only when they are explicitly annotated
* by some of the JAXB annotations.
*/
FIELD,
/**
* Every public getter/setter pair and every public field will be
* automatically bound to XML, unless annotated by {@link XmlTransient}.
*
* Fields or getter/setter pairs that are private, protected, or
* defaulted to package-only access are bound to XML only when they are
* explicitly annotated by the appropriate JAXB annotations.
*/
PUBLIC_MEMBER,
/**
* None of the fields or properties is bound to XML unless they
* are specifically annotated with some of the JAXB annotations.
*/
NONE
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.Inherited;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p> Controls the ordering of fields and properties in a class. </p>
*
* <h3>Usage </h3>
*
* <p> <tt> @XmlAccessorOrder </tt> annotation can be used with the following
* program elements:</p>
*
* <ul>
* <li> package</li>
* <li> a top level class </li>
* </ul>
*
* <p> See "Package Specification" in <tt>javax.xml.bind</tt> package javadoc for
* additional common information.</p>
*
* <p>The effective {@link XmlAccessOrder} on a class is determined
* as follows:
*
* <ul>
* <li> If there is a <tt>@XmlAccessorOrder</tt> on a class, then
* it is used. </li>
* <li> Otherwise, if a <tt>@XmlAccessorOrder </tt> exists on one of
* its super classes, then it is inherited (by the virtue of
* {@link Inherited})
* <li> Otherwise, the <tt>@XmlAccessorOrder</tt> on the package
* of the class is used, if it's there.
* <li> Otherwise {@link XmlAccessOrder#UNDEFINED}.
* </ul>
*
* <p>This annotation can be used with the following annotations:
* {@link XmlType}, {@link XmlRootElement}, {@link XmlAccessorType},
* {@link XmlSchema}, {@link XmlSchemaType}, {@link XmlSchemaTypes},
* , {@link XmlJavaTypeAdapter}. It can also be used with the
* following annotations at the package level: {@link XmlJavaTypeAdapter}.
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
* @see XmlAccessOrder
*/
@Inherited @Retention(RUNTIME) @Target({PACKAGE, TYPE})
public @interface XmlAccessorOrder {
XmlAccessOrder value() default XmlAccessOrder.UNDEFINED;
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.Inherited;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p> Controls whether fields or Javabean properties are serialized by default. </p>
*
* <p> <b> Usage </b> </p>
*
* <p> <tt>@XmlAccessorType</tt> annotation can be used with the following program elements:</p>
*
* <ul>
* <li> package</li>
* <li> a top level class </li>
* </ul>
*
* <p> See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p>This annotation provides control over the default serialization
* of properties and fields in a class.
*
* <p>The annotation <tt> @XmlAccessorType </tt> on a package applies to
* all classes in the package. The following inheritance
* semantics apply:
*
* <ul>
* <li> If there is a <tt>@XmlAccessorType</tt> on a class, then it
* is used. </li>
* <li> Otherwise, if a <tt>@XmlAccessorType</tt> exists on one of
* its super classes, then it is inherited.
* <li> Otherwise, the <tt>@XmlAccessorType </tt> on a package is
* inherited.
* </ul>
* <p> <b> Defaulting Rules: </b> </p>
*
* <p>By default, if <tt>@XmlAccessorType </tt> on a package is absent,
* then the following package level annotation is assumed.</p>
* <pre>
* &#64;XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
* </pre>
* <p> By default, if <tt>@XmlAccessorType</tt> on a class is absent,
* and none of its super classes is annotated with
* <tt>@XmlAccessorType</tt>, then the following default on the class
* is assumed: </p>
* <pre>
* &#64;XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
* </pre>
* <p>This annotation can be used with the following annotations:
* {@link XmlType}, {@link XmlRootElement}, {@link XmlAccessorOrder},
* {@link XmlSchema}, {@link XmlSchemaType}, {@link XmlSchemaTypes},
* , {@link XmlJavaTypeAdapter}. It can also be used with the
* following annotations at the package level: {@link XmlJavaTypeAdapter}.
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
* @see XmlAccessType
*/
@Inherited @Retention(RUNTIME) @Target({PACKAGE, TYPE})
public @interface XmlAccessorType {
/**
* Specifies whether fields or properties are serialized.
*
* @see XmlAccessType
*/
XmlAccessType value() default XmlAccessType.PUBLIC_MEMBER;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.namespace.QName;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Map;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
/**
* <p>
* Maps a JavaBean property to a map of wildcard attributes.
*
* <p> <b>Usage</b> </p>
* <p>
* The <tt>&#64;XmlAnyAttribute</tt> annotation can be used with the
* following program elements:
* <ul>
* <li> JavaBean property </li>
* <li> non static, non transient field </li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* The usage is subject to the following constraints:
* <ul>
* <li> At most one field or property in a class can be annotated
* with <tt>&#64;XmlAnyAttribute</tt>. </li>
* <li> The type of the property or the field must <tt>java.util.Map</tt> </li>
* </ul>
*
* <p>
* While processing attributes to be unmarshalled into a value class,
* each attribute that is not statically associated with another
* JavaBean property, via {@link XmlAttribute}, is entered into the
* wildcard attribute map represented by
* {@link Map}&lt;{@link QName},{@link Object}>. The attribute QName is the
* map's key. The key's value is the String value of the attribute.
*
* @author Kohsuke Kawaguchi, Sun Microsystems, Inc.
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD})
public @interface XmlAnyAttribute {
}

View File

@@ -0,0 +1,288 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import org.w3c.dom.Element;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.List;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Maps a JavaBean property to XML infoset representation and/or JAXB element.
*
* <p>
* This annotation serves as a "catch-all" property while unmarshalling
* xml content into a instance of a JAXB annotated class. It typically
* annotates a multi-valued JavaBean property, but it can occur on
* single value JavaBean property. During unmarshalling, each xml element
* that does not match a static &#64;XmlElement or &#64;XmlElementRef
* annotation for the other JavaBean properties on the class, is added to this
* "catch-all" property.
*
* <p>
* <h2>Usages:</h2>
* <pre>
* &#64;XmlAnyElement
* public {@link Element}[] others;
*
* // Collection of {@link Element} or JAXB elements.
* &#64;XmlAnyElement(lax="true")
* public {@link Object}[] others;
*
* &#64;XmlAnyElement
* private List&lt;{@link Element}> nodes;
*
* &#64;XmlAnyElement
* private {@link Element} node;
* </pre>
*
* <h2>Restriction usage constraints</h2>
* <p>
* This annotation is mutually exclusive with
* {@link XmlElement}, {@link XmlAttribute}, {@link XmlValue},
* {@link XmlElements}, {@link XmlID}, and {@link XmlIDREF}.
*
* <p>
* There can be only one {@link XmlAnyElement} annotated JavaBean property
* in a class and its super classes.
*
* <h2>Relationship to other annotations</h2>
* <p>
* This annotation can be used with {@link XmlJavaTypeAdapter}, so that users
* can map their own data structure to DOM, which in turn can be composed
* into XML.
*
* <p>
* This annotation can be used with {@link XmlMixed} like this:
* <pre>
* // List of java.lang.String or DOM nodes.
* &#64;XmlAnyElement &#64;XmlMixed
* List&lt;Object> others;
* </pre>
*
*
* <h2>Schema To Java example</h2>
*
* The following schema would produce the following Java class:
* <pre>
* &lt;xs:complexType name="foo">
* &lt;xs:sequence>
* &lt;xs:element name="a" type="xs:int" />
* &lt;xs:element name="b" type="xs:int" />
* &lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* <pre>
* class Foo {
* int a;
* int b;
* &#64;{@link XmlAnyElement}
* List&lt;Element> any;
* }
* </pre>
*
* It can unmarshal instances like
*
* <pre>
* &lt;foo xmlns:e="extra">
* &lt;a>1</a>
* &lt;e:other /> // this will be bound to DOM, because unmarshalling is orderless
* &lt;b>3</b>
* &lt;e:other />
* &lt;c>5</c> // this will be bound to DOM, because the annotation doesn't remember namespaces.
* &lt;/foo>
* </pre>
*
*
*
* The following schema would produce the following Java class:
* <pre>
* &lt;xs:complexType name="bar">
* &lt;xs:complexContent>
* &lt;xs:extension base="foo">
* &lt;xs:sequence>
* &lt;xs:element name="c" type="xs:int" />
* &lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
* &lt;/xs:sequence>
* &lt;/xs:extension>
* &lt;/xs:complexType>
* </pre>
*
* <pre>
* class Bar extends Foo {
* int c;
* // Foo.getAny() also represents wildcard content for type definition bar.
* }
* </pre>
*
*
* It can unmarshal instances like
*
* <pre>
* &lt;bar xmlns:e="extra">
* &lt;a>1</a>
* &lt;e:other /> // this will be bound to DOM, because unmarshalling is orderless
* &lt;b>3</b>
* &lt;e:other />
* &lt;c>5</c> // this now goes to Bar.c
* &lt;e:other /> // this will go to Foo.any
* &lt;/bar>
* </pre>
*
*
*
*
* <h2>Using {@link XmlAnyElement} with {@link XmlElementRef}</h2>
* <p>
* The {@link XmlAnyElement} annotation can be used with {@link XmlElementRef}s to
* designate additional elements that can participate in the content tree.
*
* <p>
* The following schema would produce the following Java class:
* <pre>
* &lt;xs:complexType name="foo">
* &lt;xs:choice maxOccurs="unbounded" minOccurs="0">
* &lt;xs:element name="a" type="xs:int" />
* &lt;xs:element name="b" type="xs:int" />
* &lt;xs:any namespace="##other" processContents="lax" />
* &lt;/xs:choice>
* &lt;/xs:complexType>
* </pre>
*
* <pre>
* class Foo {
* &#64;{@link XmlAnyElement}(lax="true")
* &#64;{@link XmlElementRefs}({
* &#64;{@link XmlElementRef}(name="a", type="JAXBElement.class")
* &#64;{@link XmlElementRef}(name="b", type="JAXBElement.class")
* })
* {@link List}&lt;{@link Object}> others;
* }
*
* &#64;XmlRegistry
* class ObjectFactory {
* ...
* &#64;XmlElementDecl(name = "a", namespace = "", scope = Foo.class)
* {@link JAXBElement}&lt;Integer> createFooA( Integer i ) { ... }
*
* &#64;XmlElementDecl(name = "b", namespace = "", scope = Foo.class)
* {@link JAXBElement}&lt;Integer> createFooB( Integer i ) { ... }
* </pre>
*
* It can unmarshal instances like
*
* <pre>
* &lt;foo xmlns:e="extra">
* &lt;a>1</a> // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
* &lt;e:other /> // this will unmarshal to a DOM {@link Element}.
* &lt;b>3</b> // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
* &lt;/foo>
* </pre>
*
*
*
*
* <h2>W3C XML Schema "lax" wildcard emulation</h2>
* The lax element of the annotation enables the emulation of the "lax" wildcard semantics.
* For example, when the Java source code is annotated like this:
* <pre>
* &#64;{@link XmlRootElement}
* class Foo {
* &#64;XmlAnyElement(lax=true)
* public {@link Object}[] others;
* }
* </pre>
* then the following document will unmarshal like this:
* <pre>
* &lt;foo>
* &lt;unknown />
* &lt;foo />
* &lt;/foo>
*
* Foo foo = unmarshal();
* // 1 for 'unknown', another for 'foo'
* assert foo.others.length==2;
* // 'unknown' unmarshals to a DOM element
* assert foo.others[0] instanceof Element;
* // because of lax=true, the 'foo' element eagerly
* // unmarshals to a Foo object.
* assert foo.others[1] instanceof Foo;
* </pre>
*
* @author Kohsuke Kawaguchi
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD})
public @interface XmlAnyElement {
/**
* Controls the unmarshaller behavior when it sees elements
* known to the current {@link JAXBContext}.
*
* <h3>When false</h3>
* <p>
* If false, all the elements that match the property will be unmarshalled
* to DOM, and the property will only contain DOM elements.
*
* <h3>When true</h3>
* <p>
* If true, when an element matches a property marked with {@link XmlAnyElement}
* is known to {@link JAXBContext} (for example, there's a class with
* {@link XmlRootElement} that has the same tag name, or there's
* {@link XmlElementDecl} that has the same tag name),
* the unmarshaller will eagerly unmarshal this element to the JAXB object,
* instead of unmarshalling it to DOM. Additionally, if the element is
* unknown but it has a known xsi:type, the unmarshaller eagerly unmarshals
* the element to a {@link JAXBElement}, with the unknown element name and
* the JAXBElement value is set to an instance of the JAXB mapping of the
* known xsi:type.
*
* <p>
* As a result, after the unmarshalling, the property can become heterogeneous;
* it can have both DOM nodes and some JAXB objects at the same time.
*
* <p>
* This can be used to emulate the "lax" wildcard semantics of the W3C XML Schema.
*/
boolean lax() default false;
/**
* Specifies the {@link DomHandler} which is responsible for actually
* converting XML from/to a DOM-like data structure.
*/
Class<? extends DomHandler> value() default W3CDomHandler.class;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.activation.DataHandler;
import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* Marks a field/property that its XML form is a uri reference to mime content.
* The mime content is optimally stored out-of-line as an attachment.
*
* A field/property must always map to the {@link DataHandler} class.
*
* <h2>Usage</h2>
* <pre>
* &#64;{@link XmlRootElement}
* class Foo {
* &#64;{@link XmlAttachmentRef}
* &#64;{@link XmlAttribute}
* {@link DataHandler} data;
*
* &#64;{@link XmlAttachmentRef}
* &#64;{@link XmlElement}
* {@link DataHandler} body;
* }
* </pre>
* The above code maps to the following XML:
* <pre>
* &lt;xs:element name="foo" xmlns:ref="http://ws-i.org/profiles/basic/1.1/xsd">
* &lt;xs:complexType>
* &lt;xs:sequence>
* &lt;xs:element name="body" type="ref:swaRef" minOccurs="0" />
* &lt;/xs:sequence>
* &lt;xs:attribute name="data" type="ref:swaRef" use="optional" />
* &lt;/xs:complexType>
* &lt;/xs:element>
* </pre>
*
* <p>
* The above binding supports WS-I AP 1.0 <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html#Referencing_Attachments_from_the_SOAP_Envelope">WS-I Attachments Profile Version 1.0.</a>
*
* @author Kohsuke Kawaguchi
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD,PARAMETER})
public @interface XmlAttachmentRef {
}

View File

@@ -0,0 +1,152 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p>
* Maps a JavaBean property to a XML attribute.
*
* <p> <b>Usage</b> </p>
* <p>
* The <tt>@XmlAttribute</tt> annotation can be used with the
* following program elements:
* <ul>
* <li> JavaBean property </li>
* <li> field </li>
* </ul>
*
* <p> A static final field is mapped to a XML fixed attribute.
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* The usage is subject to the following constraints:
* <ul>
* <li> If type of the field or the property is a collection
* type, then the collection item type must be mapped to schema
* simple type.
* <pre>
* // Examples
* &#64;XmlAttribute List&lt;Integer> items; //legal
* &#64;XmlAttribute List&lt;Bar> foo; // illegal if Bar does not map to a schema simple type
* </pre>
* </li>
* <li> If the type of the field or the property is a non
* collection type, then the type of the property or field
* must map to a simple schema type.
* <pre>
* // Examples
* &#64;XmlAttribute int foo; // legal
* &#64;XmlAttribute Foo foo; // illegal if Foo does not map to a schema simple type
* </pre>
* </li>
* <li> This annotation can be used with the following annotations:
* {@link XmlID},
* {@link XmlIDREF},
* {@link XmlList},
* {@link XmlSchemaType},
* {@link XmlValue},
* {@link XmlAttachmentRef},
* {@link XmlMimeType},
* {@link XmlInlineBinaryData},
* {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}.</li>
* </ul>
* </p>
*
* <p> <b>Example 1: </b>Map a JavaBean property to an XML attribute.</p>
* <pre>
* //Example: Code fragment
* public class USPrice {
* &#64;XmlAttribute
* public java.math.BigDecimal getPrice() {...} ;
* public void setPrice(java.math.BigDecimal ) {...};
* }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:complexType name="USPrice">
* &lt;xs:sequence>
* &lt;/xs:sequence>
* &lt;xs:attribute name="price" type="xs:decimal"/>
* &lt;/xs:complexType>
* </pre>
*
* <p> <b>Example 2: </b>Map a JavaBean property to an XML attribute with anonymous type.</p>
* See Example 7 in @{@link XmlType}.
*
* <p> <b>Example 3: </b>Map a JavaBean collection property to an XML attribute.</p>
* <pre>
* // Example: Code fragment
* class Foo {
* ...
* &#64;XmlAttribute List&lt;Integer> items;
* }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:complexType name="foo">
* ...
* &lt;xs:attribute name="items">
* &lt;xs:simpleType>
* &lt;xs:list itemType="xs:int"/>
* &lt;/xs:simpleType>
* &lt;/xs:complexType>
*
* </pre>
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @see XmlType
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlAttribute {
/**
* Name of the XML Schema attribute. By default, the XML Schema
* attribute name is derived from the JavaBean property name.
*
*/
String name() default "##default";
/**
* Specifies if the XML Schema attribute is optional or
* required. If true, then the JavaBean property is mapped to a
* XML Schema attribute that is required. Otherwise it is mapped
* to a XML Schema attribute that is optional.
*
*/
boolean required() default false;
/**
* Specifies the XML target namespace of the XML Schema
* attribute.
*
*/
String namespace() default "##default" ;
}

View File

@@ -0,0 +1,210 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.*;
/**
* Maps a JavaBean property to a XML element derived from property name.
*
* <p> <b>Usage</b> </p>
* <p>
* <tt>@XmlElement</tt> annotation can be used with the following program
* elements:
* <ul>
* <li> a JavaBean property </li>
* <li> non static, non transient field </li>
* <li> within {@link XmlElements}
* <p>
*
* </ul>
*
* The usage is subject to the following constraints:
* <ul>
* <li> This annotation can be used with following annotations:
* {@link XmlID},
* {@link XmlIDREF},
* {@link XmlList},
* {@link XmlSchemaType},
* {@link XmlValue},
* {@link XmlAttachmentRef},
* {@link XmlMimeType},
* {@link XmlInlineBinaryData},
* {@link XmlElementWrapper},
* {@link XmlJavaTypeAdapter}</li>
* <li> if the type of JavaBean property is a collection type of
* array, an indexed property, or a parameterized list, and
* this annotation is used with {@link XmlElements} then,
* <tt>@XmlElement.type()</tt> must be DEFAULT.class since the
* collection item type is already known. </li>
* </ul>
*
* <p>
* A JavaBean property, when annotated with @XmlElement annotation
* is mapped to a local element in the XML Schema complex type to
* which the containing class is mapped.
*
* <p>
* <b>Example 1: </b> Map a public non static non final field to local
* element
* <pre>
* //Example: Code fragment
* public class USPrice {
* &#64;XmlElement(name="itemprice")
* public java.math.BigDecimal price;
* }
*
* &lt;!-- Example: Local XML Schema element -->
* &lt;xs:complexType name="USPrice"/>
* &lt;xs:sequence>
* &lt;xs:element name="itemprice" type="xs:decimal" minOccurs="0"/>
* &lt;/sequence>
* &lt;/xs:complexType>
* </pre>
* <p>
*
* <b> Example 2: </b> Map a field to a nillable element.
* <pre>
*
* //Example: Code fragment
* public class USPrice {
* &#64;XmlElement(nillable=true)
* public java.math.BigDecimal price;
* }
*
* &lt;!-- Example: Local XML Schema element -->
* &lt;xs:complexType name="USPrice">
* &lt;xs:sequence>
* &lt;xs:element name="price" type="xs:decimal" nillable="true" minOccurs="0"/>
* &lt;/sequence>
* &lt;/xs:complexType>
* </pre>
* <p>
* <b> Example 3: </b> Map a field to a nillable, required element.
* <pre>
*
* //Example: Code fragment
* public class USPrice {
* &#64;XmlElement(nillable=true, required=true)
* public java.math.BigDecimal price;
* }
*
* &lt;!-- Example: Local XML Schema element -->
* &lt;xs:complexType name="USPrice">
* &lt;xs:sequence>
* &lt;xs:element name="price" type="xs:decimal" nillable="true" minOccurs="1"/>
* &lt;/sequence>
* &lt;/xs:complexType>
* </pre>
* <p>
*
* <p> <b>Example 4: </b>Map a JavaBean property to an XML element
* with anonymous type.</p>
* <p>
* See Example 6 in @{@link XmlType}.
*
* <p>
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER})
public @interface XmlElement {
/**
* Name of the XML Schema element.
* <p> If the value is "##default", then element name is derived from the
* JavaBean property name.
*/
String name() default "##default";
/**
* Customize the element declaration to be nillable.
* <p>If nillable() is true, then the JavaBean property is
* mapped to a XML Schema nillable element declaration.
*/
boolean nillable() default false;
/**
* Customize the element declaration to be required.
* <p>If required() is true, then Javabean property is mapped to
* an XML schema element declaration with minOccurs="1".
* maxOccurs is "1" for a single valued property and "unbounded"
* for a multivalued property.
* <p>If required() is false, then the Javabean property is mapped
* to XML Schema element declaration with minOccurs="0".
* maxOccurs is "1" for a single valued property and "unbounded"
* for a multivalued property.
*/
boolean required() default false;
/**
* XML target namespace of the XML Schema element.
* <p>
* If the value is "##default", then the namespace is determined
* as follows:
* <ol>
* <li>
* If the enclosing package has {@link XmlSchema} annotation,
* and its {@link XmlSchema#elementFormDefault() elementFormDefault}
* is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of
* the enclosing class.
*
* <li>
* Otherwise &#39;&#39; (which produces unqualified element in the default
* namespace.
* </ol>
*/
String namespace() default "##default";
/**
* Default value of this element.
*
* <p>
* The <pre>'\u0000'</pre> 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.
*/
String defaultValue() default "\u0000";
/**
* The Java class being referenced.
*/
Class type() default DEFAULT.class;
/**
* Used in {@link XmlElement#type()} to
* signal that the type be inferred from the signature
* of the property.
*/
static final class DEFAULT {}
}

View File

@@ -0,0 +1,216 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.METHOD;
/**
* Maps a factory method to a XML element.
*
* <p> <b>Usage</b> </p>
*
* The annotation creates a mapping between an XML schema element
* declaration and a <i> element factory method </i> 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 &#64;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:
*
* <ul>
* <li> The class containing the element factory method annotated
* with &#64;XmlElementDecl must be marked with {@link
* XmlRegistry}. </li>
* <li> The element factory method must take one parameter
* assignable to {@link Object}.</li>
* </ul>
*
* <p><b>Example 1: </b>Annotation on a factory method
* <pre>
* // Example: code fragment
* &#64;XmlRegistry
* class ObjectFactory {
* &#64;XmlElementDecl(name="foo")
* JAXBElement&lt;String> createFoo(String s) { ... }
* }
* </pre>
* <pre>
* &lt;!-- XML input -->
* &lt;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"
*
* &lt;!-- Example: XML schema definition -->
* &lt;xs:element name="foo" type="xs:string"/>
* </pre>
*
* <p><b>Example 2: </b> Element declaration with non local scope
* <p>
* The following example illustrates the use of scope annotation
* parameter in binding of element declaration in schema derived
* code.
* <p>
* The following example may be replaced in a future revision of
* this javadoc.
*
* <pre>
* &lt;!-- Example: XML schema definition -->
* &lt;xs:schema>
* &lt;xs:complexType name="pea">
* &lt;xs:choice maxOccurs="unbounded">
* &lt;xs:element name="foo" type="xs:string"/>
* &lt;xs:element name="bar" type="xs:string"/>
* &lt;/xs:choice>
* &lt;/xs:complexType>
* &lt;xs:element name="foo" type="xs:int"/>
* &lt;/xs:schema>
* </pre>
* <pre>
* // Example: expected default binding
* class Pea {
* &#64;XmlElementRefs({
* &#64;XmlElementRef(name="foo",type=JAXBElement.class)
* &#64;XmlElementRef(name="bar",type=JAXBElement.class)
* })
* List&lt;JAXBElement&lt;String>> fooOrBar;
* }
*
* &#64;XmlRegistry
* class ObjectFactory {
* &#64;XmlElementDecl(scope=Pea.class,name="foo")
* JAXBElement<String> createPeaFoo(String s);
*
* &#64;XmlElementDecl(scope=Pea.class,name="bar")
* JAXBElement<String> createPeaBar(String s);
*
* &#64;XmlElementDecl(name="foo")
* JAXBElement<Integer> createFoo(Integer i);
* }
*
* </pre>
* Without scope createFoo and createPeaFoo would become ambiguous
* since both of them map to a XML schema element with the same local
* name "foo".
*
* @see XmlRegistry
* @since JAXB 2.0
*/
@Retention(RUNTIME)
@Target({METHOD})
public @interface XmlElementDecl {
/**
* scope of the mapping.
*
* <p>
* If this is not {@link XmlElementDecl.GLOBAL}, then this element
* declaration mapping is only active within the specified class.
*/
Class scope() default GLOBAL.class;
/**
* namespace name of the XML element.
* <p>
* If the value is "##default", then the value is the namespace
* name for the package of the class containing this factory method.
*
* @see #name()
*/
String namespace() default "##default";
/**
* local name of the XML element.
*
* <p>
* <b> Note to reviewers: </b> 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.
* @see #namespace()
*/
String name();
/**
* namespace name of a substitution group's head XML element.
* <p>
* This specifies the namespace name of the XML element whose local
* name is specified by <tt>substitutionHeadName()</tt>.
* <p>
* If <tt>susbtitutionHeadName()</tt> 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 <tt>susbstitutionHeadName()</tt> is "".
* <p>
* If <tt>susbtitutionHeadName()</tt> 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 {@link
* XmlRegistry }, is mapped.
* <p>
* If <tt>susbtitutionHeadName()</tt> is not "" and the value is
* not "##default", then the value is the namespace name.
*
* @see #substitutionHeadName()
*/
String substitutionHeadNamespace() default "##default";
/**
* XML local name of a substitution group's head element.
* <p>
* If the value is "", then this element is not part of any
* substitution group.
*
* @see #substitutionHeadNamespace()
*/
String substitutionHeadName() default "";
/**
* Default value of this element.
*
* <p>
* The <pre>'\u0000'</pre> 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.
*/
String defaultValue() default "\u0000";
/**
* Used in {@link XmlElementDecl#scope()} to
* signal that the declaration is in the global scope.
*/
public final class GLOBAL {}
}

View File

@@ -0,0 +1,290 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
/**
* <p>
* Maps a JavaBean property to a XML element derived from property's type.
* <p>
* <b>Usage</b>
* <p>
* <tt>&#64;XmlElementRef</tt> annotation can be used with a
* JavaBean property or from within {@link XmlElementRefs}
* <p>
* This annotation dynamically associates an XML element name with the JavaBean
* property. When a JavaBean property is annotated with {@link
* XmlElement}, the XML element name is statically derived from the
* JavaBean property name. However, when this annotation is used, the
* XML element name is derived from the instance of the type of the
* JavaBean property at runtime.
*
* <h3> XML Schema substitution group support </h3>
* XML Schema allows a XML document author to use XML element names
* that were not statically specified in the content model of a
* 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 &#64;XmlElementRef annotation on an
* element property indicates that the element name from <tt>JAXBElement</tt>
* instance be used instead of deriving an XML element name from the
* JavaBean property name.
*
* <p>
* The usage is subject to the following constraints:
* <ul>
* <li> If the collection item type (for collection property) or
* property type (for single valued property) is
* {@link javax.xml.bind.JAXBElement}, then
* <tt>&#64;XmlElementRef}.name()</tt> and <tt>&#64;XmlElementRef.namespace()</tt> must
* point an element factory method with an @XmlElementDecl
* annotation in a class annotated with @XmlRegistry (usually
* ObjectFactory class generated by the schema compiler) :
* <ul>
* <li> @XmlElementDecl.name() must equal @XmlElementRef.name() </li>
* <li> @XmlElementDecl.namespace() must equal @XmlElementRef.namespace(). </li>
* </ul>
* </li>
* <li> If the collection item type (for collection property) or
* property type (for single valued property) is not
* {@link javax.xml.bind.JAXBElement}, then the type referenced by the
* property or field must be annotated with {@link XmlRootElement}. </li>
* <li> This annotation can be used with the following annotations:
* {@link XmlElementWrapper}, {@link XmlJavaTypeAdapter}.
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p><b>Example 1: Ant Task Example</b></p>
* The following Java class hierarchy models an Ant build
* script. An Ant task corresponds to a class in the class
* hierarchy. The XML element name of an Ant task is indicated by the
* &#64;XmlRootElement annotation on its corresponding class.
* <pre>
* &#64;XmlRootElement(name="target")
* class Target {
* // The presence of &#64;XmlElementRef indicates that the XML
* // element name will be derived from the &#64;XmlRootElement
* // annotation on the type (for e.g. "jar" for JarTask).
* &#64;XmlElementRef
* List&lt;Task> tasks;
* }
*
* abstract class Task {
* }
*
* &#64;XmlRootElement(name="jar")
* class JarTask extends Task {
* ...
* }
*
* &#64;XmlRootElement(name="javac")
* class JavacTask extends Task {
* ...
* }
*
* &lt;!-- XML Schema fragment -->
* &lt;xs:element name="target" type="Target">
* &lt;xs:complexType name="Target">
* &lt;xs:sequence>
* &lt;xs:choice maxOccurs="unbounded">
* &lt;xs:element ref="jar">
* &lt;xs:element ref="javac">
* &lt;/xs:choice>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
*
* </pre>
* <p>
* Thus the following code fragment:
* <pre>
* Target target = new Target();
* target.tasks.add(new JarTask());
* target.tasks.add(new JavacTask());
* marshal(target);
* </pre>
* will produce the following XML output:
* <pre>
* &lt;target>
* &lt;jar>
* ....
* &lt;/jar>
* &lt;javac>
* ....
* &lt;/javac>
* &lt;/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).
*
* <p><b>Example 2: XML Schema Susbstitution group support</b>
* <p> The following example shows the annotations for XML Schema
* substitution groups. The annotations and the ObjectFactory are
* derived from the schema.
*
* <pre>
* &#64;XmlElement
* class Math {
* // The value of {@link #type()}is
* // JAXBElement.class , which indicates the XML
* // element name ObjectFactory - in general a class marked
* // with &#64;XmlRegistry. (See ObjectFactory below)
* //
* // The {@link #name()} is "operator", a pointer to a
* // factory method annotated with a
* // {@link XmlElementDecl} with the name "operator". Since
* // "operator" is the head of a substitution group that
* // contains elements "add" and "sub" elements, "operator"
* // element can be substituted in an instance document by
* // elements "add" or "sub". At runtime, JAXBElement
* // instance contains the element name that has been
* // substituted in the XML document.
* //
* &#64;XmlElementRef(type=JAXBElement.class,name="operator")
* JAXBElement&lt;? extends Operator> term;
* }
*
* &#64;XmlRegistry
* class ObjectFactory {
* &#64;XmlElementDecl(name="operator")
* JAXBElement&lt;Operator> createOperator(Operator o) {...}
* &#64;XmlElementDecl(name="add",substitutionHeadName="operator")
* JAXBElement&lt;Operator> createAdd(Operator o) {...}
* &#64;XmlElementDecl(name="sub",substitutionHeadName="operator")
* JAXBElement&lt;Operator> createSub(Operator o) {...}
* }
*
* class Operator {
* ...
* }
* </pre>
* <p>
* Thus, the following code fragment
* <pre>
* Math m = new Math();
* m.term = new ObjectFactory().createAdd(new Operator());
* marshal(m);
* </pre>
* will produce the following XML output:
* <pre>
* &lt;math>
* &lt;add>...&lt;/add>
* &lt;/math>
* </pre>
*
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems,Inc. </li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlElementRefs
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD})
public @interface XmlElementRef {
/**
* The Java type being referenced.
* <p>
* If the value is DEFAULT.class, the type is inferred from the
* the type of the JavaBean property.
*/
Class type() default DEFAULT.class;
/**
* This parameter and {@link #name()} are used to determine the
* XML element for the JavaBean property.
*
* <p> If <tt>type()</tt> is <tt>JAXBElement.class</tt> , then
* <tt>namespace()</tt> and <tt>name()</tt>
* point to a factory method with {@link XmlElementDecl}. The XML
* element name is the element name from the factory method's
* {@link XmlElementDecl} annotation or if an element from its
* substitution group (of which it is a head element) has been
* substituted in the XML document, then the element name is from the
* {@link XmlElementDecl} on the substituted element.
*
* <p> If {@link #type()} is not <tt>JAXBElement.class</tt>, then
* the XML element name is the XML element name statically
* associated with the type using the annotation {@link
* XmlRootElement} on the type. If the type is not annotated with
* an {@link XmlElementDecl}, then it is an error.
*
* <p> If <tt>type()</tt> is not <tt>JAXBElement.class</tt>, then
* this value must be "".
*
*/
String namespace() default "";
/**
*
* @see #namespace()
*/
String name() default "##default";
/**
* Used in {@link XmlElementRef#type()} to
* signal that the type be inferred from the signature
* of the property.
*/
static final class DEFAULT {}
/**
* Customize the element declaration to be required.
* <p>
* If required() is true, then Javabean property is mapped to
* an XML schema element declaration with minOccurs="1".
* maxOccurs is "1" for a single valued property and "unbounded"
* for a multivalued property.
*
* <p>
* If required() is false, then the Javabean property is mapped
* to XML Schema element declaration with minOccurs="0".
* maxOccurs is "1" for a single valued property and "unbounded"
* for a multivalued property.
*
* <p>
* For compatibility with JAXB 2.1, this property defaults to <tt>true</tt>,
* despite the fact that {@link XmlElement#required()} defaults to false.
*
* @since 2.2
*/
boolean required() default true;
}

View File

@@ -0,0 +1,59 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Marks a property that refers to classes with {@link XmlElement}
* or JAXBElement.
*
* <p>
* Compared to an element property (property with {@link XmlElement}
* annotation), a reference property has a different substitution semantics.
* When a sub-class is assigned to a property, an element property produces
* the same tag name with @xsi:type, whereas a reference property produces
* a different tag name (the tag name that's on the the sub-class.)
*
* <p> This annotation can be used with the following annotations:
* {@link XmlJavaTypeAdapter}, {@link XmlElementWrapper}.
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
*
* @see XmlElementWrapper
* @see XmlElementRef
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD})
public @interface XmlElementRefs {
XmlElementRef[] value();
}

View File

@@ -0,0 +1,145 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Generates a wrapper element around XML representation.
*
* This is primarily intended to be used to produce a wrapper
* XML element around collections. The annotation therefore supports
* two forms of serialization shown below.
*
* <pre>
* //Example: code fragment
* int[] names;
*
* // XML Serialization Form 1 (Unwrapped collection)
* &lt;names> ... &lt;/names>
* &lt;names> ... &lt;/names>
*
* // XML Serialization Form 2 ( Wrapped collection )
* &lt;wrapperElement>
* &lt;names> value-of-item &lt;/names>
* &lt;names> value-of-item &lt;/names>
* ....
* &lt;/wrapperElement>
* </pre>
*
* <p> The two serialized XML forms allow a null collection to be
* represented either by absence or presence of an element with a
* nillable attribute.
*
* <p> <b>Usage</b> </p>
* <p>
* The <tt>@XmlElementWrapper</tt> annotation can be used with the
* following program elements:
* <ul>
* <li> JavaBean property </li>
* <li> non static, non transient field </li>
* </ul>
*
* <p>The usage is subject to the following constraints:
* <ul>
* <li> The property must be a collection property </li>
* <li> This annotation can be used with the following annotations:
* {@link XmlElement},
* {@link XmlElements},
* {@link XmlElementRef},
* {@link XmlElementRefs},
* {@link XmlJavaTypeAdapter}.</li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlElement
* @see XmlElements
* @see XmlElementRef
* @see XmlElementRefs
* @since JAXB2.0
*
*/
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlElementWrapper {
/**
* Name of the XML wrapper element. By default, the XML wrapper
* element name is derived from the JavaBean property name.
*/
String name() default "##default";
/**
* XML target namespace of the XML wrapper element.
* <p>
* If the value is "##default", then the namespace is determined
* as follows:
* <ol>
* <li>
* If the enclosing package has {@link XmlSchema} annotation,
* and its {@link XmlSchema#elementFormDefault() elementFormDefault}
* is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of
* the enclosing class.
*
* <li>
* Otherwise "" (which produces unqualified element in the default
* namespace.
* </ol>
*/
String namespace() default "##default";
/**
* If true, the absence of the collection is represented by
* using <tt>xsi:nil='true'</tt>. Otherwise, it is represented by
* the absence of the element.
*/
boolean nillable() default false;
/**
* Customize the wrapper element declaration to be required.
*
* <p>
* If required() is true, then the corresponding generated
* XML schema element declaration will have <tt>minOccurs="1"</tt>,
* to indicate that the wrapper element is always expected.
*
* <p>
* Note that this only affects the schema generation, and
* not the unmarshalling or marshalling capability. This is
* simply a mechanism to let users express their application constraints
* better.
*
* @since JAXB 2.1
*/
boolean required() default false;
}

View File

@@ -0,0 +1,177 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* <p>
* A container for multiple @{@link XmlElement} annotations.
*
* Multiple annotations of the same type are not allowed on a program
* element. This annotation therefore serves as a container annotation
* for multiple &#64;XmlElements as follows:
*
* <pre>
* &#64;XmlElements({ @XmlElement(...),@XmlElement(...) })
* </pre>
*
* <p>The <tt>@XmlElements</tt> annnotation can be used with the
* following program elements: </p>
* <ul>
* <li> a JavaBean property </li>
* <li> non static, non transient field </li>
* </ul>
*
* This annotation is intended for annotation a JavaBean collection
* property (e.g. List).
*
* <p><b>Usage</b></p>
*
* <p>The usage is subject to the following constraints:
* <ul>
* <li> This annotation can be used with the following
* annotations: @{@link XmlIDREF}, @{@link XmlElementWrapper}. </li>
* <li> If @XmlIDREF is also specified on the JavaBean property,
* then each &#64;XmlElement.type() must contain a JavaBean
* property annotated with <tt>&#64;XmlID</tt>.</li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <hr>
*
* <p><b>Example 1:</b> Map to a list of elements</p>
* <pre>
*
* // Mapped code fragment
* public class Foo {
* &#64;XmlElements(
* &#64;XmlElement(name="A", type=Integer.class),
* &#64;XmlElement(name="B", type=Float.class)
* }
* public List items;
* }
*
* &lt;!-- XML Representation for a List of {1,2.5}
* XML output is not wrapped using another element -->
* ...
* &lt;A> 1 &lt;/A>
* &lt;B> 2.5 &lt;/B>
* ...
*
* &lt;!-- XML Schema fragment -->
* &lt;xs:complexType name="Foo">
* &lt;xs:sequence>
* &lt;xs:choice minOccurs="0" maxOccurs="unbounded">
* &lt;xs:element name="A" type="xs:int"/>
* &lt;xs:element name="B" type="xs:float"/>
* &lt;xs:choice>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
*
* </pre>
*
* <p><b>Example 2:</b> Map to a list of elements wrapped with another element
* </p>
* <pre>
*
* // Mapped code fragment
* public class Foo {
* &#64;XmlElementWrapper(name="bar")
* &#64;XmlElements(
* &#64;XmlElement(name="A", type=Integer.class),
* &#64;XmlElement(name="B", type=Float.class)
* }
* public List items;
* }
*
* &lt;!-- XML Schema fragment -->
* &lt;xs:complexType name="Foo">
* &lt;xs:sequence>
* &lt;xs:element name="bar">
* &lt;xs:complexType>
* &lt;xs:choice minOccurs="0" maxOccurs="unbounded">
* &lt;xs:element name="A" type="xs:int"/>
* &lt;xs:element name="B" type="xs:float"/>
* &lt;/xs:choice>
* &lt;/xs:complexType>
* &lt;/xs:element>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* <p><b>Example 3:</b> Change element name based on type using an adapter.
* </p>
* <pre>
* class Foo {
* &#64;XmlJavaTypeAdapter(QtoPAdapter.class)
* &#64;XmlElements({
* &#64;XmlElement(name="A",type=PX.class),
* &#64;XmlElement(name="B",type=PY.class)
* })
* Q bar;
* }
*
* &#64;XmlType abstract class P {...}
* &#64;XmlType(name="PX") class PX extends P {...}
* &#64;XmlType(name="PY") class PY extends P {...}
*
* &lt;!-- XML Schema fragment -->
* &lt;xs:complexType name="Foo">
* &lt;xs:sequence>
* &lt;xs:element name="bar">
* &lt;xs:complexType>
* &lt;xs:choice minOccurs="0" maxOccurs="unbounded">
* &lt;xs:element name="A" type="PX"/>
* &lt;xs:element name="B" type="PY"/>
* &lt;/xs:choice>
* &lt;/xs:complexType>
* &lt;/xs:element>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlElement
* @see XmlElementRef
* @see XmlElementRefs
* @see XmlJavaTypeAdapter
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD,METHOD})
public @interface XmlElements {
/**
* Collection of @{@link XmlElement} annotations
*/
XmlElement[] value();
}

View File

@@ -0,0 +1,75 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* <p>
* Maps an enum type {@link Enum} to XML representation.
*
* <p>This annotation, together with {@link XmlEnumValue} provides a
* mapping of enum type to XML representation.
*
* <p> <b>Usage</b> </p>
* <p>
* The <tt>@XmlEnum</tt> annotation can be used with the
* following program elements:
* <ul>
* <li>enum type</li>
* </ul>
*
* <p> The usage is subject to the following constraints:
* <ul>
* <li> This annotation can be used the following other annotations:
* {@link XmlType},
* {@link XmlRootElement} </li>
* </ul>
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information </p>
*
* <p>An enum type is mapped to a schema simple type with enumeration
* facets. The schema type is derived from the Java type to which
* <tt>@XmlEnum.value()</tt>. Each enum constant <tt>@XmlEnumValue</tt>
* must have a valid lexical representation for the type
* <tt>@XmlEnum.value()</tt> .
*
* <p><b>Examples:</b> See examples in {@link XmlEnumValue}
*
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({TYPE})
public @interface XmlEnum {
/**
* Java type that is mapped to a XML simple type.
*
*/
Class<?> value() default String.class;
}

View File

@@ -0,0 +1,123 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
/**
* Maps an enum constant in {@link Enum} type to XML representation.
*
* <p> <b>Usage</b> </p>
*
* <p> The <tt>@XmlEnumValue</tt> annotation can be used with the
* following program elements:
* <ul>
* <li>enum constant</li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p>This annotation, together with {@link XmlEnum} provides a
* mapping of enum type to XML representation.
*
* <p>An enum type is mapped to a schema simple type with enumeration
* facets. The schema type is derived from the Java type specified in
* <tt>@XmlEnum.value()</tt>. Each enum constant <tt>@XmlEnumValue</tt>
* must have a valid lexical representation for the type
* <tt>@XmlEnum.value()</tt>
*
* <p> In the absence of this annotation, {@link Enum#name()} is used
* as the XML representation.
*
* <p> <b>Example 1: </b>Map enum constant name -> enumeration facet</p>
* <pre>
* //Example: Code fragment
* &#64;XmlEnum(String.class)
* public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:simpleType name="Card">
* &lt;xs:restriction base="xs:string"/>
* &lt;xs:enumeration value="CLUBS"/>
* &lt;xs:enumeration value="DIAMONDS"/>
* &lt;xs:enumeration value="HEARTS"/>
* &lt;xs:enumeration value="SPADES"/>
* &lt;/xs:simpleType>
* </pre>
*
* <p><b>Example 2: </b>Map enum constant name(value) -> enumeration facet </p>
* <pre>
* //Example: code fragment
* &#64;XmlType
* &#64;XmlEnum(Integer.class)
* public enum Coin {
* &#64;XmlEnumValue("1") PENNY(1),
* &#64;XmlEnumValue("5") NICKEL(5),
* &#64;XmlEnumValue("10") DIME(10),
* &#64;XmlEnumValue("25") QUARTER(25) }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:simpleType name="Coin">
* &lt;xs:restriction base="xs:int">
* &lt;xs:enumeration value="1"/>
* &lt;xs:enumeration value="5"/>
* &lt;xs:enumeration value="10"/>
* &lt;xs:enumeration value="25"/>
* &lt;/xs:restriction>
* &lt;/xs:simpleType>
* </pre>
*
* <p><b>Example 3: </b>Map enum constant name -> enumeration facet </p>
*
* <pre>
* //Code fragment
* &#64;XmlType
* &#64;XmlEnum(Integer.class)
* public enum Code {
* &#64;XmlEnumValue("1") ONE,
* &#64;XmlEnumValue("2") TWO;
* }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:simpleType name="Code">
* &lt;xs:restriction base="xs:int">
* &lt;xs:enumeration value="1"/>
* &lt;xs:enumeration value="2"/>
* &lt;/xs:restriction>
* &lt;/xs:simpleType>
* </pre>
*
* @since JAXB 2.0
*/
@Retention(RUNTIME)
@Target({FIELD})
public @interface XmlEnumValue {
String value();
}

View File

@@ -0,0 +1,94 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p>
* Maps a JavaBean property to XML ID.
*
* <p>
* To preserve referential integrity of an object graph across XML
* serialization followed by a XML deserialization, requires an object
* reference to be marshalled by reference or containment
* appropriately. Annotations <tt>&#64;XmlID</tt> and <tt>&#64;XmlIDREF</tt>
* together allow a customized mapping of a JavaBean property's
* type by containment or reference.
*
* <p><b>Usage</b> </p>
* The <tt>&#64;XmlID</tt> annotation can be used with the following
* program elements:
* <ul>
* <li> a JavaBean property </li>
* <li> non static, non transient field </li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* The usage is subject to the following constraints:
* <ul>
* <li> At most one field or property in a class can be annotated
* with <tt>&#64;XmlID</tt>. </li>
* <li> The JavaBean property's type must be <tt>java.lang.String</tt>.</li>
* <li> The only other mapping annotations that can be used
* with <tt>&#64;XmlID</tt>
* are:<tt>&#64;XmlElement</tt> and <tt>&#64;XmlAttribute</tt>.</li>
* </ul>
*
* <p><b>Example</b>: Map a JavaBean property's type to <tt>xs:ID</tt></p>
* <pre>
* // Example: code fragment
* public class Customer {
* &#64;XmlAttribute
* &#64;XmlID
* public String getCustomerID();
* public void setCustomerID(String id);
* .... other properties not shown
* }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:complexType name="Customer">
* &lt;xs:complexContent>
* &lt;xs:sequence>
* ....
* &lt;/xs:sequence>
* &lt;xs:attribute name="customerID" type="xs:ID"/>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
* </pre>
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @see XmlIDREF
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlID { }

View File

@@ -0,0 +1,250 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p>
* Maps a JavaBean property to XML IDREF.
*
* <p>
* To preserve referential integrity of an object graph across XML
* serialization followed by a XML deserialization, requires an object
* reference to be marshalled by reference or containment
* appropriately. Annotations <tt>&#64;XmlID</tt> and <tt>&#64;XmlIDREF</tt>
* together allow a customized mapping of a JavaBean property's
* type by containment or reference.
*
* <p><b>Usage</b> </p>
* The <tt>&#64;XmlIDREF</tt> annotation can be used with the following
* program elements:
* <ul>
* <li> a JavaBean property </li>
* <li> non static, non transient field </li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p> The usage is subject to the following constraints:
* <ul>
*
* <li> If the type of the field or property is a collection type,
* then the collection item type must contain a property or
* field annotated with <tt>&#64;XmlID</tt>. </li>
* <li> If the field or property is single valued, then the type of
* the property or field must contain a property or field
* annotated with <tt>&#64;XmlID</tt>.
* <p>Note: If the collection item type or the type of the
* property (for non collection type) is java.lang.Object, then
* the instance must contain a property/field annotated with
* <tt>&#64;XmlID</tt> attribute.
* </li>
* <li> This annotation can be used with the following annotations:
* {@link XmlElement}, {@link XmlAttribute}, {@link XmlList},
* and {@link XmlElements}.</li>
*
* </ul>
* <p><b>Example:</b> Map a JavaBean property to <tt>xs:IDREF</tt>
* (i.e. by reference rather than by containment)</p>
* <pre>
*
* //EXAMPLE: Code fragment
* public class Shipping {
* &#64;XmlIDREF public Customer getCustomer();
* public void setCustomer(Customer customer);
* ....
* }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:complexType name="Shipping">
* &lt;xs:complexContent>
* &lt;xs:sequence>
* &lt;xs:element name="customer" type="xs:IDREF"/>
* ....
* &lt;/xs:sequence>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
*
* </pre>
*
*
* <p><b>Example 2: </b> The following is a complete example of
* containment versus reference.
*
* <pre>
* // By default, Customer maps to complex type <tt>xs:Customer</tt>
* public class Customer {
*
* // map JavaBean property type to <tt>xs:ID</tt>
* &#64;XmlID public String getCustomerID();
* public void setCustomerID(String id);
*
* // .... other properties not shown
* }
*
*
* // By default, Invoice maps to a complex type <tt>xs:Invoice</tt>
* public class Invoice {
*
* // map by reference
* &#64;XmlIDREF public Customer getCustomer();
* public void setCustomer(Customer customer);
*
* // .... other properties not shown here
* }
*
* // By default, Shipping maps to complex type <tt>xs:Shipping</tt>
* public class Shipping {
*
* // map by reference
* &#64;XmlIDREF public Customer getCustomer();
* public void setCustomer(Customer customer);
* }
*
* // at least one class must reference Customer by containment;
* // Customer instances won't be marshalled.
* &#64;XmlElement(name="CustomerData")
* public class CustomerData {
* // map reference to Customer by containment by default.
* public Customer getCustomer();
*
* // maps reference to Shipping by containment by default.
* public Shipping getShipping();
*
* // maps reference to Invoice by containment by default.
* public Invoice getInvoice();
* }
*
* &lt;!-- XML Schema mapping for above code frament -->
*
* &lt;xs:complexType name="Invoice">
* &lt;xs:complexContent>
* &lt;xs:sequence>
* &lt;xs:element name="customer" type="xs:IDREF"/>
* ....
* &lt;/xs:sequence>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
*
* &lt;xs:complexType name="Shipping">
* &lt;xs:complexContent>
* &lt;xs:sequence>
* &lt;xs:element name="customer" type="xs:IDREF"/>
* ....
* &lt;/xs:sequence>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
*
* &lt;xs:complexType name="Customer">
* &lt;xs:complexContent>
* &lt;xs:sequence>
* ....
* &lt;/xs:sequence>
* &lt;xs:attribute name="CustomerID" type="xs:ID"/>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
*
* &lt;xs:complexType name="CustomerData">
* &lt;xs:complexContent>
* &lt;xs:sequence>
* &lt;xs:element name="customer" type="xs:Customer"/>
* &lt;xs:element name="shipping" type="xs:Shipping"/>
* &lt;xs:element name="invoice" type="xs:Invoice"/>
* &lt;/xs:sequence>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
*
* &lt;xs:element name"customerData" type="xs:CustomerData"/>
*
* &lt;!-- Instance document conforming to the above XML Schema -->
* &lt;customerData>
* &lt;customer customerID="Alice">
* ....
* &lt;/customer>
*
* &lt;shipping customer="Alice">
* ....
* &lt;/shipping>
*
* &lt;invoice customer="Alice">
* ....
* &lt;/invoice>
* &lt;/customerData>
*
* </pre>
*
* <p><b>Example 3: </b> Mapping List to repeating element of type IDREF
* <pre>
* // Code fragment
* public class Shipping {
* &#64;XmlIDREF
* &#64;XmlElement(name="Alice")
* public List customers;
* }
*
* &lt;!-- XML schema fragment -->
* &lt;xs:complexType name="Shipping">
* &lt;xs:sequence>
* &lt;xs:choice minOccurs="0" maxOccurs="unbounded">
* &lt;xs:element name="Alice" type="xs:IDREF"/>
* &lt;/xs:choice>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* <p><b>Example 4: </b> Mapping a List to a list of elements of type IDREF.
* <pre>
* //Code fragment
* public class Shipping {
* &#64;XmlIDREF
* &#64;XmlElements(
* &#64;XmlElement(name="Alice", type="Customer.class")
* &#64;XmlElement(name="John", type="InternationalCustomer.class")
* public List customers;
* }
*
* &lt;!-- XML Schema fragment -->
* &lt;xs:complexType name="Shipping">
* &lt;xs:sequence>
* &lt;xs:choice minOccurs="0" maxOccurs="unbounded">
* &lt;xs:element name="Alice" type="xs:IDREF"/>
* &lt;xs:element name="John" type="xs:IDREF"/>
* &lt;/xs:choice>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @see XmlID
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlIDREF {}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import javax.xml.transform.Source;
import javax.xml.bind.attachment.AttachmentMarshaller;
import javax.activation.DataHandler;
/**
* Disable consideration of XOP encoding for datatypes that are bound to
* base64-encoded binary data in XML.
*
* <p>
* When XOP encoding is enabled as described in {@link AttachmentMarshaller#isXOPPackage()}, this annotation disables datatypes such as {@link java.awt.Image} or {@link Source} or <tt>byte[]</tt> that are bound to base64-encoded binary from being considered for
* XOP encoding. If a JAXB property is annotated with this annotation or if
* the JAXB property's base type is annotated with this annotation,
* neither
* {@link AttachmentMarshaller#addMtomAttachment(DataHandler, String, String)}
* nor
* {@link AttachmentMarshaller#addMtomAttachment(byte[], int, int, String, String, String)} is
* ever called for the property. The binary data will always be inlined.
*
* @author Joseph Fialli
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD,TYPE})
public @interface XmlInlineBinaryData {
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
/**
* Used to map a property to a list simple type.
*
* <p><b>Usage</b> </p>
* <p>
* The <tt>@XmlList</tt> annotation can be used with the
* following program elements:
* <ul>
* <li> JavaBean property </li>
* <li> field </li>
* </ul>
*
* <p>
* When a collection property is annotated just with @XmlElement,
* each item in the collection will be wrapped by an element.
* For example,
*
* <pre>
* &#64;XmlRootElement
* class Foo {
* &#64;XmlElement
* List&lt;String> data;
* }
* </pre>
*
* would produce XML like this:
*
* <pre>
* &lt;foo>
* &lt;data>abc</data>
* &lt;data>def</data>
* &lt;/foo>
* </pre>
*
* &#64;XmlList annotation, on the other hand, allows multiple values to be
* represented as whitespace-separated tokens in a single element. For example,
*
* <pre>
* &#64;XmlRootElement
* class Foo {
* &#64;XmlElement
* &#64;XmlList
* List&lt;String> data;
* }
* </pre>
*
* the above code will produce XML like this:
*
* <pre>
* &lt;foo>
* &lt;data>abc def</data>
* &lt;/foo>
* </pre>
*
* <p>This annotation can be used with the following annotations:
* {@link XmlElement},
* {@link XmlAttribute},
* {@link XmlValue},
* {@link XmlIDREF}.
* <ul>
* <li> The use of <tt>@XmlList</tt> with {@link XmlValue} while
* allowed, is redundant since {@link XmlList} maps a
* collection type to a simple schema type that derives by
* list just as {@link XmlValue} would. </li>
*
* <li> The use of <tt>@XmlList</tt> with {@link XmlAttribute} while
* allowed, is redundant since {@link XmlList} maps a
* collection type to a simple schema type that derives by
* list just as {@link XmlAttribute} would. </li>
* </ul>
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD,METHOD,PARAMETER})
public @interface XmlList {
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import javax.xml.transform.Source;
/**
* Associates the MIME type that controls the XML representation of the property.
*
* <p>
* This annotation is used in conjunction with datatypes such as
* {@link java.awt.Image} or {@link Source} that are bound to base64-encoded binary in XML.
*
* <p>
* If a property that has this annotation has a sibling property bound to
* the xmime:contentType attribute, and if in the instance the property has a value,
* the value of the attribute takes precedence and that will control the marshalling.
*
* @author Kohsuke Kawaguchi
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD,PARAMETER})
public @interface XmlMimeType {
/**
* The textual representation of the MIME type,
* such as "image/jpeg" "image/*", "text/xml; charset=iso-8859-1" and so on.
*/
String value();
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import org.w3c.dom.Element;
import javax.xml.bind.JAXBElement;
/**
* <p>
* Annotate a JavaBean multi-valued property to support mixed content.
*
* <p>
* The usage is subject to the following constraints:
* <ul>
* <li> can be used with &#64;XmlElementRef, &#64;XmlElementRefs or &#64;XmlAnyElement</li>
* </ul>
* <p>
* The following can be inserted into &#64;XmlMixed annotated multi-valued property
* <ul>
* <li>XML text information items are added as values of java.lang.String.</li>
* <li>Children element information items are added as instances of
* {@link JAXBElement} or instances with a class that is annotated with
* &#64;XmlRootElement.</li>
* <li>Unknown content that is not be bound to a JAXB mapped class is inserted
* as {@link Element}. (Assumes property annotated with &#64;XmlAnyElement)</li>
* </ul>
*
* Below is an example of binding and creation of mixed content.
* <pre>
* &lt;!-- schema fragment having mixed content -->
* &lt;xs:complexType name="letterBody" mixed="true">
* &lt;xs:sequence>
* &lt;xs:element name="name" type="xs:string"/>
* &lt;xs:element name="quantity" type="xs:positiveInteger"/>
* &lt;xs:element name="productName" type="xs:string"/>
* &lt;!-- etc. -->
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* &lt;xs:element name="letterBody" type="letterBody"/>
*
* // Schema-derived Java code:
* // (Only annotations relevant to mixed content are shown below,
* // others are ommitted.)
* import java.math.BigInteger;
* public class ObjectFactory {
* // element instance factories
* JAXBElement&lt;LetterBody> createLetterBody(LetterBody value);
* JAXBElement&lt;String> createLetterBodyName(String value);
* JAXBElement&lt;BigInteger> createLetterBodyQuantity(BigInteger value);
* JAXBElement&lt;String> createLetterBodyProductName(String value);
* // type instance factory
* LetterBody> createLetterBody();
* }
* </pre>
* <pre>
* public class LetterBody {
* // Mixed content can contain instances of Element classes
* // Name, Quantity and ProductName. Text data is represented as
* // java.util.String for text.
* &#64;XmlMixed
* &#64;XmlElementRefs({
* &#64;XmlElementRef(name="productName", type=JAXBElement.class),
* &#64;XmlElementRef(name="quantity", type=JAXBElement.class),
* &#64;XmlElementRef(name="name", type=JAXBElement.class)})
* List getContent(){...}
* }
* </pre>
* The following is an XML instance document with mixed content
* <pre>
* &lt;letterBody>
* Dear Mr.&lt;name>Robert Smith&lt;/name>
* Your order of &lt;quantity>1&lt;/quantity> &lt;productName>Baby
* Monitor&lt;/productName> shipped from our warehouse. ....
* &lt;/letterBody>
* </pre>
* that can be constructed using following JAXB API calls.
* <pre>
* LetterBody lb = ObjectFactory.createLetterBody();
* JAXBElement&lt;LetterBody> lbe = ObjectFactory.createLetterBody(lb);
* List gcl = lb.getContent(); //add mixed content to general content property.
* gcl.add("Dear Mr."); // add text information item as a String.
*
* // add child element information item
* gcl.add(ObjectFactory.createLetterBodyName("Robert Smith"));
* gcl.add("Your order of "); // add text information item as a String
*
* // add children element information items
* gcl.add(ObjectFactory.
* createLetterBodyQuantity(new BigInteger("1")));
* gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor"));
* gcl.add("shipped from our warehouse"); // add text information item
* </pre>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
* @author Kohsuke Kawaguchi
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({FIELD,METHOD})
public @interface XmlMixed {
}

View File

@@ -0,0 +1,59 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* <p>
* Associates a namespace prefix with a XML namespace URI.
*
* <p><b>Usage</b></p>
* <p><tt>@XmlNs</tt> annotation is intended for use from other
* program annotations.
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p><b>Example:</b>See <tt>XmlSchema</tt> annotation type for an example.
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({})
public @interface XmlNs {
/**
* Namespace prefix
*/
String prefix();
/**
* Namespace URI
*/
String namespaceURI();
}

View File

@@ -0,0 +1,66 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
/**
* Enumeration of XML Schema namespace qualifications.
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p><b>Usage</b>
* <p>
* The namespace qualification values are used in the annotations
* defined in this packge. The enumeration values are mapped as follows:
*
* <p>
* <table border="1" cellpadding="4" cellspacing="3">
* <tbody>
* <tr>
* <td><b>Enum Value</b></td>
* <td><b>XML Schema Value</b></td>
* </tr>
*
* <tr valign="top">
* <td>UNQUALIFIED</td>
* <td>unqualified</td>
* </tr>
* <tr valign="top">
* <td>QUALIFIED</td>
* <td>qualified</td>
* </tr>
* <tr valign="top">
* <td>UNSET</td>
* <td>namespace qualification attribute is absent from the
* XML Schema fragment</td>
* </tr>
* </tbody>
* </table>
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
*/
public enum XmlNsForm {UNQUALIFIED, QUALIFIED, UNSET}

View File

@@ -0,0 +1,43 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Marks a class that has {@link XmlElementDecl}s.
*
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @since JAXB 2.0
* @see XmlElementDecl
*/
@Retention(RUNTIME)
@Target({TYPE})
public @interface XmlRegistry {
}

View File

@@ -0,0 +1,182 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.TYPE;
/**
* Maps a class or an enum type to an XML element.
*
* <p> <b>Usage</b> </p>
* <p>
* The &#64;XmlRootElement annotation can be used with the following program
* elements:
* <ul>
* <li> a top level class </li>
* <li> an enum type </li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p>
* When a top level class or an enum type is annotated with the
* &#64;XmlRootElement annotation, then its value is represented
* as XML element in an XML document.
*
* <p> This annotation can be used with the following annotations:
* {@link XmlType}, {@link XmlEnum}, {@link XmlAccessorType},
* {@link XmlAccessorOrder}.
* <p>
* <p>
* <b>Example 1: </b> Associate an element with XML Schema type
* <pre>
* // Example: Code fragment
* &#64;XmlRootElement
* class Point {
* int x;
* int y;
* Point(int _x,int _y) {x=_x;y=_y;}
* }
* </pre>
*
* <pre>
* //Example: Code fragment corresponding to XML output
* marshal( new Point(3,5), System.out);
* </pre>
*
* <pre>
* &lt;!-- Example: XML output -->
* &lt;point>
* &lt;x> 3 </x>
* &lt;y> 5 </y>
* &lt;/point>
* </pre>
*
* The annotation causes an global element declaration to be produced
* in the schema. The global element declaration is associated with
* the XML schema type to which the class is mapped.
*
* <pre>
* &lt;!-- Example: XML schema definition -->
* &lt;xs:element name="point" type="point"/>
* &lt;xs:complexType name="point">
* &lt;xs:sequence>
* &lt;xs:element name="x" type="xs:int"/>
* &lt;xs:element name="y" type="xs:int"/>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* <p>
*
* <b>Example 2: Orthogonality to type inheritance </b>
*
* <p>
* An element declaration annotated on a type is not inherited by its
* derived types. The following example shows this.
* <pre>
* // Example: Code fragment
* &#64;XmlRootElement
* class Point3D extends Point {
* int z;
* Point3D(int _x,int _y,int _z) {super(_x,_y);z=_z;}
* }
*
* //Example: Code fragment corresponding to XML output *
* marshal( new Point3D(3,5,0), System.out );
*
* &lt;!-- Example: XML output -->
* &lt;!-- The element name is point3D not point -->
* &lt;point3D>
* &lt;x>3&lt;/x>
* &lt;y>5&lt;/y>
* &lt;z>0&lt;/z>
* &lt;/point3D>
*
* &lt;!-- Example: XML schema definition -->
* &lt;xs:element name="point3D" type="point3D"/>
* &lt;xs:complexType name="point3D">
* &lt;xs:complexContent>
* &lt;xs:extension base="point">
* &lt;xs:sequence>
* &lt;xs:element name="z" type="xs:int"/>
* &lt;/xs:sequence>
* &lt;/xs:extension>
* &lt;/xs:complexContent>
* &lt;/xs:complexType>
* </pre>
*
* <b>Example 3: </b> Associate a global element with XML Schema type
* to which the class is mapped.
* <pre>
* //Example: Code fragment
* &#64;XmlRootElement(name="PriceElement")
* public class USPrice {
* &#64;XmlElement
* public java.math.BigDecimal price;
* }
*
* &lt;!-- Example: XML schema definition -->
* &lt;xs:element name="PriceElement" type="USPrice"/>
* &lt;xs:complexType name="USPrice">
* &lt;xs:sequence>
* &lt;xs:element name="price" type="xs:decimal"/>
* &lt;/sequence>
* &lt;/xs:complexType>
* </pre>
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
*/
@Retention(RUNTIME)
@Target({TYPE})
public @interface XmlRootElement {
/**
* namespace name of the XML element.
* <p>
* If the value is "##default", then the XML namespace name is derived
* from the package of the class ( {@link XmlSchema} ). If the
* package is unnamed, then the XML namespace is the default empty
* namespace.
*/
String namespace() default "##default";
/**
* local name of the XML element.
* <p>
* If the value is "##default", then the name is derived from the
* class name.
*
*/
String name() default "##default";
}

View File

@@ -0,0 +1,206 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p> Maps a package name to a XML namespace. </p>
*
* <h3>Usage</h3>
* <p>
* The XmlSchema annotation can be used with the following program
* elements:
* <ul>
* <li>package</li>
* </ul>
*
* <p>
* This is a package level annotation and follows the recommendations
* and restrictions contained in JSR 175, section III, "Annotations".
* Thus the usage is subject to the following constraints and
* recommendations.
* <ul>
* <li> There can only be one package declaration as noted in JSR
* 175, section III, "Annotations". </li>
* <li> JSR 175 recommends package-info.java for package level
* annotations. JAXB Providers that follow this recommendation
* will allow the package level annotations to be defined in
* package-info.java.
* </ul>
* <p>
*
* <p><b>Example 1:</b> Customize name of XML namespace to which
* package is mapped.</p>
*
* <pre>
* &#64;javax.xml.bind.annotation.XmlSchema (
* namespace = "http://www.example.com/MYPO1"
* )
*
* &lt;!-- XML Schema fragment -->
* &lt;schema
* xmlns=...
* xmlns:po=....
* targetNamespace="http://www.example.com/MYPO1"
* >
* &lt;!-- prefixes generated by default are implementation
* depedenent -->
* </pre>
*
* <p><b>Example 2:</b> Customize namespace prefix, namespace URI
* mapping</p>
*
* <pre>
* // Package level annotation
* &#64;javax.xml.bind.annotation.XmlSchema (
* xmlns = {
* &#64;javax.xml.bind.annotation.XmlNs(prefix = "po",
* namespaceURI="http://www.example.com/myPO1"),
*
* &#64;javax.xml.bind.annotation.XmlNs(prefix="xs",
* namespaceURI="http://www.w3.org/2001/XMLSchema")
* )
* )
*
* &lt;!-- XML Schema fragment -->
* &lt;schema
* xmlns:xs="http://www.w3.org/2001/XMLSchema"
* xmlns:po="http://www.example.com/PO1"
* targetNamespace="http://www.example.com/PO1">
*
* </pre>
*
* <p><b>Example 3:</b> Customize elementFormDefault</p>
* <pre>
* &#64;javax.xml.bind.annotation.XmlSchema (
* elementFormDefault=XmlNsForm.UNQUALIFIED
* ...
* )
*
* &lt;!-- XML Schema fragment -->
* &lt;schema
* xmlns="http://www.w3.org/2001/XMLSchema"
* xmlns:po="http://www.example.com/PO1"
* elementFormDefault="unqualified">
*
* </pre>
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target(PACKAGE)
public @interface XmlSchema {
/**
* Customize the namespace URI, prefix associations. By default,
* the namespace prefixes for a XML namespace are generated by a
* JAXB Provider in an implementation dependent way.
*/
XmlNs[] xmlns() default {};
/**
* Name of the XML namespace.
*/
String namespace() default "";
/**
* Namespace qualification for elements. By default, element
* default attribute will be absent from the XML Schema fragment.
*/
XmlNsForm elementFormDefault() default XmlNsForm.UNSET;
/**
* Namespace qualification for attributes. By default,
* attributesFormDefault will be absent from the XML Schema fragment.
*/
XmlNsForm attributeFormDefault() default XmlNsForm.UNSET;
/**
* Indicates that this namespace (specified by {@link #namespace()})
* has a schema already available exeternally, available at this location.
*
* <p>
* This instructs the JAXB schema generators to simply refer to
* the pointed schema, as opposed to generating components into the schema.
* This schema is assumed to match what would be otherwise produced
* by the schema generator (same element names, same type names...)
*
* <p>
* This feature is intended to be used when a set of the Java classes
* is originally generated from an existing schema, hand-written to
* match externally defined schema, or the generated schema is modified
* manually.
*
* <p>
* Value could be any absolute URI, like <tt>http://example.org/some.xsd</tt>.
* It is also possible to specify the empty string, to indicate
* that the schema is externally available but the location is
* unspecified (and thus it's the responsibility of the reader of the generate
* schema to locate it.) Finally, the default value of this property
* <tt>"##generate"</tt> indicates that the schema generator is going
* to generate components for this namespace (as it did in JAXB 2.0.)
*
* <p>
* Multiple {@link XmlSchema} annotations on multiple packages are allowed
* to govern the same {@link #namespace()}. In such case, all of them
* must have the same {@link #location()} values.
*
*
* <h3>Note to implementor</h3>
* <p>
* More precisely, the value must be either <tt>""</tt>, <tt>"##generate"</tt>, or
* <a href="http://www.w3.org/TR/xmlschema-2/#anyURI">
* a valid lexical representation of <tt>xs:anyURI</tt></a> that begins
* with <tt>&lt;scheme>:</tt>.
*
* <p>
* A schema generator is expected to generate a corresponding
* <tt>&lt;xs:import namespace="..." schemaLocation="..."/></tt> (or
* no <tt>schemaLocation</tt> attribute at all if the empty string is specified.)
* However, the schema generator is allowed to use a different value in
* the <tt>schemaLocation</tt> attribute (including not generating
* such attribute), for example so that the user can specify a local
* copy of the resource through the command line interface.
*
* @since JAXB2.1
*/
String location() default NO_LOCATION;
/**
* The default value of the {@link #location()} attribute,
* which indicates that the schema generator will generate
* components in this namespace.
*/
// the actual value is chosen because ## is not a valid
// sequence in xs:anyURI.
static final String NO_LOCATION = "##generate";
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Maps a Java type to a simple schema built-in type.
*
* <p> <b>Usage</b> </p>
* <p>
* <tt>@XmlSchemaType</tt> annotation can be used with the following program
* elements:
* <ul>
* <li> a JavaBean property </li>
* <li> field </li>
* <li> package</li>
* </ul>
*
* <p> <tt>@XmlSchemaType</tt> annotation defined for Java type
* applies to all references to the Java type from a property/field.
* A <tt>@XmlSchemaType</tt> annotation specified on the
* property/field overrides the <tt>@XmlSchemaType</tt> annotation
* specified at the package level.
*
* <p> This annotation can be used with the following annotations:
* {@link XmlElement}, {@link XmlAttribute}.
* <p>
* <b>Example 1: </b> Customize mapping of XMLGregorianCalendar on the
* field.
*
* <pre>
* //Example: Code fragment
* public class USPrice {
* &#64;XmlElement
* &#64;XmlSchemaType(name="date")
* public XMLGregorianCalendar date;
* }
*
* &lt;!-- Example: Local XML Schema element -->
* &lt;xs:complexType name="USPrice"/>
* &lt;xs:sequence>
* &lt;xs:element name="date" type="xs:date"/>
* &lt;/sequence>
* &lt;/xs:complexType>
* </pre>
*
* <p> <b> Example 2: </b> Customize mapping of XMLGregorianCalendar at package
* level </p>
* <pre>
* package foo;
* &#64;javax.xml.bind.annotation.XmlSchemaType(
* name="date", type=javax.xml.datatype.XMLGregorianCalendar.class)
* }
* </pre>
*
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD,METHOD,PACKAGE})
public @interface XmlSchemaType {
String name();
String namespace() default "http://www.w3.org/2001/XMLSchema";
/**
* If this annotation is used at the package level, then value of
* the type() must be specified.
*/
Class type() default DEFAULT.class;
/**
* Used in {@link XmlSchemaType#type()} to
* signal that the type be inferred from the signature
* of the property.
*/
static final class DEFAULT {}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2005, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.PACKAGE;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* <p>
* A container for multiple @{@link XmlSchemaType} annotations.
*
* <p> Multiple annotations of the same type are not allowed on a program
* element. This annotation therefore serves as a container annotation
* for multiple &#64;XmlSchemaType annotations as follows:
*
* <pre>
* &#64;XmlSchemaTypes({ @XmlSchemaType(...), @XmlSchemaType(...) })
* </pre>
* <p>The <tt>@XmlSchemaTypes</tt> annnotation can be used to
* define {@link XmlSchemaType} for different types at the
* package level.
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* @author <ul><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlSchemaType
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({PACKAGE})
public @interface XmlSchemaTypes {
/**
* Collection of @{@link XmlSchemaType} annotations
*/
XmlSchemaType[] value();
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2006, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import javax.xml.bind.JAXBContext;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* Instructs JAXB to also bind other classes when binding this class.
*
* <p>
* Java makes it impractical/impossible to list all sub-classes of
* a given class. This often gets in a way of JAXB users, as it JAXB
* cannot automatically list up the classes that need to be known
* to {@link JAXBContext}.
*
* <p>
* For example, with the following class definitions:
*
* <pre>
* class Animal {}
* class Dog extends Animal {}
* class Cat extends Animal {}
* </pre>
*
* <p>
* The user would be required to create {@link JAXBContext} as
* <tt>JAXBContext.newInstance(Dog.class,Cat.class)</tt>
* (<tt>Animal</tt> will be automatically picked up since <tt>Dog</tt>
* and <tt>Cat</tt> refers to it.)
*
* <p>
* {@link XmlSeeAlso} annotation would allow you to write:
* <pre>
* &#64;XmlSeeAlso({Dog.class,Cat.class})
* class Animal {}
* class Dog extends Animal {}
* class Cat extends Animal {}
* </pre>
*
* <p>
* This would allow you to do <tt>JAXBContext.newInstance(Animal.class)</tt>.
* By the help of this annotation, JAXB implementations will be able to
* correctly bind <tt>Dog</tt> and <tt>Cat</tt>.
*
* @author Kohsuke Kawaguchi
* @since JAXB2.1
*/
@Target({ElementType.TYPE})
@Retention(RUNTIME)
public @interface XmlSeeAlso {
Class[] value();
}

View File

@@ -0,0 +1,95 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p>
* Prevents the mapping of a JavaBean property/type to XML representation.
* <p>
* The <tt>@XmlTransient</tt> annotation is useful for resolving name
* collisions between a JavaBean property name and a field name or
* preventing the mapping of a field/property. A name collision can
* occur when the decapitalized JavaBean property name and a field
* name are the same. If the JavaBean property refers to the field,
* then the name collision can be resolved by preventing the
* mapping of either the field or the JavaBean property using the
* <tt>@XmlTransient</tt> annotation.
*
* <p>
* When placed on a class, it indicates that the class shouldn't be mapped
* to XML by itself. Properties on such class will be mapped to XML along
* with its derived classes, as if the class is inlined.
*
* <p><b>Usage</b></p>
* <p> The <tt>@XmlTransient</tt> annotation can be used with the following
* program elements:
* <ul>
* <li> a JavaBean property </li>
* <li> field </li>
* <li> class </li>
* </ul>
*
* <p><tt>@XmlTransient</tt>is mutually exclusive with all other
* JAXB defined annotations. </p>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <p><b>Example:</b> Resolve name collision between JavaBean property and
* field name </p>
*
* <pre>
* // Example: Code fragment
* public class USAddress {
*
* // The field name "name" collides with the property name
* // obtained by bean decapitalization of getName() below
* &#64;XmlTransient public String name;
*
* String getName() {..};
* String setName() {..};
* }
*
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:complexType name="USAddress">
* &lt;xs:sequence>
* &lt;xs:element name="name" type="xs:string"/>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD, METHOD, TYPE})
public @interface XmlTransient {}

View File

@@ -0,0 +1,452 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* <p>
* Maps a class or an enum type to a XML Schema type.
*
* <p><b>Usage</b></p>
* <p> The <tt>@XmlType</tt> annnotation can be used with the following program
* elements:
* <ul>
* <li> a top level class </li>
* <li> an enum type </li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* <h3> Mapping a Class </h3>
* <p>
* A class maps to a XML Schema type. A class is a data container for
* values represented by properties and fields. A schema type is a
* data container for values represented by schema components within a
* schema type's content model (e.g. model groups, attributes etc).
* <p> To be mapped, a class must either have a public no-arg
* constructor or a static no-arg factory method. The static factory
* method can be specified in <tt>factoryMethod()</tt> and
* <tt>factoryClass()</tt> annotation elements. The static factory
* method or the no-arg constructor is used during unmarshalling to
* create an instance of this class. If both are present, the static
* factory method overrides the no-arg constructor.
* <p>
* A class maps to either a XML Schema complex type or a XML Schema simple
* type. The XML Schema type is derived based on the
* mapping of JavaBean properties and fields contained within the
* class. The schema type to which the class is mapped can either be
* named or anonymous. A class can be mapped to an anonymous schema
* type by annotating the class with <tt>&#64XmlType(name="")</tt>.
* <p>
* Either a global element, local element or a local attribute can be
* associated with an anonymous type as follows:
* <ul>
* <li><b>global element: </b> A global element of an anonymous
* type can be derived by annotating the class with @{@link
* XmlRootElement}. See Example 3 below. </li>
*
* <li><b>local element: </b> A JavaBean property that references
* a class annotated with @XmlType(name="") and is mapped to the
* element associated with the anonymous type. See Example 4
* below.</li>
*
* <li><b>attribute: </b> A JavaBean property that references
* a class annotated with @XmlType(name="") and is mapped to the
* attribute associated with the anonymous type. See Example 5 below. </li>
* </ul>
* <b> Mapping to XML Schema Complex Type </b>
* <ul>
* <li>If class is annotated with <tt>@XmlType(name="") </tt>, it
* is mapped to an anonymous type otherwise, the class name maps
* to a complex type name. The <tt>XmlName()</tt> annotation element
* can be used to customize the name.</li>
*
* <li> Properties and fields that are mapped to elements are mapped to a
* content model within a complex type. The annotation element
* <tt>propOrder()</tt> can be used to customize the content model to be
* <tt>xs:all</tt> or <tt>xs:sequence</tt>. It is used for specifying
* the order of XML elements in <tt>xs:sequence</tt>. </li>
*
* <li> Properties and fields can be mapped to attributes within the
* complex type. </li>
*
* <li> The targetnamespace of the XML Schema type can be customized
* using the annotation element <tt>namespace()</tt>. </li>
* </ul>
*
* <p>
* <b> Mapping class to XML Schema simple type </b>
* <p>
* A class can be mapped to a XML Schema simple type using the
* <tt>@XmlValue</tt> annotation. For additional details and examples,
* see @{@link XmlValue} annotation type.
* <p>
* The following table shows the mapping of the class to a XML Schema
* complex type or simple type. The notational symbols used in the table are:
* <ul>
* <li> -> : represents a mapping </li>
* <li> [x]+ : one or more occurances of x </li>
* <li> [ <tt>@XmlValue</tt> property ]: JavaBean property annotated with
* <tt>@XmlValue</tt></li>
* <li> X : don't care
* </ul>
* <blockquote>
* <table border="1" cellpadding="4" cellspacing="3">
* <tbody>
* <tr>
* <td><b>Target</b></td>
* <td><b>propOrder</b></td>
* <td><b>ClassBody</b></td>
* <td><b>ComplexType</b></td>
* <td><b>SimpleType</b></td>
* </tr>
*
* <tr valign="top">
* <td>Class</td>
* <td>{}</td>
* <td>[property]+ -> elements</td>
* <td>complexcontent<br>xs:all</td>
* <td> </td>
* </tr>
*
* <tr valign="top">
* <td>Class</td>
* <td>non empty</td>
* <td>[property]+ -> elements</td>
* <td>complexcontent<br>xs:sequence</td>
* <td> </td>
* </tr>
*
* <tr valign="top">
* <td>Class</td>
* <td>X</td>
* <td>no property -> element</td>
* <td>complexcontent<br>empty sequence</td>
* <td> </td>
* </tr>
*
* <tr valign="top">
* <td>Class</td>
* <td>X</td>
* <td>1 [ <tt>@XmlValue</tt> property] && <br> [property]+
* ->attributes</td>
* <td>simplecontent</td>
* <td> </td>
* </tr>
*
* <tr valign="top">
* <td>Class</td>
* <td>X</td>
* <td>1 [ <tt>@XmlValue</tt> property ]&& <br> no properties
* -> attribute</td>
* <td> </td>
* <td>simpletype</td>
* <td> </td>
* </tr>
* </tbody>
* </table>
* </blockquote>
*
* <h3> Mapping an enum type </h3>
*
* An enum type maps to a XML schema simple type with enumeration
* facets. The following annotation elements are ignored since they
* are not meaningful: <tt>propOrder()</tt> , <tt>factoryMethod()</tt> ,
* <tt>factoryClass()</tt> .
*
* <h3> Usage with other annotations </h3>
* <p> This annotation can be used with the following annotations:
* {@link XmlRootElement}, {@link XmlAccessorOrder}, {@link XmlAccessorType},
* {@link XmlEnum}. However, {@link
* XmlAccessorOrder} and {@link XmlAccessorType} are ignored when this
* annotation is used on an enum type.
*
* <p> <b> Example 1: </b> Map a class to a complex type with
* xs:sequence with a customized ordering of JavaBean properties.
* </p>
*
* <pre>
* &#64;XmlType(propOrder={"street", "city" , "state", "zip", "name" })
* public class USAddress {
* String getName() {..};
* void setName(String) {..};
*
* String getStreet() {..};
* void setStreet(String) {..};
*
* String getCity() {..};
* void setCity(String) {..};
*
* String getState() {..};
* void setState(String) {..};
*
* java.math.BigDecimal getZip() {..};
* void setZip(java.math.BigDecimal) {..};
* }
*
* &lt;!-- XML Schema mapping for USAddress -->
* &lt;xs:complexType name="USAddress">
* &lt;xs:sequence>
* &lt;xs:element name="street" type="xs:string"/>
* &lt;xs:element name="city" type="xs:string"/>
* &lt;xs:element name="state" type="xs:string"/>
* &lt;xs:element name="zip" type="xs:decimal"/>
* &lt;xs:element name="name" type="xs:string"/>
* &lt;/xs:all>
* &lt;/xs:complexType>
* </pre>
* <p> <b> Example 2: </b> Map a class to a complex type with
* xs:all </p>
* <pre>
* &#64;XmlType(propOrder={})
* public class USAddress { ...}
*
* &lt;!-- XML Schema mapping for USAddress -->
* &lt;xs:complexType name="USAddress">
* &lt;xs:all>
* &lt;xs:element name="name" type="xs:string"/>
* &lt;xs:element name="street" type="xs:string"/>
* &lt;xs:element name="city" type="xs:string"/>
* &lt;xs:element name="state" type="xs:string"/>
* &lt;xs:element name="zip" type="xs:decimal"/>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
*</pre>
* <p> <b> Example 3: </b> Map a class to a global element with an
* anonymous type.
* </p>
* <pre>
* &#64;XmlRootElement
* &#64;XmlType(name="")
* public class USAddress { ...}
*
* &lt;!-- XML Schema mapping for USAddress -->
* &lt;xs:element name="USAddress">
* &lt;xs:complexType>
* &lt;xs:sequence>
* &lt;xs:element name="name" type="xs:string"/>
* &lt;xs:element name="street" type="xs:string"/>
* &lt;xs:element name="city" type="xs:string"/>
* &lt;xs:element name="state" type="xs:string"/>
* &lt;xs:element name="zip" type="xs:decimal"/>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* &lt;/xs:element>
* </pre>
*
* <p> <b> Example 4: </b> Map a property to a local element with
* anonmyous type.
* <pre>
* //Example: Code fragment
* public class Invoice {
* USAddress addr;
* ...
* }
*
* &#64;XmlType(name="")
* public class USAddress { ... }
* }
*
* &lt;!-- XML Schema mapping for USAddress -->
* &lt;xs:complexType name="Invoice">
* &lt;xs:sequence>
* &lt;xs:element name="addr">
* &lt;xs:complexType>
* &lt;xs:element name="name", type="xs:string"/>
* &lt;xs:element name="city", type="xs:string"/>
* &lt;xs:element name="city" type="xs:string"/>
* &lt;xs:element name="state" type="xs:string"/>
* &lt;xs:element name="zip" type="xs:decimal"/>
* &lt;/xs:complexType>
* ...
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* <p> <b> Example 5: </b> Map a property to an attribute with
* anonymous type.
*
* <pre>
*
* //Example: Code fragment
* public class Item {
* public String name;
* &#64;XmlAttribute
* public USPrice price;
* }
*
* // map class to anonymous simple type.
* &#64;XmlType(name="")
* public class USPrice {
* &#64;XmlValue
* public java.math.BigDecimal price;
* }
*
* &lt;!-- Example: XML Schema fragment -->
* &lt;xs:complexType name="Item">
* &lt;xs:sequence>
* &lt;xs:element name="name" type="xs:string"/>
* &lt;xs:attribute name="price">
* &lt;xs:simpleType>
* &lt;xs:restriction base="xs:decimal"/>
* &lt;/xs:simpleType>
* &lt;/xs:attribute>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* <p> <b> Example 6: </b> Define a factoryClass and factoryMethod
*
* <pre>
* &#64;XmlType(name="USAddressType", factoryClass=USAddressFactory.class,
* factoryMethod="getUSAddress")
* public class USAddress {
*
* private String city;
* private String name;
* private String state;
* private String street;
* private int zip;
*
* public USAddress(String name, String street, String city,
* String state, int zip) {
* this.name = name;
* this.street = street;
* this.city = city;
* this.state = state;
* this.zip = zip;
* }
* }
*
* public class USAddressFactory {
* public static USAddress getUSAddress(){
* return new USAddress("Mark Baker", "23 Elm St",
* "Dayton", "OH", 90952);
* }
*
* </pre>
*
* <p> <b> Example 7: </b> Define factoryMethod and use the default factoryClass
*
* <pre>
* &#64;XmlType(name="USAddressType", factoryMethod="getNewInstance")
* public class USAddress {
*
* private String city;
* private String name;
* private String state;
* private String street;
* private int zip;
*
* private USAddress() {}
*
* public static USAddress getNewInstance(){
* return new USAddress();
* }
* }
* </pre>
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @see XmlElement
* @see XmlAttribute
* @see XmlValue
* @see XmlSchema
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({TYPE})
public @interface XmlType {
/**
* Name of the XML Schema type which the class is mapped.
*/
String name() default "##default" ;
/**
* Specifies the order for XML Schema elements when class is
* mapped to a XML Schema complex type.
*
* <p> Refer to the table for how the propOrder affects the
* mapping of class </p>
*
* <p> The propOrder is a list of names of JavaBean properties in
* the class. Each name in the list is the name of a Java
* identifier of the JavaBean property. The order in which
* JavaBean properties are listed is the order of XML Schema
* elements to which the JavaBean properties are mapped. </p>
* <p> All of the JavaBean properties being mapped to XML Schema elements
* must be listed.
* <p> A JavaBean property or field listed in propOrder must not
* be transient or annotated with <tt>@XmlTransient</tt>.
* <p> The default ordering of JavaBean properties is determined
* by @{@link XmlAccessorOrder}.
*/
String[] propOrder() default {""};
/**
* Name of the target namespace of the XML Schema type. By
* default, this is the target namespace to which the package
* containing the class is mapped.
*/
String namespace() default "##default" ;
/**
* Class containing a no-arg factory method for creating an
* instance of this class. The default is this class.
*
* <p>If <tt>factoryClass</tt> is DEFAULT.class and
* <tt>factoryMethod</tt> is "", then there is no static factory
* method.
*
* <p>If <tt>factoryClass</tt> is DEFAULT.class and
* <tt>factoryMethod</tt> is not "", then
* <tt>factoryMethod</tt> is the name of a static factory method
* in this class.
*
* <p>If <tt>factoryClass</tt> is not DEFAULT.class, then
* <tt>factoryMethod</tt> must not be "" and must be the name of
* a static factory method specified in <tt>factoryClass</tt>.
*/
Class factoryClass() default DEFAULT.class;
/**
* Used in {@link XmlType#factoryClass()} to
* signal that either factory mehod is not used or
* that it's in the class with this {@link XmlType} itself.
*/
static final class DEFAULT {}
/**
* Name of a no-arg factory method in the class specified in
* <tt>factoryClass</tt> factoryClass().
*
*/
String factoryMethod() default "";
}

View File

@@ -0,0 +1,131 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p>
* Enables mapping a class to a XML Schema complex type with a
* simpleContent or a XML Schema simple type.
* </p>
*
* <p>
* <b> Usage: </b>
* <p>
* The <tt>@XmlValue</tt> annotation can be used with the following program
* elements:
* <ul>
* <li> a JavaBean property.</li>
* <li> non static, non transient field.</li>
* </ul>
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* The usage is subject to the following usage constraints:
* <ul>
* <li>At most one field or property can be annotated with the
* <tt>@XmlValue</tt> annotation. </li>
*
* <li><tt>@XmlValue</tt> can be used with the following
* annotations: {@link XmlList}. However this is redundant since
* {@link XmlList} maps a type to a simple schema type that derives by
* list just as {@link XmlValue} would. </li>
*
* <li>If the type of the field or property is a collection type,
* then the collection item type must map to a simple schema
* type. </li>
*
* <li>If the type of the field or property is not a collection
* type, then the type must map to a XML Schema simple type. </li>
*
* </ul>
* </p>
* <p>
* If the annotated JavaBean property is the sole class member being
* mapped to XML Schema construct, then the class is mapped to a
* simple type.
*
* If there are additional JavaBean properties (other than the
* JavaBean property annotated with <tt>@XmlValue</tt> annotation)
* that are mapped to XML attributes, then the class is mapped to a
* complex type with simpleContent.
* </p>
*
* <p> <b> Example 1: </b> Map a class to XML Schema simpleType</p>
*
* <pre>
*
* // Example 1: Code fragment
* public class USPrice {
* &#64;XmlValue
* public java.math.BigDecimal price;
* }
*
* &lt;!-- Example 1: XML Schema fragment -->
* &lt;xs:simpleType name="USPrice">
* &lt;xs:restriction base="xs:decimal"/>
* &lt;/xs:simpleType>
*
* </pre>
*
* <p><b> Example 2: </b> Map a class to XML Schema complexType with
* with simpleContent.</p>
*
* <pre>
*
* // Example 2: Code fragment
* public class InternationalPrice {
* &#64;XmlValue
* public java.math.BigDecimal price;
*
* &#64;XmlAttribute
* public String currency;
* }
*
* &lt;!-- Example 2: XML Schema fragment -->
* &lt;xs:complexType name="InternationalPrice">
* &lt;xs:simpleContent>
* &lt;xs:extension base="xs:decimal">
* &lt;xs:attribute name="currency" type="xs:string"/>
* &lt;/xs:extension>
* &lt;/xs:simpleContent>
* &lt;/xs:complexType>
*
* </pre>
* </p>
*
* @author Sekhar Vajjhala, Sun Microsystems, Inc.
* @see XmlType
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlValue {}

View File

@@ -0,0 +1,119 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation.adapters;
/**
* Built-in {@link XmlAdapter} to handle <tt>xs:token</tt> and its derived types.
*
* <p>
* This adapter removes leading and trailing whitespaces, then truncate any
* sequnce of tab, CR, LF, and SP by a single whitespace character ' '.
*
* @author Kohsuke Kawaguchi
* @since JAXB 2.0
*/
public class CollapsedStringAdapter extends XmlAdapter<String,String> {
/**
* Removes leading and trailing whitespaces of the string
* given as the parameter, then truncate any
* sequnce of tab, CR, LF, and SP by a single whitespace character ' '.
*/
public String unmarshal(String text) {
if(text==null) return null; // be defensive
int len = text.length();
// most of the texts are already in the collapsed form.
// so look for the first whitespace in the hope that we will
// never see it.
int s=0;
while(s<len) {
if(isWhiteSpace(text.charAt(s)))
break;
s++;
}
if(s==len)
// the input happens to be already collapsed.
return text;
// we now know that the input contains spaces.
// let's sit down and do the collapsing normally.
StringBuilder result = new StringBuilder(len /*allocate enough size to avoid re-allocation*/ );
if(s!=0) {
for( int i=0; i<s; i++ )
result.append(text.charAt(i));
result.append(' ');
}
boolean inStripMode = true;
for (int i = s+1; i < len; i++) {
char ch = text.charAt(i);
boolean b = isWhiteSpace(ch);
if (inStripMode && b)
continue; // skip this character
inStripMode = b;
if (inStripMode)
result.append(' ');
else
result.append(ch);
}
// remove trailing whitespaces
len = result.length();
if (len > 0 && result.charAt(len - 1) == ' ')
result.setLength(len - 1);
// whitespaces are already collapsed,
// so all we have to do is to remove the last one character
// if it's a whitespace.
return result.toString();
}
/**
* No-op.
*
* Just return the same string given as the parameter.
*/
public String marshal(String s) {
return s;
}
/** returns true if the specified char is a white space character. */
protected static boolean isWhiteSpace(char ch) {
// most of the characters are non-control characters.
// so check that first to quickly return false for most of the cases.
if( ch>0x20 ) return false;
// other than we have to do four comparisons.
return ch == 0x9 || ch == 0xA || ch == 0xD || ch == 0x20;
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation.adapters;
import javax.xml.bind.DatatypeConverter;
/**
* {@link XmlAdapter} for <tt>xs:hexBinary</tt>.
*
* <p>
* This {@link XmlAdapter} binds <tt>byte[]</tt> to the hexBinary representation in XML.
*
* @author Kohsuke Kawaguchi
* @since JAXB 2.0
*/
public final class HexBinaryAdapter extends XmlAdapter<String,byte[]> {
public byte[] unmarshal(String s) {
if(s==null) return null;
return DatatypeConverter.parseHexBinary(s);
}
public String marshal(byte[] bytes) {
if(bytes==null) return null;
return DatatypeConverter.printHexBinary(bytes);
}
}

View File

@@ -0,0 +1,92 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation.adapters;
/**
* {@link XmlAdapter} to handle <tt>xs:normalizedString</tt>.
*
* <p>
* Replaces any tab, CR, and LF by a whitespace character ' ',
* as specified in <a href="http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace">the whitespace facet 'replace'</a>
*
* @author Kohsuke Kawaguchi, Martin Grebac
* @since JAXB 2.0
*/
public final class NormalizedStringAdapter extends XmlAdapter<String,String> {
/**
* Replace any tab, CR, and LF by a whitespace character ' ',
* as specified in <a href="http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace">the whitespace facet 'replace'</a>
*/
public String unmarshal(String text) {
if(text==null) return null; // be defensive
int i=text.length()-1;
// look for the first whitespace char.
while( i>=0 && !isWhiteSpaceExceptSpace(text.charAt(i)) )
i--;
if( i<0 )
// no such whitespace. replace(text)==text.
return text;
// we now know that we need to modify the text.
// allocate a char array to do it.
char[] buf = text.toCharArray();
buf[i--] = ' ';
for( ; i>=0; i-- )
if( isWhiteSpaceExceptSpace(buf[i]))
buf[i] = ' ';
return new String(buf);
}
/**
* No-op.
*
* Just return the same string given as the parameter.
*/
public String marshal(String s) {
return s;
}
/**
* Returns true if the specified char is a white space character
* but not 0x20.
*/
protected static boolean isWhiteSpaceExceptSpace(char ch) {
// most of the characters are non-control characters.
// so check that first to quickly return false for most of the cases.
if( ch>=0x20 ) return false;
// other than we have to do four comparisons.
return ch == 0x9 || ch == 0xA || ch == 0xD;
}
}

View File

@@ -0,0 +1,193 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation.adapters;
/**
* Adapts a Java type for custom marshaling.
*
* <p> <b> Usage: </b> </p>
*
* <p>
* Some Java types do not map naturally to a XML representation, for
* example <tt>HashMap</tt> or other non JavaBean classes. Conversely,
* a XML repsentation may map to a Java type but an application may
* choose to accesss the XML representation using another Java
* type. For example, the schema to Java binding rules bind
* xs:DateTime by default to XmlGregorianCalendar. But an application
* may desire to bind xs:DateTime to a custom type,
* MyXmlGregorianCalendar, for example. In both cases, there is a
* mismatch between <i> bound type </i>, used by an application to
* access XML content and the <i> value type</i>, that is mapped to an
* XML representation.
*
* <p>
* This abstract class defines methods for adapting a bound type to a value
* type or vice versa. The methods are invoked by the JAXB binding
* framework during marshaling and unmarshalling:
*
* <ul>
* <li> <b> XmlAdapter.marshal(...): </b> During marshalling, JAXB
* binding framework invokes XmlAdapter.marshal(..) to adapt a
* bound type to value type, which is then marshaled to XML
* representation. </li>
*
* <li> <b> XmlAdapter.unmarshal(...): </b> During unmarshalling,
* JAXB binding framework first unmarshals XML representation
* to a value type and then invokes XmlAdapter.unmarshal(..) to
* adapt the value type to a bound type. </li>
* </ul>
*
* Writing an adapter therefore involves the following steps:
*
* <ul>
* <li> Write an adapter that implements this abstract class. </li>
* <li> Install the adapter using the annotation {@link
* XmlJavaTypeAdapter} </li>
* </ul>
*
* <p><b>Example:</b> Customized mapping of <tt>HashMap</tt></p>
* <p> The following example illustrates the use of
* <tt>&#64;XmlAdapter</tt> and <tt>&#64;XmlJavaTypeAdapter</tt> to
* customize the mapping of a <tt>HashMap</tt>.
*
* <p> <b> Step 1: </b> Determine the desired XML representation for HashMap.
*
* <pre>
* &lt;hashmap>
* &lt;entry key="id123">this is a value&lt;/entry>
* &lt;entry key="id312">this is another value&lt;/entry>
* ...
* &lt;/hashmap>
* </pre>
*
* <p> <b> Step 2: </b> Determine the schema definition that the
* desired XML representation shown above should follow.
*
* <pre>
*
* &lt;xs:complexType name="myHashMapType">
* &lt;xs:sequence>
* &lt;xs:element name="entry" type="myHashMapEntryType"
* minOccurs = "0" maxOccurs="unbounded"/>
* &lt;/xs:sequence>
* &lt;/xs:complexType>
*
* &lt;xs:complexType name="myHashMapEntryType">
* &lt;xs:simpleContent>
* &lt;xs:extension base="xs:string">
* &lt;xs:attribute name="key" type="xs:int"/>
* &lt;/xs:extension>
* &lt;/xs:simpleContent>
* &lt;/xs:complexType>
*
* </pre>
*
* <p> <b> Step 3: </b> Write value types that can generate the above
* schema definition.
*
* <pre>
* public class MyHashMapType {
* List&lt;MyHashMapEntryType> entry;
* }
*
* public class MyHashMapEntryType {
* &#64;XmlAttribute
* public Integer key;
*
* &#64;XmlValue
* public String value;
* }
* </pre>
*
* <p> <b> Step 4: </b> Write the adapter that adapts the value type,
* MyHashMapType to a bound type, HashMap, used by the application.
*
* <pre>
* public final class MyHashMapAdapter extends
* XmlAdapter&lt;MyHashMapType,HashMap> { ... }
*
* </pre>
*
* <p> <b> Step 5: </b> Use the adapter.
*
* <pre>
* public class Foo {
* &#64;XmlJavaTypeAdapter(MyHashMapAdapter.class)
* HashMap hashmap;
* ...
* }
* </pre>
*
* The above code fragment will map to the following schema:
*
* <pre>
* &lt;xs:complexType name="Foo">
* &lt;xs:sequence>
* &lt;xs:element name="hashmap" type="myHashMapType"
* &lt;/xs:sequence>
* &lt;/xs:complexType>
* </pre>
*
* @param <BoundType>
* The type that JAXB doesn't know how to handle. An adapter is written
* to allow this type to be used as an in-memory representation through
* the <tt>ValueType</tt>.
* @param <ValueType>
* The type that JAXB knows how to handle out of the box.
*
* @author <ul><li>Sekhar Vajjhala, Sun Microsystems Inc.</li> <li> Kohsuke Kawaguchi, Sun Microsystems Inc.</li></ul>
* @see XmlJavaTypeAdapter
* @since JAXB 2.0
*/
public abstract class XmlAdapter<ValueType,BoundType> {
/**
* Do-nothing constructor for the derived classes.
*/
protected XmlAdapter() {}
/**
* Convert a value type to a bound type.
*
* @param v
* The value to be converted. Can be null.
* @throws Exception
* if there's an error during the conversion. The caller is responsible for
* reporting the error to the user through {@link javax.xml.bind.ValidationEventHandler}.
*/
public abstract BoundType unmarshal(ValueType v) throws Exception;
/**
* Convert a bound type to a value type.
*
* @param v
* The value to be convereted. Can be null.
* @throws Exception
* if there's an error during the conversion. The caller is responsible for
* reporting the error to the user through {@link javax.xml.bind.ValidationEventHandler}.
*/
public abstract ValueType marshal(BoundType v) throws Exception;
}

View File

@@ -0,0 +1,116 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation.adapters;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlSchemaTypes;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.PACKAGE;
/**
* Use an adapter that implements {@link XmlAdapter} for custom marshaling.
*
* <p> <b> Usage: </b> </p>
*
* <p> The <tt>@XmlJavaTypeAdapter</tt> annotation can be used with the
* following program elements:
* <ul>
* <li> a JavaBean property </li>
* <li> field </li>
* <li> parameter </li>
* <li> package </li>
* <li> from within {@link XmlJavaTypeAdapters} </li>
* </ul>
*
* <p> When <tt>@XmlJavaTypeAdapter</tt> annotation is defined on a
* class, it applies to all references to the class.
* <p> When <tt>@XmlJavaTypeAdapter</tt> annotation is defined at the
* package level it applies to all references from within the package
* to <tt>@XmlJavaTypeAdapter.type()</tt>.
* <p> When <tt>@XmlJavaTypeAdapter</tt> annotation is defined on the
* field, property or parameter, then the annotation applies to the
* field, property or the parameter only.
* <p> A <tt>@XmlJavaTypeAdapter</tt> annotation on a field, property
* or parameter overrides the <tt>@XmlJavaTypeAdapter</tt> annotation
* associated with the class being referenced by the field, property
* or parameter.
* <p> A <tt>@XmlJavaTypeAdapter</tt> annotation on a class overrides
* the <tt>@XmlJavaTypeAdapter</tt> annotation specified at the
* package level for that class.
*
* <p>This annotation can be used with the following other annotations:
* {@link XmlElement}, {@link XmlAttribute}, {@link XmlElementRef},
* {@link XmlElementRefs}, {@link XmlAnyElement}. This can also be
* used at the package level with the following annotations:
* {@link XmlAccessorType}, {@link XmlSchema}, {@link XmlSchemaType},
* {@link XmlSchemaTypes}.
*
* <p><b> Example: </b> See example in {@link XmlAdapter}
*
* @author <ul><li>Sekhar Vajjhala, Sun Microsystems Inc.</li> <li> Kohsuke Kawaguchi, Sun Microsystems Inc.</li></ul>
* @since JAXB2.0
* @see XmlAdapter
*/
@Retention(RUNTIME) @Target({PACKAGE,FIELD,METHOD,TYPE,PARAMETER})
public @interface XmlJavaTypeAdapter {
/**
* Points to the class that converts a value type to a bound type or vice versa.
* See {@link XmlAdapter} for more details.
*/
Class<? extends XmlAdapter> value();
/**
* If this annotation is used at the package level, then value of
* the type() must be specified.
*/
Class type() default DEFAULT.class;
/**
* Used in {@link XmlJavaTypeAdapter#type()} to
* signal that the type be inferred from the signature
* of the field, property, parameter or the class.
*/
static final class DEFAULT {}
}

View File

@@ -0,0 +1,62 @@
/*
* 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.bind.annotation.adapters;
import static java.lang.annotation.ElementType.PACKAGE;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* <p>
* A container for multiple @{@link XmlJavaTypeAdapter} annotations.
*
* <p> Multiple annotations of the same type are not allowed on a program
* element. This annotation therefore serves as a container annotation
* for multiple &#64;XmlJavaTypeAdapter as follows:
*
* <pre>
* &#64;XmlJavaTypeAdapters ({ @XmlJavaTypeAdapter(...),@XmlJavaTypeAdapter(...) })
* </pre>
*
* <p>The <tt>@XmlJavaTypeAdapters</tt> annnotation is useful for
* defining {@link XmlJavaTypeAdapter} annotations for different types
* at the package level.
*
* <p>See "Package Specification" in javax.xml.bind.package javadoc for
* additional common information.</p>
*
* @author <ul><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>
* @see XmlJavaTypeAdapter
* @since JAXB2.0
*/
@Retention(RUNTIME) @Target({PACKAGE})
public @interface XmlJavaTypeAdapters {
/**
* Collection of @{@link XmlJavaTypeAdapter} annotations
*/
XmlJavaTypeAdapter[] value();
}