001: /*
002: * Created by IntelliJ IDEA.
003: * User: tom
004: * Date: May 28, 2001
005: * Time: 10:35:05 PM
006: * To change template for new class use
007: * Code Style | Class Templates options (Tools | IDE Options).
008: */
009: package org.apache.ojb.odmg.shared;
010:
011: import org.apache.commons.lang.builder.ToStringBuilder;
012: import org.apache.commons.lang.builder.ToStringStyle;
013:
014: import java.io.Serializable;
015: import java.util.ArrayList;
016: import java.util.Arrays;
017:
018: public class PersonImpl implements Person, Serializable {
019: // technical attributes only needed for O/R mapping
020: private int id;
021: private int motherId;
022: private int fatherId;
023:
024: // domain specific attributes
025: private String firstname;
026: private String lastname;
027: private Person mother;
028: private Person father;
029: private Person[] children;
030:
031: public PersonImpl() {
032: }
033:
034: public String getFirstname() {
035: return firstname;
036: }
037:
038: public String getLastname() {
039: return lastname;
040: }
041:
042: public Person getMother() {
043: return mother;
044: }
045:
046: public Person getFather() {
047: return father;
048: }
049:
050: public Person[] getChildren() {
051: return children;
052: }
053:
054: public void setFirstname(String pFirstname) {
055: firstname = pFirstname;
056: }
057:
058: public void setLastname(String pLastname) {
059: lastname = pLastname;
060: }
061:
062: public void setMother(Person pMother) {
063: mother = pMother;
064: }
065:
066: public void setFather(Person pFather) {
067: father = pFather;
068: }
069:
070: public void setChildren(Person[] pChildren) {
071: children = pChildren;
072: }
073:
074: public void addChild(Person pChild) {
075: int numOfChildren = ((children == null) ? 0 : children.length);
076: Person[] newKids = new Person[numOfChildren + 1];
077: ArrayList list = new ArrayList(Arrays.asList(children));
078: list.add(pChild);
079: list.toArray(newKids);
080: }
081:
082: /**
083: * Gets the fatherId.
084: * @return Returns a int
085: */
086: public int getFatherId() {
087: return fatherId;
088: }
089:
090: /**
091: * Sets the fatherId.
092: * @param fatherId The fatherId to set
093: */
094: public void setFatherId(int fatherId) {
095: this .fatherId = fatherId;
096: }
097:
098: /**
099: * Gets the id.
100: * @return Returns a int
101: */
102: public int getId() {
103: return id;
104: }
105:
106: /**
107: * Sets the id.
108: * @param id The id to set
109: */
110: public void setId(int id) {
111: this .id = id;
112: }
113:
114: /**
115: * Gets the motherId.
116: * @return Returns a int
117: */
118: public int getMotherId() {
119: return motherId;
120: }
121:
122: /**
123: * Sets the motherId.
124: * @param motherId The motherId to set
125: */
126: public void setMotherId(int motherId) {
127: this .motherId = motherId;
128: }
129:
130: public String toString() {
131: ToStringBuilder buf = new ToStringBuilder(this ,
132: ToStringStyle.MULTI_LINE_STYLE);
133: buf.append("id", id);
134: buf.append("firstname", firstname);
135: buf.append("lastname", lastname);
136: buf.append("motherId", motherId);
137: buf.append("mother", mother != null ? "PersonImpl@"
138: + System.identityHashCode(mother) + "(" + motherId
139: + ")" : null);
140: buf.append("fatherId", fatherId);
141: buf.append("father", father != null ? "PersonImpl@"
142: + System.identityHashCode(father) + "(" + fatherId
143: + ")" : null);
144: return buf.toString();
145: }
146: }
|