PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/jaxrs/providers/jaxb/src/test/java/org/jboss/resteasy/test/providers/jaxb/regression/Kunde.java

https://bitbucket.org/cprenzberg/resteasy
Java | 311 lines | 252 code | 54 blank | 5 comment | 31 complexity | d3fdac9e3eeb60a4f28450fbd427d7c7 MD5 | raw file
  1. package org.jboss.resteasy.test.providers.jaxb.regression;
  2. import javax.xml.bind.annotation.XmlAccessType;
  3. import javax.xml.bind.annotation.XmlAccessorType;
  4. import javax.xml.bind.annotation.XmlAttribute;
  5. import javax.xml.bind.annotation.XmlElement;
  6. import javax.xml.bind.annotation.XmlElementWrapper;
  7. import javax.xml.bind.annotation.XmlRootElement;
  8. import javax.xml.bind.annotation.XmlSeeAlso;
  9. import javax.xml.bind.annotation.XmlTransient;
  10. import java.text.DateFormat;
  11. import java.text.ParseException;
  12. import java.util.Date;
  13. import java.util.GregorianCalendar;
  14. import java.util.List;
  15. import java.util.Locale;
  16. import static java.util.Calendar.YEAR;
  17. @XmlRootElement
  18. @XmlSeeAlso({
  19. Firmenkunde.class,
  20. Privatkunde.class
  21. })
  22. @XmlAccessorType(XmlAccessType.FIELD)
  23. public abstract class Kunde implements java.io.Serializable
  24. {
  25. private static final long serialVersionUID = 8488010636885492122L;
  26. public static final int NACHNAME_LENGTH_MIN = 2;
  27. public static final int NACHNAME_LENGTH_MAX = 32;
  28. public static final int VORNAME_LENGTH_MAX = 32;
  29. public static final int KUNDENNR_LENGTH_MAX = 32;
  30. public static final int DETAILS_LENGTH_MAX = 128 * 1024;
  31. public static final int PASSWORD_LENGTH_MAX = 256;
  32. public static final String PRIVATKUNDE = "P";
  33. public static final String FIRMENKUNDE = "F";
  34. static final String FIND_KUNDEN = "findKunden";
  35. static final String FIND_KUNDEN_BY_NACHNAME = "findKundenByNachname";
  36. static final String FIND_KUNDEN_BY_NACHNAME_FETCH_BESTELLUNGEN = "findKundenByNachnameFetchBestellungen";
  37. static final String FIND_KUNDE_BY_ID_FETCH_BESTELLUNGEN = "findKundeByIdFetchBestellungen";
  38. static final String FIND_KUNDEN_BY_PLZ = "findKundenByPlz";
  39. static final String PARAM_KUNDE_ID = "kundeId";
  40. static final String PARAM_KUNDE_NACHNAME = "nachname";
  41. static final String PARAM_KUNDE_ADRESSE_PLZ = "plz";
  42. // Alternativen: TABLE, SEQUENCE, IDENTITY, AUTO, NONE (=default)
  43. @XmlAttribute(name = "id", required = true)
  44. protected Long id = -1L;
  45. @XmlTransient
  46. protected int version = 0;
  47. @XmlElement(required = true)
  48. protected String nachname = "";
  49. protected String vorname = "";
  50. @XmlAttribute(required = true)
  51. protected String kundennr = "NnVn-001";
  52. protected Date seit = null;
  53. @XmlTransient
  54. protected int anzJahre;
  55. @XmlElement(name = "betreuer")
  56. protected String betreuerKey;
  57. @XmlElementWrapper(name = "bestellungen")
  58. @XmlElement(name = "bestellung")
  59. protected List<String> bestellungenKeys;
  60. protected String details;
  61. @XmlTransient
  62. protected String password = "";
  63. @XmlTransient
  64. protected Date erzeugt = null;
  65. @XmlTransient
  66. protected Date aktualisiert = null;
  67. public Kunde()
  68. {
  69. super();
  70. }
  71. public Long getId()
  72. {
  73. return id;
  74. }
  75. public void setId(Long id)
  76. {
  77. this.id = id;
  78. }
  79. public int getVersion()
  80. {
  81. return version;
  82. }
  83. public void setVersion(int version)
  84. {
  85. this.version = version;
  86. }
  87. public String getNachname()
  88. {
  89. return nachname;
  90. }
  91. public void setNachname(String nachname)
  92. {
  93. this.nachname = nachname;
  94. }
  95. public String getVorname()
  96. {
  97. return vorname;
  98. }
  99. public void setVorname(String vorname)
  100. {
  101. this.vorname = vorname;
  102. }
  103. public String getKundennr()
  104. {
  105. return kundennr;
  106. }
  107. public void setKundennr(String kundennr)
  108. {
  109. this.kundennr = kundennr;
  110. }
  111. public Date getSeit()
  112. {
  113. return seit;
  114. }
  115. public void setSeit(Date seit)
  116. {
  117. this.seit = seit;
  118. }
  119. public int getAnzJahre()
  120. {
  121. final GregorianCalendar now = new GregorianCalendar();
  122. final GregorianCalendar seitCal = new GregorianCalendar();
  123. Date temp = seit;
  124. if (temp == null)
  125. temp = new Date();
  126. seitCal.setTime(temp);
  127. anzJahre = now.get(YEAR) - seitCal.get(YEAR);
  128. return anzJahre;
  129. }
  130. // Parameter, z.B. DateFormat.MEDIUM, Locale.GERMANY
  131. // MEDIUM fuer Format dd.MM.yyyy
  132. public String getSeitAsString(int style, Locale locale)
  133. {
  134. Date temp = seit;
  135. if (temp == null)
  136. temp = new Date();
  137. final DateFormat f = DateFormat.getDateInstance(style, locale);
  138. return f.format(temp);
  139. }
  140. // Parameter, z.B. DateFormat.MEDIUM, Locale.GERMANY
  141. // MEDIUM fuer Format dd.MM.yyyy
  142. public void setSeit(String seit, int style, Locale locale)
  143. {
  144. final DateFormat f = DateFormat.getDateInstance(style, locale);
  145. try
  146. {
  147. this.seit = f.parse(seit);
  148. }
  149. catch (ParseException e)
  150. {
  151. }
  152. }
  153. public String getBetreuerKey()
  154. {
  155. return betreuerKey;
  156. }
  157. public void setBetreuerKey(String betreuerKey)
  158. {
  159. this.betreuerKey = betreuerKey;
  160. }
  161. public List<String> getBestellungenKeys()
  162. {
  163. return bestellungenKeys;
  164. }
  165. public void setBestellungenKeys(List<String> bestellungenKeys)
  166. {
  167. this.bestellungenKeys = bestellungenKeys;
  168. }
  169. abstract public String getArt();
  170. public String getDetails()
  171. {
  172. return details;
  173. }
  174. public void setDetails(String details)
  175. {
  176. this.details = details;
  177. }
  178. public String getPassword()
  179. {
  180. return password;
  181. }
  182. public void setPassword(String passwort)
  183. {
  184. this.password = passwort;
  185. }
  186. public Date getAktualisiert()
  187. {
  188. return aktualisiert;
  189. }
  190. public void setAktualisiert(Date aktualisiert)
  191. {
  192. this.aktualisiert = aktualisiert;
  193. }
  194. public Date getErzeugt()
  195. {
  196. return erzeugt;
  197. }
  198. public void setErzeugt(Date erzeugt)
  199. {
  200. this.erzeugt = erzeugt;
  201. }
  202. @Override
  203. public String toString()
  204. {
  205. return "id=" + id + ", version=" + version +
  206. ", nachname=" + nachname + ", vorname=" + vorname +
  207. ", nr=" + kundennr +
  208. ", seit=" + getSeitAsString(DateFormat.MEDIUM, Locale.GERMANY) +
  209. ", anzJahre=" + getAnzJahre() +
  210. ", password=" + password +
  211. ", erzeugt=" + erzeugt +
  212. ", aktualisiert=" + aktualisiert;
  213. }
  214. @Override
  215. public int hashCode()
  216. {
  217. final int PRIME = 31;
  218. int result = 1;
  219. result = PRIME * result + ((nachname == null) ? 0 : nachname.hashCode());
  220. result = PRIME * result + ((seit == null) ? 0 : seit.hashCode());
  221. result = PRIME * result + ((vorname == null) ? 0 : vorname.hashCode());
  222. return result;
  223. }
  224. @Override
  225. public boolean equals(Object obj)
  226. {
  227. if (this == obj)
  228. return true;
  229. if (obj == null)
  230. return false;
  231. if (getClass() != obj.getClass())
  232. return false;
  233. final Kunde other = (Kunde) obj;
  234. if (nachname == null)
  235. {
  236. if (other.nachname != null)
  237. return false;
  238. }
  239. else if (!nachname.equals(other.nachname))
  240. return false;
  241. if (seit == null)
  242. {
  243. if (other.seit != null)
  244. return false;
  245. }
  246. else if (!seit.equals(other.seit))
  247. return false;
  248. if (vorname == null)
  249. {
  250. if (other.vorname != null)
  251. return false;
  252. }
  253. else if (!vorname.equals(other.vorname))
  254. return false;
  255. return true;
  256. }
  257. }