KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > persistance > bo > CentralOffice


1 package org.objectweb.rentacar.persistance.bo;
2
3 import java.util.HashSet JavaDoc;
4 import java.util.Set JavaDoc;
5
6 import javax.persistence.CascadeType;
7 import javax.persistence.Entity;
8 import javax.persistence.GeneratedValue;
9 import javax.persistence.Id;
10 import javax.persistence.JoinColumn;
11 import javax.persistence.OneToMany;
12
13 import org.hibernate.annotations.GenericGenerator;
14 import org.objectweb.rentacar.persistance.dao.AgencyDAO;
15 import org.objectweb.rentacar.persistance.dao.DAOException;
16 import org.apache.commons.lang.builder.EqualsBuilder;
17 import org.apache.commons.lang.builder.HashCodeBuilder;
18 import org.apache.commons.lang.builder.ToStringBuilder;
19
20 /**
21  *
22  * @author ofabre
23  *
24  */

25 @Entity
26 public class CentralOffice {
27     
28     // Fields
29
private String JavaDoc centralOfficeId;
30     
31     private String JavaDoc host;
32     
33     private String JavaDoc port;
34     
35     // Relations
36
private Set JavaDoc<Agency> agencies;
37
38     public CentralOffice() {
39         super();
40         // TODO Auto-generated constructor stub
41
}
42
43     public CentralOffice(Set JavaDoc<Agency> agencies) {
44         super();
45         this.agencies = agencies;
46     }
47     
48     public CentralOffice(String JavaDoc centralOfficeId, Set JavaDoc<Agency> agencies) {
49         super();
50         // TODO Auto-generated constructor stub
51
this.centralOfficeId = centralOfficeId;
52         this.agencies = agencies;
53     }
54     
55     public CentralOffice(CentralOfficeVO centralOfficeVO) {
56         super();
57         // TODO Auto-generated constructor stub
58
this.centralOfficeId = centralOfficeVO.getCentralOfficeId();
59         Set JavaDoc<Agency> agencies = new HashSet JavaDoc<Agency>();
60         for (String JavaDoc agencyId : centralOfficeVO.getAgencies()) {
61             try {
62                 agencies.add((Agency)AgencyDAO.getInstance().retrieveById(Agency.class, agencyId));
63             } catch (DAOException e) {
64                 e.printStackTrace();
65             }
66         }
67         this.agencies = agencies;
68         this.host = centralOfficeVO.getHost();
69         this.port = centralOfficeVO.getPort();
70     }
71
72     @OneToMany(cascade=CascadeType.ALL)
73     @JoinColumn(name = "centralOffice_centralOfficeId")
74     public Set JavaDoc<Agency> getAgencies() {
75         return agencies;
76     }
77
78     public void setAgencies(Set JavaDoc<Agency> agencies) {
79         this.agencies = agencies;
80     }
81
82     @Id @GeneratedValue(generator = "system-uuid")
83     @GenericGenerator(name="system-uuid", strategy = "uuid")
84     public String JavaDoc getCentralOfficeId() {
85         return centralOfficeId;
86     }
87
88     public void setCentralOfficeId(String JavaDoc centralOfficeId) {
89         this.centralOfficeId = centralOfficeId;
90     }
91
92     public String JavaDoc getHost() {
93         return host;
94     }
95
96     public void setHost(String JavaDoc host) {
97         this.host = host;
98     }
99
100     public String JavaDoc getPort() {
101         return port;
102     }
103
104     public void setPort(String JavaDoc port) {
105         this.port = port;
106     }
107
108     /**
109      * @see java.lang.Object#equals(Object)
110      */

111     public boolean equals(Object JavaDoc object) {
112         if (!(object instanceof CentralOffice)) {
113             return false;
114         }
115         CentralOffice rhs = (CentralOffice) object;
116         return new EqualsBuilder().append(this.centralOfficeId,
117                 rhs.centralOfficeId).append(this.host, rhs.host).append(
118                 this.agencies, rhs.agencies).append(this.port, rhs.port)
119                 .isEquals();
120     }
121
122     /**
123      * @see java.lang.Object#hashCode()
124      */

125     public int hashCode() {
126         return new HashCodeBuilder(135413657, -892320915).append(
127                 this.centralOfficeId).append(this.host).append(this.agencies)
128                 .append(this.port).toHashCode();
129     }
130
131     /**
132      * @see java.lang.Object#toString()
133      */

134     public String JavaDoc toString() {
135         return new ToStringBuilder(this).append("centralOfficeId",
136                 this.centralOfficeId).append("agencies", this.agencies).append(
137                 "host", this.host).append("port", this.port).toString();
138     }
139     
140     
141
142 }
143
Popular Tags