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: CustomerImpl.java,v 1.1 2006-09-11 12:27:25 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.business.customer;
021:
022: import com.lutris.airsent.spec.AirSentException;
023:
024: import com.lutris.airsent.business.*;
025:
026: import com.lutris.airsent.spec.customer.Customer;
027:
028: import com.lutris.airsent.business.address.*;
029:
030: import com.lutris.airsent.spec.address.Address;
031:
032: import com.lutris.airsent.data.person.*;
033: import com.lutris.appserver.server.sql.DatabaseManagerException;
034: import com.lutris.appserver.server.sql.ObjectIdException;
035: import com.lutris.dods.builder.generator.query.DataObjectException;
036:
037: /**
038: * Customer implementation
039: */
040: public class CustomerImpl implements Customer, java.io.Serializable {
041:
042: CustomerDO customerDO = null;
043: PersonDO personDO = null;
044:
045: /**
046: * Create a new customer
047: *
048: * @exception if an error occurs
049: */
050: CustomerImpl() throws AirSentException {
051: try {
052: customerDO = CustomerDO.createVirgin();
053: personDO = PersonDO.createVirgin();
054:
055: AddressManager af = HomeManagerImpl.getInstance()
056: .getAddressManager();
057:
058: AddressImpl addr = af.create();
059:
060: personDO.setAddressID(addr.getDataObject());
061: customerDO.setPersonID(personDO);
062: } catch (Exception e) {
063: throw new AirSentException(e);
064: }
065: }
066:
067: /**
068: * Create an existing customer
069: *
070: * @param customer customer data object
071: * @exception if an error occurs
072: */
073: public CustomerImpl(CustomerDO customer) throws AirSentException {
074: try {
075: customerDO = customer;
076: personDO = customerDO.getPersonID();
077: } catch (Exception e) {
078: throw new AirSentException(e);
079: }
080: }
081:
082: /**
083: * Gets the customer handle.
084: *
085: * @return database id
086: * @exception if an error occurs
087: */
088: public String getHandle() throws AirSentException {
089: try {
090: return customerDO.getHandle();
091: } catch (Exception e) {
092: throw new AirSentException(e);
093: }
094: }
095:
096: /**
097: * Gets the first name.
098: *
099: * @exception if an error occurs
100: */
101: public String getFirstName() throws AirSentException {
102: try {
103: return personDO.getFirstName();
104: } catch (Exception e) {
105: throw new AirSentException(e);
106: }
107: }
108:
109: /**
110: * Sets the first name.
111: *
112: * @exception if an error occurs
113: */
114: public void setFirstName(String first) throws AirSentException,
115: AirSentBusinessException {
116: if (first.length() > Customer.MAX_FIRST_NAME) {
117: throw new AirSentBusinessException("Exceeds maximum size");
118: }
119: try {
120: personDO.setFirstName(first);
121: } catch (Exception e) {
122: throw new AirSentException(e);
123: }
124: }
125:
126: /**
127: * Gets the last name.
128: *
129: * @return last name
130: * @exception if an error occurs
131: */
132: public String getLastName() throws AirSentException {
133: try {
134: return personDO.getLastName();
135: } catch (Exception e) {
136: throw new AirSentException(e);
137: }
138: }
139:
140: /**
141: * Set the last name.
142: *
143: * @param last last name
144: * @exception if an error occurs
145: */
146: public void setLastName(String last) throws AirSentException,
147: AirSentBusinessException {
148: if (last.length() > Customer.MAX_LAST_NAME) {
149: throw new AirSentBusinessException("Exceeds maximum size");
150: }
151: try {
152: personDO.setLastName(last);
153: } catch (Exception e) {
154: throw new AirSentException(e);
155: }
156: }
157:
158: /**
159: * Gets the email.
160: *
161: * @return email address
162: * @exception if an error occurs
163: */
164: public String getEmail() throws AirSentException {
165: try {
166: return personDO.getEmail();
167: } catch (Exception e) {
168: throw new AirSentException(e);
169: }
170: }
171:
172: /**
173: * Sets the email.
174: *
175: * @param email email address
176: * @exception if an error occurs
177: */
178: public void setEmail(String email) throws AirSentException,
179: AirSentBusinessException {
180: if (email.length() > Customer.MAX_EMAIL) {
181: throw new AirSentBusinessException("Exceeds maximum size");
182: }
183: try {
184: personDO.setEmail(email);
185: } catch (Exception e) {
186: throw new AirSentException(e);
187: }
188: }
189:
190: /**
191: * Gets the address.
192: *
193: * @return address
194: * @exception if an error occurs
195: */
196: public Address getAddress() throws AirSentException {
197: try {
198: AddressManager af = HomeManagerImpl.getInstance()
199: .getAddressManager();
200: return af.create(personDO.getAddressID());
201: } catch (Exception e) {
202: throw new AirSentException(e);
203: }
204: }
205:
206: /**
207: * Gets the business.
208: *
209: * @return business
210: * @exception if an error occurs
211: */
212: public String getBusiness() throws AirSentException {
213: try {
214: return customerDO.getBusiness();
215: } catch (Exception e) {
216: throw new AirSentException(e);
217: }
218: }
219:
220: /**
221: * Sets the business.
222: *
223: * @param business business
224: * @exception if an error occurs
225: */
226: public void setBusiness(String business) throws AirSentException,
227: AirSentBusinessException {
228: if (business.length() > Customer.MAX_BUSINESS) {
229: throw new AirSentBusinessException("Exceeds maximum size");
230: }
231: try {
232: customerDO.setBusiness(business);
233: } catch (Exception e) {
234: throw new AirSentException(e);
235: }
236: }
237:
238: /**
239: * Gets the login.
240: *
241: * @return login name
242: * @exception if an error occurs
243: */
244: public String getLogin() throws AirSentException {
245: try {
246: return customerDO.getLogin();
247: } catch (Exception e) {
248: throw new AirSentException(e);
249: }
250: }
251:
252: /**
253: * Sets the login.
254: *
255: * @param login login name
256: * @exception if an error occurs
257: */
258: public void setLogin(String login) throws AirSentException,
259: AirSentBusinessException {
260: if (login.length() > Customer.MAX_LOGIN) {
261: throw new AirSentBusinessException("Exceeds maximum size");
262: }
263: try {
264: customerDO.setLogin(login);
265: } catch (Exception e) {
266: throw new AirSentException(e);
267: }
268: }
269:
270: /**
271: * Gets the password.
272: *
273: * @return password
274: * @exception if an error occurs
275: */
276: public String getPassword() throws AirSentException {
277: try {
278: return customerDO.getPassword();
279: } catch (Exception e) {
280: throw new AirSentException(e);
281: }
282: }
283:
284: /**
285: * Sets the password.
286: *
287: * @param password password
288: * @exception if an error occurs
289: */
290: public void setPassword(String password) throws AirSentException,
291: AirSentBusinessException {
292: if (password.length() > Customer.MAX_PASSWORD) {
293: throw new AirSentBusinessException("Exceeds maximum size");
294: }
295: try {
296: customerDO.setPassword(password);
297: } catch (Exception e) {
298: throw new AirSentException(e);
299: }
300: }
301:
302: /**
303: * Saves the customer.
304: *
305: * @exception if an error occurs
306: */
307: public void save() throws AirSentException {
308: try {
309: customerDO.commit();
310: } catch (Exception e) {
311: throw new AirSentException(e);
312: }
313: }
314:
315: /**
316: * Deletes the customer.
317: *
318: * @exception if an error occurs
319: */
320: public void delete() throws AirSentException {
321: try {
322: customerDO.delete();
323: } catch (Exception e) {
324: throw new AirSentException(e);
325: }
326: }
327: }
|