Skip to content

Commit

Permalink
Update Code structure to support new models
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Thorley authored and EsendexDev committed Dec 29, 2015
1 parent 2f71c26 commit c3b45ac
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public ContactResponse createResponse(ContactDto dto) {
resp.setMobileNumber(dto.getPhoneNumber());
resp.setQuickName(dto.getQuickname());


return resp;
}

Expand Down
25 changes: 18 additions & 7 deletions src/main/java/esendex/sdk/java/model/transfer/Dto.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@

package esendex.sdk.java.model.transfer;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

/**
* Base xml resource class. This is the superclass for all xml resources.
* When a Dto is the root xml entity then the xml namespace (xmlns)
* attribute will be set. Any Dto may have a URI attribute to provide
* When a Dto is the root xml entity then the xml namespace (xmlns)
* attribute will be set. Any Dto may have a URI attribute to provide
* access to a more complete resource
*
*
* @author Mike Whittaker
*/
public abstract class Dto {


@XStreamAlias("id")
@XStreamAsAttribute
private String id;

@XStreamAlias("uri")
@XStreamAsAttribute
private String uri;

@XStreamAlias("xmlns")
@XStreamAsAttribute
private String xmlns;

public Dto() {
}

Expand Down Expand Up @@ -57,7 +68,7 @@ public void setId(String id) {
public void setUri(String uri) {
this.uri = uri;
}

public void setXmlns(String xmlns) {
this.xmlns = xmlns;
}
Expand All @@ -66,7 +77,7 @@ public void setXmlns(String xmlns) {
* {@inheritDoc}
*/
@Override
public String toString() {
public String toString() {
return "id: " + id +
"\nuri: " + uri +
"\nxmlns: " + xmlns;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/esendex/sdk/java/model/transfer/LinkDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package esendex.sdk.java.model.transfer;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

@XStreamAlias("link")
public class LinkDto {

@XStreamAlias("rel")
@XStreamAsAttribute
private String rel;

@XStreamAlias("href")
@XStreamAsAttribute
private String href;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,35 @@
import java.util.ArrayList;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamImplicit;
import esendex.sdk.java.model.transfer.PageableDto;
import esendex.sdk.java.model.transfer.contact.ContactDto;

/**
* The response from certain services containing a collection of
* ContactResponse.
* @author Mike Whittaker
*/
public class ContactCollectionDto extends PageableDto {

private List<ContactDto> contacts;
@XStreamImplicit(itemFieldName = "contact")
private List contacts = new ArrayList();

private Object readResolve() {
if (contacts == null) contacts = new ArrayList<ContactDto>();
return this;
@XStreamImplicit(itemFieldName = "link")
private List link = new ArrayList();

public ContactCollectionDto(List<ContactDto> contacts) {
this.contacts = contacts;
}

public ContactCollectionDto() {
public List getLink() {
return link;
}

/**
* Creates a ContactCollectionDto populated with a List of
* ContactDtos.
* @param contacts the List of contacts
*/
public ContactCollectionDto(List<ContactDto> contacts) {
this.contacts = contacts;
public void setLink(List link) {
this.link = link;
}

/**
* Gets the contacts.
* @return the contacts
*/
public List<ContactDto> getContacts() {
return contacts;
}

public void setContacts(List<ContactDto> contacts) {
public void setContacts(List contacts) {
this.contacts = contacts;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return super.toString() + "\n" + contacts;
}
}
128 changes: 37 additions & 91 deletions src/main/java/esendex/sdk/java/model/transfer/contact/ContactDto.java
Original file line number Diff line number Diff line change
@@ -1,128 +1,74 @@

package esendex.sdk.java.model.transfer.contact;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import esendex.sdk.java.model.transfer.Dto;
import esendex.sdk.java.model.transfer.LinkDto;

/**
* Base class for contact requests and responses. This class directly holds the
* parsed xml data. Subclasses should merely allow selective access.
* @author Mike Whittaker
*/
import java.util.ArrayList;
import java.util.List;

@XStreamAlias("contact")
public class ContactDto extends Dto {

@XStreamAlias("firstname")
private String firstname;

@XStreamAlias("lastname")
private String lastname;

@XStreamAlias("quickname")
private String quickname;

@XStreamAlias("phonenumber")
private String phonenumber;
private String accountreference;

@XStreamOmitField
private String link;
@XStreamAlias("accountreference")
private String accountreference;

public ContactDto() {
}
@XStreamImplicit(itemFieldName = "link")
private List link = new ArrayList();


/**
* The first name of this Contact. This may not be returned if the property
* has not been set for the Contact.
* @return the contacts first name
*/
public String getFirstname() {
return firstname;
}

/**
* The last name of this Contact. This may not be returned if
* the property has not been set for the Contact.
* @return the contacts last name
*/
public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return lastname;
}

/**
* This is the human-friendly shortcut for the Contact and can be used as
* a Message recipient instead of a telephone number. Where firstname
* and lastname have been set when the Contact was created, it may be a
* concatenation of these two values.
* @return the contacts quickname
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}

public String getQuickname() {
return quickname;
}

/**
* The telephone number associated with this Contact.
* @return the phone number
*/
public String getPhoneNumber() {
return phonenumber;
public void setQuickname(String quickname) {
this.quickname = quickname;
}

/**
* The accountReference associated with this Contact.
* @return the Account Reference
*/
public String getAccountReference() {return accountreference; }

/**
* Sets the firstname.
* @param firstname the first name to set
* @see #getFirstname()
*/
public void setFirstname(String firstname) {
this.firstname = firstname;
public String getPhoneNumber() {
return phonenumber;
}

/**
* Sets the lastname.
* @param lastname the last name to set
* @see #getLastname()
*/
public void setLastname(String lastname) {
this.lastname = lastname;
public void setPhoneNumber(String phonenumber) {
this.phonenumber = phonenumber;
}

/**
* Sets the quickname.
* @param quickname the quick name to set
* @see #getQuickname()
*/
public void setQuickname(String quickname) {
this.quickname = quickname;
public String getAccountReference() {
return accountreference;
}

/**
* Sets the phonenumber.
* @param phonenumber the mobile number to set
* @see #getPhoneNumber()
*/
public void setPhoneNumber(String phonenumber) {
this.phonenumber = phonenumber;
public void setAccountReference(String accountreference) {
this.accountreference = accountreference;
}

/**
* Sets the type.
* @param accountReference the accountReference to set
* @see #getAccountReference() ()
*/
public void setAccountReference(String accountReference) {
this.accountreference = accountReference;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {

return super.toString() +
"\nfirstname:" + firstname +
"\nlastname:" + lastname +
"\nquickname:" + quickname +
"\nmobilenumber:" + phonenumber +
"\naccountreference:" + accountreference;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package esendex.sdk.java.model.transfer.contact;


import com.thoughtworks.xstream.annotations.XStreamAlias;
import esendex.sdk.java.model.transfer.Dto;

@XStreamAlias("response")
public class ContactResponseDto {
public class ContactResponseDto extends Dto {

@XStreamAlias("contact")
private NewContactDto contact;// = new ArrayList();
private ContactDto contact;

public ContactDto getContact() {
return contact;
}

public void setContact(ContactDto contact) {
this.contact = contact;
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/esendex/sdk/java/parser/XmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* @author Mike Whittaker
*/
public interface XmlParser {

/**
* Converts if possible, a String, that must be in XML format, to a Dto.
* @param xml the character data to be converted
* @return a Dto object representing the argument
* @throws EsendexException if there is any problem reading or parseing the
* XML.
*/
Dto fromXml(String xml) throws EsendexException;
Object fromXml(String xml) throws EsendexException;

/**
* Converts a Dto Object to XML character data.
Expand Down
Loading

0 comments on commit c3b45ac

Please sign in to comment.