All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spinjar.javax.xml.bind.annotation.XmlRootElement Maven / Gradle / Ivy

There is a newer version: 7.23.0-alpha1
Show newest version
/*
 * Copyright (c) 2004, 2018 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0, which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

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.
 *
 * 

Usage

*

* The @XmlRootElement annotation can be used with the following program * elements: *

    *
  • a top level class
  • *
  • an enum type
  • *
* *

See "Package Specification" in javax.xml.bind.package javadoc for * additional common information.

* *

* When a top level class or an enum type is annotated with the * @XmlRootElement annotation, then its value is represented * as XML element in an XML document. * *

This annotation can be used with the following annotations: * {@link XmlType}, {@link XmlEnum}, {@link XmlAccessorType}, * {@link XmlAccessorOrder}. *

*

* Example 1: Associate an element with XML Schema type *

 *     // Example: Code fragment
 *     @XmlRootElement
 *     class Point {
 *        int x;
 *        int y;
 *        Point(int _x,int _y) {x=_x;y=_y;}
 *     }
 * 
* *
 *     //Example: Code fragment corresponding to XML output
 *     marshal( new Point(3,5), System.out);
 * 
* *
{@code
 * 
 *     
 *     
 *        3 
 *        5 
 *     
 * }
* * 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. * *
{@code
 * 
 *     
 *     
 *     
 *       
 *         
 *         
 *       
 *     
 * }
* *

* * Example 2: Orthogonality to type inheritance * *

* An element declaration annotated on a type is not inherited by its * derived types. The following example shows this. *

 *     // Example: Code fragment
 *     @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 );
 * {@code
 * 
 *     
 *     
 *     
 *       3
 *       5
 *       0
 *     
 *
 *     
 *     
 *     
 *       
 *         
 *           
 *             
 *           
 *         
 *       
 *     
 * }
* * Example 3: Associate a global element with XML Schema type * to which the class is mapped. *
 *     //Example: Code fragment
 *     @XmlRootElement(name="PriceElement")
 *     public class USPrice {
 *         @XmlElement
 *         public java.math.BigDecimal price;
 *     }
 * {@code
 * 
 *     
 *     
 *     
 *       
 *         
 *       
 *     
 * }
* * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 */ @Retention(RUNTIME) @Target({TYPE}) public @interface XmlRootElement { /** * namespace name of the XML element. *

* 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. *

* If the value is "##default", then the name is derived from the * class name. * */ String name() default "##default"; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy