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:
Kai S. K. Engelbart 2019-12-28 22:03:41 +02:00
parent 8bff9184b6
commit cf05f8e1d3
11 changed files with 231 additions and 205 deletions

View File

@ -24,18 +24,6 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/jaxb">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/xjb">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>

View File

@ -1,8 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/main/xjb=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding//target/generated-sources/jaxb=UTF-8
encoding/<project>=UTF-8

View File

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="envoy-common">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/target/generated-sources/jaxb"/>
<wb-resource deploy-path="/" source-path="/src/main/xjb"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>

39
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>informatik-ag-ngl</groupId>
<artifactId>envoy-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.2-alpha</version>
<name>Envoy Common</name>
<url>https://github.com/informatik-ag-ngl/envoy-common</url>
@ -16,44 +16,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
<build>
<finalName>envoy-common</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/xjb</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>envoy.schema</packageName>
<sources>
<source>src/main/resources</source>
</sources>
</configuration>
</plugin>
</plugins>
</build>
</project>

View 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
}
}

View 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; }
}

View 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;
}
}

View File

@ -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); }
}

View File

@ -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&auml;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); }
}

View File

@ -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>

View File

@ -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>