Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,73 @@
package com.baeldung.jaxb;
import java.util.Date;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
@XmlRootElement(name = "book")
@XmlType(propOrder = { "id", "name", "date" })
public class Book {
private Long id;
private String name;
private String author;
private Date date;
@XmlAttribute
public void setId(Long id) {
this.id = id;
}
@XmlElement(name = "title")
public void setName(String name) {
this.name = name;
}
@XmlTransient
public void setAuthor(String author) {
this.author = author;
}
public String getName() {
return name;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Long getId() {
return id;
}
public String getAuthor() {
return author;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
@@ -0,0 +1,28 @@
package com.baeldung.jaxb;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class DateAdapter extends XmlAdapter<String, Date> {
private static final ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>() {
@Override
protected DateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
};
@Override
public Date unmarshal(String v) throws Exception {
return dateFormat.get().parse(v);
}
@Override
public String marshal(Date v) throws Exception {
return dateFormat.get().format(v);
}
}
@@ -0,0 +1,25 @@
package com.baeldung.jaxb.dateunmarshalling;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.datatype.XMLGregorianCalendar;
@XmlRootElement(name = "book")
public class Book {
@XmlElement(name = "title", required = true)
private String title;
@XmlElement(name = "published", required = true)
private XMLGregorianCalendar published;
public XMLGregorianCalendar getPublished() {
return published;
}
@Override
public String toString() {
return "[title: " + title + "; published: " + published.toString() + "]";
}
}
@@ -0,0 +1,27 @@
package com.baeldung.jaxb.dateunmarshalling;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Date;
@XmlRootElement(name = "book")
public class BookDateAdapter {
@XmlElement(name = "title", required = true)
private String title;
@XmlElement(name = "published", required = true)
@XmlJavaTypeAdapter(DateAdapter.class)
private Date published;
public Date getPublished() {
return published;
}
@Override
public String toString() {
return "[title: " + title + "; published: " + published.toString() + "]";
}
}
@@ -0,0 +1,27 @@
package com.baeldung.jaxb.dateunmarshalling;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.time.LocalDateTime;
@XmlRootElement(name = "book")
public class BookLocalDateTimeAdapter {
@XmlElement(name = "title", required = true)
private String title;
@XmlElement(name = "published", required = true)
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
private LocalDateTime published;
public LocalDateTime getPublished() {
return published;
}
@Override
public String toString() {
return "[title: " + title + "; published: " + published.toString() + "]";
}
}
@@ -0,0 +1,21 @@
package com.baeldung.jaxb.dateunmarshalling;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateAdapter extends XmlAdapter<String, Date> {
private static final String CUSTOM_FORMAT_STRING = "yyyy-MM-dd HH:mm:ss";
@Override
public String marshal(Date v) {
return new SimpleDateFormat(CUSTOM_FORMAT_STRING).format(v);
}
@Override
public Date unmarshal(String v) throws Exception {
return new SimpleDateFormat(CUSTOM_FORMAT_STRING).parse(v);
}
}
@@ -0,0 +1,45 @@
package com.baeldung.jaxb.dateunmarshalling;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.InputStream;
public class JaxbDateUnmarshalling {
public static final String DEFAULT_DATE_UNMARSHALLING_FILE = "default-date-unmarshalling.xml";
public static final String CUSTOM_DATE_UNMARSHALLING_FILE = "custom-date-unmarshalling.xml";
public static Book unmarshalDates(InputStream inputFile) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Book.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return (Book) jaxbUnmarshaller.unmarshal(inputFile);
}
public static BookDateAdapter unmarshalDatesUsingCustomXmlAdapter(InputStream inputFile) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(BookDateAdapter.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return (BookDateAdapter) jaxbUnmarshaller.unmarshal(inputFile);
}
public static BookLocalDateTimeAdapter unmarshalDatesUsingJava8(InputStream inputFile) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(BookLocalDateTimeAdapter.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return (BookLocalDateTimeAdapter) jaxbUnmarshaller.unmarshal(inputFile);
}
public static InputStream getInputStream(String file) {
ClassLoader classLoader = JaxbDateUnmarshalling.class.getClassLoader();
return classLoader.getResourceAsStream(file);
}
public static void main(String[] args) throws JAXBException {
Book book = unmarshalDates(getInputStream(DEFAULT_DATE_UNMARSHALLING_FILE));
BookDateAdapter bookDateAdapter = unmarshalDatesUsingCustomXmlAdapter(getInputStream(CUSTOM_DATE_UNMARSHALLING_FILE));
BookLocalDateTimeAdapter bookLocalDateTimeAdapter = unmarshalDatesUsingJava8(getInputStream(CUSTOM_DATE_UNMARSHALLING_FILE));
System.out.println(book);
System.out.println(bookDateAdapter);
System.out.println(bookLocalDateTimeAdapter);
}
}
@@ -0,0 +1,21 @@
package com.baeldung.jaxb.dateunmarshalling;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
private DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public String marshal(LocalDateTime dateTime) {
return dateTime.format(dateFormat);
}
@Override
public LocalDateTime unmarshal(String dateTime) {
return LocalDateTime.parse(dateTime, dateFormat);
}
}
@@ -0,0 +1,48 @@
package com.baeldung.jaxb.gen;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.baeldung.jaxb.gen package.
* <p>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: com.baeldung.jaxb.gen
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link UserRequest }
*
*/
public UserRequest createUserRequest() {
return new UserRequest();
}
/**
* Create an instance of {@link UserResponse }
*
*/
public UserResponse createUserResponse() {
return new UserResponse();
}
}
@@ -0,0 +1,87 @@
package com.baeldung.jaxb.gen;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for UserRequest complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="UserRequest"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserRequest", propOrder = {
"id",
"name"
})
@XmlRootElement(name = "userRequest")
public class UserRequest
implements Serializable
{
private final static long serialVersionUID = -1L;
protected int id;
@XmlElement(required = true)
protected String name;
/**
* Gets the value of the id property.
*
*/
public int getId() {
return id;
}
/**
* Sets the value of the id property.
*
*/
public void setId(int value) {
this.id = value;
}
/**
* 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;
}
}
@@ -0,0 +1,149 @@
package com.baeldung.jaxb.gen;
import java.io.Serializable;
import java.util.Calendar;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
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.adapters.XmlJavaTypeAdapter;
import org.w3._2001.xmlschema.Adapter1;
/**
* <p>Java class for UserResponse complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="UserResponse"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="gender" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="created" type="{http://www.w3.org/2001/XMLSchema}dateTime"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserResponse", propOrder = {
"id",
"name",
"gender",
"created"
})
@XmlRootElement(name = "userResponse")
public class UserResponse
implements Serializable
{
private final static long serialVersionUID = -1L;
protected int id;
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String gender;
@XmlElement(required = true, type = String.class)
@XmlJavaTypeAdapter(Adapter1 .class)
@XmlSchemaType(name = "dateTime")
protected Calendar created;
/**
* Gets the value of the id property.
*
*/
public int getId() {
return id;
}
/**
* Sets the value of the id property.
*
*/
public void setId(int value) {
this.id = value;
}
/**
* 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;
}
/**
* Gets the value of the gender property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getGender() {
return gender;
}
/**
* Sets the value of the gender property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setGender(String value) {
this.gender = value;
}
/**
* Gets the value of the created property.
*
* @return
* possible object is
* {@link String }
*
*/
public Calendar getCreated() {
return created;
}
/**
* Sets the value of the created property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCreated(Calendar value) {
this.created = value;
}
}
@@ -0,0 +1,2 @@
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.baeldung.com/jaxb/gen", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.baeldung.jaxb.gen;
@@ -0,0 +1,23 @@
package org.w3._2001.xmlschema;
import java.util.Calendar;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class Adapter1
extends XmlAdapter<String, Calendar>
{
public Calendar unmarshal(String value) {
return (javax.xml.bind.DatatypeConverter.parseDateTime(value));
}
public String marshal(Calendar value) {
if (value == null) {
return null;
}
return (javax.xml.bind.DatatypeConverter.printDateTime(value));
}
}