KickJava   Java API By Example, From Geeks To Geeks.

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


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: MessengerManagerImpl.java,v 1.1 2004/08/16 09:33:11 slobodan Exp $
18  */

19
20 package com.lutris.airsent.business.messenger;
21
22 import com.lutris.airsent.business.AirSentBusinessException;
23
24 import com.lutris.airsent.data.person.MessengerDO;
25 import com.lutris.airsent.data.person.MessengerQuery;
26 import com.lutris.airsent.spec.messenger.Messenger;
27 import com.lutris.airsent.spec.messenger.MessengerManager;
28
29 /**
30  * Messenger Manager implementation.
31  *
32  *
33  * @author
34  * @version %I%, %G%
35  */

36 public class MessengerManagerImpl implements MessengerManager {
37
38     /**
39      * Creates an empty messenger
40      *
41      * @return
42      *
43      * @throws AirSentBusinessException
44      *
45      *
46      */

47     public Messenger create() throws AirSentBusinessException {
48     try {
49         return new MessengerImpl();
50     } catch (Exception JavaDoc ex) {
51         throw new AirSentBusinessException("Error creating Messenger");
52     }
53     }
54
55
56     public Messenger create(String JavaDoc id) throws AirSentBusinessException {
57     try {
58         return new MessengerImpl(id);
59     } catch (Exception JavaDoc ex) {
60         throw new AirSentBusinessException("Error creating Messenger");
61     }
62     }
63
64
65     /**
66      * Finds a messenger by its badge.
67      *
68      *
69      * @param badge
70      *
71      * @return
72      *
73      * @throws AirSentBusinessException
74      *
75      *
76      */

77     public Messenger findByBadge(String JavaDoc badge)
78         throws AirSentBusinessException {
79     Messenger theMessenger = null;
80
81     try {
82         MessengerQuery query = new MessengerQuery();
83
84         // Require that we only find ONE Messenger
85
query.setQueryBadge(badge);
86
87         MessengerDO[] messengerDO = query.getDOArray();
88
89         if (messengerDO.length == 0) {
90         return null;
91         } else {
92         return new MessengerImpl(messengerDO[0]);
93         }
94     } catch (Exception JavaDoc ex) {
95         throw new AirSentBusinessException("Exception in findByInvoice",
96                            ex);
97     }
98     }
99
100     /**
101      * Find a messenger by its proximity to a geocode. NOT currently in
102      * use.
103      *
104      *
105      * @param geocode
106      *
107      * @return
108      *
109      * @throws AirSentBusinessException
110      *
111      *
112      */

113     public Messenger findByProximity(String JavaDoc geocode)
114         throws AirSentBusinessException {
115     Messenger theMessenger = null;
116
117     try {
118         MessengerQuery query = new MessengerQuery();
119
120         // Require that we only find ONE Messenger
121
query.requireUniqueInstance();
122         query.setQueryGeocode(geocode);
123
124         MessengerDO theMessengerDO = query.getNextDO();
125
126         theMessenger = new MessengerImpl(theMessengerDO);
127
128         return theMessenger;
129     } catch (Exception JavaDoc ex) {
130         throw new AirSentBusinessException("Exception in findByInvoice",
131                            ex);
132     }
133     }
134
135     /**
136      * Get all the messengers.
137      *
138      *
139      * @return
140      *
141      * @throws AirSentBusinessException
142      *
143      *
144      */

145     public Messenger[] findAll() throws AirSentBusinessException {
146     Messenger[] theMessengerArray = null;
147
148     try {
149         MessengerQuery query = new MessengerQuery();
150
151         // To restrict the set of messengers returned
152
// to the that of the specific owner set in the query
153
MessengerDO[] DOarray = query.getDOArray();
154
155         theMessengerArray = new Messenger[DOarray.length];
156
157         for (int i = 0; i < DOarray.length; i++) {
158         theMessengerArray[i] = new MessengerImpl(DOarray[i]);
159         }
160     } catch (Exception JavaDoc ex) {
161         throw new AirSentBusinessException("Exception in findByMessenger",
162                            ex);
163     }
164
165     return theMessengerArray;
166     }
167
168     /**
169      * Validate a messenger login and password.
170      *
171      *
172      * @param badge
173      * @param password
174      *
175      * @return
176      *
177      * @throws AirSentBusinessException
178      *
179      *
180      */

181     public Messenger validatePassword(String JavaDoc badge, String JavaDoc password)
182         throws AirSentBusinessException {
183     Messenger theMessenger = null;
184
185     try {
186         if ((theMessenger = findByBadge(badge)) == null) {
187         return null;
188         } else {
189         if (theMessenger.getPassword().equals(password)) {
190             return theMessenger;
191         } else {
192             return null;
193         }
194         }
195     } catch (Exception JavaDoc ex) {
196         throw new AirSentBusinessException("Exception in validateLogin",
197                            ex);
198     }
199     }
200
201 }
202
203
Popular Tags