001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: MessengerManagerImpl.java,v 1.1 2006-09-11 12:27:25 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.business.messenger;
021:
022: import com.lutris.airsent.business.AirSentBusinessException;
023:
024: import com.lutris.airsent.data.person.MessengerDO;
025: import com.lutris.airsent.data.person.MessengerQuery;
026: import com.lutris.airsent.spec.messenger.Messenger;
027: import com.lutris.airsent.spec.messenger.MessengerManager;
028:
029: /**
030: * Messenger Manager implementation.
031: *
032: *
033: * @author
034: * @version %I%, %G%
035: */
036: public class MessengerManagerImpl implements MessengerManager {
037:
038: /**
039: * Creates an empty messenger
040: *
041: * @return
042: *
043: * @throws AirSentBusinessException
044: *
045: *
046: */
047: public Messenger create() throws AirSentBusinessException {
048: try {
049: return new MessengerImpl();
050: } catch (Exception ex) {
051: throw new AirSentBusinessException(
052: "Error creating Messenger");
053: }
054: }
055:
056: public Messenger create(String id) throws AirSentBusinessException {
057: try {
058: return new MessengerImpl(id);
059: } catch (Exception ex) {
060: throw new AirSentBusinessException(
061: "Error creating Messenger");
062: }
063: }
064:
065: /**
066: * Finds a messenger by its badge.
067: *
068: *
069: * @param badge
070: *
071: * @return
072: *
073: * @throws AirSentBusinessException
074: *
075: *
076: */
077: public Messenger findByBadge(String badge)
078: throws AirSentBusinessException {
079: Messenger theMessenger = null;
080:
081: try {
082: MessengerQuery query = new MessengerQuery();
083:
084: // Require that we only find ONE Messenger
085: query.setQueryBadge(badge);
086:
087: MessengerDO[] messengerDO = query.getDOArray();
088:
089: if (messengerDO.length == 0) {
090: return null;
091: } else {
092: return new MessengerImpl(messengerDO[0]);
093: }
094: } catch (Exception ex) {
095: throw new AirSentBusinessException(
096: "Exception in findByInvoice", ex);
097: }
098: }
099:
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 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 ex) {
130: throw new AirSentBusinessException(
131: "Exception in findByInvoice", 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 ex) {
161: throw new AirSentBusinessException(
162: "Exception in findByMessenger", 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 badge, String 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 ex) {
196: throw new AirSentBusinessException(
197: "Exception in validateLogin", ex);
198: }
199: }
200:
201: }
|