KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > shared > PersonImpl


1 /*
2  * Created by IntelliJ IDEA.
3  * User: tom
4  * Date: May 28, 2001
5  * Time: 10:35:05 PM
6  * To change template for new class use
7  * Code Style | Class Templates options (Tools | IDE Options).
8  */

9 package org.apache.ojb.odmg.shared;
10
11 import org.apache.commons.lang.builder.ToStringBuilder;
12 import org.apache.commons.lang.builder.ToStringStyle;
13
14 import java.io.Serializable JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Arrays JavaDoc;
17
18 public class PersonImpl implements Person, Serializable JavaDoc
19 {
20     // technical attributes only needed for O/R mapping
21
private int id;
22     private int motherId;
23     private int fatherId;
24
25     // domain specific attributes
26
private String JavaDoc firstname;
27     private String JavaDoc lastname;
28     private Person mother;
29     private Person father;
30     private Person[] children;
31
32     public PersonImpl()
33     {
34     }
35
36     public String JavaDoc getFirstname()
37     {
38         return firstname;
39     }
40
41     public String JavaDoc getLastname()
42     {
43         return lastname;
44     }
45
46     public Person getMother()
47     {
48         return mother;
49     }
50
51     public Person getFather()
52     {
53         return father;
54     }
55
56     public Person[] getChildren()
57     {
58         return children;
59     }
60
61     public void setFirstname(String JavaDoc pFirstname)
62     {
63         firstname = pFirstname;
64     }
65
66     public void setLastname(String JavaDoc pLastname)
67     {
68         lastname = pLastname;
69     }
70
71     public void setMother(Person pMother)
72     {
73         mother = pMother;
74     }
75
76     public void setFather(Person pFather)
77     {
78         father = pFather;
79     }
80
81     public void setChildren(Person[] pChildren)
82     {
83         children = pChildren;
84     }
85
86     public void addChild(Person pChild)
87     {
88         int numOfChildren = ((children == null) ? 0 : children.length);
89         Person[] newKids = new Person[numOfChildren + 1];
90         ArrayList JavaDoc list = new ArrayList JavaDoc(Arrays.asList(children));
91         list.add(pChild);
92         list.toArray(newKids);
93     }
94
95     /**
96      * Gets the fatherId.
97      * @return Returns a int
98      */

99     public int getFatherId()
100     {
101         return fatherId;
102     }
103
104     /**
105      * Sets the fatherId.
106      * @param fatherId The fatherId to set
107      */

108     public void setFatherId(int fatherId)
109     {
110         this.fatherId = fatherId;
111     }
112
113     /**
114      * Gets the id.
115      * @return Returns a int
116      */

117     public int getId()
118     {
119         return id;
120     }
121
122     /**
123      * Sets the id.
124      * @param id The id to set
125      */

126     public void setId(int id)
127     {
128         this.id = id;
129     }
130
131     /**
132      * Gets the motherId.
133      * @return Returns a int
134      */

135     public int getMotherId()
136     {
137         return motherId;
138     }
139
140     /**
141      * Sets the motherId.
142      * @param motherId The motherId to set
143      */

144     public void setMotherId(int motherId)
145     {
146         this.motherId = motherId;
147     }
148
149     public String JavaDoc toString()
150     {
151         ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
152         buf.append("id", id);
153         buf.append("firstname", firstname);
154         buf.append("lastname", lastname);
155         buf.append("motherId", motherId);
156         buf.append("mother", mother != null ? "PersonImpl@" + System.identityHashCode(mother) + "(" + motherId + ")" : null);
157         buf.append("fatherId", fatherId);
158         buf.append("father", father != null ? "PersonImpl@" + System.identityHashCode(father) + "(" + fatherId + ")" : null);
159         return buf.toString();
160     }
161 }
162
Popular Tags