home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / Guest.m < prev    next >
Encoding:
Text File  |  1996-08-23  |  1.5 KB  |  61 lines

  1. /*
  2.         Copyright (c) 1996, NeXT Software, Inc.
  3.         All rights reserved.
  4.  
  5.         You may freely copy, distribute and reuse the code in this example.
  6.         NeXT disclaims any warranty of any kind, expressed or implied,
  7.         as to its fitness for any particular use.
  8. */
  9. #import <BusinessLogic/Guest.h>
  10. #import <BusinessLogic/Member.h>
  11.  
  12. @implementation Guest
  13.  
  14. - (void)awakeFromInsertionInEditingContext:(EOEditingContext *)ctx
  15. {
  16.     // set default values
  17.     if (!costRestriction)
  18.         costRestriction = [[NSDecimalNumber alloc] initWithString:@"50"]; // Limit is $50 by default
  19.  
  20.     [super awakeFromInsertionInEditingContext:ctx];
  21. }
  22.  
  23. - (NSDecimalNumber *)costRestriction
  24. {
  25.     return costRestriction;
  26. }
  27.  
  28. - (void)setCostRestriction:(NSDecimalNumber *)restriction
  29. {
  30.     [self willChange];
  31.     [costRestriction autorelease];
  32.     costRestriction = [restriction copy];
  33. }
  34.  
  35. - (NSException *)validateForSave
  36. {
  37.     NSException *error;
  38.     
  39.     if([[self costRestriction] compare:[member costRestriction]] == NSOrderedDescending) {
  40.         return [NSException validationExceptionWithFormat:@"The cost restriction for the guest %@ is greater than his/her sponsor %@.", [self fullName], [member fullName]];
  41.     }
  42.     
  43.     // Our sponsoring member must validate some of our changes
  44.     error = [super validateForSave];
  45.     return (error) ? error : [member validateForSave];
  46. }
  47.  
  48. - (Member *)member
  49. {
  50.     return member;
  51. }
  52.  
  53. - (void)dealloc
  54. {
  55.     [costRestriction release];
  56.     [member release];
  57.     [super dealloc];
  58. }
  59.  
  60. @end
  61.