Replaced sync XSD by custom objects
* Removed JAXB dependencies * Added User, Message and TextMessage * Changed version to 0.2-alpha in POM
This commit is contained in:
		
							
								
								
									
										97
									
								
								src/main/java/envoy/data/Message.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/main/java/envoy/data/Message.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
package envoy.data;
 | 
			
		||||
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a unique message with a unique, numeric ID. Further metadata
 | 
			
		||||
 * includes the sender and recipient {@link User}s, as well as the creation
 | 
			
		||||
 * date and the current {@link MessageStatus}.<br>
 | 
			
		||||
 * <br>
 | 
			
		||||
 * Project: <strong>envoy-common</strong><br>
 | 
			
		||||
 * File: <strong>Message.java</strong><br>
 | 
			
		||||
 * Created: <strong>28.12.2019</strong><br>
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.2-alpha
 | 
			
		||||
 */
 | 
			
		||||
public abstract class Message implements Serializable {
 | 
			
		||||
 | 
			
		||||
	private final long	id;
 | 
			
		||||
	private final User	sender, recipient;
 | 
			
		||||
	private final Date	date;
 | 
			
		||||
 | 
			
		||||
	private MessageStatus status;
 | 
			
		||||
 | 
			
		||||
	private static final long serialVersionUID = -4393477412979594435L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link Message} from the client's perspective. The current date
 | 
			
		||||
	 * is used as the message date and the status is set to
 | 
			
		||||
	 * {@link MessageStatus#WAITING}.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param id        unique ID
 | 
			
		||||
	 * @param sender    the user who sends the message
 | 
			
		||||
	 * @param recipient the user who receives the message
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public Message(long id, User sender, User recipient) {
 | 
			
		||||
		this.id			= id;
 | 
			
		||||
		this.sender		= sender;
 | 
			
		||||
		this.recipient	= recipient;
 | 
			
		||||
		date			= new Date();
 | 
			
		||||
		status			= MessageStatus.WAITING;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the ID of this message
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public long getId() { return id; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the sender of this message
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public User getSender() { return sender; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the recipient of this message
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public User getRecipient() { return recipient; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the date at which this message was created
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public Date getDate() { return date; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the current status of this message
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public MessageStatus getStatus() { return status; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Changes the current {@link MessageStatus} to the next logical status.<br>
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * The underlying order is as follows:
 | 
			
		||||
	 * <ol>
 | 
			
		||||
	 * <li>{@link MessageStatus#WAITING}
 | 
			
		||||
	 * <li>{@link MessageStatus#SENT}
 | 
			
		||||
	 * <li>{@link MessageStatus#RECEIVED}
 | 
			
		||||
	 * <li>{@link MessageStatus#READ}
 | 
			
		||||
	 * </ol>
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public void nextStatus() {
 | 
			
		||||
		if (status == MessageStatus.READ) throw new IllegalStateException("Message status READ is already reached");
 | 
			
		||||
		status = MessageStatus.values()[status.ordinal() + 1];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static enum MessageStatus {
 | 
			
		||||
		WAITING, SENT, RECEIVED, READ
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								src/main/java/envoy/data/TextMessage.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/main/java/envoy/data/TextMessage.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
package envoy.data;
 | 
			
		||||
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a {@link Message} with content that is comprised of text.<br>
 | 
			
		||||
 * <br>
 | 
			
		||||
 * Project: <strong>envoy-common</strong><br>
 | 
			
		||||
 * File: <strong>TextMessage.java</strong><br>
 | 
			
		||||
 * Created: <strong>28.12.2019</strong><br>
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.2-alpha
 | 
			
		||||
 */
 | 
			
		||||
public class TextMessage extends Message {
 | 
			
		||||
 | 
			
		||||
	private final String content;
 | 
			
		||||
 | 
			
		||||
	private static final long serialVersionUID = 1538164720632899917L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link TextMessage} from the client's perspective. The current
 | 
			
		||||
	 * date
 | 
			
		||||
	 * is used as the message date and the status is set to
 | 
			
		||||
	 * {@link MessageStatus#WAITING}.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param id        unique ID
 | 
			
		||||
	 * @param sender    the user who sends the message
 | 
			
		||||
	 * @param recipient the user who receives the message
 | 
			
		||||
	 * @param content   the content of the message
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public TextMessage(long id, User sender, User recipient, String content) {
 | 
			
		||||
		super(id, sender, recipient);
 | 
			
		||||
		this.content = content;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,content=%s]",
 | 
			
		||||
				getId(),
 | 
			
		||||
				getSender(),
 | 
			
		||||
				getRecipient(),
 | 
			
		||||
				new SimpleDateFormat("dd.MM.yyyy hh:mm:ss").format(getDate()),
 | 
			
		||||
				getStatus(),
 | 
			
		||||
				content);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the content of this {@link TextMessage}
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public String getContent() { return content; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										71
									
								
								src/main/java/envoy/data/User.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								src/main/java/envoy/data/User.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
package envoy.data;
 | 
			
		||||
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a unique user with a unique, numeric ID, a name and a current
 | 
			
		||||
 * {@link UserStatus}.<br>
 | 
			
		||||
 * <br>
 | 
			
		||||
 * Project: <strong>envoy-common</strong><br>
 | 
			
		||||
 * File: <strong>User.java</strong><br>
 | 
			
		||||
 * Created: <strong>28.12.2019</strong><br>
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.2-alpha
 | 
			
		||||
 */
 | 
			
		||||
public class User implements Serializable {
 | 
			
		||||
 | 
			
		||||
	private final long		id;
 | 
			
		||||
	private final String	name;
 | 
			
		||||
 | 
			
		||||
	private UserStatus status;
 | 
			
		||||
 | 
			
		||||
	private static final long serialVersionUID = 3530947374856708236L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link User}. The {@link UserStatus} is set to
 | 
			
		||||
	 * {@link UserStatus#OFFLINE}.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param id   unique ID
 | 
			
		||||
	 * @param name user name
 | 
			
		||||
	 * @since Envoy Client v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public User(long id, String name) {
 | 
			
		||||
		this.id		= id;
 | 
			
		||||
		this.name	= name;
 | 
			
		||||
		status		= UserStatus.OFFLINE;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the ID of this {@link User}
 | 
			
		||||
	 * @since Envoy Client v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public long getId() { return id; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the name of this {@link User}
 | 
			
		||||
	 * @since Envoy Client v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public String getName() { return name; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the current status of this user
 | 
			
		||||
	 * @since Envoy Client v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public UserStatus getStatus() { return status; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sets the current status of this user
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param status the status to set
 | 
			
		||||
	 * @since Envoy Client v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public void setStatus(UserStatus status) { this.status = status; }
 | 
			
		||||
 | 
			
		||||
	public static enum UserStatus {
 | 
			
		||||
		ONLINE, AWAY, BUSY, OFFLINE;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
package envoy.schema;
 | 
			
		||||
 | 
			
		||||
import javax.xml.bind.annotation.XmlEnum;
 | 
			
		||||
import javax.xml.bind.annotation.XmlType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Project: <strong>envoy-common</strong><br>
 | 
			
		||||
 * File: <strong>MessageState.java</strong><br>
 | 
			
		||||
 * Created: <strong>11 Oct 2019</strong><br>
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 */
 | 
			
		||||
@XmlType(name = "")
 | 
			
		||||
@XmlEnum
 | 
			
		||||
public enum MessageState {
 | 
			
		||||
 | 
			
		||||
	Waiting, Sent, Received, Read;
 | 
			
		||||
 | 
			
		||||
	public String value() { return name(); }
 | 
			
		||||
 | 
			
		||||
	public static MessageState fromValue(String v) { return valueOf(v); }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
package envoy.schema;
 | 
			
		||||
 | 
			
		||||
import javax.xml.bind.annotation.XmlEnum;
 | 
			
		||||
import javax.xml.bind.annotation.XmlType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Project: <strong>envoy-common</strong><br>
 | 
			
		||||
 * File: <strong>UserStatus.java</strong><br>
 | 
			
		||||
 * Created: <strong>27 Oct 2019</strong><br>
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Maximilian Käfer
 | 
			
		||||
 */
 | 
			
		||||
@XmlType(name = "")
 | 
			
		||||
@XmlEnum
 | 
			
		||||
public enum UserStatus {
 | 
			
		||||
 | 
			
		||||
	Online, DoNotDisturb, AFK, Offline;
 | 
			
		||||
 | 
			
		||||
	public String value() { return name(); }
 | 
			
		||||
 | 
			
		||||
	public static UserStatus fromValue(String v) { return valueOf(v); }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,70 +0,0 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 | 
			
		||||
	targetNamespace="https://github.com/informatik-ag-ngl"
 | 
			
		||||
	xmlns="https://github.com/informatik-ag-ngl"
 | 
			
		||||
	elementFormDefault="qualified">
 | 
			
		||||
 | 
			
		||||
	<xs:element name="Sync">
 | 
			
		||||
		<xs:complexType>
 | 
			
		||||
			<xs:sequence>
 | 
			
		||||
				<xs:element name="Message" type="Message" minOccurs="0"
 | 
			
		||||
					maxOccurs="unbounded" />
 | 
			
		||||
				<xs:element name="User" type="User" minOccurs="0"
 | 
			
		||||
					maxOccurs="unbounded" />
 | 
			
		||||
			</xs:sequence>
 | 
			
		||||
		</xs:complexType>
 | 
			
		||||
	</xs:element>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	<xs:complexType name="Message">
 | 
			
		||||
		<xs:sequence>
 | 
			
		||||
			<xs:element name="Metadata">
 | 
			
		||||
				<xs:complexType>
 | 
			
		||||
					<xs:sequence>
 | 
			
		||||
						<xs:element name="Sender" type="xs:long" />
 | 
			
		||||
						<xs:element name="Recipient" type="xs:long" />
 | 
			
		||||
						<xs:element name="Date" type="xs:dateTime" />
 | 
			
		||||
						<xs:element name="MessageId" type="xs:long" />
 | 
			
		||||
						<xs:element name="State">
 | 
			
		||||
							<xs:simpleType>
 | 
			
		||||
								<xs:restriction base="xs:string">
 | 
			
		||||
									<xs:enumeration value="Waiting" />
 | 
			
		||||
									<xs:enumeration value="Sent" />
 | 
			
		||||
									<xs:enumeration value="Received" />
 | 
			
		||||
									<xs:enumeration value="Read" />
 | 
			
		||||
								</xs:restriction>
 | 
			
		||||
							</xs:simpleType>
 | 
			
		||||
						</xs:element>
 | 
			
		||||
					</xs:sequence>
 | 
			
		||||
				</xs:complexType>
 | 
			
		||||
			</xs:element>
 | 
			
		||||
			<xs:element name="Content" maxOccurs="unbounded">
 | 
			
		||||
				<xs:complexType>
 | 
			
		||||
					<xs:sequence>
 | 
			
		||||
						<xs:element name="text" type="xs:string" />
 | 
			
		||||
					</xs:sequence>
 | 
			
		||||
					<xs:attribute name="type" type="xs:string" />
 | 
			
		||||
				</xs:complexType>
 | 
			
		||||
			</xs:element>
 | 
			
		||||
		</xs:sequence>
 | 
			
		||||
	</xs:complexType>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	<xs:complexType name="User">
 | 
			
		||||
		<xs:sequence>
 | 
			
		||||
			<xs:element name="Name" type="xs:string" />
 | 
			
		||||
			<xs:element name="ID" type="xs:long" />
 | 
			
		||||
			<xs:element name="Status">
 | 
			
		||||
				<xs:simpleType>
 | 
			
		||||
					<xs:restriction base="xs:string">
 | 
			
		||||
						<xs:enumeration value="Online" />
 | 
			
		||||
						<xs:enumeration value="DoNotDisturb" />
 | 
			
		||||
						<xs:enumeration value="AFK" />
 | 
			
		||||
						<xs:enumeration value="Offline" />
 | 
			
		||||
					</xs:restriction>
 | 
			
		||||
				</xs:simpleType>
 | 
			
		||||
			</xs:element>
 | 
			
		||||
		</xs:sequence>
 | 
			
		||||
	</xs:complexType>
 | 
			
		||||
 | 
			
		||||
</xs:schema>
 | 
			
		||||
@@ -1,33 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE xml>
 | 
			
		||||
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
 | 
			
		||||
	xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
 | 
			
		||||
	xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
 | 
			
		||||
	jaxb:extensionBindingPrefixes="xjc" version="2.1">
 | 
			
		||||
	<jaxb:globalBindings generateIsSetMethod="true"
 | 
			
		||||
		fixedAttributeAsConstantProperty="true">
 | 
			
		||||
		<xjc:serializable />
 | 
			
		||||
	</jaxb:globalBindings>
 | 
			
		||||
	<jaxb:bindings
 | 
			
		||||
		schemaLocation="../resources/sync_schema.xsd">
 | 
			
		||||
		
 | 
			
		||||
		<jaxb:bindings node="//xs:element[@name='Message']">
 | 
			
		||||
			<jaxb:property name="Messages"/>
 | 
			
		||||
		</jaxb:bindings>
 | 
			
		||||
		
 | 
			
		||||
		<jaxb:bindings node="//xs:element[@name='User']">
 | 
			
		||||
			<jaxb:property name="Users"/>
 | 
			
		||||
		</jaxb:bindings>
 | 
			
		||||
		
 | 
			
		||||
		<jaxb:bindings
 | 
			
		||||
			node="//xs:element[@name='State']/xs:simpleType">
 | 
			
		||||
			<jaxb:typesafeEnumClass name="MessageState" />
 | 
			
		||||
		</jaxb:bindings>
 | 
			
		||||
 | 
			
		||||
		<jaxb:bindings
 | 
			
		||||
			node="//xs:element[@name='Status']/xs:simpleType">
 | 
			
		||||
			<jaxb:typesafeEnumClass name="UserStatus" />
 | 
			
		||||
		</jaxb:bindings>
 | 
			
		||||
		
 | 
			
		||||
	</jaxb:bindings>
 | 
			
		||||
</jaxb:bindings>
 | 
			
		||||
		Reference in New Issue
	
	Block a user