diff --git a/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java b/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java index 9b0bd3efa681f..1cb84d420855e 100644 --- a/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java +++ b/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java @@ -45,7 +45,9 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationTarget.Kind; import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -98,7 +100,14 @@ class JaxbProcessor { "text", "xml", "unknown"); - private static final DotName XML_ROOT = DotName.createSimple("javax.xml.bind.annotation.XmlRootElement"); + + private static final DotName XML_ROOT_ELEMENT = DotName.createSimple(XmlRootElement.class.getName()); + private static final DotName XML_TYPE = DotName.createSimple(XmlType.class.getName()); + private static final DotName XML_REGISTRY = DotName.createSimple(XmlRegistry.class.getName()); + private static final DotName XML_SCHEMA = DotName.createSimple(XmlSchema.class.getName()); + private static final DotName XML_JAVA_TYPE_ADAPTER = DotName.createSimple(XmlJavaTypeAdapter.class.getName()); + + private static final List REGISTER_TYPE_FOR_REFLECTION_ANNOTATIONS = Arrays.asList(XML_TYPE, XML_REGISTRY); @Inject BuildProducer reflectiveClass; @@ -122,16 +131,44 @@ void process(BuildProducer substrateProps, return; } - Collection xmlRoot = combinedIndexBuildItem.getIndex().getAnnotations(XML_ROOT); - for (AnnotationInstance i : xmlRoot) { - addReflectiveClass(false, true, i.target().asClass().name().toString()); + IndexView index = combinedIndexBuildItem.getIndex(); + + Collection xmlRootElementInstances = index.getAnnotations(XML_ROOT_ELEMENT); + for (AnnotationInstance xmlRootElementInstance : xmlRootElementInstances) { + addReflectiveClass(true, true, xmlRootElementInstance.target().asClass().name().toString()); } - if (xmlRoot.isEmpty() && + if (xmlRootElementInstances.isEmpty() && fileRoots.isEmpty()) { return; } + // Register classes for reflection based on JAXB annotations + for (DotName registerTypeAnnotation : REGISTER_TYPE_FOR_REFLECTION_ANNOTATIONS) { + for (AnnotationInstance registerTypeForReflectionAnnotationInstance : index + .getAnnotations(registerTypeAnnotation)) { + if (registerTypeForReflectionAnnotationInstance.target().kind() == Kind.CLASS) { + addReflectiveClass(true, true, + registerTypeForReflectionAnnotationInstance.target().asClass().name().toString()); + } + } + } + + // Register package-infos for reflection + for (AnnotationInstance xmlSchemaInstance : index.getAnnotations(XML_SCHEMA)) { + if (xmlSchemaInstance.target().kind() == Kind.CLASS) { + reflectiveClass.produce( + new ReflectiveClassBuildItem(false, false, xmlSchemaInstance.target().asClass().name().toString())); + } + } + + // Register XML Java type adapters for reflection + for (AnnotationInstance xmlJavaTypeAdapterInstance : index.getAnnotations(XML_JAVA_TYPE_ADAPTER)) { + reflectiveClass.produce( + new ReflectiveClassBuildItem(true, true, xmlJavaTypeAdapterInstance.value().asClass().name().toString())); + } + addReflectiveClass(false, false, "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); + addReflectiveClass(false, false, "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl"); addReflectiveClass(false, false, "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); addReflectiveClass(false, false, "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"); addReflectiveClass(true, false, "com.sun.xml.bind.v2.ContextFactory"); diff --git a/integration-tests/main/pom.xml b/integration-tests/main/pom.xml index 73c1702805e35..af52f00dba0f6 100644 --- a/integration-tests/main/pom.xml +++ b/integration-tests/main/pom.xml @@ -83,6 +83,10 @@ io.quarkus quarkus-elytron-security + + io.quarkus + quarkus-jaxb + diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/Feed.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/Feed.java new file mode 100644 index 0000000000000..0b675daabdf8f --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/Feed.java @@ -0,0 +1,1165 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2014.09.12 at 03:00:35 PM CEST +// + +package io.quarkus.it.jaxb.mapper.codegen.feed; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.datatype.XMLGregorianCalendar; + +/** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}anyURI"/>
+ *         <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="link" maxOccurs="unbounded" minOccurs="0">
+ *           <complexType>
+ *             <simpleContent>
+ *               <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *                 <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                 <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                 <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *               </extension>
+ *             </simpleContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="updated" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
+ *         <element name="subtitle" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="generator" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="entry" maxOccurs="unbounded" minOccurs="0">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="id" type="{http://www.w3.org/2001/XMLSchema}anyURI"/>
+ *                   <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *                   <element name="link">
+ *                     <complexType>
+ *                       <simpleContent>
+ *                         <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *                           <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *                         </extension>
+ *                       </simpleContent>
+ *                     </complexType>
+ *                   </element>
+ *                   <element name="updated" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
+ *                   <element name="summary">
+ *                     <complexType>
+ *                       <simpleContent>
+ *                         <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *                           <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </extension>
+ *                       </simpleContent>
+ *                     </complexType>
+ *                   </element>
+ *                   <element name="author">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <sequence>
+ *                             <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *                           </sequence>
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                   <element name="category">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <sequence>
+ *                             <element name="term" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *                             <element name="scheme" type="{http://www.w3.org/2001/XMLSchema}anyURI"/>
+ *                             <element name="label" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *                           </sequence>
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                   <element name="content" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *       </sequence>
+ *       <attribute ref="{http://www.w3.org/XML/1998/namespace}lang"/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "id", + "title", + "link", + "updated", + "subtitle", + "generator", + "entry" +}) +@XmlRootElement(name = "feed") +public class Feed { + + @XmlElement(required = true) + @XmlSchemaType(name = "anyURI") + protected String id; + @XmlElement(required = true) + protected String title; + protected List link; + @XmlElement(required = true) + @XmlSchemaType(name = "dateTime") + protected XMLGregorianCalendar updated; + @XmlElement(required = true) + protected String subtitle; + @XmlElement(required = true) + protected String generator; + protected List entry; + @XmlAttribute(name = "lang", namespace = "http://www.w3.org/XML/1998/namespace") + protected String lang; + + /** + * Gets the value of the id property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getId() { + return id; + } + + /** + * Sets the value of the id property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setId(String value) { + this.id = value; + } + + /** + * Gets the value of the title property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Sets the value of the title property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Gets the value of the link property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the link property. + * + *

+ * For example, to add a new item, do as follows: + * + *

+     * getLink().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Feed.Link } + * + * + */ + public List getLink() { + if (link == null) { + link = new ArrayList(); + } + return this.link; + } + + /** + * Gets the value of the updated property. + * + * @return + * possible object is + * {@link XMLGregorianCalendar } + * + */ + public XMLGregorianCalendar getUpdated() { + return updated; + } + + /** + * Sets the value of the updated property. + * + * @param value + * allowed object is + * {@link XMLGregorianCalendar } + * + */ + public void setUpdated(XMLGregorianCalendar value) { + this.updated = value; + } + + /** + * Gets the value of the subtitle property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSubtitle() { + return subtitle; + } + + /** + * Sets the value of the subtitle property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSubtitle(String value) { + this.subtitle = value; + } + + /** + * Gets the value of the generator property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenerator() { + return generator; + } + + /** + * Sets the value of the generator property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenerator(String value) { + this.generator = value; + } + + /** + * Gets the value of the entry property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the entry property. + * + *

+ * For example, to add a new item, do as follows: + * + *

+     * getEntry().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Feed.Entry } + * + * + */ + public List getEntry() { + if (entry == null) { + entry = new ArrayList(); + } + return this.entry; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}anyURI"/>
+     *         <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *         <element name="link">
+     *           <complexType>
+     *             <simpleContent>
+     *               <extension base="<http://www.w3.org/2001/XMLSchema>string">
+     *                 <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+     *               </extension>
+     *             </simpleContent>
+     *           </complexType>
+     *         </element>
+     *         <element name="updated" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
+     *         <element name="summary">
+     *           <complexType>
+     *             <simpleContent>
+     *               <extension base="<http://www.w3.org/2001/XMLSchema>string">
+     *                 <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </extension>
+     *             </simpleContent>
+     *           </complexType>
+     *         </element>
+     *         <element name="author">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <sequence>
+     *                   <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *                 </sequence>
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *         <element name="category">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <sequence>
+     *                   <element name="term" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *                   <element name="scheme" type="{http://www.w3.org/2001/XMLSchema}anyURI"/>
+     *                   <element name="label" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *                 </sequence>
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *         <element name="content" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "id", + "title", + "link", + "updated", + "summary", + "author", + "category", + "content" + }) + public static class Entry { + + @XmlElement(required = true) + @XmlSchemaType(name = "anyURI") + protected String id; + @XmlElement(required = true) + protected String title; + @XmlElement(required = true) + protected Feed.Entry.Link link; + @XmlElement(required = true) + @XmlSchemaType(name = "dateTime") + protected XMLGregorianCalendar updated; + @XmlElement(required = true) + protected Feed.Entry.Summary summary; + @XmlElement(required = true) + protected Feed.Entry.Author author; + @XmlElement(required = true) + protected Feed.Entry.Category category; + @XmlElement(required = true) + protected String content; + + /** + * Gets the value of the id property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getId() { + return id; + } + + /** + * Sets the value of the id property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setId(String value) { + this.id = value; + } + + /** + * Gets the value of the title property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Sets the value of the title property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Gets the value of the link property. + * + * @return + * possible object is + * {@link Feed.Entry.Link } + * + */ + public Feed.Entry.Link getLink() { + return link; + } + + /** + * Sets the value of the link property. + * + * @param value + * allowed object is + * {@link Feed.Entry.Link } + * + */ + public void setLink(Feed.Entry.Link value) { + this.link = value; + } + + /** + * Gets the value of the updated property. + * + * @return + * possible object is + * {@link XMLGregorianCalendar } + * + */ + public XMLGregorianCalendar getUpdated() { + return updated; + } + + /** + * Sets the value of the updated property. + * + * @param value + * allowed object is + * {@link XMLGregorianCalendar } + * + */ + public void setUpdated(XMLGregorianCalendar value) { + this.updated = value; + } + + /** + * Gets the value of the summary property. + * + * @return + * possible object is + * {@link Feed.Entry.Summary } + * + */ + public Feed.Entry.Summary getSummary() { + return summary; + } + + /** + * Sets the value of the summary property. + * + * @param value + * allowed object is + * {@link Feed.Entry.Summary } + * + */ + public void setSummary(Feed.Entry.Summary value) { + this.summary = value; + } + + /** + * Gets the value of the author property. + * + * @return + * possible object is + * {@link Feed.Entry.Author } + * + */ + public Feed.Entry.Author getAuthor() { + return author; + } + + /** + * Sets the value of the author property. + * + * @param value + * allowed object is + * {@link Feed.Entry.Author } + * + */ + public void setAuthor(Feed.Entry.Author value) { + this.author = value; + } + + /** + * Gets the value of the category property. + * + * @return + * possible object is + * {@link Feed.Entry.Category } + * + */ + public Feed.Entry.Category getCategory() { + return category; + } + + /** + * Sets the value of the category property. + * + * @param value + * allowed object is + * {@link Feed.Entry.Category } + * + */ + public void setCategory(Feed.Entry.Category value) { + this.category = value; + } + + /** + * Gets the value of the content property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getContent() { + return content; + } + + /** + * Sets the value of the content property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setContent(String value) { + this.content = value; + } + + /** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <sequence>
+         *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+         *       </sequence>
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "name" + }) + public static class Author { + + @XmlElement(required = true) + protected String name; + + /** + * Gets the value of the name property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getName() { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setName(String value) { + this.name = value; + } + + } + + /** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <sequence>
+         *         <element name="term" type="{http://www.w3.org/2001/XMLSchema}string"/>
+         *         <element name="scheme" type="{http://www.w3.org/2001/XMLSchema}anyURI"/>
+         *         <element name="label" type="{http://www.w3.org/2001/XMLSchema}string"/>
+         *       </sequence>
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "term", + "scheme", + "label" + }) + public static class Category { + + @XmlElement(required = true) + protected String term; + @XmlElement(required = true) + @XmlSchemaType(name = "anyURI") + protected String scheme; + @XmlElement(required = true) + protected String label; + + /** + * Gets the value of the term property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTerm() { + return term; + } + + /** + * Sets the value of the term property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTerm(String value) { + this.term = value; + } + + /** + * Gets the value of the scheme property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getScheme() { + return scheme; + } + + /** + * Sets the value of the scheme property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setScheme(String value) { + this.scheme = value; + } + + /** + * Gets the value of the label property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLabel() { + return label; + } + + /** + * Sets the value of the label property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLabel(String value) { + this.label = value; + } + + } + + /** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <simpleContent>
+         *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+         *       <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+         *     </extension>
+         *   </simpleContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "value" + }) + public static class Link { + + @XmlValue + protected String value; + @XmlAttribute(name = "rel") + protected String rel; + @XmlAttribute(name = "type") + protected String type; + @XmlAttribute(name = "href") + @XmlSchemaType(name = "anyURI") + protected String href; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the rel property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRel() { + return rel; + } + + /** + * Sets the value of the rel property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRel(String value) { + this.rel = value; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the href property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getHref() { + return href; + } + + /** + * Sets the value of the href property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setHref(String value) { + this.href = value; + } + + } + + /** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <simpleContent>
+         *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+         *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </extension>
+         *   </simpleContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "value" + }) + public static class Summary { + + @XmlValue + protected String value; + @XmlAttribute(name = "type") + protected String type; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + } + + } + + /** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <simpleContent>
+     *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+     *       <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+     *     </extension>
+     *   </simpleContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "value" + }) + public static class Link { + + @XmlValue + protected String value; + @XmlAttribute(name = "rel") + protected String rel; + @XmlAttribute(name = "type") + protected String type; + @XmlAttribute(name = "href") + @XmlSchemaType(name = "anyURI") + protected String href; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the rel property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRel() { + return rel; + } + + /** + * Sets the value of the rel property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRel(String value) { + this.rel = value; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the href property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getHref() { + return href; + } + + /** + * Sets the value of the href property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setHref(String value) { + this.href = value; + } + + } + +} diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/ObjectFactory.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/ObjectFactory.java new file mode 100644 index 0000000000000..90b047516a3e0 --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/ObjectFactory.java @@ -0,0 +1,94 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2014.09.12 at 03:00:35 PM CEST +// + +package io.quarkus.it.jaxb.mapper.codegen.feed; + +import javax.xml.bind.annotation.XmlRegistry; + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the io.quarkus.it.jaxb.mapper.codegen.feed package. + *

+ * An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: + * io.quarkus.it.jaxb.mapper.codegen.feed + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Feed } + * + */ + public Feed createFeed() { + return new Feed(); + } + + /** + * Create an instance of {@link Feed.Entry } + * + */ + public Feed.Entry createFeedEntry() { + return new Feed.Entry(); + } + + /** + * Create an instance of {@link Feed.Link } + * + */ + public Feed.Link createFeedLink() { + return new Feed.Link(); + } + + /** + * Create an instance of {@link Feed.Entry.Link } + * + */ + public Feed.Entry.Link createFeedEntryLink() { + return new Feed.Entry.Link(); + } + + /** + * Create an instance of {@link Feed.Entry.Summary } + * + */ + public Feed.Entry.Summary createFeedEntrySummary() { + return new Feed.Entry.Summary(); + } + + /** + * Create an instance of {@link Feed.Entry.Author } + * + */ + public Feed.Entry.Author createFeedEntryAuthor() { + return new Feed.Entry.Author(); + } + + /** + * Create an instance of {@link Feed.Entry.Category } + * + */ + public Feed.Entry.Category createFeedEntryCategory() { + return new Feed.Entry.Category(); + } + +} diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/package-info.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/package-info.java new file mode 100644 index 0000000000000..a4ab47c146d5c --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/codegen/feed/package-info.java @@ -0,0 +1,9 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2014.09.12 at 03:00:35 PM CEST +// + +@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.w3.org/2005/Atom", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package io.quarkus.it.jaxb.mapper.codegen.feed; diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/process/UnmarshalRSSProcess.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/process/UnmarshalRSSProcess.java new file mode 100644 index 0000000000000..7f47faa1ba1b1 --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/mapper/process/UnmarshalRSSProcess.java @@ -0,0 +1,80 @@ +package io.quarkus.it.jaxb.mapper.process; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.enterprise.context.ApplicationScoped; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + +import io.quarkus.it.jaxb.mapper.codegen.feed.Feed; +import io.quarkus.it.jaxb.mapper.codegen.feed.Feed.Entry; +import io.quarkus.it.jaxb.object.Category; +import io.quarkus.it.jaxb.object.INews; +import io.quarkus.it.jaxb.object.QuarkusNews; + +@ApplicationScoped +public class UnmarshalRSSProcess { + + private static String CODEGEN_PACKAGE = "io.quarkus.it.jaxb.mapper.codegen.feed"; + private static String FEED = "\n" + + "\n" + + "\n" + + "\n" + + "Quarkus\n" + + "\n" + + "2019-08-02T00:00:00+02:00\n" + + "\n" + + "\n" + + "https://quarkus.io/blog/\n" + + "\n" + + "\n" + + "2019-08-01T00:00:00+02:00\n" + + "2019-08-01T00:00:00+02:00\n" + + "https://quarkus.io/blog/hibernate-orm-config-profiles/\n" + + "\n" + + "<![CDATA[Tips to use Hibernate ORM with Quarkus profiles and live coding mode]]>\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""; + + public Collection retrieveLastNews(int nbNews, Category category) { + return getQuarkusNews(getFeed()).subList(0, nbNews); + } + + private Feed getFeed() { + try { + JAXBContext jc = JAXBContext.newInstance(CODEGEN_PACKAGE); + Unmarshaller unmarshaller = jc.createUnmarshaller(); + return (Feed) unmarshaller.unmarshal(new StringReader(FEED)); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private List getQuarkusNews(Feed feed) { + List quarkusNews = new ArrayList<>(); + for (Entry entry : feed.getEntry()) { + quarkusNews.add(mapToQuarkusNews(entry)); + } + return quarkusNews; + } + + private QuarkusNews mapToQuarkusNews(Entry entry) { + QuarkusNews quarkusNews = new QuarkusNews(); + quarkusNews.setTitle(entry.getTitle()); + quarkusNews.setDescription(entry.getContent()); + quarkusNews.setContent(entry.getContent()); + quarkusNews.setAuthor(entry.getAuthor().getName()); + quarkusNews.setUrl(entry.getLink().getHref()); + return quarkusNews; + } +} diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/Category.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/Category.java new file mode 100644 index 0000000000000..1114d99561b65 --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/Category.java @@ -0,0 +1,5 @@ +package io.quarkus.it.jaxb.object; + +public enum Category { + TIPS +} diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/INews.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/INews.java new file mode 100644 index 0000000000000..a3041b9f64539 --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/INews.java @@ -0,0 +1,50 @@ +package io.quarkus.it.jaxb.object; + +import java.util.Date; + +/** + * Describes the news objects proposed by erpds. + */ +public interface INews { + + /** + * @return the unique {@link INews} identifier. + */ + public Long getId(); + + /** + * @return the {@link INews} title. + */ + public String getTitle(); + + /** + * @return the {@link INews} description. + */ + public String getDescription(); + + /** + * @return the {@link INews} author name. + */ + public String getAuthor(); + + /** + * @return the exact date when the {@link INews} has been requested. + */ + public Date getRequestedDate(); + + /** + * @return the actual {@link INews} date. + */ + public Date getDate(); + + /** + * @return the {@link INews} category. + */ + public Category getCategory(); + + /** + * @return the {@link INews} url. + */ + public String getUrl(); + +} \ No newline at end of file diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/QuarkusNews.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/QuarkusNews.java new file mode 100644 index 0000000000000..e2f6df8f8c2c8 --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/object/QuarkusNews.java @@ -0,0 +1,138 @@ +package io.quarkus.it.jaxb.object; + +import java.io.Serializable; +import java.util.Date; + +import javax.xml.bind.annotation.XmlRootElement; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@XmlRootElement +@RegisterForReflection +public class QuarkusNews implements Serializable, INews { + + private Long id; + private int version; + + private String title; + private String description; + private String author; + private String url; + private String content; + private Date requestedDate; + private Date date; + private Category category; + + @Override + public Long getId() { + return this.id; + } + + public void setId(final Long id) { + this.id = id; + } + + public int getVersion() { + return this.version; + } + + public void setVersion(final int version) { + this.version = version; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof QuarkusNews)) { + return false; + } + QuarkusNews other = (QuarkusNews) obj; + if (id != null) { + if (!id.equals(other.id)) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + @Override + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @Override + public Date getRequestedDate() { + return requestedDate; + } + + public void setRequestedDate(Date requestedDate) { + this.requestedDate = requestedDate; + } + + @Override + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + @Override + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } +} \ No newline at end of file diff --git a/integration-tests/main/src/main/java/io/quarkus/it/jaxb/rest/NewsResource.java b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/rest/NewsResource.java new file mode 100644 index 0000000000000..21bc12bd1dd4b --- /dev/null +++ b/integration-tests/main/src/main/java/io/quarkus/it/jaxb/rest/NewsResource.java @@ -0,0 +1,35 @@ +package io.quarkus.it.jaxb.rest; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import io.quarkus.it.jaxb.mapper.process.UnmarshalRSSProcess; +import io.quarkus.it.jaxb.object.Category; +import io.quarkus.it.jaxb.object.INews; + +@Path("/test/jaxb/getnews") +public class NewsResource { + + @Inject + UnmarshalRSSProcess newsProcessor; + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getNews() { + try { + final Collection results = new ArrayList<>(); + results.addAll(newsProcessor.retrieveLastNews(1, Category.TIPS)); + return Response.ok(results).build(); + } catch (Exception e) { + e.printStackTrace(); + } + return Response.noContent().build(); + } +} \ No newline at end of file diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/JaxbITCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/JaxbITCase.java new file mode 100644 index 0000000000000..bae68ef09a70e --- /dev/null +++ b/integration-tests/main/src/test/java/io/quarkus/it/main/JaxbITCase.java @@ -0,0 +1,8 @@ +package io.quarkus.it.main; + +import io.quarkus.test.junit.SubstrateTest; + +@SubstrateTest +public class JaxbITCase extends JaxbTestCase { + +} diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/JaxbTestCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/JaxbTestCase.java new file mode 100644 index 0000000000000..8c32cf33add5c --- /dev/null +++ b/integration-tests/main/src/test/java/io/quarkus/it/main/JaxbTestCase.java @@ -0,0 +1,18 @@ +package io.quarkus.it.main; + +import static org.hamcrest.Matchers.contains; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; + +@QuarkusTest +public class JaxbTestCase { + + @Test + public void testNews() { + RestAssured.when().get("/test/jaxb/getnews").then() + .body("author", contains("Emmanuel Bernard")); + } +}