KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > domain > Customer


1 package sellwin.domain;
2
3 import java.util.*;
4 import java.io.*;
5
6 // SellWin http://sourceforge.net/projects/sellwincrm
7
//Contact support@open-app.com for commercial help with SellWin
8
//This software is provided "AS IS", without a warranty of any kind.
9

10
11 /**
12  * This class represents a customer in the system.
13  * This class holds column values found in the 'customer' database
14  * table.
15  */

16 public class Customer implements Serializable {
17
18     public final static String JavaDoc UNASSIGNED = "Unassigned";
19
20     private long pk; //primary key
21
private String JavaDoc name; //unique
22
private Address shipAddress;
23     private Address billAddress;
24     private int annualSales;
25     private String JavaDoc industry;
26     private String JavaDoc channel;
27     private Address contact;
28     private String JavaDoc modifiedBy;
29     private Date modifiedDate;
30     private boolean updatedLocally=false;
31     private boolean addedLocally=false;
32     private ArrayList inventory = new ArrayList(); //array of CustomerInventory objects
33

34     public Customer() {
35         annualSales = 0;
36         industry="";
37         channel="";
38         modifiedDate = new Date();
39         shipAddress = new Address();
40         billAddress = new Address();
41         contact = new Address();
42     }
43
44     public final void clear() {
45         name = UNASSIGNED;
46         annualSales = 0;
47         industry = "";
48         channel = "";
49         for (int i = 0; i < inventory.size(); i++) {
50             inventory.remove(i);
51         }
52     }
53
54     public final void setPK(long l) { pk = l; }
55     public final long getPK() { return pk; }
56
57     public final void setBillAddress(Address a) { billAddress = a; }
58     public final Address getBillAddress() { return billAddress; }
59     public final void setShipAddress(Address a) { shipAddress = a; }
60     public final Address getShipAddress() { return shipAddress; }
61
62     public final void setModifiedDate(Date d) {
63         modifiedDate = d;
64         getBillAddress().setModifiedDate(d);
65         getShipAddress().setModifiedDate(d);
66         getContact().setModifiedDate(d);
67     }
68     public final Date getModifiedDate() { return modifiedDate; }
69
70     public final void setModifiedBy(String JavaDoc b) {
71         modifiedBy = b;
72         getBillAddress().setModifiedBy(b);
73         getShipAddress().setModifiedBy(b);
74         getContact().setModifiedBy(b);
75     }
76     public final String JavaDoc getModifiedBy() { return modifiedBy; }
77
78     public final void addInventory(CustomerInventory inv) {
79         inventory.add(inv);
80     }
81
82     public final ArrayList getInventory() { return inventory; }
83
84     public final void setName(String JavaDoc name) {
85         this.name = name;
86     }
87
88     public final String JavaDoc getName() { return name; }
89
90     public final void setAnnualSales(int x) {
91         annualSales = x;
92     }
93
94     public final int getAnnualSales() { return annualSales; }
95
96     public final void setChannel(String JavaDoc s) {
97         channel = s;
98     }
99
100     public final String JavaDoc getChannel() { return channel; }
101
102     public final void setIndustry(String JavaDoc s) {
103         industry = s;
104     }
105
106     public final String JavaDoc getIndustry() { return industry; }
107
108     public final void setContact(Address s) {
109         contact = s;
110     }
111
112     public final Address getContact() { return contact; }
113
114     public final void setInventory(ArrayList p) {
115         inventory = p;
116     }
117
118     public final void setUpdatedLocally(boolean b) { updatedLocally=b; }
119     public final void setAddedLocally(boolean b) { addedLocally=b; }
120     public final boolean getUpdatedLocally() { return updatedLocally; }
121     public final boolean getAddedLocally() { return addedLocally; }
122
123     public final Customer copy() {
124         Customer copy = new Customer();
125
126         copy.pk = pk;
127
128         if (billAddress != null)
129             copy.billAddress = billAddress.copy();
130         if (shipAddress != null)
131             copy.shipAddress = shipAddress.copy();
132         if (name != null)
133             copy.name = new String JavaDoc(name);
134         copy.annualSales = annualSales;
135         if (industry != null)
136             copy.industry = new String JavaDoc(industry);
137         if (channel != null)
138             copy.channel = new String JavaDoc(channel);
139         if (contact != null)
140             copy.contact = contact.copy();
141
142         CustomerInventory product, productCopy;
143         ArrayList inventory = getInventory();
144         for (int i=0;i<inventory.size();i++) {
145             product = (CustomerInventory)inventory.get(i);
146             productCopy = product.copy();
147             copy.addInventory(productCopy);
148         }
149         return copy;
150     }
151     
152     public final void print() {
153         System.out.println("<<CUSTOMER"+name+">>");
154         System.out.println("pk ="+ pk);
155         System.out.println("Annual Sales="+ annualSales);
156         System.out.println("Industry="+industry);
157         System.out.println("Channel="+channel);
158         CustomerInventory inv=null;
159         for (int i=0;i<inventory.size();i++) {
160             inv = (CustomerInventory)inventory.get(i);
161             inv.print();
162         }
163     }
164 }
165
Popular Tags