KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > airsent > business > messenger > MessengerImpl


1 /*
2  * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
3  * Reserved.
4  *
5  * This source code file is distributed by Lutris Technologies, Inc. for
6  * use only by licensed users of product(s) that include this source
7  * file. Use of this source file or the software that uses it is covered
8  * by the terms and conditions of the Lutris Enhydra Development License
9  * Agreement included with this product.
10  *
11  * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
12  * ANY KIND, either express or implied. See the License for the specific terms
13  * governing rights and limitations under the License.
14  *
15  * Contributor(s):
16  *
17  * $Id: MessengerImpl.java,v 1.1 2004/08/16 09:33:11 slobodan Exp $
18  */

19
20 package com.lutris.airsent.business.messenger;
21
22
23 import com.lutris.airsent.spec.AirSentException;
24 import com.lutris.airsent.business.*;
25
26
27 import com.lutris.airsent.spec.messenger.Messenger;
28 import com.lutris.airsent.spec.customer.Customer;
29 import com.lutris.airsent.spec.address.Address;
30 import com.lutris.airsent.business.address.AddressManager;
31
32 import com.lutris.airsent.business.address.*;
33 import com.lutris.airsent.business.address.AddressImpl;
34
35 import com.lutris.airsent.data.person.*;
36 import com.lutris.appserver.server.sql.*;
37 import com.lutris.dods.builder.generator.query.DataObjectException;
38
39 /**
40  * Messenger implementation.
41  */

42 public class MessengerImpl implements Messenger, java.io.Serializable JavaDoc {
43     MessengerDO messengerDO = null;
44     PersonDO personDO = null;
45     
46     /**
47      * Constructs empty Messenger
48      *
49      * @exception if an error occurs
50      */

51     MessengerImpl()
52         throws AirSentException {
53     try {
54         messengerDO = MessengerDO.createVirgin();
55         personDO = PersonDO.createVirgin();
56             AddressManager af = HomeManagerImpl.getInstance().getAddressManager();
57             AddressImpl addr = af.create();
58             personDO.setAddressID(addr.getDataObject());
59         messengerDO.setPersonID(personDO);
60     } catch (Exception JavaDoc ex) {
61         throw new AirSentException("Error creating Messenger", ex);
62     }
63     }
64
65     /**
66      * Constructs messenger using data object.
67      *
68      * @exception if an error occurs
69      */

70     MessengerImpl(MessengerDO messenger)
71         throws AirSentException {
72     try {
73         this.messengerDO = messenger;
74         this.personDO = messengerDO.getPersonID();
75     } catch (Exception JavaDoc ex) {
76         throw new AirSentException("Error creating Messenger", ex);
77     }
78     }
79     
80     /**
81      * Constructs messenger using database handle
82      *
83      * @exception if an error occurs
84      */

85     MessengerImpl(String JavaDoc id)
86         throws AirSentException {
87     try {
88         this.messengerDO = messengerDO.createExisting(id);
89         this.personDO = messengerDO.getPersonID();
90     } catch (Exception JavaDoc ex) {
91         throw new AirSentException("Error creating Messenger", ex);
92     }
93     }
94
95     /**
96      * Get messengers database handle
97      *
98      * @return database id
99      * @exception if an error occurs
100      */

101     public String JavaDoc getHandle()
102         throws AirSentException {
103     try {
104         return messengerDO.getHandle();
105     } catch (Exception JavaDoc ex) {
106         throw new AirSentException("Error getting messenger's handle", ex);
107     }
108     }
109
110     /**
111      * Get first name.
112      *
113      * @return first name
114      * @exception if an error occurs
115      */

116     public String JavaDoc getFirstName()
117         throws AirSentException {
118     try {
119         return personDO.getFirstName();
120     } catch (Exception JavaDoc ex) {
121         throw new AirSentException("Error getting messenger's firstname", ex);
122     }
123     }
124
125     /**
126      * Set first name.
127      *
128      * @param first first name
129      * @exception if an error occurs
130      * @exception if business rules are violated
131      */

132     public void setFirstName(String JavaDoc first)
133         throws AirSentException, AirSentBusinessException {
134         if (first.length() > Customer.MAX_FIRST_NAME) {
135             throw new AirSentBusinessException("Exceeds maximum size");
136         }
137     try {
138         this.personDO.setFirstName(first);
139     } catch (Exception JavaDoc ex) {
140         throw new AirSentException("Error setting messenger's name", ex);
141     }
142     }
143
144     /**
145      * Get email.
146      * @return email address
147      * @exception if an error occurs
148      */

149     public String JavaDoc getEmail()
150         throws AirSentException {
151     try {
152         return personDO.getEmail();
153     } catch (Exception JavaDoc ex) {
154         throw new AirSentException("Error getting messenger's firstname", ex);
155     }
156     }
157
158     /**
159      * Set Email.
160      *
161      * @param email
162      * @exception if an error occurs
163      * @exception if business rules are violated
164
165      */

166     public void setEmail(String JavaDoc email)
167         throws AirSentException, AirSentBusinessException {
168         if (email.length() > Customer.MAX_EMAIL) {
169             throw new AirSentBusinessException("Exceeds maximum size");
170         }
171     try {
172         this.personDO.setEmail(email);
173     } catch (Exception JavaDoc ex) {
174         throw new AirSentException("Error setting messenger's name", ex);
175     }
176     }
177
178     /**
179      * Get last name.
180      *
181      * @return last name
182      * @exception if an error occurs
183      */

184     public String JavaDoc getLastName()
185         throws AirSentException {
186     try {
187         return personDO.getLastName();
188     } catch (Exception JavaDoc ex) {
189         throw new AirSentException("Error getting messenger's lastname", ex);
190     }
191     }
192
193     /**
194      * Set last name.
195      *
196      * @param last
197      * @exception if an error occurs
198      * @exception if business rules are violated
199      */

200     public void setLastName(String JavaDoc last)
201         throws AirSentException, AirSentBusinessException {
202         if (last.length() > Customer.MAX_LAST_NAME) {
203             throw new AirSentBusinessException("Exceeds maximum size");
204         }
205     try {
206         this.personDO.setLastName(last);
207     } catch (Exception JavaDoc ex) {
208         throw new AirSentException("Error setting messenger's last name", ex);
209     }
210     }
211
212     /**
213      * Gets the address.
214      * @exception if an error occurs
215      *
216      * @return address
217      * @exception if an error occurs
218      */

219     public Address getAddress()
220         throws AirSentException {
221     try {
222             AddressManager af = HomeManagerImpl.getInstance().getAddressManager();
223             return af.create(personDO.getAddressID());
224     } catch (Exception JavaDoc ex) {
225         throw new AirSentBusinessException("Error getting messenger's address", ex);
226     }
227     }
228
229
230     /**
231      * Get badge.
232      *
233      * @return badge
234      * @exception if an error occurs
235      */

236     public String JavaDoc getBadge()
237         throws AirSentException {
238     try {
239         return messengerDO.getBadge();
240     } catch (Exception JavaDoc ex) {
241         throw new AirSentBusinessException("Error getting messenger's badge", ex);
242     }
243     }
244
245     /**
246      *
247      * @exception if an error occurs
248      * @exception if business rules are violated
249      */

250     public void setBadge(String JavaDoc badge)
251         throws AirSentException, AirSentBusinessException {
252         if (badge.length() > Messenger.MAX_BADGE) {
253             throw new AirSentBusinessException("Exceeds maximum size");
254         }
255     try {
256         this.messengerDO.setBadge(badge);
257     } catch (Exception JavaDoc ex) {
258         throw new AirSentException("Error setting messenger's badge", ex);
259     }
260     }
261
262     /**
263      * Get password.
264      *
265      * @return password
266      * @exception if an error occurs
267      */

268     public String JavaDoc getPassword()
269         throws AirSentException {
270     try {
271         return messengerDO.getPassword();
272     } catch (Exception JavaDoc ex) {
273         throw new AirSentException("Error getting customers's lastname", ex);
274     }
275     }
276
277     /**
278      * Set password.
279      *
280      * @exception if an error occurs
281      * @exception if business rules are violated
282      */

283     public void setPassword(String JavaDoc password)
284         throws AirSentException, AirSentBusinessException {
285         if (password.length() > Messenger.MAX_PASSWORD) {
286             throw new AirSentBusinessException("Exceeds maximum size");
287         }
288     try {
289         this.messengerDO.setPassword(password);
290     } catch (Exception JavaDoc ex) {
291         throw new AirSentException("Error setting customers's last name", ex);
292     }
293     }
294
295     /**
296      * Gets the geocode. NOT currently used.
297      *
298      * @return code
299      * @exception if an error occurs
300      */

301     public String JavaDoc getGeocode()
302         throws AirSentException {
303     try {
304         return messengerDO.getGeocode();
305     } catch (Exception JavaDoc ex) {
306         throw new AirSentException("Error getting messenger's geocode", ex);
307     }
308     }
309
310     /**
311      * Saves the messenger.
312      *
313      * @exception if an error occurs
314      */

315     public void save()
316         throws AirSentException {
317     try {
318         this.messengerDO.commit();
319     } catch (Exception JavaDoc ex) {
320         throw new AirSentException("Error saving address", ex);
321     }
322     }
323
324     /**
325      * Deletes the messenger.
326      *
327      * @exception if an error occurs
328      */

329     public void delete()
330         throws AirSentException {
331     try {
332         this.messengerDO.delete();
333     } catch (Exception JavaDoc ex) {
334         throw new AirSentException("Error deleting address", ex);
335     }
336     }
337 }
338
339
Popular Tags