D:\CreditRepair\CreditRepair_PM_Structure\Development\Source\SourcePackages\CreditRepairProject\DynamicBusinessRulesFramework\src\java\loaders_jaxb_web_services\Employee.java
  1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 
  6 package loaders_jaxb_web_services;
  7 
  8 /**
  9  *
 10  * @author sameldin
 11  */
 12 import javax.xml.bind.JAXBContext;
 13 import javax.xml.bind.JAXBException;
 14 import javax.xml.bind.annotation.*;
 15 import java.io.StringReader;
 16 import java.io.StringWriter;
 17 
 18 @XmlRootElement(name = "employee")
 19 @XmlAccessorType(XmlAccessType.FIELD)
 20 public class Employee
 21 {
 22     @XmlAttribute
 23     private int id;
 24 
 25     /**
 26      * Employee's first name
 27      */
 28     @XmlElement
 29     private String firstName;
 30 
 31     /**
 32      * Employee's middle name
 33      */
 34     @XmlElement
 35     private String middleName;
 36 
 37     /**
 38      * Employee's last name
 39      */
 40     @XmlElement
 41     private String lastName;
 42 
 43     public Employee()
 44     {
 45     }
 46 
 47     public int getId()
 48     {
 49         return id;
 50     }
 51 
 52     public void setId(int id)
 53     {
 54         this.id = id;
 55     }
 56 
 57     public String getLastName()
 58     {
 59         return lastName;
 60     }
 61 
 62     public void setLastName(String lastName)
 63     {
 64         this.lastName = lastName;
 65     }
 66 
 67     public String getMiddleName()
 68     {
 69         return middleName;
 70     }
 71 
 72     public void setMiddleName(String middleName)
 73     {
 74         this.middleName = middleName;
 75     }
 76 
 77     public String getFirstName()
 78     {
 79         return firstName;
 80     }
 81 
 82     public void setFirstName(String firstName)
 83     {
 84         this.firstName = firstName;
 85     }
 86 
 87     @Override
 88     public boolean equals(Object o)
 89     {
 90         if (this == o) return true;
 91         if (o == null || getClass() != o.getClass()) return false;
 92 
 93         Employee employee = (Employee) o;
 94 
 95         if (id != employee.id) return false;
 96         if (firstName != null ? !firstName.equals(employee.firstName) :
 97             employee.firstName != null) return false;
 98         if (lastName != null ? !lastName.equals(employee.lastName) :
 99             employee.lastName != null) return false;
100         if (middleName != null ? !middleName.equals(employee.middleName) :
101             employee.middleName != null) return false;
102 
103         return true;
104     }
105 
106     @Override
107     public int hashCode()
108     {
109         int result = id;
110         result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
111         result = 31 * result + (middleName != null ? middleName.hashCode() : 0);
112         result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
113         return result;
114     }
115 
116     @Override
117     public String toString()
118     {
119         return "Employee{" +
120             "id=" + id +
121             ", firstName='" + firstName + '\'' +
122             ", middleName='" + middleName + '\'' +
123             ", lastName='" + lastName + '\'' +
124             '}';
125     }
126 
127     public static void main(String args[]) throws JAXBException
128     {
129         final Employee john = new Employee();
130         john.setId(1);
131         john.setFirstName("John");
132         john.setMiddleName("Robert");
133         john.setLastName("Doe");
134 
135         // write it out as XML
136         final JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class);
137         StringWriter writer = new StringWriter();
138         jaxbContext.createMarshaller().marshal(john, writer);
139 
140         // read it from XML
141         final Employee johnRead =
142             (Employee) jaxbContext.createUnmarshaller().unmarshal(
143                 new StringReader(writer.toString()));
144         if (john.equals(johnRead))
145         {   // write the new object out as XML again.
146             writer = new StringWriter();
147             jaxbContext.createMarshaller().marshal(johnRead, writer);
148             System.out.println(
149                 "johnRead was identical to john: \n" + writer.toString());
150         }
151         else
152         {
153             System.out.println("john and johnRead are not equal");
154         }
155     }
156 
157 }
158