diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2aa7adf..fe69ce5 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: - java_version: [ 11, 17, 21 ] + java_version: [ 21 ] steps: - name: Checkout for build diff --git a/api/src/main/java/jakarta/xml/bind/Binder.java b/api/src/main/java/jakarta/xml/bind/Binder.java index acf2a17..cb3f17f 100644 --- a/api/src/main/java/jakarta/xml/bind/Binder.java +++ b/api/src/main/java/jakarta/xml/bind/Binder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -242,9 +242,9 @@ protected Binder() {} * *

* This is a convenience method of: - *

-     * updateXML( jaxbObject, getXMLNode(jaxbObject));
-     * 
+ * {@snippet : + * updateXML( jaxbObject, getXMLNode(jaxbObject)); + * } * * @param jaxbObject the XML Binding object * diff --git a/api/src/main/java/jakarta/xml/bind/DatatypeConverter.java b/api/src/main/java/jakarta/xml/bind/DatatypeConverter.java index 27549e4..f40c844 100644 --- a/api/src/main/java/jakarta/xml/bind/DatatypeConverter.java +++ b/api/src/main/java/jakarta/xml/bind/DatatypeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -28,23 +28,21 @@ * implementation of parse and print methods. These methods are invoked by * custom parse and print methods. For example, the binding of xsd:dateTime * to a long can be customized using parse and print methods as follows: - *
- *
- *    // Customized parse method 
- *    public long myParseCal( String dateTimeString ) {
- *        java.util.Calendar cal = DatatypeConverter.parseDateTime(dateTimeString);
- *        long longval = convert_calendar_to_long(cal); //application specific
- *        return longval;
- *    }
- *     
- *    // Customized print method
- *    public String myPrintCal( Long longval ) {
- *        java.util.Calendar cal = convert_long_to_calendar(longval) ; //application specific
- *        String dateTimeString = DatatypeConverter.printDateTime(cal);
- *        return dateTimeString;
- *    }
- *    
- *
+ * {@snippet : + * // Customized parse method + * public long myParseCal( String dateTimeString ) { + * java.util.Calendar cal = DatatypeConverter.parseDateTime(dateTimeString); + * long longval = convert_calendar_to_long(cal); //application specific + * return longval; + * } + * + * // Customized print method + * public String myPrintCal( Long longval ) { + * java.util.Calendar cal = convert_long_to_calendar(longval) ; //application specific + * String dateTimeString = DatatypeConverter.printDateTime(cal); + * return dateTimeString; + * } + * } *

* There is a static parse and print method corresponding to each parse and * print method respectively in the {@link DatatypeConverterInterface @@ -75,7 +73,6 @@ * @see PrintConversionEvent * @since 1.6, JAXB 1.0 */ - final public class DatatypeConverter { // delegate to this instance of DatatypeConverter diff --git a/api/src/main/java/jakarta/xml/bind/JAXBContext.java b/api/src/main/java/jakarta/xml/bind/JAXBContext.java index f2295f0..e25266c 100644 --- a/api/src/main/java/jakarta/xml/bind/JAXBContext.java +++ b/api/src/main/java/jakarta/xml/bind/JAXBContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -67,13 +67,13 @@ * application is able to unmarshal XML documents that are instances of * any of the schemas listed in the {@code contextPath}. For example: * - *

- *      JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
- *      Unmarshaller u = jc.createUnmarshaller();
- *      FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
- *      BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
- *      BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPath
- * 
+ * {@snippet : + * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" ); + * Unmarshaller u = jc.createUnmarshaller(); + * FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok + * BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok + * BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPath + * } * *

* The client application may also generate Java content trees explicitly rather @@ -91,10 +91,10 @@ * order to create objects of that type, the client application would use the * factory method like this: * - *

- *       com.acme.foo.PurchaseOrder po =
- *           com.acme.foo.ObjectFactory.createPurchaseOrder();
- * 
+ * {@snippet : + * com.acme.foo.PurchaseOrder po = + * com.acme.foo.ObjectFactory.createPurchaseOrder(); + * } * *

* Once the client application has an instance of the the schema derived object, @@ -128,17 +128,17 @@ * Here is a simple example that unmarshals an XML document and then marshals * it back out: * - *

- *        JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ * {@snippet :
+ *  JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
  *
- *        // unmarshal from foo.xml
- *        Unmarshaller u = jc.createUnmarshaller();
- *        FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
+ *  // unmarshal from foo.xml
+ *  Unmarshaller u = jc.createUnmarshaller();
+ *  FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
  *
- *        // marshal to System.out
- *        Marshaller m = jc.createMarshaller();
- *        m.marshal( fooObj, System.out );
- * 
+ * // marshal to System.out + * Marshaller m = jc.createMarshaller(); + * m.marshal( fooObj, System.out ); + * } * * *

Validation

@@ -416,13 +416,13 @@ public static JAXBContext newInstance( String contextPath, // * For example, in the following Java code, if you do // * {@code newInstance(Foo.class)}, the newly created {@link JAXBContext} // * will recognize both {@code Foo} and {@code Bar}, but not {@code Zot}: -// *
-//     * class Foo {
-//     *      Bar b;
+//     * {@snippet :
+//     *  class Foo {
+//     *       Bar b;
+//     *  }
+//     *  class Bar { int x; }
+//     *  class Zot extends Bar { int y; }
 //     * }
-//     * class Bar { int x; }
-//     * class Zot extends Bar { int y; }
-//     * 
// * // * Therefore, a typical client application only needs to specify the // * top-level classes, but it needs to be careful. @@ -491,15 +491,15 @@ public static JAXBContext newInstance( String contextPath, * For example, in the following Java code, if you do * {@code newInstance(Foo.class)}, the newly created {@link JAXBContext} * will recognize both {@code Foo} and {@code Bar}, but not {@code Zot} or {@code FooBar}: - *
-     * class Foo {
-     *      @XmlTransient FooBar c;
-     *      Bar b;
+     * {@snippet :
+     *  class Foo {
+     *       @XmlTransient FooBar c;
+     *       Bar b;
+     *  }
+     *  class Bar { int x; }
+     *  class Zot extends Bar { int y; }
+     *  class FooBar { }
      * }
-     * class Bar { int x; }
-     * class Zot extends Bar { int y; }
-     * class FooBar { }
-     * 
* * Therefore, a typical client application only needs to specify the * top-level classes, but it needs to be careful. diff --git a/api/src/main/java/jakarta/xml/bind/Marshaller.java b/api/src/main/java/jakarta/xml/bind/Marshaller.java index f21c48a..c2ddac0 100644 --- a/api/src/main/java/jakarta/xml/bind/Marshaller.java +++ b/api/src/main/java/jakarta/xml/bind/Marshaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -24,114 +24,92 @@ * *

* Assume the following setup code for all following code fragments: - *

- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
- *       Object element = u.unmarshal( new File( "foo.xml" ) );
- *       Marshaller m = jc.createMarshaller();
- *    
- *
+ * {@snippet : + * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); + * Unmarshaller u = jc.createUnmarshaller(); + * Object element = u.unmarshal( new File( "foo.xml" ) ); + * Marshaller m = jc.createMarshaller(); + * } * *

* Marshalling to a File: - *

- *
- *       OutputStream os = new FileOutputStream( "nosferatu.xml" );
- *       m.marshal( element, os );
- *    
- *
+ * {@snippet : + * OutputStream os = new FileOutputStream( "nosferatu.xml" ); + * m.marshal( element, os ); + * } * *

* Marshalling to a SAX ContentHandler: - *

- *
- *       // assume MyContentHandler instanceof ContentHandler
- *       m.marshal( element, new MyContentHandler() );
- *    
- *
+ * {@snippet : + * // assume MyContentHandler instanceof ContentHandler + * m.marshal( element, new MyContentHandler() ); + * } * *

* Marshalling to a DOM Node: - *

- *
- *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- *       dbf.setNamespaceAware(true);
- *       DocumentBuilder db = dbf.newDocumentBuilder();
- *       Document doc = db.newDocument();
+ * {@snippet :
+ *  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ *  dbf.setNamespaceAware(true);
+ *  DocumentBuilder db = dbf.newDocumentBuilder();
+ *  Document doc = db.newDocument();
  *
- *       m.marshal( element, doc );
- *    
- *
+ * m.marshal( element, doc ); + * } * *

* Marshalling to a java.io.OutputStream: - *

- *
- *       m.marshal( element, System.out );
- *    
- *
+ * {@snippet : + * m.marshal( element, System.out ); + * } * *

* Marshalling to a java.io.Writer: - *

- *
- *       m.marshal( element, new PrintWriter( System.out ) );
- *    
- *
+ * {@snippet : + * m.marshal( element, new PrintWriter( System.out ) ); + * } * *

* Marshalling to a javax.xml.transform.SAXResult: - *

- *
- *       // assume MyContentHandler instanceof ContentHandler
- *       SAXResult result = new SAXResult( new MyContentHandler() );
+ * {@snippet :
+ *  // assume MyContentHandler instanceof ContentHandler
+ *  SAXResult result = new SAXResult( new MyContentHandler() );
  *
- *       m.marshal( element, result );
- *    
- *
+ * m.marshal( element, result ); + * } * *

* Marshalling to a javax.xml.transform.DOMResult: - *

- *
- *       DOMResult result = new DOMResult();
+ * {@snippet :
+ *  DOMResult result = new DOMResult();
  *
- *       m.marshal( element, result );
- *    
- *
+ * m.marshal( element, result ); + * } * *

* Marshalling to a javax.xml.transform.StreamResult: - *

- *
- *       StreamResult result = new StreamResult( System.out );
+ * {@snippet :
+ *  StreamResult result = new StreamResult( System.out );
  *
- *       m.marshal( element, result );
- *    
- *
+ * m.marshal( element, result ); + * } * *

* Marshalling to a javax.xml.stream.XMLStreamWriter: - *

- *
- *       XMLStreamWriter xmlStreamWriter =
- *           XMLOutputFactory.newInstance().createXMLStreamWriter( ... );
+ * {@snippet :
+ *  XMLStreamWriter xmlStreamWriter =
+ *      XMLOutputFactory.newInstance().createXMLStreamWriter( ... );
  *
- *       m.marshal( element, xmlStreamWriter );
- *    
- *
+ * m.marshal( element, xmlStreamWriter ); + * } * *

* Marshalling to a javax.xml.stream.XMLEventWriter: - *

- *
- *       XMLEventWriter xmlEventWriter =
- *           XMLOutputFactory.newInstance().createXMLEventWriter( ... );
+ * {@snippet :
+ *  XMLEventWriter xmlEventWriter =
+ *      XMLOutputFactory.newInstance().createXMLEventWriter( ... );
  *
- *       m.marshal( element, xmlEventWriter );
- *    
- *
+ * m.marshal( element, xmlEventWriter ); + * } * *

* @@ -269,15 +247,13 @@ *

* Class defined event callback methods allow any Jakarta XML Binding mapped class to specify * its own specific callback methods by defining methods with the following method signatures: - *

- *
- *   // Invoked by Marshaller after it has created an instance of this object.
- *   boolean beforeMarshal(Marshaller);
+ * {@snippet :
+ *  // Invoked by Marshaller after it has created an instance of this object.
+ *  boolean beforeMarshal(Marshaller);
  *
- *   // Invoked by Marshaller after it has marshalled all properties of this object.
- *   void afterMarshal(Marshaller);
- * 
- *
+ * // Invoked by Marshaller after it has marshalled all properties of this object. + * void afterMarshal(Marshaller); + * } * The class defined event callback methods should be used when the callback method requires * access to non-public methods and/or fields of the class. *

diff --git a/api/src/main/java/jakarta/xml/bind/Unmarshaller.java b/api/src/main/java/jakarta/xml/bind/Unmarshaller.java index a43f0fe..2431771 100644 --- a/api/src/main/java/jakarta/xml/bind/Unmarshaller.java +++ b/api/src/main/java/jakarta/xml/bind/Unmarshaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -23,144 +23,128 @@ * *

* Unmarshalling from a File: - *

- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
- *       Object o = u.unmarshal( new File( "nosferatu.xml" ) );
- *    
- *
+ * {@snippet : + * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); + * Unmarshaller u = jc.createUnmarshaller(); + * Object o = u.unmarshal( new File( "nosferatu.xml" ) ); + * } * * *

* Unmarshalling from an InputStream: - *

- *
- *       InputStream is = new FileInputStream( "nosferatu.xml" );
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
- *       Object o = u.unmarshal( is );
- *    
- *
+ * {@snippet : + * InputStream is = new FileInputStream( "nosferatu.xml" ); + * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); + * Unmarshaller u = jc.createUnmarshaller(); + * Object o = u.unmarshal( is ); + * } * *

* Unmarshalling from a URL: - *

- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
- *       URL url = new URL( "http://beaker.east/nosferatu.xml" );
- *       Object o = u.unmarshal( url );
- *    
- *
+ * {@snippet : + * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); + * Unmarshaller u = jc.createUnmarshaller(); + * URL url = new URL( "http://beaker.east/nosferatu.xml" ); + * Object o = u.unmarshal( url ); + * } * *

* Unmarshalling from a StringBuffer using a * {@code javax.xml.transform.stream.StreamSource}: - *

- *
{@code
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
- *       StringBuffer xmlStr = new StringBuffer( "..." );
- *       Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
- *    }
- *
+ * {@snippet : + * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); + * Unmarshaller u = jc.createUnmarshaller(); + * StringBuffer xmlStr = new StringBuffer( "..." ); + * Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) ); + * } * *

* Unmarshalling from a {@code org.w3c.dom.Node}: - *

- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
+ * {@snippet :
+ *  JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *  Unmarshaller u = jc.createUnmarshaller();
  *
- *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- *       dbf.setNamespaceAware(true);
- *       DocumentBuilder db = dbf.newDocumentBuilder();
- *       Document doc = db.parse(new File( "nosferatu.xml"));
+ *  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ *  dbf.setNamespaceAware(true);
+ *  DocumentBuilder db = dbf.newDocumentBuilder();
+ *  Document doc = db.parse(new File( "nosferatu.xml"));
 
- *       Object o = u.unmarshal( doc );
- *    
- *
+ * Object o = u.unmarshal( doc ); + * } * *

* Unmarshalling from a {@code javax.xml.transform.sax.SAXSource} using a * client specified validating SAX2.0 parser: - *

- *
- *       // configure a validating SAX2.0 parser (Xerces2)
- *       static final String JAXP_SCHEMA_LANGUAGE =
- *           "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
- *       static final String JAXP_SCHEMA_LOCATION =
- *           "http://java.sun.com/xml/jaxp/properties/schemaSource";
- *       static final String W3C_XML_SCHEMA =
- *           "http://www.w3.org/2001/XMLSchema";
+ * {@snippet :
+ *  // configure a validating SAX2.0 parser (Xerces2)
+ *  static final String JAXP_SCHEMA_LANGUAGE =
+ *       "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+ *  static final String JAXP_SCHEMA_LOCATION =
+ *       "http://java.sun.com/xml/jaxp/properties/schemaSource";
+ *  static final String W3C_XML_SCHEMA =
+ *       "http://www.w3.org/2001/XMLSchema";
  *
- *       System.setProperty( "javax.xml.parsers.SAXParserFactory",
- *                           "org.apache.xerces.jaxp.SAXParserFactoryImpl" );
+ *  System.setProperty( "javax.xml.parsers.SAXParserFactory",
+ *                      "org.apache.xerces.jaxp.SAXParserFactoryImpl" );
  *
- *       SAXParserFactory spf = SAXParserFactory.newInstance();
- *       spf.setNamespaceAware(true);
- *       spf.setValidating(true);
- *       SAXParser saxParser = spf.newSAXParser();
+ *  SAXParserFactory spf = SAXParserFactory.newInstance();
+ *  spf.setNamespaceAware(true);
+ *  spf.setValidating(true);
+ *  SAXParser saxParser = spf.newSAXParser();
  *
- *       try {
- *           saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
- *           saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://....");
- *       } catch (SAXNotRecognizedException x) {
- *           // exception handling omitted
- *       }
+ *  try {
+ *      saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+ *      saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://....");
+ *  } catch (SAXNotRecognizedException x) {
+ *      // exception handling omitted
+ *  }
  *
- *       XMLReader xmlReader = saxParser.getXMLReader();
- *       SAXSource source =
- *           new SAXSource( xmlReader, new InputSource( "http://..." ) );
+ *  XMLReader xmlReader = saxParser.getXMLReader();
+ *  SAXSource source =
+ *      new SAXSource( xmlReader, new InputSource( "http://..." ) );
  *
- *       // Setup Jakarta XML Binding to unmarshal
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
- *       ValidationEventCollector vec = new ValidationEventCollector();
- *       u.setEventHandler( vec );
+ *  // Setup Jakarta XML Binding to unmarshal
+ *  JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *  Unmarshaller u = jc.createUnmarshaller();
+ *  ValidationEventCollector vec = new ValidationEventCollector();
+ *  u.setEventHandler( vec );
  *
- *       // turn off the Jakarta XML Binding provider's default validation mechanism to
- *       // avoid duplicate validation
- *       u.setValidating( false )
+ *  // turn off the Jakarta XML Binding provider's default validation mechanism to
+ *  // avoid duplicate validation
+ *  u.setValidating( false )
  *
- *       // unmarshal
- *       Object o = u.unmarshal( source );
+ *  // unmarshal
+ *  Object o = u.unmarshal( source );
  *
- *       // check for events
- *       if( vec.hasEvents() ) {
- *          // iterate over events
- *       }
- *    
- *
+ * // check for events + * if( vec.hasEvents() ) { + * // iterate over events + * } + * } * *

* Unmarshalling from a StAX XMLStreamReader: - *

- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
+ * {@snippet :
+ *  JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *  Unmarshaller u = jc.createUnmarshaller();
  *
- *       javax.xml.stream.XMLStreamReader xmlStreamReader =
- *           javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... );
+ *  javax.xml.stream.XMLStreamReader xmlStreamReader =
+ *      javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... );
  *
- *       Object o = u.unmarshal( xmlStreamReader );
- *    
- *
+ * Object o = u.unmarshal( xmlStreamReader ); + * } * *

* Unmarshalling from a StAX XMLEventReader: - *

- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
+ * {@snippet :
+ *  JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *  Unmarshaller u = jc.createUnmarshaller();
  *
- *       javax.xml.stream.XMLEventReader xmlEventReader =
- *           javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... );
+ *  javax.xml.stream.XMLEventReader xmlEventReader =
+ *      javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... );
  *
- *       Object o = u.unmarshal( xmlEventReader );
- *    
- *
+ * Object o = u.unmarshal( xmlEventReader ); + * } * *

* @@ -262,37 +246,36 @@ * unmarshal by declaredType method. *

* Unmarshal by declaredType from a {@code org.w3c.dom.Node}: - *

- *
{@code
- *       Schema fragment for example
- *       
- *          ...<\xs:complexType>
- *          
- *          
- *              
- *                 
- *                    
- *                    
- *                    ...
- *                 
- *              
- *          
- *       
- *
- *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
- *       Unmarshaller u = jc.createUnmarshaller();
+ * {@snippet lang="XML" :
+ *   
+ *   
+ *     ...
+ *     
+ *     
+ *       
+ *         
+ *           
+ *           
+ *           ...
+ *         
+ *       
+ *     
+ *   
+ * }
+ * {@snippet :
+ *  JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *  Unmarshaller u = jc.createUnmarshaller();
  *
- *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- *       dbf.setNamespaceAware(true);
- *       DocumentBuilder db = dbf.newDocumentBuilder();
- *       Document doc = db.parse(new File( "nosferatu.xml"));
- *       Element  fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
- *                                  // local element declaration in schema.
+ *  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ *  dbf.setNamespaceAware(true);
+ *  DocumentBuilder db = dbf.newDocumentBuilder();
+ *  Document doc = db.parse(new File( "nosferatu.xml"));
+ *  Element  fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
+ *                             // local element declaration in schema.
  *
- *       // FooType is the Jakarta XML Binding mapping of the type of local element declaration foo.
- *       JAXBElement foo = u.unmarshal( fooSubtree, FooType.class);
- *    }
- *
+ * // FooType is the Jakarta XML Binding mapping of the type of local element declaration foo. + * JAXBElement foo = u.unmarshal( fooSubtree, FooType.class); + * } * *

* Support for SAX2.0 Compliant Parsers
@@ -354,17 +337,15 @@ *

* 'Class defined' event callback methods allow any Jakarta XML Binding mapped class to specify * its own specific callback methods by defining methods with the following method signature: - *

- *
- *   // This method is called immediately after the object is created and before the unmarshalling of this
- *   // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
- *   void beforeUnmarshal(Unmarshaller, Object parent);
+ * {@snippet :
+ *  // This method is called immediately after the object is created and before the unmarshalling of this
+ *  // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
+ *  void beforeUnmarshal(Unmarshaller, Object parent);
  *
- *   //This method is called after all the properties (except IDREF) are unmarshalled for this object,
- *   //but before this object is set to the parent object.
- *   void afterUnmarshal(Unmarshaller, Object parent);
- * 
- *
+ * //This method is called after all the properties (except IDREF) are unmarshalled for this object, + * //but before this object is set to the parent object. + * void afterUnmarshal(Unmarshaller, Object parent); + * } * The class defined callback methods should be used when the callback method requires * access to non-public methods and/or fields of the class. *

diff --git a/api/src/main/java/jakarta/xml/bind/UnmarshallerHandler.java b/api/src/main/java/jakarta/xml/bind/UnmarshallerHandler.java index 4228437..8932bbf 100644 --- a/api/src/main/java/jakarta/xml/bind/UnmarshallerHandler.java +++ b/api/src/main/java/jakarta/xml/bind/UnmarshallerHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -19,22 +19,22 @@ * Applications can use this interface to use their Jakarta XML Binding provider as a component * in an XML pipeline. For example: * - *

- *       JAXBContext context = JAXBContext.newInstance( "org.acme.foo" );
+ * {@snippet :
+ *  JAXBContext context = JAXBContext.newInstance( "org.acme.foo" );
  *
- *       Unmarshaller unmarshaller = context.createUnmarshaller();
+ *  Unmarshaller unmarshaller = context.createUnmarshaller();
  * 
- *       UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
+ *  UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
  *
- *       SAXParserFactory spf = SAXParserFactory.newInstance();
- *       spf.setNamespaceAware( true );
+ *  SAXParserFactory spf = SAXParserFactory.newInstance();
+ *  spf.setNamespaceAware( true );
  * 
- *       XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- *       xmlReader.setContentHandler( unmarshallerHandler );
- *       xmlReader.parse(new InputSource( new FileInputStream( XML_FILE ) ) );
+ *  XMLReader xmlReader = spf.newSAXParser().getXMLReader();
+ *  xmlReader.setContentHandler( unmarshallerHandler );
+ *  xmlReader.parse(new InputSource( new FileInputStream( XML_FILE ) ) );
  *
- *       MyObject myObject= (MyObject)unmarshallerHandler.getResult();                          
- * 
+ * MyObject myObject= (MyObject)unmarshallerHandler.getResult(); + * } * *

* This interface is reusable: even if the user fails to unmarshal diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlAccessorType.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlAccessorType.java index 87cb24d..bc62aa8 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlAccessorType.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlAccessorType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -52,16 +52,16 @@ * *

By default, if {@code @XmlAccessorType} on a package is absent, * then the following package level annotation is assumed.

- *
- *   @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
- * 
+ * {@snippet : + * @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) + * } *

By default, if {@code @XmlAccessorType} on a class is absent, * and none of its super classes is annotated with * {@code @XmlAccessorType}, then the following default on the class * is assumed:

- *
- *   @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
- * 
+ * {@snippet : + * @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) + * } *

This annotation can be used with the following annotations: * {@link XmlType}, {@link XmlRootElement}, {@link XmlAccessorOrder}, * {@link XmlSchema}, {@link XmlSchemaType}, {@link XmlSchemaTypes}, @@ -72,7 +72,6 @@ * @since 1.6, JAXB 2.0 * @see XmlAccessType */ - @Inherited @Retention(RUNTIME) @Target({PACKAGE, TYPE}) public @interface XmlAccessorType { diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlAnyElement.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlAnyElement.java index 8be8ce6..863d6c0 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlAnyElement.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlAnyElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -28,28 +28,28 @@ * *

* This annotation serves as a "catch-all" property while unmarshalling - * xml content into a instance of a Jakarta XML Binding annotated class. It typically - * annotates a multi-valued JavaBean property, but it can occur on + * xml content into an instance of a Jakarta XML Binding annotated class. It typically + * annotates a multivalued JavaBean property, but it can occur on * single value JavaBean property. During unmarshalling, each xml element * that does not match a static @XmlElement or @XmlElementRef * annotation for the other JavaBean properties on the class, is added to this * "catch-all" property. * *

Usages:

- *
- * @XmlAnyElement
- * public {@link Element}[] others;
+ * {@snippet :
+ *  @XmlAnyElement
+ *  public Element[] others;
  *
- * // Collection of {@link Element} or JAXBElements.
- * @XmlAnyElement(lax="true")
- * public {@link Object}[] others;
+ *  // Collection of Element or JAXBElements.
+ *  @XmlAnyElement(lax="true")
+ *  public Object[] others;
  *
- * @XmlAnyElement
- * private List<{@link Element}> nodes;
+ *  @XmlAnyElement
+ *  private List nodes;
  *
- * @XmlAnyElement
- * private {@link Element} node;
- * 
+ * @XmlAnyElement + * private Element node; + * } * *

Restriction usage constraints

*

@@ -69,82 +69,84 @@ * *

* This annotation can be used with {@link XmlMixed} like this: - *

- * // List of java.lang.String or DOM nodes.
- * @XmlAnyElement @XmlMixed
- * List<Object> others;
- * 
+ * {@snippet : + * // List of java.lang.String or DOM nodes. + * @XmlAnyElement + * @XmlMixed + * List others; + * } * * *

Schema To Java example

* * The following schema would produce the following Java class: - *
{@code
- * 
- *   
- *     
- *     
- *     
- *   
- * 
- * }
- * - *
- * class Foo {
- *   int a;
- *   int b;
- *   @{@link XmlAnyElement}
- *   List<Element> any;
+ * {@snippet lang="XML" :
+ *  
+ *    
+ *      
+ *      
+ *      
+ *    
+ *  
+ * }
+ *
+ * {@snippet :
+ *  class Foo {
+ *      int a;
+ *      int b;
+ *      @XmlAnyElement
+ *      List any;
+ *  }
  * }
- * 
* * It can unmarshal instances like * - *
{@code
- * 
- *   1
- *     // this will be bound to DOM, because unmarshalling is orderless
- *   3
- *   
- *   5     // this will be bound to DOM, because the annotation doesn't remember namespaces.
- * 
- * }
+ * {@snippet lang="XML" : + * + * 1 + * + * 3 + * + * 5 + * + * } * * * * The following schema would produce the following Java class: - *
{@code
- * 
- *   
- *   
- *     
- *       
- *       
- *     
- *   
- * 
- * }
- * - *
- * class Bar extends Foo {
- *   int c;
- *   // Foo.getAny() also represents wildcard content for type definition bar.
+ * {@snippet lang="XML" :
+ *  
+ *    
+ *      
+ *        
+ *          
+ *          
+ *        
+ *      
+ *    
+ *  
+ * }
+ *
+ * {@snippet :
+ *  class Bar extends Foo {
+ *      int c;
+ *      // Foo.getAny() also represents wildcard content for type definition bar.
+ *  }
  * }
- * 
* * * It can unmarshal instances like * - *
{@code
- * 
- *   1
- *     // this will be bound to DOM, because unmarshalling is orderless
- *   3
- *   
- *   5     // this now goes to Bar.c
- *     // this will go to Foo.any
- * 
- * }
+ * {@snippet lang="XML" : + * + * 1 + * + * 3 + * + * 5 + * + * + * } * * * @@ -156,45 +158,46 @@ * *

* The following schema would produce the following Java class: - *

{@code
- * 
- *   
- *     
- *     
- *     
- *   
- * 
- * }
- * - *
- * class Foo {
- *   @{@link XmlAnyElement}(lax="true")
- *   @{@link XmlElementRefs}({
- *     @{@link XmlElementRef}(name="a", type="JAXBElement.class")
- *     @{@link XmlElementRef}(name="b", type="JAXBElement.class")
- *   })
- *   {@link List}<{@link Object}> others;
+ * {@snippet lang="XML" :
+ *  
+ *    
+ *      
+ *      
+ *      
+ *    
+ *  
  * }
  *
- * @XmlRegistry
- * class ObjectFactory {
- *   ...
- *   @XmlElementDecl(name = "a", namespace = "", scope = Foo.class)
- *   {@link JAXBElement}<Integer> createFooA( Integer i ) { ... }
- *
- *   @XmlElementDecl(name = "b", namespace = "", scope = Foo.class)
- *   {@link JAXBElement}<Integer> createFooB( Integer i ) { ... }
- * 
+ * {@snippet : + * class Foo { + * @XmlAnyElement(lax="true") + * @XmlElementRefs({ + * @XmlElementRef(name="a", type="JAXBElement.class"), + * @XmlElementRef(name="b", type="JAXBElement.class") + * }) + * List others; + * } + * + * @XmlRegistry + * class ObjectFactory { + * ... + * @XmlElementDecl(name = "a", namespace = "", scope = Foo.class) + * JAXBElement createFooA( Integer i ) { ... } + * + * @XmlElementDecl(name = "b", namespace = "", scope = Foo.class) + * JAXBElement createFooB( Integer i ) { ... } + * } + * } * * It can unmarshal instances like * - *
- *{@code }
- *{@code   1}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
- *{@code   }  // this will unmarshal to a DOM {@link Element}.
- *{@code   3}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
- *{@code }
- * 
+ * {@snippet lang="XML" : + * + * 1 + * + * 3 + * + * } * * * @@ -202,29 +205,30 @@ *

W3C XML Schema "lax" wildcard emulation

* 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: - *
- * @{@link XmlRootElement}
- * class Foo {
- *   @XmlAnyElement(lax=true)
- *   public {@link Object}[] others;
+ * {@snippet :
+ *  @XmlRootElement
+ *  class Foo {
+ *      @XmlAnyElement(lax=true)
+ *      public Object[] others;
+ *  }
  * }
- * 
* then the following document will unmarshal like this: - *
{@code
- * 
- *   
- *   
- * 
- *
- * 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;
- * }
+ * {@snippet lang="XML" : + * + * + * + * + * } + * {@snippet : + * 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; + * } * * @author Kohsuke Kawaguchi * @since 1.6, JAXB 2.0 diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlAttachmentRef.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlAttachmentRef.java index 49cc99c..92e0e33 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlAttachmentRef.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlAttachmentRef.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -27,29 +27,29 @@ * A field/property must always map to the {@link DataHandler} class. * *

Usage

- *
- * @{@link XmlRootElement}
- * class Foo {
- *   @{@link XmlAttachmentRef}
- *   @{@link XmlAttribute}
- *   {@link DataHandler} data;
+ * {@snippet :
+ *  @XmlRootElement
+ *  class Foo {
+ *      @XmlAttachmentRef
+ *      @XmlAttribute
+ *      DataHandler data;
  *
- *   @{@link XmlAttachmentRef}
- *   @{@link XmlElement}
- *   {@link DataHandler} body;
+ *      @XmlAttachmentRef
+ *      @XmlElement
+ *      DataHandler body;
+ *  }
  * }
- * 
* The above code maps to the following XML: - *
{@code
- * 
- *   
- *     
- *       
- *     
- *     
- *   
- * 
- * }
+ * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * } * *

* The above binding supports WS-I AP 1.0 WS-I Attachments Profile Version 1.0. diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlAttribute.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlAttribute.java index 746d413..dbc3af1 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlAttribute.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -39,20 +39,20 @@ *

  • If type of the field or the property is a collection * type, then the collection item type must be mapped to schema * simple type. - *
    - *     // Examples
    - *     @XmlAttribute List<Integer> items; //legal
    - *     @XmlAttribute List<Bar> foo; // illegal if Bar does not map to a schema simple type
    - * 
    + * {@snippet : + * // Examples + * @XmlAttribute List items; //legal + * @XmlAttribute List foo; // illegal if Bar does not map to a schema simple type + * } *
  • *
  • 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. - *
    - *     // Examples
    - *     @XmlAttribute int foo; // legal
    - *     @XmlAttribute Foo foo; // illegal if Foo does not map to a schema simple type
    - * 
    + * {@snippet : + * // Examples + * @XmlAttribute int foo; // legal + * @XmlAttribute Foo foo; // illegal if Foo does not map to a schema simple type + * } *
  • *
  • This annotation can be used with the following annotations: * {@link XmlID}, @@ -67,50 +67,50 @@ * * *

    Example 1: Map a JavaBean property to an XML attribute.

    - *
    - *     //Example: Code fragment
    - *     public class USPrice { 
    - *         @XmlAttribute
    - *         public java.math.BigDecimal getPrice() {...} ;
    - *         public void setPrice(java.math.BigDecimal ) {...};
    - *     }
    - * {@code
    - * 
    - *     
    - *     
    - *       
    - *       
    - *       
    - *     
    - * }
    + * {@snippet : + * //Example: Code fragment + * public class USPrice { + * @XmlAttribute + * public java.math.BigDecimal getPrice() {...} ; + * public void setPrice(java.math.BigDecimal ) {...}; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * } * *

    Example 2: Map a JavaBean property to an XML attribute with anonymous type.

    * See Example 7 in @{@link XmlType}. * *

    Example 3: Map a JavaBean collection property to an XML attribute.

    - *
    - *     // Example: Code fragment
    - *     class Foo {
    - *         ...
    - *         @XmlAttribute List<Integer> items;
    - *     } 
    - * {@code
    - * 
    - *     
    - *     
    - *     	 ...
    - *       
    - *         
    - *           
    - *         
    - *     
    - *
    - * }
    + * {@snippet : + * // Example: Code fragment + * class Foo { + * ... + * @XmlAttribute + * List items; + * } + * } + * {@snippet lang="XML" : + * + * + * ... + * + * + * + * + + * + * } * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlType * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target({FIELD, METHOD}) public @interface XmlAttribute { /** diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlElement.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlElement.java index 02f2ce9..5ddead8 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlElement.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -60,56 +60,56 @@ *

    * Example 1: Map a public non static non final field to local * element - *

    - *     //Example: Code fragment
    - *     public class USPrice {
    - *        {@literal @}XmlElement(name="itemprice")
    - *         public java.math.BigDecimal price;
    - *     }
    - * {@code
    - *
    - *     
    - *     
    - *       
    - *         
    - *       
    - *     
    - *   }
    + * {@snippet : + * //Example: Code fragment + * public class USPrice { + * @XmlElement(name="itemprice") + * public java.math.BigDecimal price; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * } *

    * * Example 2: Map a field to a nillable element. - *

    - *     //Example: Code fragment
    - *     public class USPrice {
    - *        {@literal @}XmlElement(nillable=true)
    - *         public java.math.BigDecimal price;
    - *     }
    - * {@code
    - *
    - *     
    - *     
    - *       
    - *         
    - *       
    - *     
    - *   }
    + * {@snippet : + * //Example: Code fragment + * public class USPrice { + * @XmlElement(nillable=true) + * public java.math.BigDecimal price; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * } *

    * Example 3: Map a field to a nillable, required element. - *

    - *     //Example: Code fragment
    - *     public class USPrice {
    - *        {@literal @}XmlElement(nillable=true, required=true)
    - *         public java.math.BigDecimal price;
    - *     }
    - * {@code
    - *
    - *     
    - *     
    - *       
    - *         
    - *       
    - *     
    - *   }
    + * {@snippet : + * //Example: Code fragment + * public class USPrice { + * @XmlElement(nillable=true, required=true) + * public java.math.BigDecimal price; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * } * *

    Example 4: Map a JavaBean property to an XML element * with anonymous type.

    @@ -119,7 +119,6 @@ * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER}) public @interface XmlElement { /** diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlElementDecl.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlElementDecl.java index 6ddebfc..aa637a9 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlElementDecl.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlElementDecl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -42,30 +42,31 @@ * * *

    Example 1: Annotation on a factory method - *

    - *     // Example: code fragment
    - *     @XmlRegistry
    - *     class ObjectFactory {
    - *         @XmlElementDecl(name="foo")
    - *         JAXBElement<String> createFoo(String s) { ... }
    - *     }
    - * 
    - *
     {@code
    - *
    - *     
    - *     string
    - *
    - *     // Example: code fragment corresponding to XML input
    - *     JAXBElement o =
    - *     (JAXBElement)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"
    - *
    - *     
    - *     
    - * }
    + * {@snippet : + * // Example: code fragment + * @XmlRegistry + * class ObjectFactory { + * @XmlElementDecl(name="foo") + * JAXBElement createFoo(String s) { ... } + * } + * } + * {@snippet lang="XML" : + * + * string + *} + * {@snippet : + * // Example: code fragment corresponding to XML input + * JAXBElement o = + * (JAXBElement)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" + * } + * {@snippet lang="XML" : + * + * + * } * *

    Example 2: Element declaration with non local scope *

    @@ -76,7 +77,7 @@ * The following example may be replaced in a future revision of * this javadoc. * - *

    {@code
    + * {@snippet lang="XML" :
      *     
      *     
      *       
    @@ -87,8 +88,8 @@
      *       
      *       
      *     
    - * }
    - *
    + * }
    + * {@snippet :
      *     // Example: expected default binding
      *     class Pea {
      *         @XmlElementRefs({
    @@ -109,8 +110,7 @@
      *         @XmlElementDecl(name="foo")
      *         JAXBElement<Integer> createFoo(Integer i);
      *     }
    - *
    - * 
    + * } * Without scope createFoo and createPeaFoo would become ambiguous * since both of them map to a XML schema element with the same local * name "foo". diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlElementRef.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlElementRef.java index f6d1595..7f6da81 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlElementRef.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlElementRef.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -41,10 +41,10 @@ * support for substitution groups using an element property, * (section 5.5.5, "Element Property" of Jakarta XML Binding specification). An * element property method signature is of the form: - *
    {@code
    - *     public void setTerm(JAXBElement);
    - *     public JAXBElement getTerm();
    - * }
    + * {@snippet : + * public void setTerm(JAXBElement); + * public JAXBElement getTerm(); + * } *

    * An element factory method annotated with {@link XmlElementDecl} is * used to create a {@code JAXBElement} instance, containing an XML @@ -83,62 +83,62 @@ * 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 - * @XmlRootElement annotation on its corresponding class. - *

    - *     @XmlRootElement(name="target")
    - *     class Target {
    - *         // The presence of @XmlElementRef indicates that the XML
    - *         // element name will be derived from the @XmlRootElement
    - *         // annotation on the type (for e.g. "jar" for JarTask).
    - *         @XmlElementRef
    - *         List<Task> tasks;
    - *     }
    + * XmlRootElement annotation on its corresponding class.
    + * {@snippet :
    + *  @XmlRootElement(name="target")
    + *  class Target {
    + *      // The presence of @XmlElementRef indicates that the XML
    + *      // element name will be derived from the @XmlRootElement
    + *      // annotation on the type (for e.g. "jar" for JarTask).
    + *      @XmlElementRef
    + *      List tasks;
    + *  }
      *
    - *     abstract class Task {
    - *     }
    + *  abstract class Task {
    + *  }
      *
    - *     @XmlRootElement(name="jar")
    - *     class JarTask extends Task {
    - *         ...
    - *     }
    + *  @XmlRootElement(name="jar")
    + *  class JarTask extends Task {
    + *      ...
    + *  }
      *
    - *     @XmlRootElement(name="javac")
    - *     class JavacTask extends Task {
    - *         ...
    - *     }
    - * {@code
    - *
    - *     
    - *     
    - *     
    - *       
    - *         
    - *           
    - *           
    - *         
    - *       
    - *     
    - *
    - * }
    + * @XmlRootElement(name="javac") + * class JavacTask extends Task { + * ... + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * } *

    * Thus the following code fragment: - *

    - *     Target target = new Target();
    - *     target.tasks.add(new JarTask());
    - *     target.tasks.add(new JavacTask());
    - *     marshal(target);
    - * 
    + * {@snippet : + * Target target = new Target(); + * target.tasks.add(new JarTask()); + * target.tasks.add(new JavacTask()); + * marshal(target); + * } * will produce the following XML output: - *
    {@code
    - *     
    - *       
    - *         ....
    - *       
    - *       
    - *         ....
    - *       
    - *     
    - * }
    + * {@snippet lang="XML" : + * + * + * .... + * + * + * .... + * + * + * } *

    * It is not an error to have a class that extends {@code Task} * that doesn't have {@link XmlRootElement}. But they can't show up in an @@ -149,55 +149,55 @@ * substitution groups. The annotations and the ObjectFactory are * derived from the schema. * - *

    - *     @XmlElement
    - *     class Math {
    - *         //  The value of {@link #type()}is
    - *         //  JAXBElement.class , which indicates the XML
    - *         //  element name ObjectFactory - in general a class marked
    - *         //  with @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.
    - *         //
    - *         @XmlElementRef(type=JAXBElement.class,name="operator")
    - *         JAXBElement<? extends Operator> term;
    - *     }
    + * {@snippet :
    + *  @XmlElement
    + *  class Math {
    + *      //  The value of type() is // @link substring="type()" target="#type()"
    + *      //  JAXBElement.class , which indicates the XML
    + *      //  element name ObjectFactory - in general a class marked
    + *      //  with @XmlRegistry. (See ObjectFactory below)
    + *      //
    + *      //  The name() is "operator", a pointer to a // @link substring="name()" target="#name()"
    + *      // factory method annotated with a
    + *      //  XmlElementDecl with the name "operator". Since //@link substring="XmlElementDecl" target="XmlElementDecl"
    + *      //  "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.
    + *      //
    + *      @XmlElementRef(type=JAXBElement.class,name="operator")
    + *      JAXBElement term;
    + *  }
      *
    - *     @XmlRegistry
    - *     class ObjectFactory {
    - *         @XmlElementDecl(name="operator")
    - *         JAXBElement<Operator> createOperator(Operator o) {...}
    - *         @XmlElementDecl(name="add",substitutionHeadName="operator")
    - *         JAXBElement<Operator> createAdd(Operator o) {...}
    - *         @XmlElementDecl(name="sub",substitutionHeadName="operator")
    - *         JAXBElement<Operator> createSub(Operator o) {...}
    - *     }
    + *  @XmlRegistry
    + *  class ObjectFactory {
    + *      @XmlElementDecl(name="operator")
    + *      JAXBElement createOperator(Operator o) {...}
    + *      @XmlElementDecl(name="add",substitutionHeadName="operator")
    + *      JAXBElement createAdd(Operator o) {...}
    + *      @XmlElementDecl(name="sub",substitutionHeadName="operator")
    + *      JAXBElement createSub(Operator o) {...}
    + *  }
      *
    - *     class Operator {
    - *         ...
    - *     }
    - * 
    + * class Operator { + * ... + * } + * } *

    * Thus, the following code fragment - *

    - *     Math m = new Math();
    - *     m.term = new ObjectFactory().createAdd(new Operator());
    - *     marshal(m);
    - * 
    + * {@snippet : + * Math m = new Math(); + * m.term = new ObjectFactory().createAdd(new Operator()); + * marshal(m); + * } * will produce the following XML output: - *
    {@code
    - *     
    - *       ...
    - *     
    - * }
    + * {@snippet lang="XML" : + * + * ... + * + * } * * * @author
    • Kohsuke Kawaguchi, Sun Microsystems,Inc.
    • Sekhar Vajjhala, Sun Microsystems, Inc.
    diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlElementWrapper.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlElementWrapper.java index 949cb59..4319175 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlElementWrapper.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlElementWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -24,21 +24,22 @@ * XML element around collections. The annotation therefore supports * two forms of serialization shown below. * - *
    {@code
    - *    //Example: code fragment
    - *      int[] names;
    - *
    - *    // XML Serialization Form 1 (Unwrapped collection)
    - *     ... 
    - *     ... 
    + * {@snippet :
    + *  //Example: code fragment
    + *  int[] names;
    + * }
    + * {@snippet lang="XML" :
    + *  
    + *   ... 
    + *   ... 
      * 
    - *    // XML Serialization Form 2 ( Wrapped collection )
    - *    
    - *        value-of-item 
    - *        value-of-item 
    - *       ....
    - *    
    - * }
    + * + * + * value-of-item + * value-of-item + * .... + * + * } * *

    The two serialized XML forms allow a null collection to be * represented either by absence or presence of an element with a @@ -75,7 +76,6 @@ * @since 1.6, JAXB 2.0 * */ - @Retention(RUNTIME) @Target({FIELD, METHOD}) public @interface XmlElementWrapper { /** diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlElements.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlElements.java index 3febf01..79a434b 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlElements.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlElements.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -23,11 +23,11 @@ * * Multiple annotations of the same type are not allowed on a program * element. This annotation therefore serves as a container annotation - * for multiple @XmlElements as follows: + * for multiple {@code @XmlElements} as follows: * - *

    - * @XmlElements({ @XmlElement(...),@XmlElement(...) })
    - * 
    + * {@snippet : + * @XmlElements({ @XmlElement(...), @XmlElement(...) }) + * } * *

    The {@code @XmlElements} annotation can be used with the * following program elements:

    @@ -46,7 +46,7 @@ *
  • This annotation can be used with the following * annotations: @{@link XmlIDREF}, @{@link XmlElementWrapper}.
  • *
  • If @XmlIDREF is also specified on the JavaBean property, - * then each @XmlElement.type() must contain a JavaBean + * then each @XmlElement.type() must contain a JavaBean * property annotated with {@code @XmlID}.
  • * * @@ -56,98 +56,95 @@ *
    * *

    Example 1: Map to a list of elements

    - *
    - *    
    - *    // Mapped code fragment
    - *    public class Foo {
    - *        @XmlElements(
    - *            @XmlElement(name="A", type=Integer.class),
    - *            @XmlElement(name="B", type=Float.class)
    - *         )
    - *         public List items;
    - *    }
    - * {@code
    - * 
    - *    
    - *    ...
    - *     1 
    - *     2.5 
    - *    ...
    - *
    - *    
    - *    
    - *      
    - *        
    - *          
    - *          
    - *        
    - *      
    - *    
    + * {@snippet :
    + *  // Mapped code fragment
    + *  public class Foo {
    + *      @XmlElements({
    + *          @XmlElement(name="A", type=Integer.class),
    + *          @XmlElement(name="B", type=Float.class)
    + *       })
    + *      public List items;
    + *  }
    + * }
    + * {@snippet lang="XML" :
    + *  
    + *  ...
    + *   1 
    + *   2.5 
    + *  ...
      *
    - * }
    + * + * + * + * + * + * + * + * + * + * } * *

    Example 2: Map to a list of elements wrapped with another element *

    - *
    - * 
    - *    // Mapped code fragment
    - *    public class Foo {
    - *        @XmlElementWrapper(name="bar")
    - *        @XmlElements(
    - *            @XmlElement(name="A", type=Integer.class),
    - *            @XmlElement(name="B", type=Float.class)
    - *        }
    - *        public List items;
    - *    }
    - * {@code
    - * 
    - *    
    - *    
    - *      
    - *        
    - *          
    - *            
    - *              
    - *              
    - *            
    - *          
    - *        
    - *      
    - *    
    - * }
    + * {@snippet : + * // Mapped code fragment + * public class Foo { + * @XmlElementWrapper(name="bar") + * @XmlElements({ + * @XmlElement(name="A", type=Integer.class), + * @XmlElement(name="B", type=Float.class) + * }) + * public List items; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * + * + * } * *

    Example 3: Change element name based on type using an adapter. *

    - *
    - *    class Foo {
    - *       @XmlJavaTypeAdapter(QtoPAdapter.class)
    - *       @XmlElements({
    - *           @XmlElement(name="A",type=PX.class),
    - *           @XmlElement(name="B",type=PY.class)
    - *       })
    - *       Q bar;
    - *    }
    - * 
    - *    @XmlType abstract class P {...}
    - *    @XmlType(name="PX") class PX extends P {...}
    - *    @XmlType(name="PY") class PY extends P {...}
    - * {@code
    + * {@snippet :
    + *  class Foo {
    + *      @XmlJavaTypeAdapter(QtoPAdapter.class)
    + *      @XmlElements({
    + *          @XmlElement(name="A",type=PX.class),
    + *          @XmlElement(name="B",type=PY.class)
    + *      })
    + *      Q bar;
    + *  }
      * 
    - *    
    - *    
    - *      
    - *        
    - *          
    - *            
    - *              
    - *              
    - *            
    - *          
    - *        
    - *      
    - *    
    - * }
    + * @XmlType abstract class P {...} + * @XmlType(name="PX") class PX extends P {...} + * @XmlType(name="PY") class PY extends P {...} + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * + * + * } * * @author
    • Kohsuke Kawaguchi, Sun Microsystems, Inc.
    • Sekhar Vajjhala, Sun Microsystems, Inc.
    * @see XmlElement diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlEnumValue.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlEnumValue.java index a139f12..e0a3ff1 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlEnumValue.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlEnumValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -42,65 +42,67 @@ * as the XML representation. * *

    Example 1: Map enum constant name {@literal ->} enumeration facet

    - *
    - *     //Example: Code fragment
    - *     @XmlEnum(String.class)
    - *     public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
    - * {@code
    - * 
    - *     
    - *     
    - *       
    - *         
    - *         
    - *         
    - *         
    - *     
    - * }
    + * {@snippet : + * //Example: Code fragment + * @XmlEnum(String.class) + * public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + + * + * } * *

    Example 2: Map enum constant name(value) {@literal ->} enumeration facet

    - *
    - *     //Example: code fragment
    - *     @XmlType
    - *     @XmlEnum(Integer.class)
    - *     public enum Coin { 
    - *         @XmlEnumValue("1") PENNY(1),
    - *         @XmlEnumValue("5") NICKEL(5),
    - *         @XmlEnumValue("10") DIME(10),
    - *         @XmlEnumValue("25") QUARTER(25) }
    - * {@code
    - * 
    - *     
    - *     
    - *       
    - *         
    - *         
    - *         
    - *         
    - *       
    - *     
    - * }
    + * {@snippet : + * //Example: code fragment + * @XmlType + * @XmlEnum(Integer.class) + * public enum Coin { + * @XmlEnumValue("1") PENNY(1), + * @XmlEnumValue("5") NICKEL(5), + * @XmlEnumValue("10") DIME(10), + * @XmlEnumValue("25") QUARTER(25) + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * } * *

    Example 3: Map enum constant name {@literal ->} enumeration facet

    * - *
    - *     //Code fragment
    - *     @XmlType
    - *     @XmlEnum(Integer.class)
    - *     public enum Code {
    - *         @XmlEnumValue("1") ONE,
    - *         @XmlEnumValue("2") TWO;
    - *     }
    - * {@code
    - * 
    - *     
    - *     
    - *       
    - *         
    - *         
    - *       
    - *     
    - * }
    + * {@snippet : + * //Code fragment + * @XmlType + * @XmlEnum(Integer.class) + * public enum Code { + * @XmlEnumValue("1") ONE, + * @XmlEnumValue("2") TWO + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * } * * @since 1.6, JAXB 2.0 */ diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlID.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlID.java index 2b68e12..7a1f923 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlID.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlID.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -49,33 +49,32 @@ * * *

    Example: Map a JavaBean property's type to {@code xs:ID}

    - *
    - *    // Example: code fragment
    - *    public class Customer {
    - *        @XmlAttribute
    - *        @XmlID
    - *        public String getCustomerID();
    - *        public void setCustomerID(String id);
    - *        .... other properties not shown 
    - *    }
    - * {@code
    - * 
    - *    
    - *    
    - *      
    - *        
    - *          ....
    - *        
    - *        
    - *      
    - *    
    - * }
    + * {@snippet : + * // Example: code fragment + * public class Customer { + * @XmlAttribute + * @XmlID + * public String getCustomerID(); + * public void setCustomerID(String id); + * .... other properties not shown + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * .... + * + * + * + * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlIDREF * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target({FIELD, METHOD}) public @interface XmlID { } diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlIDREF.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlIDREF.java index 9b22e46..d00e486 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlIDREF.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlIDREF.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -59,181 +59,175 @@ * *

    Example: Map a JavaBean property to {@code xs:IDREF} * (i.e. by reference rather than by containment)

    - *
    - *
    - *   //EXAMPLE: Code fragment
    - *   public class Shipping {
    - *       @XmlIDREF public Customer getCustomer();
    - *       public void setCustomer(Customer customer);
    - *       ....
    - *    }
    - * {@code
    - * 
    - *   
    - *   
    - *     
    - *       
    - *         
    - *         ....
    - *       
    - *     
    - *   
    - *
    - * }
    + * {@snippet : + * //EXAMPLE: Code fragment + * public class Shipping { + * @XmlIDREF public Customer getCustomer(); + * public void setCustomer(Customer customer); + * .... + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * .... + * + * + * + * } * * *

    Example 2: The following is a complete example of * containment versus reference. * - *

    - *    // By default, Customer maps to complex type {@code xs:Customer}
    - *    public class Customer {
    + * {@snippet :
    + *  // By default, Customer maps to complex type {@code xs:Customer}
    + *  public class Customer {
      *        
    - *        // map JavaBean property type to {@code xs:ID}
    - *        @XmlID public String getCustomerID();
    - *        public void setCustomerID(String id);
    + *      // map JavaBean property type to {@code xs:ID}
    + *      @XmlID public String getCustomerID();
    + *      public void setCustomerID(String id);
      *
    - *        // .... other properties not shown 
    - *    }
    + *      // .... other properties not shown 
    + *  }
      *
    - *
    - *   // By default, Invoice maps to a complex type {@code xs:Invoice}
    - *   public class Invoice {
    + *  // By default, Invoice maps to a complex type {@code xs:Invoice}
    + *  public class Invoice {
      *    
    - *       // map by reference
    - *       @XmlIDREF public Customer getCustomer();       
    - *       public void setCustomer(Customer customer);
    + *      // map by reference
    + *      @XmlIDREF public Customer getCustomer();       
    + *      public void setCustomer(Customer customer);
      *
      *      // .... other properties not shown here
    - *   }
    - *
    - *   // By default, Shipping maps to complex type {@code xs:Shipping}
    - *   public class Shipping {
    - *
    - *       // map by reference
    - *       @XmlIDREF public Customer getCustomer();       
    - *       public void setCustomer(Customer customer);
    - *   }
    - *
    - *   // at least one class must reference Customer by containment;
    - *   // Customer instances won't be marshalled.
    - *   @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();     
    - *   }
    - * {@code
    - * 
    - *   
    - *
    - *   
    - *     
    - *       
    - *         
    - *         ....
    - *       
    - *     
    - *   
    - *
    - *   
    - *     
    - *       
    - *         
    - *         ....
    - *       
    - *     
    - *   
    - *
    - *   
    - *     
    - *       
    - *         ....
    - *       
    - *       
    - *     
    - *   
    - *
    - *   
    - *     
    - *       
    - *         
    - *         
    - *         
    - *       
    - *     
    - *   
    - *
    - *   
    - *
    - *   
    - *    
    - *       
    - *           ....
    - *       
    - *
    - *       
    - *           ....
    - *       
    + *  }
    + *
    + *  // By default, Shipping maps to complex type {@code xs:Shipping}
    + *  public class Shipping {
    + *
    + *      // map by reference
    + *      @XmlIDREF public Customer getCustomer();       
    + *      public void setCustomer(Customer customer);
    + *  }
    + *
    + *  // at least one class must reference Customer by containment;
    + *  // Customer instances won't be marshalled.
    + *  @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();     
    + *  }
    + * }
    + * {@snippet lang="XML" :
    + *  
    + *
    + *  
    + *    
    + *      
    + *        
    + *        ....
    + *      
    + *    
    + *  
    + *
    + *  
    + *    
    + *      
    + *        
    + *        ....
    + *      
    + *    
    + *  
    + *
    + *  
    + *    
    + *      
    + *        ....
    + *      
    + *      
    + *    
    + *  
    + *
    + *  
    + *    
    + *      
    + *        
    + *        
    + *        
    + *      
    + *    
    + *  
    + *
    + *  
    + *
    + *  
    + *  
    + *    
    + *      ....
    + *    
    + *
    + *    
    + *      ....
    + *    
      *         
    - *       
    - *           ....
    - *       
    - *   
    - *
    - * }
    + * + * .... + * + * + * } * *

    Example 3: Mapping List to repeating element of type IDREF - *

    - *     // Code fragment
    - *     public class Shipping {
    - *         @XmlIDREF
    - *         @XmlElement(name="Alice")
    - *             public List customers;
    - *     }
    - * {@code
    - * 
    - *     
    - *     
    - *       
    - *         
    - *           
    - *         
    - *       
    - *     
    - * }
    + * {@snippet : + * // Code fragment + * public class Shipping { + * @XmlIDREF + * @XmlElement(name="Alice") + * public List customers; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * } * *

    Example 4: Mapping a List to a list of elements of type IDREF. - *

    - *     //Code fragment
    - *     public class Shipping {
    - *         @XmlIDREF
    - *         @XmlElements(
    - *             @XmlElement(name="Alice", type="Customer.class")
    - *              @XmlElement(name="John", type="InternationalCustomer.class")
    - *         public List customers;
    - *     }
    - * {@code
    - * 
    - *     
    - *     
    - *       
    - *         
    - *           
    - *           
    - *         
    - *       
    - *     
    - * }
    + * {@snippet : + * //Code fragment + * public class Shipping { + * @XmlIDREF + * @XmlElement(name="Alice", type="Customer.class") + * @XmlElement(name="John", type="InternationalCustomer.class") + * public List customers; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * } * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlID * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target({FIELD, METHOD}) public @interface XmlIDREF {} diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlList.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlList.java index 85b0912..6d3fde1 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlList.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -34,42 +34,42 @@ * each item in the collection will be wrapped by an element. * For example, * - *
    - * @XmlRootElement
    - * class Foo {
    - *     @XmlElement
    - *     List<String> data;
    + * {@snippet :
    + *  @XmlRootElement
    + *  class Foo {
    + *      @XmlElement
    + *      List data;
    + *  }
      * }
    - * 
    * * would produce XML like this: * - *
    {@code
    - * 
    - *   abc
    - *   def
    - * 
    - * }
    + * {@snippet lang="XML" : + * + * abc + * def + * + * } * - * @XmlList annotation, on the other hand, allows multiple values to be + * XmlList annotation, on the other hand, allows multiple values to be * represented as whitespace-separated tokens in a single element. For example, * - *
    - * @XmlRootElement
    - * class Foo {
    - *     @XmlElement
    - *     @XmlList
    - *     List<String> data;
    + * {@snippet :
    + *  @XmlRootElement
    + *  class Foo {
    + *      @XmlElement
    + *      @XmlList
    + *      List data;
    + *  }
      * }
    - * 
    * * the above code will produce XML like this: * - *
    {@code
    - * 
    - *   abc def
    - * 
    - * }
    + * {@snippet lang="XML" : + * + * abc def + * + * } * *

    This annotation can be used with the following annotations: * {@link XmlElement}, diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlMixed.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlMixed.java index a53496a..825bd22 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlMixed.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlMixed.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -12,6 +12,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; +import java.util.List; import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.ElementType.FIELD; @@ -41,71 +42,70 @@ * * * Below is an example of binding and creation of mixed content. - *

    {@code
    - * 
    + * {@snippet lang="XML" :
      *  
      *  
      *    
    - *	
    - *	
    - *	
    - *	
    + *      
    + *      
    + *      
    + *      
      *    
      *  
      *  
    - * 
    - * // Schema-derived Java code: 
    - * // (Only annotations relevant to mixed content are shown below, 
    - * //  others are omitted.)
    - * import java.math.BigInteger;
    - * public class ObjectFactory {
    - * 	// element instance factories
    - * 	JAXBElement createLetterBody(LetterBody value);
    - * 	JAXBElement     createLetterBodyName(String value);
    - * 	JAXBElement createLetterBodyQuantity(BigInteger value);
    - * 	JAXBElement     createLetterBodyProductName(String value);
    + * }
    + * {@snippet :
    + *  // Schema-derived Java code: 
    + *  // (Only annotations relevant to mixed content are shown below, 
    + *  //  others are omitted.)
    + *  import java.math.BigInteger;
    + *  public class ObjectFactory {
    + *      // element instance factories
    + * 	    JAXBElement createLetterBody(LetterBody value);
    + * 	    JAXBElement     createLetterBodyName(String value);
    + * 	    JAXBElement createLetterBodyQuantity(BigInteger value);
    + * 	    JAXBElement     createLetterBodyProductName(String value);
      *      // type instance factory
    - * 	LetterBody createLetterBody();
    + * 	    LetterBody createLetterBody();
    + *  }
      * }
    - * }
    - *
    - * 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.
    - *	@XmlMixed 
    - * 	@XmlElementRefs({
    - *		@XmlElementRef(name="productName", type=JAXBElement.class),
    - *		@XmlElementRef(name="quantity", type=JAXBElement.class),
    - *		@XmlElementRef(name="name", type=JAXBElement.class)})
    - *	List getContent(){...}
    + * {@snippet :
    + *  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.
    + *      @XmlMixed
    + *      @XmlElementRef(name="productName", type=JAXBElement.class)
    + *      @XmlElementRef(name="quantity", type=JAXBElement.class)
    + *      @XmlElementRef(name="name", type=JAXBElement.class)
    + *      List getContent(){...}
    + *  }
      * }
    - * 
    * The following is an XML instance document with mixed content - *
    {@code
    - * 
    - * Dear Mr.Robert Smith
    - * Your order of 1 Baby
    - * Monitor shipped from our warehouse. ....
    - * 
    - * }
    + * {@snippet lang="XML" : + * + * Dear Mr.Robert Smith + * Your order of 1 Baby + * Monitor shipped from our warehouse. .... + * + * } * that can be constructed using following Jakarta XML Binding API calls. - *
    {@code
    - * LetterBody lb = ObjectFactory.createLetterBody();
    - * JAXBElement 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
    + * {@snippet :
    + *  LetterBody lb = ObjectFactory.createLetterBody();
    + *  JAXBElement 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
    - * }
    + * // 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 + * } * *

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

    diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlRootElement.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlRootElement.java index 14fd21a..289febf 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlRootElement.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlRootElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -21,7 +21,7 @@ * *

    Usage

    *

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

      *
    • a top level class
    • @@ -33,7 +33,7 @@ * *

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

      This annotation can be used with the following annotations: @@ -43,45 +43,44 @@ *

      * 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;}
      - *     }
      - * 
      + * {@snippet : + * // 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);
      - * 
      + * {@snippet : + * //Example: Code fragment corresponding to XML output + * marshal( new Point(3,5), System.out); + * } * - *
      {@code
      - * 
      - *     
      - *     
      - *        3 
      - *        5 
      - *     
      - * }
      + * {@snippet lang="XML" : + * + * + * 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
      - * 
      - *     
      - *     
      - *     
      - *       
      - *         
      - *         
      - *       
      - *     
      - * }
      + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * } * *

      * @@ -90,58 +89,59 @@ *

      * 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;}
      - *     }
      + * {@snippet :
      + *  // 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: Code fragment corresponding to XML output *
      + *  marshal( new Point3D(3,5,0), System.out );
      + * }
      + * {@snippet lang="XML" :
      + *  
      + *  
      + *  
      + *    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
      - * 
      - *     
      - *     
      - *     
      - *       
      - *         
      - *       
      - *     
      - * }
      + * {@snippet : + * //Example: Code fragment + * @XmlRootElement(name="PriceElement") + * public class USPrice { + * @XmlElement + * public java.math.BigDecimal price; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlSchema.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlSchema.java index f598fcf..0c7b3d8 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlSchema.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlSchema.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -44,66 +44,62 @@ *

      Example 1: Customize name of XML namespace to which * package is mapped.

      * - *
      - *    @jakarta.xml.bind.annotation.XmlSchema (
      + * {@snippet :
      + *  @jakarta.xml.bind.annotation.XmlSchema (
        *      namespace = "http://www.example.com/MYPO1"
      - *    )
      - * {@code
      - *
      - *    
      - *    
      - *    
      - * }
      + * ) + * } + * {@snippet lang="XML" : + * + * + * + * } * *

      Example 2: Customize namespace prefix, namespace URI * mapping

      * - *
      - *    // Package level annotation
      - *    @jakarta.xml.bind.annotation.XmlSchema (
      + * {@snippet :
      + *  // Package level annotation
      + *  @jakarta.xml.bind.annotation.XmlSchema (
        *      xmlns = {
      - *        @jakarta.xml.bind.annotation.XmlNs(prefix = "po",
      + *          @jakarta.xml.bind.annotation.XmlNs(prefix = "po",
        *                   namespaceURI="http://www.example.com/myPO1"),
      - *
      - *        @jakarta.xml.bind.annotation.XmlNs(prefix="xs",
      + *          @jakarta.xml.bind.annotation.XmlNs(prefix="xs",
        *                   namespaceURI="http://www.w3.org/2001/XMLSchema")
        *      }
      - *    )
      - * {@code
      - *
      - *    
      - *    
      - *
      - * }
      + * ) + * } + * {@snippet lang="XML" : + * + * + * ... + * } * *

      Example 3: Customize elementFormDefault

      - *
      - *    @jakarta.xml.bind.annotation.XmlSchema (
      + * {@snippet :
      + *  @jakarta.xml.bind.annotation.XmlSchema (
        *      elementFormDefault=XmlNsForm.UNQUALIFIED
        *      ...
      - *    )
      - * {@code
      + *  )
      + * }
      + * {@snippet lang="XML" :
      + *  
      + *  
      + *    ...
      + * }
        *
      - *    
      - *    
      - *
      - * }
      - * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target(PACKAGE) public @interface XmlSchema { diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaType.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaType.java index 5e26737..1b840e7 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaType.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -43,31 +43,30 @@ * Example 1: Customize mapping of XMLGregorianCalendar on the * field. * - *
      - *     //Example: Code fragment
      - *     public class USPrice {
      - *         @XmlElement
      - *         @XmlSchemaType(name="date")
      - *         public XMLGregorianCalendar date;
      - *     }
      - * {@code
      - *
      - *     
      - *     
      - *       
      - *         
      - *       
      - *     
      - * }
      + * {@snippet : + * //Example: Code fragment + * public class USPrice { + * @XmlElement + * @XmlSchemaType(name="date") + * public XMLGregorianCalendar date; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * } * *

      Example 2: Customize mapping of XMLGregorianCalendar at package * level

      - *
      - *     package foo;
      - *     @jakarta.xml.bind.annotation.XmlSchemaType(
      - *          name="date", type=javax.xml.datatype.XMLGregorianCalendar.class)
      - *     }
      - * 
      + * {@snippet : + * @jakarta.xml.bind.annotation.XmlSchemaType( + * name="date", type=javax.xml.datatype.XMLGregorianCalendar.class) + * package foo; + * } * * @since 1.6, JAXB 2.0 */ diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaTypes.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaTypes.java index 1efffc7..eb21795 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaTypes.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlSchemaTypes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024 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 @@ -17,16 +17,16 @@ /** *

      - * A container for multiple @{@link XmlSchemaType} annotations. + * A container for multiple {@link XmlSchemaType} annotations. * *

      Multiple annotations of the same type are not allowed on a program * element. This annotation therefore serves as a container annotation - * for multiple @XmlSchemaType annotations as follows: + * for multiple {@link XmlSchemaType} annotations as follows: * - *

      - * @XmlSchemaTypes({ @XmlSchemaType(...), @XmlSchemaType(...) })
      - * 
      - *

      The {@code @XmlSchemaTypes} annnotation can be used to + * {@snippet : + * @XmlSchemaTypes({ @XmlSchemaType(...), @XmlSchemaType(...) }) + * } + *

      The {@code @XmlSchemaTypes} annotation can be used to * define {@link XmlSchemaType} for different types at the * package level. * diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlSeeAlso.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlSeeAlso.java index 43994d0..ff9da96 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlSeeAlso.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlSeeAlso.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2024 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 @@ -28,11 +28,11 @@ *

      * For example, with the following class definitions: * - *

      - * class Animal {}
      - * class Dog extends Animal {}
      - * class Cat extends Animal {}
      - * 
      + * {@snippet : + * class Animal {} + * class Dog extends Animal {} + * class Cat extends Animal {} + * } * *

      * The user would be required to create {@link JAXBContext} as @@ -42,12 +42,12 @@ * *

      * {@link XmlSeeAlso} annotation would allow you to write: - *

      - * @XmlSeeAlso({Dog.class,Cat.class})
      - * class Animal {}
      - * class Dog extends Animal {}
      - * class Cat extends Animal {}
      - * 
      + * {@snippet : + * @XmlSeeAlso({Dog.class,Cat.class}) + * class Animal {} + * class Dog extends Animal {} + * class Cat extends Animal {} + * } * *

      * This would allow you to do {@code JAXBContext.newInstance(Animal.class)}. diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlTransient.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlTransient.java index c0eca4b..ab479ba 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlTransient.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlTransient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -51,32 +51,30 @@ *

      Example: Resolve name collision between JavaBean property and * field name

      * - *
      - *   // Example: Code fragment
      - *   public class USAddress {
      + * {@snippet :
      + *  // Example: Code fragment
      + *  public class USAddress {
        *
      - *       // The field name "name" collides with the property name 
      - *       // obtained by bean decapitalization of getName() below
      - *       @XmlTransient public String name;
      + *      // The field name "name" collides with the property name
      + *      // obtained by bean decapitalization of getName() below
      + *      @XmlTransient public String name;
        *
      - *       String getName() {..};
      - *       String setName() {..};
      - *   }
      - *
      - * {@code   
      - * 
      - *   
      - *   
      - *     
      - *       
      - *     
      - *   
      - * }
      + * String getName() {..}; + * String setName() {..}; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target({FIELD, METHOD, TYPE}) public @interface XmlTransient {} diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlType.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlType.java index d705da6..9bd52f3 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlType.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -178,156 +178,156 @@ * xs:sequence with a customized ordering of JavaBean properties. *

      * - *
      - *   @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) {..};
      - *   }
      - * {@code
      - *
      - *   
      - *   
      - *     
      - *       
      - *       
      - *       
      - *       
      - *       
      - *     
      - *   
      - * }
      + * {@snippet : + * @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) {..}; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * } *

      Example 2: Map a class to a complex type with * xs:all

      - *
      - * @XmlType(propOrder={})
      - * public class USAddress { ...}
      - * {@code
      - *
      - * 
      - * 
      - *   
      - *     
      - *     
      - *     
      - *     
      - *     
      - *   
      - * 
      - *}
      + * {@snippet : + * @XmlType(propOrder={}) + * public class USAddress { ...} + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * } *

      Example 3: Map a class to a global element with an * anonymous type. *

      - *
      - *   @XmlRootElement
      - *   @XmlType(name="")
      - *   public class USAddress { ...}
      - * {@code
      - *
      - *   
      - *   
      - *     
      - *       
      - *         
      - *         
      - *         
      - *         
      - *         
      - *       
      - *     
      - *   
      - * }
      + * {@snippet : + * @XmlRootElement + * @XmlType(name="") + * public class USAddress { ...} + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * + * } * *

      Example 4: Map a property to a local element with * anonymous type. - *

      - *   //Example: Code fragment
      - *   public class Invoice {
      - *       USAddress addr;
      - *           ...
      - *       }
      - *
      - *   @XmlType(name="")
      - *   public class USAddress { ... }
      - *   }
      - * {@code
      - *
      - *   
      - *   
      - *     
      - *       
      - *         
      - *           
      - *           
      - *           
      - *           
      - *           
      - *         
      - *       ...
      - *     
      - *   
      - * }
      + * {@snippet : + * //Example: Code fragment + * public class Invoice { + * USAddress addr; + * ... + * } + * + * @XmlType(name="") + * public class USAddress { ... } + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * + * ... + * + * + * } * *

      Example 5: Map a property to an attribute with * anonymous type. * - *

      - *
      - *     //Example: Code fragment
      - *     public class Item {
      - *         public String name;
      - *         @XmlAttribute
      - *         public USPrice price;
      - *     }
      - *
      - *     // map class to anonymous simple type.
      - *     @XmlType(name="")
      - *     public class USPrice {
      - *         @XmlValue
      - *         public java.math.BigDecimal price;
      - *     }
      - * {@code
      - *
      - *     
      - *     
      - *       
      - *         
      - *         
      - *           
      - *             
      - *           
      - *         
      - *       
      - *     
      - * }
      + * {@snippet : + * //Example: Code fragment + * public class Item { + * public String name; + * @XmlAttribute + * public USPrice price; + * } + * + * // map class to anonymous simple type. + * @XmlType(name="") + * public class USPrice { + * @XmlValue + * public java.math.BigDecimal price; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * } * *

      Example 6: Define a factoryClass and factoryMethod * - *

      - *      @XmlType(name="USAddressType", factoryClass=USAddressFactory.class,
      - *      factoryMethod="getUSAddress")
      - *      public class USAddress {
      + * {@snippet :
      + *  @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;
      + *      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) {
      + *              String state, int zip) {
        *          this.name = name;
        *          this.street = street;
        *          this.city = city;
      @@ -338,31 +338,32 @@
        *
        *  public class USAddressFactory {
        *      public static USAddress getUSAddress(){
      - *       return new USAddress("Mark Baker", "23 Elm St",
      - *          "Dayton", "OH", 90952);
      - *  }
      + *          return new USAddress("Mark Baker", "23 Elm St",
      + *                               "Dayton", "OH", 90952);
      + *      }
        *
      - * 
      + * } + * } * *

      Example 7: Define factoryMethod and use the default factoryClass * - *

      - *      @XmlType(name="USAddressType", factoryMethod="getNewInstance")
      - *      public class USAddress {
      + * {@snippet :
      + *  @XmlType(name="USAddressType", factoryMethod="getNewInstance")
      + *  public class USAddress {
        *
      - *          private String city;
      - *          private String name;
      - *          private String state;
      - *          private String street;
      - *          private int    zip;
      + *      private String city;
      + *      private String name;
      + *      private String state;
      + *      private String street;
      + *      private int    zip;
        *
      - *          private USAddress() {}
      + *      private USAddress() {}
        *
      - *          public static USAddress getNewInstance(){
      - *              return new USAddress();
      - *          }
      + *      public static USAddress getNewInstance(){
      + *          return new USAddress();
        *      }
      - * 
      + * } + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlElement @@ -394,7 +395,7 @@ *

      All of the JavaBean properties being mapped to XML Schema elements * must be listed. *

      A JavaBean property or field listed in propOrder must not - * be transient or annotated with {@code @XmlTransient}. + * be transient or annotated with } @XmlTransient}. *

      The default ordering of JavaBean properties is determined * by @{@link XmlAccessorOrder}. */ diff --git a/api/src/main/java/jakarta/xml/bind/annotation/XmlValue.java b/api/src/main/java/jakarta/xml/bind/annotation/XmlValue.java index f24c015..d4648ef 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/XmlValue.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/XmlValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -65,52 +65,47 @@ * *

      Example 1: Map a class to XML Schema simpleType

      * - *
      - * 
      - *     // Example 1: Code fragment
      - *     public class USPrice {
      - *         @XmlValue
      - *         public java.math.BigDecimal price;
      - *     }
      - * {@code
      - * 
      - *     
      - *     
      - *       
      - *     
      - *
      - * }
      + * {@snippet : + * // Example 1: Code fragment + * public class USPrice { + * @XmlValue + * public java.math.BigDecimal price; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * } * *

      Example 2: Map a class to XML Schema complexType with * with simpleContent.

      - * - *
        *
      - *   // Example 2: Code fragment
      - *   public class InternationalPrice {
      - *       @XmlValue
      - *       public java.math.BigDecimal price;
      + * {@snippet :
      + *  // Example 2: Code fragment
      + *  public class InternationalPrice {
      + *      @XmlValue
      + *      public java.math.BigDecimal price;
        * 
      - *       @XmlAttribute
      - *       public String currency;
      - *   }
      - * {@code
      - * 
      - *   
      - *   
      - *     
      - *       
      - *         
      - *       
      - *     
      - *   
      - *
      - * }
      + * @XmlAttribute + * public String currency; + * } + * } + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * } * * @author Sekhar Vajjhala, Sun Microsystems, Inc. * @see XmlType * @since 1.6, JAXB 2.0 */ - @Retention(RUNTIME) @Target({FIELD, METHOD}) public @interface XmlValue {} diff --git a/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlAdapter.java b/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlAdapter.java index 926338b..e992168 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlAdapter.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -60,81 +60,78 @@ * *

      Step 1: Determine the desired XML representation for HashMap. * - *

      {@code
      - *     
      - *         this is a value
      - *         this is another value
      - *         ...
      - *     
      - * }
      + * {@snippet lang="XML" : + * + * this is a value + * this is another value + * ... + * + * } * *

      Step 2: Determine the schema definition that the * desired XML representation shown above should follow. * - *

      {@code
      - *     
      - *     
      - *       
      - *         
      - *       
      - *     
      - *
      - *     
      - *       
      - *         
      - *           
      - *         
      - *       
      - *     
      - *
      - * }
      + * {@snippet lang="XML" : + * + * + * + * + * + * + * + * + * + * + * + * + * + * } * *

      Step 3: Write value types that can generate the above * schema definition. * - *

      - *     public class MyHashMapType {
      - *         List<MyHashMapEntryType> entry;
      - *     }
      + * {@snippet :
      + *  public class MyHashMapType {
      + *      List<MyHashMapEntryType> entry;
      + *  }
        *
      - *     public class MyHashMapEntryType {
      - *         @XmlAttribute
      - *         public Integer key; 
      + *  public class MyHashMapEntryType {
      + *      @XmlAttribute
      + *      public Integer key;
        *
      - *         @XmlValue
      - *         public String value;
      - *     }
      - * 
      + * @XmlValue + * public String value; + * } + * } * *

      Step 4: Write the adapter that adapts the value type, * MyHashMapType to a bound type, HashMap, used by the application. * - *

      {@code
      - *     public final class MyHashMapAdapter extends
      - *                        XmlAdapter { ... }
      - *      
      - * }
      + * {@snippet : + * public final class MyHashMapAdapter extends + * XmlAdapter { ... } + * } * *

      Step 5: Use the adapter. * - *

      - *     public class Foo {
      - *         @XmlJavaTypeAdapter(MyHashMapAdapter.class)
      - *         HashMap hashmap;
      - *         ...
      - *     }
      - * 
      + * {@snippet : + * public class Foo { + * @XmlJavaTypeAdapter(MyHashMapAdapter.class) + * HashMap hashmap; + * ... + * } + * } * * The above code fragment will map to the following schema: * - *
      {@code
      - *     
      - *       
      - *         
      - *       
      - *     
      - * }
      + * {@snippet lang="XML" : + * + * + * + * + * + * } * * @param * The type that Jakarta XML Binding doesn't know how to handle. An adapter is written diff --git a/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java b/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java index dfe0607..c300b21 100644 --- a/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java +++ b/api/src/main/java/jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024 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 @@ -23,9 +23,9 @@ * element. This annotation therefore serves as a container annotation * for multiple @XmlJavaTypeAdapter as follows: * - *
      - * @XmlJavaTypeAdapters ({ @XmlJavaTypeAdapter(...),@XmlJavaTypeAdapter(...) })
      - * 
      + * {@snippet : + * @XmlJavaTypeAdapters ({ @XmlJavaTypeAdapter(...), @XmlJavaTypeAdapter(...) }) + * } * *

      The {@code @XmlJavaTypeAdapters} annotation is useful for * defining {@link XmlJavaTypeAdapter} annotations for different types diff --git a/api/src/main/java/jakarta/xml/bind/util/JAXBResult.java b/api/src/main/java/jakarta/xml/bind/util/JAXBResult.java index 249cc04..31f5e31 100644 --- a/api/src/main/java/jakarta/xml/bind/util/JAXBResult.java +++ b/api/src/main/java/jakarta/xml/bind/util/JAXBResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -28,22 +28,20 @@ * The following example shows how to use Jakarta XML Binding to unmarshal a document * resulting from an XSLT transformation. * - *

      - *
      - *       JAXBResult result = new JAXBResult(
      - *         JAXBContext.newInstance("org.acme.foo") );
      + * {@snippet :
      + *  JAXBResult result = new JAXBResult(
      + *    JAXBContext.newInstance("org.acme.foo") );
        *       
      - *       // set up XSLT transformation
      - *       TransformerFactory tf = TransformerFactory.newInstance();
      - *       Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
      + *  // set up XSLT transformation
      + *  TransformerFactory tf = TransformerFactory.newInstance();
      + *  Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
        *       
      - *       // run transformation
      - *       t.transform(new StreamSource("document.xml"),result);
      + *  // run transformation
      + *  t.transform(new StreamSource("document.xml"),result);
        * 
      - *       // obtain the unmarshalled content tree
      - *       Object o = result.getResult();
      - *    
      - *
      + * // obtain the unmarshalled content tree + * Object o = result.getResult(); + * } * *

      * The fact that JAXBResult derives from SAXResult is an implementation diff --git a/api/src/main/java/jakarta/xml/bind/util/JAXBSource.java b/api/src/main/java/jakarta/xml/bind/util/JAXBSource.java index 31f7648..18d2238 100644 --- a/api/src/main/java/jakarta/xml/bind/util/JAXBSource.java +++ b/api/src/main/java/jakarta/xml/bind/util/JAXBSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024 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 @@ -40,21 +40,19 @@ * The following example shows how to use Jakarta XML Binding to marshal a document * for transformation by XSLT. * - *

      - *
      - *       MyObject o = // get JAXB content tree
      + * {@snippet :
      + *  MyObject o = // get JAXB content tree
        *
      - *       // jaxbContext is a JAXBContext object from which 'o' is created.
      - *       JAXBSource source = new JAXBSource( jaxbContext, o );
      + *  // jaxbContext is a JAXBContext object from which 'o' is created.
      + *  JAXBSource source = new JAXBSource( jaxbContext, o );
        *
      - *       // set up XSLT transformation
      - *       TransformerFactory tf = TransformerFactory.newInstance();
      - *       Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
      + *  // set up XSLT transformation
      + *  TransformerFactory tf = TransformerFactory.newInstance();
      + *  Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
        *
      - *       // run transformation
      - *       t.transform(source,new StreamResult(System.out));
      - *    
      - *
      + * // run transformation + * t.transform(source,new StreamResult(System.out)); + * } * *

      * The fact that JAXBSource derives from SAXSource is an implementation